Skip to content

Commit 268225a

Browse files
Tetsuo HandaTetsuo Handa
authored andcommitted
tomoyo: preparation step for building as a loadable LSM module
In order to allow Makefile to generate tomoyo.ko as output, rename tomoyo.c to hooks.h and cut out LSM hook registration part that will be built into vmlinux from hooks.h to init.c . Also, update comments and relocate some variables. No behavior changes. Signed-off-by: Tetsuo Handa <[email protected]>
1 parent de5cb0d commit 268225a

File tree

6 files changed

+112
-116
lines changed

6 files changed

+112
-116
lines changed

security/tomoyo/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-y = audit.o common.o condition.o domain.o environ.o file.o gc.o group.o load_policy.o memory.o mount.o network.o realpath.o securityfs_if.o tomoyo.o util.o
2+
obj-y = audit.o common.o condition.o domain.o environ.o file.o gc.o group.o init.o load_policy.o memory.o mount.o network.o realpath.o securityfs_if.o util.o
33

44
targets += builtin-policy.h
55

security/tomoyo/gc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <linux/kthread.h>
1010
#include <linux/slab.h>
1111

12+
/* Lock for GC. */
13+
DEFINE_SRCU(tomoyo_ss);
14+
1215
/**
1316
* tomoyo_memory_free - Free memory for elements.
1417
*

security/tomoyo/tomoyo.c renamed to security/tomoyo/hooks.h

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
3-
* security/tomoyo/tomoyo.c
3+
* security/tomoyo/hooks.h
44
*
55
* Copyright (C) 2005-2011 NTT DATA CORPORATION
66
*/
77

8-
#include <linux/lsm_hooks.h>
9-
#include <uapi/linux/lsm.h>
108
#include "common.h"
119

