Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 235090
b: refs/heads/master
c: 890275b
h: refs/heads/master
v: v3
  • Loading branch information
Mimi Zohar committed Feb 10, 2011
1 parent 97461b9 commit 21b3ffa
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a5c96ebf1d71df0c5fb77ab58c9aeb307cf02372
refs/heads/master: 890275b5eb79e9933d12290473eab9ac38da0051
5 changes: 4 additions & 1 deletion trunk/fs/file_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ struct file *alloc_file(struct path *path, fmode_t mode,
file_take_write(file);
WARN_ON(mnt_clone_write(path->mnt));
}
ima_counts_get(file);
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
i_readcount_inc(path->dentry->d_inode);
return file;
}
EXPORT_SYMBOL(alloc_file);
Expand Down Expand Up @@ -251,6 +252,8 @@ static void __fput(struct file *file)
fops_put(file->f_op);
put_pid(file->f_owner.pid);
file_sb_list_del(file);
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
i_readcount_dec(inode);
if (file->f_mode & FMODE_WRITE)
drop_file_write_access(file);
file->f_path.dentry = NULL;
Expand Down
3 changes: 2 additions & 1 deletion trunk/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
if (error)
goto cleanup_all;
}
ima_counts_get(f);
if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
i_readcount_inc(inode);

f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);

Expand Down
6 changes: 0 additions & 6 deletions trunk/include/linux/ima.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern void ima_inode_free(struct inode *inode);
extern int ima_file_check(struct file *file, int mask);
extern void ima_file_free(struct file *file);
extern int ima_file_mmap(struct file *file, unsigned long prot);
extern void ima_counts_get(struct file *file);

#else
static inline int ima_bprm_check(struct linux_binprm *bprm)
Expand Down Expand Up @@ -53,10 +52,5 @@ static inline int ima_file_mmap(struct file *file, unsigned long prot)
return 0;
}

static inline void ima_counts_get(struct file *file)
{
return;
}

#endif /* CONFIG_IMA_H */
#endif /* _LINUX_IMA_H */
2 changes: 0 additions & 2 deletions trunk/security/integrity/ima/ima_iint.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ void ima_inode_free(struct inode *inode)
printk(KERN_INFO "%s: readcount: %u\n", __func__,
atomic_read(&inode->i_readcount));

atomic_set(&inode->i_readcount, 0);

if (!IS_IMA(inode))
return;

Expand Down
25 changes: 8 additions & 17 deletions trunk/security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,27 @@ static bool ima_limit_imbalance(struct file *file)
}

/*
* ima_counts_get - increment file counts
* ima_rdwr_violation_check
*
* Maintain read/write counters for all files, but only
* invalidate the PCR for measured files:
* 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.
*
*/
void ima_counts_get(struct file *file)
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))
if (!S_ISREG(inode->i_mode) || !ima_initialized)
return;

spin_lock(&inode->i_lock);

if (!ima_initialized)
goto out;
mutex_lock(&inode->i_mutex); /* file metadata: permissions, xattr */

if (mode & FMODE_WRITE) {
if (atomic_read(&inode->i_readcount) && IS_IMA(inode))
Expand All @@ -125,11 +121,7 @@ void ima_counts_get(struct file *file)
if (atomic_read(&inode->i_writecount) > 0)
send_writers = true;
out:
/* remember the vfs deals with i_writecount */
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
atomic_inc(&inode->i_readcount);

spin_unlock(&inode->i_lock);
mutex_unlock(&inode->i_mutex);

if (send_tomtou)
ima_add_violation(inode, dentry->d_name.name, "invalid_pcr",
Expand Down Expand Up @@ -158,7 +150,6 @@ static void ima_dec_counts(struct inode *inode, struct file *file)
}
return;
}
atomic_dec(&inode->i_readcount);
}
}

Expand Down Expand Up @@ -203,8 +194,7 @@ static void ima_file_free_noiint(struct inode *inode, struct file *file)
* ima_file_free - called on __fput()
* @file: pointer to file structure being freed
*
* Flag files that changed, based on i_version;
* and decrement the i_readcount.
* Flag files that changed, based on i_version
*/
void ima_file_free(struct file *file)
{
Expand Down Expand Up @@ -318,6 +308,7 @@ int ima_file_check(struct file *file, int mask)
{
int rc;

ima_rdwr_violation_check(file);
rc = process_measurement(file, file->f_dentry->d_name.name,
mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
FILE_CHECK);
Expand Down

0 comments on commit 21b3ffa

Please sign in to comment.