aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_main.c
diff options
context:
space:
mode:
authorMimi Zohar <zohar@linux.vnet.ibm.com>2009-02-04 09:07:02 -0500
committerJames Morris <jmorris@namei.org>2009-02-05 17:05:33 -0500
commit1df9f0a73178718969ae47d813b8e7aab2cf073c (patch)
tree6bd3d8838858f0e93acd8f7969b7d0e5ce2bfb08 /security/integrity/ima/ima_main.c
parentf4bd857bc8ed997c25ec06b56ef8064aafa6d4f3 (diff)
Integrity: IMA file free imbalance
The number of calls to ima_path_check()/ima_file_free() should be balanced. An extra call to fput(), indicates the file could have been accessed without first being measured. Although f_count is incremented/decremented in places other than fget/fput, like fget_light/fput_light and get_file, the current task must already hold a file refcnt. The call to __fput() is delayed until the refcnt becomes 0, resulting in ima_file_free() flagging any changes. - add hook to increment opencount for IPC shared memory(SYSV), shmat files, and /dev/zero - moved NULL iint test in opencount_get() Signed-off-by: Mimi Zohar <zohar@us.ibm.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/integrity/ima/ima_main.c')
-rw-r--r--security/integrity/ima/ima_main.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 871e356e8d6c..f4e7266f5aee 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -66,6 +66,19 @@ void ima_file_free(struct file *file)
66 return; 66 return;
67 67
68 mutex_lock(&iint->mutex); 68 mutex_lock(&iint->mutex);
69 if (iint->opencount <= 0) {
70 printk(KERN_INFO
71 "%s: %s open/free imbalance (r:%ld w:%ld o:%ld f:%ld)\n",
72 __FUNCTION__, file->f_dentry->d_name.name,
73 iint->readcount, iint->writecount,
74 iint->opencount, atomic_long_read(&file->f_count));
75 if (!(iint->flags & IMA_IINT_DUMP_STACK)) {
76 dump_stack();
77 iint->flags |= IMA_IINT_DUMP_STACK;
78 }
79 }
80 iint->opencount--;
81
69 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 82 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
70 iint->readcount--; 83 iint->readcount--;
71 84
@@ -119,6 +132,7 @@ static int get_path_measurement(struct ima_iint_cache *iint, struct file *file,
119 pr_info("%s dentry_open failed\n", filename); 132 pr_info("%s dentry_open failed\n", filename);
120 return rc; 133 return rc;
121 } 134 }
135 iint->opencount++;
122 iint->readcount++; 136 iint->readcount++;
123 137
124 rc = ima_collect_measurement(iint, file); 138 rc = ima_collect_measurement(iint, file);
@@ -159,6 +173,7 @@ int ima_path_check(struct path *path, int mask)
159 return 0; 173 return 0;
160 174
161 mutex_lock(&iint->mutex); 175 mutex_lock(&iint->mutex);
176 iint->opencount++;
162 if ((mask & MAY_WRITE) || (mask == 0)) 177 if ((mask & MAY_WRITE) || (mask == 0))
163 iint->writecount++; 178 iint->writecount++;
164 else if (mask & (MAY_READ | MAY_EXEC)) 179 else if (mask & (MAY_READ | MAY_EXEC))
@@ -219,6 +234,21 @@ out:
219 return rc; 234 return rc;
220} 235}
221 236
237static void opencount_get(struct file *file)
238{
239 struct inode *inode = file->f_dentry->d_inode;
240 struct ima_iint_cache *iint;
241
242 if (!ima_initialized || !S_ISREG(inode->i_mode))
243 return;
244 iint = ima_iint_find_insert_get(inode);
245 if (!iint)
246 return;
247 mutex_lock(&iint->mutex);
248 iint->opencount++;
249 mutex_unlock(&iint->mutex);
250}
251
222/** 252/**
223 * ima_file_mmap - based on policy, collect/store measurement. 253 * ima_file_mmap - based on policy, collect/store measurement.
224 * @file: pointer to the file to be measured (May be NULL) 254 * @file: pointer to the file to be measured (May be NULL)
@@ -242,6 +272,18 @@ int ima_file_mmap(struct file *file, unsigned long prot)
242 return 0; 272 return 0;
243} 273}
244 274
275/*
276 * ima_shm_check - IPC shm and shmat create/fput a file
277 *
278 * Maintain the opencount for these files to prevent unnecessary
279 * imbalance messages.
280 */
281void ima_shm_check(struct file *file)
282{
283 opencount_get(file);
284 return;
285}
286
245/** 287/**
246 * ima_bprm_check - based on policy, collect/store measurement. 288 * ima_bprm_check - based on policy, collect/store measurement.
247 * @bprm: contains the linux_binprm structure 289 * @bprm: contains the linux_binprm structure