1210
/**
@@ -18,10 +16,6 @@ struct tomoyo_domain_info *tomoyo_domain(void)
1816
{
1917
struct tomoyo_task *s = tomoyo_task(current);
2018

21-
if (s->old_domain_info && !current->in_execve) {
22-
atomic_dec(&s->old_domain_info->users);
23-
s->old_domain_info = NULL;
24-
}
2519
return s->domain_info;
2620
}
2721

@@ -62,26 +56,6 @@ static void tomoyo_bprm_committed_creds(const struct linux_binprm *bprm)
6256
s->old_domain_info = NULL;
6357
}
6458

65-
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
66-
/**
67-
* tomoyo_bprm_creds_for_exec - Target for security_bprm_creds_for_exec().
68-
*
69-
* @bprm: Pointer to "struct linux_binprm".
70-
*
71-
* Returns 0.
72-
*/
73-
static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm)
74-
{
75-
/*
76-
* Load policy if /sbin/tomoyo-init exists and /sbin/init is requested
77-
* for the first time.
78-
*/
79-
if (!tomoyo_policy_loaded)
80-
tomoyo_load_policy(bprm->filename);
81-
return 0;
82-
}
83-
#endif
84-
8559
/**
8660
* tomoyo_bprm_check_security - Target for security_bprm_check().
8761
*
@@ -501,10 +475,6 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
501475
return tomoyo_socket_sendmsg_permission(sock, msg, size);
502476
}
503477

504-
struct lsm_blob_sizes tomoyo_blob_sizes __ro_after_init = {
505-
.lbs_task = sizeof(struct tomoyo_task),
506-
};
507-
508478
/**
509479
* tomoyo_task_alloc - Target for security_task_alloc().
510480
*
@@ -543,81 +513,3 @@ static void tomoyo_task_free(struct task_struct *task)
543513
s->old_domain_info = NULL;
544514
}
545515
}
546-
547-
static const struct lsm_id tomoyo_lsmid = {
548-
.name = "tomoyo",
549-
.id = LSM_ID_TOMOYO,
550-
};
551-
552-
/*
553-
* tomoyo_security_ops is a "struct security_operations" which is used for
554-
* registering TOMOYO.
555-
*/
556-
static struct security_hook_list tomoyo_hooks[] __ro_after_init = {
557-
LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),
558-
LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds),
559-
LSM_HOOK_INIT(task_alloc, tomoyo_task_alloc),
560-
LSM_HOOK_INIT(task_free, tomoyo_task_free),
561-
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
562-
LSM_HOOK_INIT(bprm_creds_for_exec, tomoyo_bprm_creds_for_exec),
563-
#endif
564-
LSM_HOOK_INIT(bprm_check_security, tomoyo_bprm_check_security),
565-
LSM_HOOK_INIT(file_fcntl, tomoyo_file_fcntl),
566-
LSM_HOOK_INIT(file_open, tomoyo_file_open),
567-
LSM_HOOK_INIT(file_truncate, tomoyo_file_truncate),
568-
LSM_HOOK_INIT(path_truncate, tomoyo_path_truncate),
569-
LSM_HOOK_INIT(path_unlink, tomoyo_path_unlink),
570-
LSM_HOOK_INIT(path_mkdir, tomoyo_path_mkdir),
571-
LSM_HOOK_INIT(path_rmdir, tomoyo_path_rmdir),
572-
LSM_HOOK_INIT(path_symlink, tomoyo_path_symlink),
573-
LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod),
574-
LSM_HOOK_INIT(path_link, tomoyo_path_link),
575-
LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
576-
LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr),
577-
LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
578-
LSM_HOOK_INIT(file_ioctl_compat, tomoyo_file_ioctl),
579-
LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
580-
LSM_HOOK_INIT(path_chown, tomoyo_path_chown),
581-
LSM_HOOK_INIT(path_chroot, tomoyo_path_chroot),
582-
LSM_HOOK_INIT(sb_mount, tomoyo_sb_mount),
583-
LSM_HOOK_INIT(sb_umount, tomoyo_sb_umount),
584-
LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot),
585-
LSM_HOOK_INIT(socket_bind, tomoyo_socket_bind),
586-
LSM_HOOK_INIT(socket_connect, tomoyo_socket_connect),
587-
LSM_HOOK_INIT(socket_listen, tomoyo_socket_listen),
588-
LSM_HOOK_INIT(socket_sendmsg, tomoyo_socket_sendmsg),
589-
};
590-
591-
/* Lock for GC. */
592-
DEFINE_SRCU(tomoyo_ss);
593-
594-
int tomoyo_enabled __ro_after_init = 1;
595-
596-
/**
597-
* tomoyo_init - Register TOMOYO Linux as a LSM module.
598-
*
599-
* Returns 0.
600-
*/
601-
static int __init tomoyo_init(void)
602-
{
603-
struct tomoyo_task *s = tomoyo_task(current);
604-
605-
/* register ourselves with the security framework */
606-
security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks),
607-
&tomoyo_lsmid);
608-
pr_info("TOMOYO Linux initialized\n");
609-
s->domain_info = &tomoyo_kernel_domain;
610-
atomic_inc(&tomoyo_kernel_domain.users);
611-
s->old_domain_info = NULL;
612-
tomoyo_mm_init();
613-
614-
return 0;
615-
}
616-
617-
DEFINE_LSM(tomoyo) = {
618-
.name = "tomoyo",
619-
.enabled = &tomoyo_enabled,
620-
.flags = LSM_FLAG_LEGACY_MAJOR,
621-
.blobs = &tomoyo_blob_sizes,
622-
.init = tomoyo_init,
623-
};

