Skip to content

Commit 64c62f0

Browse files
eparistorvalds
authored andcommitted
IMA: drop refcnt from ima_iint_cache since it isn't needed
Since finding a struct ima_iint_cache requires a valid struct inode, and the struct ima_iint_cache is supposed to have the same lifetime as a struct inode (technically they die together but don't need to be created at the same time) we don't have to worry about the ima_iint_cache outliving or dieing before the inode. So the refcnt isn't useful. Just get rid of it and free the structure when the inode is freed. Signed-off-by: Eric Paris <eapris@redhat.com> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bc7d2a3 commit 64c62f0

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

security/integrity/ima/ima.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ struct ima_iint_cache {
107107
unsigned char flags;
108108
u8 digest[IMA_DIGEST_SIZE];
109109
struct mutex mutex; /* protects: version, flags, digest */
110-
struct kref refcount; /* ima_iint_cache reference count */
111110
};
112111

113112
/* LIM API function definitions */
@@ -125,8 +124,7 @@ void ima_template_show(struct seq_file *m, void *e,
125124
* integrity data associated with an inode.
126125
*/
127126
struct ima_iint_cache *ima_iint_insert(struct inode *inode);
128-
struct ima_iint_cache *ima_iint_find_get(struct inode *inode);
129-
void iint_free(struct kref *kref);
127+
struct ima_iint_cache *ima_iint_find(struct inode *inode);
130128

131129
/* IMA policy related functions */
132130
enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK };

security/integrity/ima/ima_iint.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,26 @@ static struct ima_iint_cache *__ima_iint_find(struct inode *inode)
5353
}
5454

5555
/*
56-
* ima_iint_find_get - return the iint associated with an inode
57-
*
58-
* ima_iint_find_get gets a reference to the iint. Caller must
59-
* remember to put the iint reference.
56+
* ima_iint_find - return the iint associated with an inode
6057
*/
61-
struct ima_iint_cache *ima_iint_find_get(struct inode *inode)
58+
struct ima_iint_cache *ima_iint_find(struct inode *inode)
6259
{
6360
struct ima_iint_cache *iint;
6461

6562
spin_lock(&ima_iint_lock);
6663
iint = __ima_iint_find(inode);
67-
if (iint)
68-
kref_get(&iint->refcount);
6964
spin_unlock(&ima_iint_lock);
7065

7166
return iint;
7267
}
7368

69+
static void iint_free(struct ima_iint_cache *iint)
70+
{
71+
iint->version = 0;
72+
iint->flags = 0UL;
73+
kmem_cache_free(iint_cache, iint);
74+
}
75+
7476
/**
7577
* ima_inode_alloc - allocate an iint associated with an inode
7678
* @inode: pointer to the inode
@@ -113,19 +115,9 @@ int ima_inode_alloc(struct inode *inode)
113115
return 0;
114116
out_err:
115117
spin_unlock(&ima_iint_lock);
116-
kref_put(&new_iint->refcount, iint_free);
117-
return rc;
118-
}
118+
iint_free(new_iint);
119119

120-
/* iint_free - called when the iint refcount goes to zero */
121-
void iint_free(struct kref *kref)
122-
{
123-
struct ima_iint_cache *iint = container_of(kref, struct ima_iint_cache,
124-
refcount);
125-
iint->version = 0;
126-
iint->flags = 0UL;
127-
kref_init(&iint->refcount);
128-
kmem_cache_free(iint_cache, iint);
120+
return rc;
129121
}
130122

131123
/**
@@ -148,8 +140,11 @@ void ima_inode_free(struct inode *inode)
148140
if (iint)
149141
rb_erase(&iint->rb_node, &ima_iint_tree);
150142
spin_unlock(&ima_iint_lock);
151-
if (iint)
152-
kref_put(&iint->refcount, iint_free);
143+
144+
if (!iint)
145+
return;
146+
147+
iint_free(iint);
153148
}
154149

155150
static void init_once(void *foo)
@@ -160,7 +155,6 @@ static void init_once(void *foo)
160155
iint->version = 0;
161156
iint->flags = 0UL;
162157
mutex_init(&iint->mutex);
163-
kref_init(&iint->refcount);
164158
}
165159

166160
static int __init ima_iintcache_init(void)

security/integrity/ima/ima_main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ static void ima_file_free_iint(struct ima_iint_cache *iint, struct inode *inode,
186186

187187
spin_unlock(&inode->i_lock);
188188
mutex_unlock(&iint->mutex);
189-
190-
kref_put(&iint->refcount, iint_free);
191189
}
192190

193191
static void ima_file_free_noiint(struct inode *inode, struct file *file)
@@ -213,7 +211,7 @@ void ima_file_free(struct file *file)
213211

214212
if (!iint_initialized || !S_ISREG(inode->i_mode))
215213
return;
216-
iint = ima_iint_find_get(inode);
214+
iint = ima_iint_find(inode);
217215

218216
if (iint)
219217
ima_file_free_iint(iint, inode, file);
@@ -236,7 +234,7 @@ static int process_measurement(struct file *file, const unsigned char *filename,
236234
if (rc != 0)
237235
return rc;
238236
retry:
239-
iint = ima_iint_find_get(inode);
237+
iint = ima_iint_find(inode);
240238
if (!iint) {
241239
rc = ima_inode_alloc(inode);
242240
if (!rc || rc == -EEXIST)
@@ -255,7 +253,6 @@ static int process_measurement(struct file *file, const unsigned char *filename,
255253
ima_store_measurement(iint, file, filename);
256254
out:
257255
mutex_unlock(&iint->mutex);
258-
kref_put(&iint->refcount, iint_free);
259256
return rc;
260257
}
261258

0 commit comments

Comments
 (0)