Skip to content

Commit a427fd1

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Remove tomoyo_policy_memory_lock spinlock.
tomoyo_policy_lock mutex already protects it. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent f9732ea commit a427fd1

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

‎security/tomoyo/common.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
10431043
void tomoyo_get_attributes(struct tomoyo_obj_info *obj);
10441044
void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
10451045
void tomoyo_load_policy(const char *filename);
1046-
void tomoyo_memory_free(void *ptr);
10471046
void tomoyo_normalize_line(unsigned char *buffer);
10481047
void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
10491048
void tomoyo_print_ip(char *buf, const unsigned int size,

‎security/tomoyo/gc.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
#include <linux/kthread.h>
99
#include <linux/slab.h>
1010

11+
/**
12+
* tomoyo_memory_free - Free memory for elements.
13+
*
14+
* @ptr: Pointer to allocated memory.
15+
*
16+
* Returns nothing.
17+
*
18+
* Caller holds tomoyo_policy_lock mutex.
19+
*/
20+
static inline void tomoyo_memory_free(void *ptr)
21+
{
22+
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] -= ksize(ptr);
23+
kfree(ptr);
24+
}
25+
1126
/* The list for "struct tomoyo_io_buffer". */
1227
static LIST_HEAD(tomoyo_io_buffer_list);
1328
/* Lock for protecting tomoyo_io_buffer_list. */
@@ -215,6 +230,8 @@ static void tomoyo_del_acl(struct list_head *element)
215230
* @element: Pointer to "struct list_head".
216231
*
217232
* Returns nothing.
233+
*
234+
* Caller holds tomoyo_policy_lock mutex.
218235
*/
219236
static inline void tomoyo_del_domain(struct list_head *element)
220237
{
@@ -416,12 +433,13 @@ static void tomoyo_try_to_gc(const enum tomoyo_policy_id type,
416433
(element, typeof(struct tomoyo_domain_info),
417434
list)->users))
418435
goto reinject;
419-
tomoyo_del_domain(element);
420436
break;
421437
case TOMOYO_MAX_POLICY:
422438
break;
423439
}
424440
mutex_lock(&tomoyo_policy_lock);
441+
if (type == TOMOYO_ID_DOMAIN)
442+
tomoyo_del_domain(element);
425443
tomoyo_memory_free(element);
426444
return;
427445
reinject:

‎security/tomoyo/memory.c‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ void tomoyo_warn_oom(const char *function)
2727
panic("MAC Initialization failed.\n");
2828
}
2929

30-
/* Lock for protecting tomoyo_memory_used. */
31-
static DEFINE_SPINLOCK(tomoyo_policy_memory_lock);
3230
/* Memoy currently used by policy/audit log/query. */
3331
unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
3432
/* Memory quota for "policy"/"audit log"/"query". */
@@ -42,22 +40,19 @@ unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
4240
* Returns true on success, false otherwise.
4341
*
4442
* Returns true if @ptr is not NULL and quota not exceeded, false otherwise.
43+
*
44+
* Caller holds tomoyo_policy_lock mutex.
4545
*/
4646
bool tomoyo_memory_ok(void *ptr)
4747
{
4848
if (ptr) {
4949
const size_t s = ksize(ptr);
50-
bool result;
51-
spin_lock(&tomoyo_policy_memory_lock);
5250
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] += s;
53-
result = !tomoyo_memory_quota[TOMOYO_MEMORY_POLICY] ||
54-
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] <=
55-
tomoyo_memory_quota[TOMOYO_MEMORY_POLICY];
56-
if (!result)
57-
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] -= s;
58-
spin_unlock(&tomoyo_policy_memory_lock);
59-
if (result)
51+
if (!tomoyo_memory_quota[TOMOYO_MEMORY_POLICY] ||
52+
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] <=
53+
tomoyo_memory_quota[TOMOYO_MEMORY_POLICY])
6054
return true;
55+
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] -= s;
6156
}
6257
tomoyo_warn_oom(__func__);
6358
return false;
@@ -71,6 +66,8 @@ bool tomoyo_memory_ok(void *ptr)
7166
*
7267
* Returns pointer to allocated memory on success, NULL otherwise.
7368
* @data is zero-cleared on success.
69+
*
70+
* Caller holds tomoyo_policy_lock mutex.
7471
*/
7572
void *tomoyo_commit_ok(void *data, const unsigned int size)
7673
{
@@ -84,20 +81,6 @@ void *tomoyo_commit_ok(void *data, const unsigned int size)
8481
return NULL;
8582
}
8683

87-
/**
88-
* tomoyo_memory_free - Free memory for elements.
89-
*
90-
* @ptr: Pointer to allocated memory.
91-
*/
92-
void tomoyo_memory_free(void *ptr)
93-
{
94-
size_t s = ksize(ptr);
95-
spin_lock(&tomoyo_policy_memory_lock);
96-
tomoyo_memory_used[TOMOYO_MEMORY_POLICY] -= s;
97-
spin_unlock(&tomoyo_policy_memory_lock);
98-
kfree(ptr);
99-
}
100-
10184
/**
10285
* tomoyo_get_group - Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
10386
*

0 commit comments

Comments
 (0)