Lines Matching +full:files +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0-only
53 if (strcmp(template_desc->name, IMA_TEMPLATE_IMA_NAME) == 0) { in hash_setup()
87 if ((func == MMAP_CHECK) && mapping_writably_mapped(file->f_mapping)) { in mmap_violation_check()
88 rc = -ETXTBSY; in mmap_violation_check()
91 if (!*pathbuf) /* ima_rdwr_violation possibly pre-fetched */ in mmap_violation_check()
92 *pathname = ima_d_path(&file->f_path, pathbuf, in mmap_violation_check()
103 * Only invalidate the PCR for measured files:
104 * - Opening a file for write when already open for read,
106 * - Opening a file for read when already open for write,
118 fmode_t mode = file->f_mode; in ima_rdwr_violation_check()
122 if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) { in ima_rdwr_violation_check()
127 &iint->atomic_flags)) in ima_rdwr_violation_check()
132 set_bit(IMA_MUST_MEASURE, &iint->atomic_flags); in ima_rdwr_violation_check()
140 *pathname = ima_d_path(&file->f_path, pathbuf, filename); in ima_rdwr_violation_check()
153 fmode_t mode = file->f_mode; in ima_check_last_writer()
159 mutex_lock(&iint->mutex); in ima_check_last_writer()
160 if (atomic_read(&inode->i_writecount) == 1) { in ima_check_last_writer()
162 &iint->atomic_flags); in ima_check_last_writer()
164 !inode_eq_iversion(inode, iint->version) || in ima_check_last_writer()
165 (iint->flags & IMA_NEW_FILE)) { in ima_check_last_writer()
166 iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE); in ima_check_last_writer()
167 iint->measured_pcrs = 0; in ima_check_last_writer()
172 mutex_unlock(&iint->mutex); in ima_check_last_writer()
176 * ima_file_free - called on __fput()
179 * Flag files that changed, based on i_version
186 if (!ima_policy_flag || !S_ISREG(inode->i_mode)) in ima_file_free()
214 if (!ima_policy_flag || !S_ISREG(inode->i_mode)) in process_measurement()
218 * bitmask based on the appraise/audit/measurement policy. in process_measurement()
239 rc = -ENOMEM; in process_measurement()
253 mutex_lock(&iint->mutex); in process_measurement()
255 if (test_and_clear_bit(IMA_CHANGE_ATTR, &iint->atomic_flags)) in process_measurement()
257 iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED | in process_measurement()
262 * Re-evaulate the file if either the xattr has changed or the in process_measurement()
266 if (test_and_clear_bit(IMA_CHANGE_XATTR, &iint->atomic_flags) || in process_measurement()
267 ((inode->i_sb->s_iflags & SB_I_IMA_UNVERIFIABLE_SIGNATURE) && in process_measurement()
268 !(inode->i_sb->s_iflags & SB_I_UNTRUSTED_MOUNTER) && in process_measurement()
270 iint->flags &= ~IMA_DONE_MASK; in process_measurement()
271 iint->measured_pcrs = 0; in process_measurement()
274 /* Determine if already appraised/measured based on bitmask in process_measurement()
278 iint->flags |= action; in process_measurement()
280 action &= ~((iint->flags & (IMA_DONE_MASK ^ IMA_MEASURED)) >> 1); in process_measurement()
283 if ((action & IMA_MEASURE) && (iint->measured_pcrs & (0x1 << pcr))) in process_measurement()
288 !(test_bit(IMA_DIGSIG, &iint->atomic_flags))) { in process_measurement()
291 (xattr_value->type == EVM_IMA_XATTR_DIGSIG)) in process_measurement()
292 set_bit(IMA_DIGSIG, &iint->atomic_flags); in process_measurement()
293 iint->flags |= IMA_HASHED; in process_measurement()
295 set_bit(IMA_UPDATE_XATTR, &iint->atomic_flags); in process_measurement()
310 strcmp(template_desc->name, IMA_TEMPLATE_IMA_NAME) != 0) { in process_measurement()
316 * an additional measurement list entry, if needed, based on the in process_measurement()
319 if (iint->flags & IMA_MODSIG_ALLOWED) { in process_measurement()
323 iint->flags & IMA_MEASURED) in process_measurement()
331 if (rc != 0 && rc != -EBADF && rc != -EINVAL) in process_measurement()
334 if (!pathbuf) /* ima_rdwr_violation possibly pre-fetched */ in process_measurement()
335 pathname = ima_d_path(&file->f_path, &pathbuf, filename); in process_measurement()
343 if (rc != -EPERM) { in process_measurement()
357 if ((file->f_flags & O_DIRECT) && (iint->flags & IMA_PERMIT_DIRECTIO)) in process_measurement()
360 if ((mask & MAY_WRITE) && test_bit(IMA_DIGSIG, &iint->atomic_flags) && in process_measurement()
361 !(iint->flags & IMA_NEW_FILE)) in process_measurement()
362 rc = -EACCES; in process_measurement()
363 mutex_unlock(&iint->mutex); in process_measurement()
371 return -EACCES; in process_measurement()
372 if (file->f_mode & FMODE_WRITE) in process_measurement()
373 set_bit(IMA_UPDATE_XATTR, &iint->atomic_flags); in process_measurement()
379 * ima_file_mmap - based on policy, collect/store measurement.
383 * Measure files being mmapped executable based on the ima_must_measure()
387 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
403 * ima_file_mprotect - based on policy, limit mprotect change
406 * Files can be mmap'ed read/write and later changed to execute to circumvent
408 * would be taken before i_mutex), files can not be measured or appraised at
412 * On mprotect change success, return 0. On failure, return -EACESS.
417 struct file *file = vma->vm_file; in ima_file_mprotect()
428 if (!(ima_policy_flag & IMA_APPRAISE) || !vma->vm_file || in ima_file_mprotect()
429 !(prot & PROT_EXEC) || (vma->vm_flags & VM_EXEC)) in ima_file_mprotect()
433 inode = file_inode(vma->vm_file); in ima_file_mprotect()
442 result = -EPERM; in ima_file_mprotect()
444 file = vma->vm_file; in ima_file_mprotect()
445 pathname = ima_d_path(&file->f_path, &pathbuf, filename); in ima_file_mprotect()
447 "collect_data", "failed-mprotect", result, 0); in ima_file_mprotect()
455 * ima_bprm_check - based on policy, collect/store measurement.
465 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
473 ret = process_measurement(bprm->file, current_cred(), secid, NULL, 0, in ima_bprm_check()
478 security_cred_getsecid(bprm->cred, &secid); in ima_bprm_check()
479 return process_measurement(bprm->file, bprm->cred, secid, NULL, 0, in ima_bprm_check()
484 * ima_path_check - based on policy, collect/store measurement.
488 * Measure files based on the ima_must_measure() policy decision.
491 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
505 * ima_file_hash - return the stored measurement if a file has been hashed and
516 * The file hash returned is based on the entire file, including the appended
519 * If IMA is disabled or if no measurement is available, return -EOPNOTSUPP.
520 * If the parameters are incorrect, return -EINVAL.
529 return -EINVAL; in ima_file_hash()
532 return -EOPNOTSUPP; in ima_file_hash()
537 return -EOPNOTSUPP; in ima_file_hash()
539 mutex_lock(&iint->mutex); in ima_file_hash()
545 if (!iint->ima_hash) { in ima_file_hash()
546 mutex_unlock(&iint->mutex); in ima_file_hash()
547 return -EOPNOTSUPP; in ima_file_hash()
553 copied_size = min_t(size_t, iint->ima_hash->length, buf_size); in ima_file_hash()
554 memcpy(buf, iint->ima_hash->digest, copied_size); in ima_file_hash()
556 hash_algo = iint->ima_hash->algo; in ima_file_hash()
557 mutex_unlock(&iint->mutex); in ima_file_hash()
564 * ima_post_create_tmpfile - mark newly created tmpfile as new
586 set_bit(IMA_UPDATE_XATTR, &iint->atomic_flags); in ima_post_create_tmpfile()
587 iint->ima_file_status = INTEGRITY_PASS; in ima_post_create_tmpfile()
591 * ima_post_path_mknod - mark as a new inode
594 * Mark files created via the mknodat syscall as new, so that the
600 struct inode *inode = dentry->d_inode; in ima_post_path_mknod()
612 /* needed for re-opening empty files */ in ima_post_path_mknod()
613 iint->flags |= IMA_NEW_FILE; in ima_post_path_mknod()
617 * ima_read_file - pre-measure/appraise hook decision based on policy
622 * Permit reading a file based on policy. The policy rules are written
626 * For permission return 0, otherwise return -EACCES.
635 * Do devices using pre-allocated memory run the risk of the in ima_read_file()
666 * ima_post_read_file - in memory collect/appraise/audit measurement
672 * Measure/appraise/audit in memory file based on policy. Policy rules
676 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
690 return -EACCES; in ima_post_read_file()
701 * ima_load_data - appraise decision based on policy
710 * For permission return 0, otherwise return -EACCES.
724 return -EACCES; in ima_load_data()
729 return -EACCES; /* INTEGRITY_UNKNOWN */ in ima_load_data()
735 return -EACCES; /* INTEGRITY_UNKNOWN */ in ima_load_data()
744 return -EACCES; /* INTEGRITY_UNKNOWN */ in ima_load_data()
753 * ima_post_load_data - appraise decision based on policy
757 * @description: @id-specific description of contents
759 * Measure/appraise/audit in memory buffer based on policy. Policy rules
763 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
773 return -EACCES; /* INTEGRITY_UNKNOWN */ in ima_post_load_data()
782 * process_buffer_measurement - Measure the buffer to ima log.
791 * Based on policy, the buffer is measured into the ima log.
818 * Both LSM hooks and auxilary based buffer measurements are in process_buffer_measurement()
819 * based on policy. To avoid code duplication, differentiate in process_buffer_measurement()
836 template = lookup_template_desc("ima-buf"); in process_buffer_measurement()
837 ret = template_desc_init_fields(template->fmt, in process_buffer_measurement()
838 &(template->fields), in process_buffer_measurement()
839 &(template->num_fields)); in process_buffer_measurement()
842 (strlen(template->name) ? in process_buffer_measurement()
843 template->name : template->fmt), ret); in process_buffer_measurement()
849 iint.ima_hash->algo = ima_hash_algo; in process_buffer_measurement()
850 iint.ima_hash->length = hash_digest_size[ima_hash_algo]; in process_buffer_measurement()
880 * ima_kexec_cmdline - measure kexec cmdline boot args
899 "kexec-cmdline", KEXEC_CMDLINE, 0, NULL); in ima_kexec_cmdline()