/* * ima_rdwr_violation_check * * Only invalidate the PCR for measured files: * - Opening a file for write when already open for read, * results in a time of measure, time of use (ToMToU) error. * - Opening a file for read when already open for write, * could result in a file measurement error. * */ static void ima_rdwr_violation_check(struct file *file, struct integrity_iint_cache *iint, int must_measure, char **pathbuf, const char **pathname) { struct inode *inode = file_inode(file); fmode_t mode = file->f_mode; bool send_tomtou = false, send_writers = false; if (mode & FMODE_WRITE) { if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) { if (!iint) iint = integrity_iint_find(inode); /* IMA_MEASURE is set from reader side */ if (iint && (iint->flags & IMA_MEASURE)) send_tomtou = true; } } else { if ((atomic_read(&inode->i_writecount) > 0) && must_measure) send_writers = true; } if (!send_tomtou && !send_writers) return; *pathname = ima_d_path(&file->f_path, pathbuf); if (send_tomtou) ima_add_violation(file, *pathname, iint, "invalid_pcr", "ToMToU"); if (send_writers) ima_add_violation(file, *pathname, iint, "invalid_pcr", "open_writers"); }
/* * ima_rdwr_violation_check * * Only invalidate the PCR for measured files: * - Opening a file for write when already open for read, * results in a time of measure, time of use (ToMToU) error. * - Opening a file for read when already open for write, * could result in a file measurement error. * */ static void ima_rdwr_violation_check(struct file *file) { struct dentry *dentry = file->f_path.dentry; struct inode *inode = dentry->d_inode; fmode_t mode = file->f_mode; int rc; bool send_tomtou = false, send_writers = false; if (!S_ISREG(inode->i_mode) || !ima_initialized) return; mutex_lock(&inode->i_mutex); /* file metadata: permissions, xattr */ if (mode & FMODE_WRITE) { if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) send_tomtou = true; goto out; } rc = ima_must_measure(inode, MAY_READ, FILE_CHECK); if (rc < 0) goto out; if (atomic_read(&inode->i_writecount) > 0) send_writers = true; out: mutex_unlock(&inode->i_mutex); if (send_tomtou) ima_add_violation(inode, dentry->d_name.name, "invalid_pcr", "ToMToU"); if (send_writers) ima_add_violation(inode, dentry->d_name.name, "invalid_pcr", "open_writers"); }
static void ima_read_write_check(enum iint_pcr_error error, struct ima_iint_cache *iint, struct inode *inode, const unsigned char *filename) { switch (error) { case TOMTOU: if (iint->readcount > 0) ima_add_violation(inode, filename, "invalid_pcr", "ToMToU"); break; case OPEN_WRITERS: if (iint->writecount > 0) ima_add_violation(inode, filename, "invalid_pcr", "open_writers"); break; } }
/* * ima_rdwr_violation_check * * Only invalidate the PCR for measured files: * - Opening a file for write when already open for read, * results in a time of measure, time of use (ToMToU) error. * - Opening a file for read when already open for write, * could result in a file measurement error. * */ static void ima_rdwr_violation_check(struct file *file) { struct dentry *dentry = file->f_path.dentry; struct inode *inode = file_inode(file); fmode_t mode = file->f_mode; int must_measure; bool send_tomtou = false, send_writers = false; char *pathbuf = NULL; const char *pathname; if (!S_ISREG(inode->i_mode) || !ima_initialized) return; mutex_lock(&inode->i_mutex); /* file metadata: permissions, xattr */ if (mode & FMODE_WRITE) { if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) send_tomtou = true; goto out; } must_measure = ima_must_measure(inode, MAY_READ, FILE_CHECK); if (!must_measure) goto out; if (atomic_read(&inode->i_writecount) > 0) send_writers = true; out: mutex_unlock(&inode->i_mutex); if (!send_tomtou && !send_writers) return; pathname = ima_d_path(&file->f_path, &pathbuf); if (!pathname || strlen(pathname) > IMA_EVENT_NAME_LEN_MAX) pathname = dentry->d_name.name; if (send_tomtou) ima_add_violation(file, pathname, "invalid_pcr", "ToMToU"); if (send_writers) ima_add_violation(file, pathname, "invalid_pcr", "open_writers"); kfree(pathbuf); }
/* * ima_rdwr_violation_check * * Only invalidate the PCR for measured files: * - Opening a file for write when already open for read, * results in a time of measure, time of use (ToMToU) error. * - Opening a file for read when already open for write, * could result in a file measurement error. * */ static void ima_rdwr_violation_check(struct file *file) { struct inode *inode = file_inode(file); fmode_t mode = file->f_mode; bool send_tomtou = false, send_writers = false; char *pathbuf = NULL; const char *pathname; if (!S_ISREG(inode->i_mode) || !ima_initialized) return; if (mode & FMODE_WRITE) { if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) { struct integrity_iint_cache *iint; iint = integrity_iint_find(inode); /* IMA_MEASURE is set from reader side */ if (iint && (iint->flags & IMA_MEASURE)) send_tomtou = true; } } else { if ((atomic_read(&inode->i_writecount) > 0) && ima_must_measure(inode, MAY_READ, FILE_CHECK)) send_writers = true; } if (!send_tomtou && !send_writers) return; pathname = ima_d_path(&file->f_path, &pathbuf); if (send_tomtou) ima_add_violation(file, pathname, "invalid_pcr", "ToMToU"); if (send_writers) ima_add_violation(file, pathname, "invalid_pcr", "open_writers"); kfree(pathbuf); }