Skip to content

Commit 9353384

Browse files
eparisAl Viro
authored andcommitted
ima: only insert at inode creation time
iints are supposed to be allocated when an inode is allocated (during security_inode_alloc()) But we have code which will attempt to allocate an iint during measurement calls. If we couldn't allocate the iint and we cared, we should have died during security_inode_alloc(). Not make the code more complex and less efficient. Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent ec29ea5 commit 9353384

3 files changed

Lines changed: 14 additions & 66 deletions

File tree

‎security/integrity/ima/ima.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ void ima_template_show(struct seq_file *m, void *e,
128128
*/
129129
struct ima_iint_cache *ima_iint_insert(struct inode *inode);
130130
struct ima_iint_cache *ima_iint_find_get(struct inode *inode);
131-
struct ima_iint_cache *ima_iint_find_insert_get(struct inode *inode);
132131
void ima_iint_delete(struct inode *inode);
133132
void iint_free(struct kref *kref);
134133
void iint_rcu_free(struct rcu_head *rcu);

‎security/integrity/ima/ima_iint.c‎

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ struct ima_iint_cache *ima_iint_find_get(struct inode *inode)
4545
return iint;
4646
}
4747

48-
/* Allocate memory for the iint associated with the inode
49-
* from the iint_cache slab, initialize the iint, and
50-
* insert it into the radix tree.
51-
*
52-
* On success return a pointer to the iint; on failure return NULL.
48+
/**
49+
* ima_inode_alloc - allocate an iint associated with an inode
50+
* @inode: pointer to the inode
5351
*/
54-
struct ima_iint_cache *ima_iint_insert(struct inode *inode)
52+
int ima_inode_alloc(struct inode *inode)
5553
{
5654
struct ima_iint_cache *iint = NULL;
5755
int rc = 0;
5856

5957
if (!ima_initialized)
60-
return iint;
58+
return 0;
59+
6160
iint = kmem_cache_alloc(iint_cache, GFP_NOFS);
6261
if (!iint)
63-
return iint;
62+
return -ENOMEM;
6463

6564
rc = radix_tree_preload(GFP_NOFS);
6665
if (rc < 0)
@@ -70,63 +69,13 @@ struct ima_iint_cache *ima_iint_insert(struct inode *inode)
7069
rc = radix_tree_insert(&ima_iint_store, (unsigned long)inode, iint);
7170
spin_unlock(&ima_iint_lock);
7271
out:
73-
if (rc < 0) {
72+
if (rc < 0)
7473
kmem_cache_free(iint_cache, iint);
75-
if (rc == -EEXIST) {
76-
spin_lock(&ima_iint_lock);
77-
iint = radix_tree_lookup(&ima_iint_store,
78-
(unsigned long)inode);
79-
spin_unlock(&ima_iint_lock);
80-
} else
81-
iint = NULL;
82-
}
83-
radix_tree_preload_end();
84-
return iint;
85-
}
86-
87-
/**
88-
* ima_inode_alloc - allocate an iint associated with an inode
89-
* @inode: pointer to the inode
90-
*/
91-
int ima_inode_alloc(struct inode *inode)
92-
{
93-
struct ima_iint_cache *iint;
94-
95-
if (!ima_initialized)
96-
return 0;
97-
98-
iint = ima_iint_insert(inode);
99-
if (!iint)
100-
return -ENOMEM;
101-
return 0;
102-
}
103-
104-
/* ima_iint_find_insert_get - get the iint associated with an inode
105-
*
106-
* Most insertions are done at inode_alloc, except those allocated
107-
* before late_initcall. When the iint does not exist, allocate it,
108-
* initialize and insert it, and increment the iint refcount.
109-
*
110-
* (Can't initialize at security_initcall before any inodes are
111-
* allocated, got to wait at least until proc_init.)
112-
*
113-
* Return the iint.
114-
*/
115-
struct ima_iint_cache *ima_iint_find_insert_get(struct inode *inode)
116-
{
117-
struct ima_iint_cache *iint = NULL;
11874

119-
iint = ima_iint_find_get(inode);
120-
if (iint)
121-
return iint;
122-
123-
iint = ima_iint_insert(inode);
124-
if (iint)
125-
kref_get(&iint->refcount);
75+
radix_tree_preload_end();
12676

127-
return iint;
77+
return rc;
12878
}
129-
EXPORT_SYMBOL_GPL(ima_iint_find_insert_get);
13079

13180
/* iint_free - called when the iint refcount goes to zero */
13281
void iint_free(struct kref *kref)

‎security/integrity/ima/ima_main.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ int ima_path_check(struct path *path, int mask, int update_counts)
161161

162162
if (!ima_initialized || !S_ISREG(inode->i_mode))
163163
return 0;
164-
iint = ima_iint_find_insert_get(inode);
164+
iint = ima_iint_find_get(inode);
165165
if (!iint)
166166
return 0;
167167

@@ -219,7 +219,7 @@ static int process_measurement(struct file *file, const unsigned char *filename,
219219

220220
if (!ima_initialized || !S_ISREG(inode->i_mode))
221221
return 0;
222-
iint = ima_iint_find_insert_get(inode);
222+
iint = ima_iint_find_get(inode);
223223
if (!iint)
224224
return -ENOMEM;
225225

@@ -255,7 +255,7 @@ void ima_counts_put(struct path *path, int mask)
255255
*/
256256
if (!ima_initialized || !inode || !S_ISREG(inode->i_mode))
257257
return;
258-
iint = ima_iint_find_insert_get(inode);
258+
iint = ima_iint_find_get(inode);
259259
if (!iint)
260260
return;
261261

@@ -286,7 +286,7 @@ void ima_counts_get(struct file *file)
286286

287287
if (!ima_initialized || !S_ISREG(inode->i_mode))
288288
return;
289-
iint = ima_iint_find_insert_get(inode);
289+
iint = ima_iint_find_get(inode);
290290
if (!iint)
291291
return;
292292
mutex_lock(&iint->mutex);

0 commit comments

Comments
 (0)