diff options
Diffstat (limited to 'security/integrity/ima/ima_iint.c')
-rw-r--r-- | security/integrity/ima/ima_iint.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c index 0936a7197e47..969a1c1cb333 100644 --- a/security/integrity/ima/ima_iint.c +++ b/security/integrity/ima/ima_iint.c | |||
@@ -53,24 +53,26 @@ static struct ima_iint_cache *__ima_iint_find(struct inode *inode) | |||
53 | } | 53 | } |
54 | 54 | ||
55 | /* | 55 | /* |
56 | * ima_iint_find_get - return the iint associated with an inode | 56 | * ima_iint_find - 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. | ||
60 | */ | 57 | */ |
61 | struct ima_iint_cache *ima_iint_find_get(struct inode *inode) | 58 | struct ima_iint_cache *ima_iint_find(struct inode *inode) |
62 | { | 59 | { |
63 | struct ima_iint_cache *iint; | 60 | struct ima_iint_cache *iint; |
64 | 61 | ||
65 | spin_lock(&ima_iint_lock); | 62 | spin_lock(&ima_iint_lock); |
66 | iint = __ima_iint_find(inode); | 63 | iint = __ima_iint_find(inode); |
67 | if (iint) | ||
68 | kref_get(&iint->refcount); | ||
69 | spin_unlock(&ima_iint_lock); | 64 | spin_unlock(&ima_iint_lock); |
70 | 65 | ||
71 | return iint; | 66 | return iint; |
72 | } | 67 | } |
73 | 68 | ||
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 | |||
74 | /** | 76 | /** |
75 | * ima_inode_alloc - allocate an iint associated with an inode | 77 | * ima_inode_alloc - allocate an iint associated with an inode |
76 | * @inode: pointer to the inode | 78 | * @inode: pointer to the inode |
@@ -113,19 +115,9 @@ int ima_inode_alloc(struct inode *inode) | |||
113 | return 0; | 115 | return 0; |
114 | out_err: | 116 | out_err: |
115 | spin_unlock(&ima_iint_lock); | 117 | spin_unlock(&ima_iint_lock); |
116 | kref_put(&new_iint->refcount, iint_free); | 118 | iint_free(new_iint); |
117 | return rc; | ||
118 | } | ||
119 | 119 | ||
120 | /* iint_free - called when the iint refcount goes to zero */ | 120 | return rc; |
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); | ||
129 | } | 121 | } |
130 | 122 | ||
131 | /** | 123 | /** |
@@ -148,8 +140,11 @@ void ima_inode_free(struct inode *inode) | |||
148 | if (iint) | 140 | if (iint) |
149 | rb_erase(&iint->rb_node, &ima_iint_tree); | 141 | rb_erase(&iint->rb_node, &ima_iint_tree); |
150 | spin_unlock(&ima_iint_lock); | 142 | spin_unlock(&ima_iint_lock); |
151 | if (iint) | 143 | |
152 | kref_put(&iint->refcount, iint_free); | 144 | if (!iint) |
145 | return; | ||
146 | |||
147 | iint_free(iint); | ||
153 | } | 148 | } |
154 | 149 | ||
155 | static void init_once(void *foo) | 150 | static void init_once(void *foo) |
@@ -160,7 +155,6 @@ static void init_once(void *foo) | |||
160 | iint->version = 0; | 155 | iint->version = 0; |
161 | iint->flags = 0UL; | 156 | iint->flags = 0UL; |
162 | mutex_init(&iint->mutex); | 157 | mutex_init(&iint->mutex); |
163 | kref_init(&iint->refcount); | ||
164 | } | 158 | } |
165 | 159 | ||
166 | static int __init ima_iintcache_init(void) | 160 | static int __init ima_iintcache_init(void) |