aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_main.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2010-10-25 14:41:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-26 14:37:18 -0400
commitb9593d309d17c57e9ddc3934d641902533896ca9 (patch)
treefa7fd9ced4a79f102e653ee4a5dc348aa1a41c21 /security/integrity/ima/ima_main.c
parentad16ad00c34d3f320a5876b3d711ef6bc81362e1 (diff)
IMA: use i_writecount rather than a private counter
IMA tracks the number of struct files which are holding a given inode readonly and the number which are holding the inode write or r/w. It needs this information so when a new reader or writer comes in it can tell if this new file will be able to invalidate results it already made about existing files. aka if a task is holding a struct file open RO, IMA measured the file and recorded those measurements and then a task opens the file RW IMA needs to note in the logs that the old measurement may not be correct. It's called a "Time of Measure Time of Use" (ToMToU) issue. The same is true is a RO file is opened to an inode which has an open writer. We cannot, with any validity, measure the file in question since it could be changing. This patch attempts to use the i_writecount field to track writers. The i_writecount field actually embeds more information in it's value than IMA needs but it should work for our purposes and allow us to shrink the struct inode even more. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/integrity/ima/ima_main.c')
-rw-r--r--security/integrity/ima/ima_main.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 2f9b5d50424e..24660bf3f82a 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -94,8 +94,6 @@ static void ima_inc_counts(struct ima_iint_cache *iint, fmode_t mode)
94 94
95 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 95 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
96 iint->readcount++; 96 iint->readcount++;
97 if (mode & FMODE_WRITE)
98 iint->writecount++;
99} 97}
100 98
101/* 99/*
@@ -173,18 +171,16 @@ static void ima_dec_counts(struct ima_iint_cache *iint, struct inode *inode,
173 iint->readcount--; 171 iint->readcount--;
174 } 172 }
175 if (mode & FMODE_WRITE) { 173 if (mode & FMODE_WRITE) {
176 if (unlikely(iint->writecount == 0)) 174 if (atomic_read(&inode->i_writecount) <= 0)
177 dump = true; 175 dump = true;
178 iint->writecount--; 176 if (atomic_read(&inode->i_writecount) == 1 &&
179 if (iint->writecount == 0) { 177 iint->version != inode->i_version)
180 if (iint->version != inode->i_version) 178 iint->flags &= ~IMA_MEASURED;
181 iint->flags &= ~IMA_MEASURED;
182 }
183 } 179 }
184 180
185 if (dump && !ima_limit_imbalance(file)) { 181 if (dump && !ima_limit_imbalance(file)) {
186 printk(KERN_INFO "%s: open/free imbalance (r:%u w:%u)\n", 182 printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
187 __func__, iint->readcount, iint->writecount); 183 __func__, iint->readcount);
188 dump_stack(); 184 dump_stack();
189 } 185 }
190} 186}