Lines Matching full:file
13 * File: ima_main.c
19 #include <linux/file.h>
84 /* Prevent mmap'ing a file execute that is already mmap'ed write */
85 static int mmap_violation_check(enum ima_hooks func, struct file *file, in mmap_violation_check() argument
93 mapping_writably_mapped(file->f_mapping)) { in mmap_violation_check()
95 inode = file_inode(file); in mmap_violation_check()
98 *pathname = ima_d_path(&file->f_path, pathbuf, in mmap_violation_check()
110 * - Opening a file for write when already open for read,
112 * - Opening a file for read when already open for write,
113 * could result in a file measurement error.
116 static void ima_rdwr_violation_check(struct file *file, in ima_rdwr_violation_check() argument
123 struct inode *inode = file_inode(file); in ima_rdwr_violation_check()
124 fmode_t mode = file->f_mode; in ima_rdwr_violation_check()
146 *pathname = ima_d_path(&file->f_path, pathbuf, filename); in ima_rdwr_violation_check()
149 ima_add_violation(file, *pathname, iint, in ima_rdwr_violation_check()
152 ima_add_violation(file, *pathname, iint, in ima_rdwr_violation_check()
157 struct inode *inode, struct file *file) in ima_check_last_writer() argument
159 fmode_t mode = file->f_mode; in ima_check_last_writer()
172 vfs_getattr_nosec(&file->f_path, &stat, in ima_check_last_writer()
180 ima_update_xattr(iint, file); in ima_check_last_writer()
188 * @file: pointer to file structure being freed
192 void ima_file_free(struct file *file) in ima_file_free() argument
194 struct inode *inode = file_inode(file); in ima_file_free()
204 ima_check_last_writer(iint, inode, file); in ima_file_free()
207 static int process_measurement(struct file *file, const struct cred *cred, in process_measurement() argument
211 struct inode *backing_inode, *inode = file_inode(file); in process_measurement()
233 action = ima_get_action(file_mnt_idmap(file), inode, cred, secid, in process_measurement()
257 ima_rdwr_violation_check(file, iint, action & IMA_MEASURE, in process_measurement()
276 * Re-evaulate the file if either the xattr has changed or the in process_measurement()
277 * kernel has no way of detecting file change on the filesystem. in process_measurement()
288 /* Detect and re-evaluate changes made to the backing file. */ in process_measurement()
289 backing_inode = d_real_inode(file_dentry(file)); in process_measurement()
316 xattr_len = ima_read_xattr(file_dentry(file), in process_measurement()
329 rc = mmap_violation_check(func, file, &pathbuf, in process_measurement()
340 xattr_len = ima_read_xattr(file_dentry(file), in process_measurement()
346 * template format and whether the file was already measured. in process_measurement()
359 rc = ima_collect_measurement(iint, file, buf, size, hash_algo, modsig); in process_measurement()
364 pathname = ima_d_path(&file->f_path, &pathbuf, filename); in process_measurement()
367 ima_store_measurement(iint, file, pathname, in process_measurement()
374 rc = ima_appraise_measurement(func, iint, file, in process_measurement()
380 rc = mmap_violation_check(func, file, &pathbuf, in process_measurement()
386 if ((file->f_flags & O_DIRECT) && (iint->flags & IMA_PERMIT_DIRECTIO)) in process_measurement()
394 integrity_audit_msg(AUDIT_INTEGRITY_DATA, file_inode(file), in process_measurement()
411 if (file->f_mode & FMODE_WRITE) in process_measurement()
419 * @file: pointer to the file to be measured (May be NULL)
427 * On success return 0. On integrity appraisal error, assuming the file
430 int ima_file_mmap(struct file *file, unsigned long reqprot, in ima_file_mmap() argument
436 if (!file) in ima_file_mmap()
442 ret = process_measurement(file, current_cred(), secid, NULL, in ima_file_mmap()
449 return process_measurement(file, current_cred(), secid, NULL, in ima_file_mmap()
471 struct file *file; in ima_file_mprotect() local
481 /* Is mprotect making an mmap'ed file executable? */ in ima_file_mprotect()
496 /* Is the mmap'ed file in policy? */ in ima_file_mprotect()
503 file = vma->vm_file; in ima_file_mprotect()
504 pathname = ima_d_path(&file->f_path, &pathbuf, filename); in ima_file_mprotect()
517 * The OS protects against an executable file, already open for write,
518 * from being executed in deny_write_access() and an executable file,
523 * On success return 0. On integrity appraisal error, assuming the file
532 ret = process_measurement(bprm->file, current_cred(), secid, NULL, 0, in ima_bprm_check()
538 return process_measurement(bprm->file, bprm->cred, secid, NULL, 0, in ima_bprm_check()
544 * @file: pointer to the file to be measured
549 * On success return 0. On integrity appraisal error, assuming the file
552 int ima_file_check(struct file *file, int mask) in ima_file_check() argument
557 return process_measurement(file, current_cred(), secid, NULL, 0, in ima_file_check()
563 static int __ima_inode_hash(struct inode *inode, struct file *file, char *buf, in __ima_inode_hash() argument
575 if ((!iint || !(iint->flags & IMA_COLLECTED)) && file) { in __ima_inode_hash()
583 rc = ima_collect_measurement(&tmp_iint, file, NULL, 0, in __ima_inode_hash()
625 * ima_file_hash - return a measurement of the file
626 * @file: pointer to the file
635 * The file hash returned is based on the entire file, including the appended
641 int ima_file_hash(struct file *file, char *buf, size_t buf_size) in ima_file_hash() argument
643 if (!file) in ima_file_hash()
646 return __ima_inode_hash(file_inode(file), file, buf, buf_size); in ima_file_hash()
716 * file data can be written later.
744 * @file: pointer to the file to be measured/appraised/audit
748 * Permit reading a file based on policy. The policy rules are written
750 * a file requires a file descriptor.
754 int ima_read_file(struct file *file, enum kernel_read_file_id read_id, in ima_read_file() argument
776 /* Read entire file for all partial reads. */ in ima_read_file()
779 return process_measurement(file, current_cred(), secid, NULL, in ima_read_file()
793 * @file: pointer to the file to be measured/appraised/audit
794 * @buf: pointer to in memory file contents
795 * @size: size of in memory file contents
798 * Measure/appraise/audit in memory file based on policy. Policy rules
801 * On success return 0. On integrity appraisal error, assuming the file
804 int ima_post_read_file(struct file *file, void *buf, loff_t size, in ima_post_read_file() argument
811 if (!file && read_id == READING_X509_CERTIFICATE) in ima_post_read_file()
814 if (!file || !buf || size == 0) { /* should never happen */ in ima_post_read_file()
822 return process_measurement(file, current_cred(), secid, buf, size, in ima_post_read_file()
833 * data provided by userspace. Enforce policy rules requiring a file
849 …pr_err("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load… in ima_load_data()
854 …pr_err("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load… in ima_load_data()
869 …pr_err("impossible to appraise a module without a file descriptor. sig_enforce kernel parameter mi… in ima_load_data()
881 * @buf: pointer to in memory file contents
882 * @size: size of in memory file contents
889 * On success return 0. On integrity appraisal error, assuming the file
1035 * @kernel_fd: file descriptor of the kexec kernel being loaded
1049 if (!f.file) in ima_kexec_cmdline()
1052 process_buffer_measurement(file_mnt_idmap(f.file), file_inode(f.file), in ima_kexec_cmdline()