aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_main.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2010-10-25 14:41:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-26 14:37:18 -0400
commita178d2027d3198b0a04517d764326ab71cd73da2 (patch)
treed81b9336328ba1741231b318a6f8187f627581fd /security/integrity/ima/ima_main.c
parentb9593d309d17c57e9ddc3934d641902533896ca9 (diff)
IMA: move read counter into struct inode
IMA currently allocated an inode integrity structure for every inode in core. This stucture is about 120 bytes long. Most files however (especially on a system which doesn't make use of IMA) will never need any of this space. The problem is that if IMA is enabled we need to know information about the number of readers and the number of writers for every inode on the box. At the moment we collect that information in the per inode iint structure and waste the rest of the space. This patch moves those counters into the struct inode so we can eventually stop allocating an IMA integrity structure except when absolutely needed. This patch does the minimum needed to move the location of the data. Further cleanups, especially the location of counter updates, may still be possible. 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.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 24660bf3f82a..2a77b14fee27 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -86,17 +86,6 @@ out:
86} 86}
87 87
88/* 88/*
89 * Update the counts given an fmode_t
90 */
91static void ima_inc_counts(struct ima_iint_cache *iint, fmode_t mode)
92{
93 assert_spin_locked(&iint->inode->i_lock);
94
95 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
96 iint->readcount++;
97}
98
99/*
100 * ima_counts_get - increment file counts 89 * ima_counts_get - increment file counts
101 * 90 *
102 * Maintain read/write counters for all files, but only 91 * Maintain read/write counters for all files, but only
@@ -112,27 +101,23 @@ void ima_counts_get(struct file *file)
112 struct dentry *dentry = file->f_path.dentry; 101 struct dentry *dentry = file->f_path.dentry;
113 struct inode *inode = dentry->d_inode; 102 struct inode *inode = dentry->d_inode;
114 fmode_t mode = file->f_mode; 103 fmode_t mode = file->f_mode;
115 struct ima_iint_cache *iint;
116 int rc; 104 int rc;
117 bool send_tomtou = false, send_writers = false; 105 bool send_tomtou = false, send_writers = false;
118 106
119 if (!iint_initialized || !S_ISREG(inode->i_mode)) 107 if (!S_ISREG(inode->i_mode))
120 return; 108 return;
121 iint = ima_iint_find_get(inode); 109
122 if (!iint)
123 return;
124 mutex_lock(&iint->mutex);
125 spin_lock(&inode->i_lock); 110 spin_lock(&inode->i_lock);
126 111
127 if (!ima_initialized) 112 if (!ima_initialized)
128 goto out; 113 goto out;
129 114
130 rc = ima_must_measure(iint, inode, MAY_READ, FILE_CHECK); 115 rc = ima_must_measure(NULL, inode, MAY_READ, FILE_CHECK);
131 if (rc < 0) 116 if (rc < 0)
132 goto out; 117 goto out;
133 118
134 if (mode & FMODE_WRITE) { 119 if (mode & FMODE_WRITE) {
135 if (iint->readcount) 120 if (inode->i_readcount)
136 send_tomtou = true; 121 send_tomtou = true;
137 goto out; 122 goto out;
138 } 123 }
@@ -140,10 +125,10 @@ void ima_counts_get(struct file *file)
140 if (atomic_read(&inode->i_writecount) > 0) 125 if (atomic_read(&inode->i_writecount) > 0)
141 send_writers = true; 126 send_writers = true;
142out: 127out:
143 ima_inc_counts(iint, file->f_mode); 128 /* remember the vfs deals with i_writecount */
129 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
130 inode->i_readcount++;
144 spin_unlock(&inode->i_lock); 131 spin_unlock(&inode->i_lock);
145 mutex_unlock(&iint->mutex);
146 kref_put(&iint->refcount, iint_free);
147 132
148 if (send_tomtou) 133 if (send_tomtou)
149 ima_add_violation(inode, dentry->d_name.name, "invalid_pcr", 134 ima_add_violation(inode, dentry->d_name.name, "invalid_pcr",
@@ -166,9 +151,9 @@ static void ima_dec_counts(struct ima_iint_cache *iint, struct inode *inode,
166 assert_spin_locked(&inode->i_lock); 151 assert_spin_locked(&inode->i_lock);
167 152
168 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { 153 if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
169 if (unlikely(iint->readcount == 0)) 154 if (unlikely(inode->i_readcount == 0))
170 dump = true; 155 dump = true;
171 iint->readcount--; 156 inode->i_readcount--;
172 } 157 }
173 if (mode & FMODE_WRITE) { 158 if (mode & FMODE_WRITE) {
174 if (atomic_read(&inode->i_writecount) <= 0) 159 if (atomic_read(&inode->i_writecount) <= 0)
@@ -180,7 +165,7 @@ static void ima_dec_counts(struct ima_iint_cache *iint, struct inode *inode,
180 165
181 if (dump && !ima_limit_imbalance(file)) { 166 if (dump && !ima_limit_imbalance(file)) {
182 printk(KERN_INFO "%s: open/free imbalance (r:%u)\n", 167 printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
183 __func__, iint->readcount); 168 __func__, inode->i_readcount);
184 dump_stack(); 169 dump_stack();
185 } 170 }
186} 171}