security/tomoyo/init.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* security/tomoyo/init.c
4+
*
5+
* Copyright (C) 2005-2011 NTT DATA CORPORATION
6+
*/
7+
8+
#include <linux/lsm_hooks.h>
9+
#include <uapi/linux/lsm.h>
10+
#include "common.h"
11+
12+
#include "hooks.h"
13+
14+
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
15+
static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm)
16+
{
17+
/*
18+
* Load policy if /sbin/tomoyo-init exists and /sbin/init is requested
19+
* for the first time.
20+
*/
21+
if (!tomoyo_policy_loaded)
22+
tomoyo_load_policy(bprm->filename);
23+
return 0;
24+
}
25+
#endif
26+
27+
struct lsm_blob_sizes tomoyo_blob_sizes __ro_after_init = {
28+
.lbs_task = sizeof(struct tomoyo_task),
29+
};
30+
31+
static const struct lsm_id tomoyo_lsmid = {
32+
.name = "tomoyo",
33+
.id = LSM_ID_TOMOYO,
34+
};
35+
36+
/* tomoyo_hooks is used for registering TOMOYO. */
37+
static struct security_hook_list tomoyo_hooks[] __ro_after_init = {
38+
LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),
39+
LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds),
40+
LSM_HOOK_INIT(task_alloc, tomoyo_task_alloc),
41+
LSM_HOOK_INIT(task_free, tomoyo_task_free),
42+
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
43+
LSM_HOOK_INIT(bprm_creds_for_exec, tomoyo_bprm_creds_for_exec),
44+
#endif
45+
LSM_HOOK_INIT(bprm_check_security, tomoyo_bprm_check_security),
46+
LSM_HOOK_INIT(file_fcntl, tomoyo_file_fcntl),
47+
LSM_HOOK_INIT(file_open, tomoyo_file_open),
48+
LSM_HOOK_INIT(file_truncate, tomoyo_file_truncate),
49+
LSM_HOOK_INIT(path_truncate, tomoyo_path_truncate),
50+
LSM_HOOK_INIT(path_unlink, tomoyo_path_unlink),
51+
LSM_HOOK_INIT(path_mkdir, tomoyo_path_mkdir),
52+
LSM_HOOK_INIT(path_rmdir, tomoyo_path_rmdir),
53+
LSM_HOOK_INIT(path_symlink, tomoyo_path_symlink),
54+
LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod),
55+
LSM_HOOK_INIT(path_link, tomoyo_path_link),
56+
LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
57+
LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr),
58+
LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
59+
LSM_HOOK_INIT(file_ioctl_compat, tomoyo_file_ioctl),
60+
LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
61+
LSM_HOOK_INIT(path_chown, tomoyo_path_chown),
62+
LSM_HOOK_INIT(path_chroot, tomoyo_path_chroot),
63+
LSM_HOOK_INIT(sb_mount, tomoyo_sb_mount),
64+
LSM_HOOK_INIT(sb_umount, tomoyo_sb_umount),
65+
LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot),
66+
LSM_HOOK_INIT(socket_bind, tomoyo_socket_bind),
67+
LSM_HOOK_INIT(socket_connect, tomoyo_socket_connect),
68+
LSM_HOOK_INIT(socket_listen, tomoyo_socket_listen),
69+
LSM_HOOK_INIT(socket_sendmsg, tomoyo_socket_sendmsg),
70+
};
71+
72+
int tomoyo_enabled __ro_after_init = 1;
73+
74+
/* Has /sbin/init started? */
75+
bool tomoyo_policy_loaded;
76+
77+
/**
78+
* tomoyo_init - Register TOMOYO Linux as a LSM module.
79+
*
80+
* Returns 0.
81+
*/
82+
static int __init tomoyo_init(void)
83+
{
84+
struct tomoyo_task *s = tomoyo_task(current);
85+
86+
/* register ourselves with the security framework */
87+
security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks),
88+
&tomoyo_lsmid);
89+
pr_info("TOMOYO Linux initialized\n");
90+
s->domain_info = &tomoyo_kernel_domain;
91+
atomic_inc(&tomoyo_kernel_domain.users);
92+
s->old_domain_info = NULL;
93+
tomoyo_mm_init();
94+
95+
return 0;
96+
}
97+
98+
DEFINE_LSM(tomoyo) = {
99+
.name = "tomoyo",
100+
.enabled = &tomoyo_enabled,
101+
.flags = LSM_FLAG_LEGACY_MAJOR,
102+
.blobs = &tomoyo_blob_sizes,
103+
.init = tomoyo_init,
104+
};

security/tomoyo/securityfs_if.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ static void __init tomoyo_create_entry(const char *name, const umode_t mode,
229229
}
230230

231231
/**
232-
* tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
232+
* tomoyo_interface_init - Initialize /sys/kernel/security/tomoyo/ interface.
233233
*
234234
* Returns 0.
235235
*/
236-
static int __init tomoyo_initerface_init(void)
236+
static int __init tomoyo_interface_init(void)
237237
{
238238
struct tomoyo_domain_info *domain;
239239
struct dentry *tomoyo_dir;
@@ -270,4 +270,4 @@ static int __init tomoyo_initerface_init(void)
270270
return 0;
271271
}
272272

273-
fs_initcall(tomoyo_initerface_init);
273+
fs_initcall(tomoyo_interface_init);

security/tomoyo/util.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
/* Lock for protecting policy. */
1414
DEFINE_MUTEX(tomoyo_policy_lock);
1515

16-
/* Has /sbin/init started? */
17-
bool tomoyo_policy_loaded;
18-
1916
/*
2017
* Mapping table from "enum tomoyo_mac_index" to
2118
* "enum tomoyo_mac_category_index".

0 commit comments

Comments
 (0)