Skip to content

Commit 847b173

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Add garbage collector.
This patch adds garbage collector support to TOMOYO. Elements are protected by "struct srcu_struct tomoyo_ss". Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent ec8e6a4 commit 847b173

7 files changed

Lines changed: 436 additions & 54 deletions

File tree

‎security/tomoyo/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
obj-y = common.o realpath.o tomoyo.o domain.o file.o
1+
obj-y = common.o realpath.o tomoyo.o domain.o file.o gc.o

‎security/tomoyo/common.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ static int tomoyo_read_profile(struct tomoyo_io_buffer *head)
10671067
*
10681068
* # cat /sys/kernel/security/tomoyo/manager
10691069
*/
1070-
static LIST_HEAD(tomoyo_policy_manager_list);
1070+
LIST_HEAD(tomoyo_policy_manager_list);
10711071

10721072
/**
10731073
* tomoyo_update_manager_entry - Add a manager entry.
@@ -2109,6 +2109,7 @@ static int tomoyo_write_control(struct file *file, const char __user *buffer,
21092109
static int tomoyo_close_control(struct file *file)
21102110
{
21112111
struct tomoyo_io_buffer *head = file->private_data;
2112+
const bool is_write = !!head->write_buf;
21122113

21132114
tomoyo_read_unlock(head->reader_idx);
21142115
/* Release memory used for policy I/O. */
@@ -2119,6 +2120,8 @@ static int tomoyo_close_control(struct file *file)
21192120
kfree(head);
21202121
head = NULL;
21212122
file->private_data = NULL;
2123+
if (is_write)
2124+
tomoyo_run_gc();
21222125
return 0;
21232126
}
21242127

‎security/tomoyo/common.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ int tomoyo_check_rewrite_permission(struct tomoyo_domain_info *domain,
638638
struct file *filp);
639639
int tomoyo_find_next_domain(struct linux_binprm *bprm);
640640

641+
/* Run garbage collector. */
642+
void tomoyo_run_gc(void);
643+
644+
void tomoyo_memory_free(void *ptr);
645+
641646
/********** External variable definitions. **********/
642647

643648
/* Lock for GC. */
@@ -646,6 +651,16 @@ extern struct srcu_struct tomoyo_ss;
646651
/* The list for "struct tomoyo_domain_info". */
647652
extern struct list_head tomoyo_domain_list;
648653

654+
extern struct list_head tomoyo_domain_initializer_list;
655+
extern struct list_head tomoyo_domain_keeper_list;
656+
extern struct list_head tomoyo_alias_list;
657+
extern struct list_head tomoyo_globally_readable_list;
658+
extern struct list_head tomoyo_pattern_list;
659+
extern struct list_head tomoyo_no_rewrite_list;
660+
extern struct list_head tomoyo_policy_manager_list;
661+
extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
662+
extern struct mutex tomoyo_name_list_lock;
663+
649664
/* Lock for protecting policy. */
650665
extern struct mutex tomoyo_policy_lock;
651666

‎security/tomoyo/domain.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain)
110110
* will cause "/usr/sbin/httpd" to belong to "<kernel> /usr/sbin/httpd" domain
111111
* unless executed from "<kernel> /etc/rc.d/init.d/httpd" domain.
112112
*/
113-
static LIST_HEAD(tomoyo_domain_initializer_list);
113+
LIST_HEAD(tomoyo_domain_initializer_list);
114114

115115
/**
116116
* tomoyo_update_domain_initializer_entry - Update "struct tomoyo_domain_initializer_entry" list.
@@ -330,7 +330,7 @@ static bool tomoyo_is_domain_initializer(const struct tomoyo_path_info *
330330
* "<kernel> /usr/sbin/sshd /bin/bash /usr/bin/passwd" domain, unless
331331
* explicitly specified by "initialize_domain".
332332
*/
333-
static LIST_HEAD(tomoyo_domain_keeper_list);
333+
LIST_HEAD(tomoyo_domain_keeper_list);
334334

335335
/**
336336
* tomoyo_update_domain_keeper_entry - Update "struct tomoyo_domain_keeper_entry" list.
@@ -533,7 +533,7 @@ static bool tomoyo_is_domain_keeper(const struct tomoyo_path_info *domainname,
533533
* /bin/busybox and domainname which the current process will belong to after
534534
* execve() succeeds is calculated using /bin/cat rather than /bin/busybox .
535535
*/
536-
static LIST_HEAD(tomoyo_alias_list);
536+
LIST_HEAD(tomoyo_alias_list);
537537

538538
/**
539539
* tomoyo_update_alias_entry - Update "struct tomoyo_alias_entry" list.

‎security/tomoyo/file.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename,
148148
* given "allow_read /lib/libc-2.5.so" to the domain which current process
149149
* belongs to.
150150
*/
151-
static LIST_HEAD(tomoyo_globally_readable_list);
151+
LIST_HEAD(tomoyo_globally_readable_list);
152152

153153
/**
154154
* tomoyo_update_globally_readable_entry - Update "struct tomoyo_globally_readable_file_entry" list.
@@ -295,7 +295,7 @@ bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head)
295295
* which pretends as if /proc/self/ is not a symlink; so that we can forbid
296296
* current process from accessing other process's information.
297297
*/
298-
static LIST_HEAD(tomoyo_pattern_list);
298+
LIST_HEAD(tomoyo_pattern_list);
299299

300300
/**
301301
* tomoyo_update_file_pattern_entry - Update "struct tomoyo_pattern_entry" list.
@@ -448,7 +448,7 @@ bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head)
448448
* " (deleted)" suffix if the file is already unlink()ed; so that we don't
449449
* need to worry whether the file is already unlink()ed or not.
450450
*/
451-
static LIST_HEAD(tomoyo_no_rewrite_list);
451+
LIST_HEAD(tomoyo_no_rewrite_list);
452452

453453
/**
454454
* tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite_entry" list.

0 commit comments

Comments
 (0)