Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 2 | /* |
| 3 | * security/tomoyo/tomoyo.c |
| 4 | * |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 5 | * Copyright (C) 2005-2011 NTT DATA CORPORATION |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
Casey Schaufler | 3c4ed7b | 2015-05-02 15:10:46 -0700 | [diff] [blame] | 8 | #include <linux/lsm_hooks.h> |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 9 | #include "common.h" |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 10 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 11 | /** |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 12 | * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread. |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 13 | * |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 14 | * Returns pointer to "struct tomoyo_domain_info" for current thread. |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 15 | */ |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 16 | struct tomoyo_domain_info *tomoyo_domain(void) |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 17 | { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 18 | struct tomoyo_task *s = tomoyo_task(current); |
Casey Schaufler | 43fc460 | 2018-09-21 17:18:07 -0700 | [diff] [blame] | 19 | |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 20 | if (s->old_domain_info && !current->in_execve) { |
| 21 | atomic_dec(&s->old_domain_info->users); |
| 22 | s->old_domain_info = NULL; |
| 23 | } |
| 24 | return s->domain_info; |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 27 | /** |
| 28 | * tomoyo_cred_prepare - Target for security_prepare_creds(). |
| 29 | * |
| 30 | * @new: Pointer to "struct cred". |
| 31 | * @old: Pointer to "struct cred". |
| 32 | * @gfp: Memory allocation flags. |
| 33 | * |
| 34 | * Returns 0. |
| 35 | */ |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 36 | static int tomoyo_cred_prepare(struct cred *new, const struct cred *old, |
| 37 | gfp_t gfp) |
| 38 | { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 39 | /* Restore old_domain_info saved by previous execve() request. */ |
| 40 | struct tomoyo_task *s = tomoyo_task(current); |
Casey Schaufler | 43fc460 | 2018-09-21 17:18:07 -0700 | [diff] [blame] | 41 | |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 42 | if (s->old_domain_info && !current->in_execve) { |
| 43 | atomic_dec(&s->domain_info->users); |
| 44 | s->domain_info = s->old_domain_info; |
| 45 | s->old_domain_info = NULL; |
| 46 | } |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 50 | /** |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 51 | * tomoyo_bprm_committed_creds - Target for security_bprm_committed_creds(). |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 52 | * |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 53 | * @bprm: Pointer to "struct linux_binprm". |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 54 | */ |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 55 | static void tomoyo_bprm_committed_creds(struct linux_binprm *bprm) |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 56 | { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 57 | /* Clear old_domain_info saved by execve() request. */ |
| 58 | struct tomoyo_task *s = tomoyo_task(current); |
| 59 | |
| 60 | atomic_dec(&s->old_domain_info->users); |
| 61 | s->old_domain_info = NULL; |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 62 | } |
| 63 | |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 64 | #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 65 | /** |
ChenXiaoSong | 98eaa63 | 2021-06-10 15:49:00 +0800 | [diff] [blame] | 66 | * tomoyo_bprm_creds_for_exec - Target for security_bprm_creds_for_exec(). |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 67 | * |
| 68 | * @bprm: Pointer to "struct linux_binprm". |
| 69 | * |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 70 | * Returns 0. |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 71 | */ |
Eric W. Biederman | b8bff59 | 2020-03-22 15:46:24 -0500 | [diff] [blame] | 72 | static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 73 | { |
| 74 | /* |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 75 | * Load policy if /sbin/tomoyo-init exists and /sbin/init is requested |
| 76 | * for the first time. |
| 77 | */ |
| 78 | if (!tomoyo_policy_loaded) |
| 79 | tomoyo_load_policy(bprm->filename); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 80 | return 0; |
| 81 | } |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 82 | #endif |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 83 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 84 | /** |
| 85 | * tomoyo_bprm_check_security - Target for security_bprm_check(). |
| 86 | * |
| 87 | * @bprm: Pointer to "struct linux_binprm". |
| 88 | * |
| 89 | * Returns 0 on success, negative value otherwise. |
| 90 | */ |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 91 | static int tomoyo_bprm_check_security(struct linux_binprm *bprm) |
| 92 | { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 93 | struct tomoyo_task *s = tomoyo_task(current); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 94 | |
| 95 | /* |
Eric W. Biederman | be619f7 | 2020-07-13 12:06:48 -0500 | [diff] [blame] | 96 | * Execute permission is checked against pathname passed to execve() |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 97 | * using current domain. |
| 98 | */ |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 99 | if (!s->old_domain_info) { |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 100 | const int idx = tomoyo_read_lock(); |
| 101 | const int err = tomoyo_find_next_domain(bprm); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 102 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 103 | tomoyo_read_unlock(idx); |
| 104 | return err; |
| 105 | } |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 106 | /* |
| 107 | * Read permission is checked against interpreters using next domain. |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 108 | */ |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 109 | return tomoyo_check_open_permission(s->domain_info, |
| 110 | &bprm->file->f_path, O_RDONLY); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 113 | /** |
| 114 | * tomoyo_inode_getattr - Target for security_inode_getattr(). |
| 115 | * |
ChenXiaoSong | 98eaa63 | 2021-06-10 15:49:00 +0800 | [diff] [blame] | 116 | * @path: Pointer to "struct path". |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 117 | * |
| 118 | * Returns 0 on success, negative value otherwise. |
| 119 | */ |
Al Viro | 3f7036a | 2015-03-08 19:28:30 -0400 | [diff] [blame] | 120 | static int tomoyo_inode_getattr(const struct path *path) |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 121 | { |
Al Viro | 3f7036a | 2015-03-08 19:28:30 -0400 | [diff] [blame] | 122 | return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 123 | } |
| 124 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 125 | /** |
| 126 | * tomoyo_path_truncate - Target for security_path_truncate(). |
| 127 | * |
| 128 | * @path: Pointer to "struct path". |
| 129 | * |
| 130 | * Returns 0 on success, negative value otherwise. |
| 131 | */ |
Al Viro | 81f4c50 | 2016-03-25 14:22:01 -0400 | [diff] [blame] | 132 | static int tomoyo_path_truncate(const struct path *path) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 133 | { |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 134 | return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 135 | } |
| 136 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 137 | /** |
| 138 | * tomoyo_path_unlink - Target for security_path_unlink(). |
| 139 | * |
| 140 | * @parent: Pointer to "struct path". |
| 141 | * @dentry: Pointer to "struct dentry". |
| 142 | * |
| 143 | * Returns 0 on success, negative value otherwise. |
| 144 | */ |
Al Viro | 989f74e | 2016-03-25 15:13:39 -0400 | [diff] [blame] | 145 | static int tomoyo_path_unlink(const struct path *parent, struct dentry *dentry) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 146 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 147 | struct path path = { .mnt = parent->mnt, .dentry = dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 148 | |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 149 | return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 150 | } |
| 151 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 152 | /** |
| 153 | * tomoyo_path_mkdir - Target for security_path_mkdir(). |
| 154 | * |
| 155 | * @parent: Pointer to "struct path". |
| 156 | * @dentry: Pointer to "struct dentry". |
| 157 | * @mode: DAC permission mode. |
| 158 | * |
| 159 | * Returns 0 on success, negative value otherwise. |
| 160 | */ |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 161 | static int tomoyo_path_mkdir(const struct path *parent, struct dentry *dentry, |
Al Viro | 4572bef | 2011-11-21 14:56:21 -0500 | [diff] [blame] | 162 | umode_t mode) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 163 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 164 | struct path path = { .mnt = parent->mnt, .dentry = dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 165 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 166 | return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path, |
| 167 | mode & S_IALLUGO); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 168 | } |
| 169 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 170 | /** |
| 171 | * tomoyo_path_rmdir - Target for security_path_rmdir(). |
| 172 | * |
| 173 | * @parent: Pointer to "struct path". |
| 174 | * @dentry: Pointer to "struct dentry". |
| 175 | * |
| 176 | * Returns 0 on success, negative value otherwise. |
| 177 | */ |
Al Viro | 989f74e | 2016-03-25 15:13:39 -0400 | [diff] [blame] | 178 | static int tomoyo_path_rmdir(const struct path *parent, struct dentry *dentry) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 179 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 180 | struct path path = { .mnt = parent->mnt, .dentry = dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 181 | |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 182 | return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 185 | /** |
| 186 | * tomoyo_path_symlink - Target for security_path_symlink(). |
| 187 | * |
| 188 | * @parent: Pointer to "struct path". |
| 189 | * @dentry: Pointer to "struct dentry". |
| 190 | * @old_name: Symlink's content. |
| 191 | * |
| 192 | * Returns 0 on success, negative value otherwise. |
| 193 | */ |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 194 | static int tomoyo_path_symlink(const struct path *parent, struct dentry *dentry, |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 195 | const char *old_name) |
| 196 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 197 | struct path path = { .mnt = parent->mnt, .dentry = dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 198 | |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 199 | return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 200 | } |
| 201 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 202 | /** |
| 203 | * tomoyo_path_mknod - Target for security_path_mknod(). |
| 204 | * |
| 205 | * @parent: Pointer to "struct path". |
| 206 | * @dentry: Pointer to "struct dentry". |
| 207 | * @mode: DAC permission mode. |
| 208 | * @dev: Device attributes. |
| 209 | * |
| 210 | * Returns 0 on success, negative value otherwise. |
| 211 | */ |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 212 | static int tomoyo_path_mknod(const struct path *parent, struct dentry *dentry, |
Al Viro | 04fc66e | 2011-11-21 14:58:38 -0500 | [diff] [blame] | 213 | umode_t mode, unsigned int dev) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 214 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 215 | struct path path = { .mnt = parent->mnt, .dentry = dentry }; |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 216 | int type = TOMOYO_TYPE_CREATE; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 217 | const unsigned int perm = mode & S_IALLUGO; |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 218 | |
| 219 | switch (mode & S_IFMT) { |
| 220 | case S_IFCHR: |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 221 | type = TOMOYO_TYPE_MKCHAR; |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 222 | break; |
| 223 | case S_IFBLK: |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 224 | type = TOMOYO_TYPE_MKBLOCK; |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 225 | break; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 226 | default: |
| 227 | goto no_dev; |
| 228 | } |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 229 | return tomoyo_mkdev_perm(type, &path, perm, dev); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 230 | no_dev: |
| 231 | switch (mode & S_IFMT) { |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 232 | case S_IFIFO: |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 233 | type = TOMOYO_TYPE_MKFIFO; |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 234 | break; |
| 235 | case S_IFSOCK: |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 236 | type = TOMOYO_TYPE_MKSOCK; |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 237 | break; |
| 238 | } |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 239 | return tomoyo_path_number_perm(type, &path, perm); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 240 | } |
| 241 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 242 | /** |
| 243 | * tomoyo_path_link - Target for security_path_link(). |
| 244 | * |
| 245 | * @old_dentry: Pointer to "struct dentry". |
| 246 | * @new_dir: Pointer to "struct path". |
| 247 | * @new_dentry: Pointer to "struct dentry". |
| 248 | * |
| 249 | * Returns 0 on success, negative value otherwise. |
| 250 | */ |
Al Viro | 3ccee46 | 2016-03-25 15:27:45 -0400 | [diff] [blame] | 251 | static int tomoyo_path_link(struct dentry *old_dentry, const struct path *new_dir, |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 252 | struct dentry *new_dentry) |
| 253 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 254 | struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry }; |
| 255 | struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 256 | |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 257 | return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 258 | } |
| 259 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 260 | /** |
| 261 | * tomoyo_path_rename - Target for security_path_rename(). |
| 262 | * |
| 263 | * @old_parent: Pointer to "struct path". |
| 264 | * @old_dentry: Pointer to "struct dentry". |
| 265 | * @new_parent: Pointer to "struct path". |
| 266 | * @new_dentry: Pointer to "struct dentry". |
| 267 | * |
| 268 | * Returns 0 on success, negative value otherwise. |
| 269 | */ |
Al Viro | 3ccee46 | 2016-03-25 15:27:45 -0400 | [diff] [blame] | 270 | static int tomoyo_path_rename(const struct path *old_parent, |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 271 | struct dentry *old_dentry, |
Al Viro | 3ccee46 | 2016-03-25 15:27:45 -0400 | [diff] [blame] | 272 | const struct path *new_parent, |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 273 | struct dentry *new_dentry) |
| 274 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 275 | struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry }; |
| 276 | struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 277 | |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 278 | return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 279 | } |
| 280 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 281 | /** |
| 282 | * tomoyo_file_fcntl - Target for security_file_fcntl(). |
| 283 | * |
| 284 | * @file: Pointer to "struct file". |
| 285 | * @cmd: Command for fcntl(). |
| 286 | * @arg: Argument for @cmd. |
| 287 | * |
| 288 | * Returns 0 on success, negative value otherwise. |
| 289 | */ |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 290 | static int tomoyo_file_fcntl(struct file *file, unsigned int cmd, |
| 291 | unsigned long arg) |
| 292 | { |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 293 | if (!(cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND))) |
| 294 | return 0; |
| 295 | return tomoyo_check_open_permission(tomoyo_domain(), &file->f_path, |
| 296 | O_WRONLY | (arg & O_APPEND)); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 297 | } |
| 298 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 299 | /** |
Eric Paris | 83d4985 | 2012-04-04 13:45:40 -0400 | [diff] [blame] | 300 | * tomoyo_file_open - Target for security_file_open(). |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 301 | * |
ChenXiaoSong | 98eaa63 | 2021-06-10 15:49:00 +0800 | [diff] [blame] | 302 | * @f: Pointer to "struct file". |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 303 | * |
| 304 | * Returns 0 on success, negative value otherwise. |
| 305 | */ |
Al Viro | 9481769 | 2018-07-10 14:13:18 -0400 | [diff] [blame] | 306 | static int tomoyo_file_open(struct file *f) |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 307 | { |
Eric W. Biederman | be619f7 | 2020-07-13 12:06:48 -0500 | [diff] [blame] | 308 | /* Don't check read permission here if called from execve(). */ |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 309 | if (current->in_execve) |
| 310 | return 0; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 311 | return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, |
| 312 | f->f_flags); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 315 | /** |
| 316 | * tomoyo_file_ioctl - Target for security_file_ioctl(). |
| 317 | * |
| 318 | * @file: Pointer to "struct file". |
| 319 | * @cmd: Command for ioctl(). |
| 320 | * @arg: Argument for @cmd. |
| 321 | * |
| 322 | * Returns 0 on success, negative value otherwise. |
| 323 | */ |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 324 | static int tomoyo_file_ioctl(struct file *file, unsigned int cmd, |
| 325 | unsigned long arg) |
| 326 | { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 327 | return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 328 | } |
| 329 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 330 | /** |
| 331 | * tomoyo_path_chmod - Target for security_path_chmod(). |
| 332 | * |
Al Viro | cdcf116 | 2011-12-08 10:51:53 -0500 | [diff] [blame] | 333 | * @path: Pointer to "struct path". |
| 334 | * @mode: DAC permission mode. |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 335 | * |
| 336 | * Returns 0 on success, negative value otherwise. |
| 337 | */ |
Al Viro | be01f9f | 2016-03-25 14:56:23 -0400 | [diff] [blame] | 338 | static int tomoyo_path_chmod(const struct path *path, umode_t mode) |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 339 | { |
Al Viro | cdcf116 | 2011-12-08 10:51:53 -0500 | [diff] [blame] | 340 | return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, path, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 341 | mode & S_IALLUGO); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 342 | } |
| 343 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 344 | /** |
| 345 | * tomoyo_path_chown - Target for security_path_chown(). |
| 346 | * |
| 347 | * @path: Pointer to "struct path". |
| 348 | * @uid: Owner ID. |
| 349 | * @gid: Group ID. |
| 350 | * |
| 351 | * Returns 0 on success, negative value otherwise. |
| 352 | */ |
Al Viro | 7fd25da | 2016-03-25 14:44:41 -0400 | [diff] [blame] | 353 | static int tomoyo_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 354 | { |
| 355 | int error = 0; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 356 | |
Eric W. Biederman | d2b31ca | 2012-06-01 16:14:19 -0600 | [diff] [blame] | 357 | if (uid_valid(uid)) |
| 358 | error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path, |
| 359 | from_kuid(&init_user_ns, uid)); |
| 360 | if (!error && gid_valid(gid)) |
| 361 | error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path, |
| 362 | from_kgid(&init_user_ns, gid)); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 363 | return error; |
| 364 | } |
| 365 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 366 | /** |
| 367 | * tomoyo_path_chroot - Target for security_path_chroot(). |
| 368 | * |
| 369 | * @path: Pointer to "struct path". |
| 370 | * |
| 371 | * Returns 0 on success, negative value otherwise. |
| 372 | */ |
Al Viro | 77b286c | 2016-03-25 15:28:43 -0400 | [diff] [blame] | 373 | static int tomoyo_path_chroot(const struct path *path) |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 374 | { |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 375 | return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 376 | } |
| 377 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 378 | /** |
| 379 | * tomoyo_sb_mount - Target for security_sb_mount(). |
| 380 | * |
| 381 | * @dev_name: Name of device file. Maybe NULL. |
| 382 | * @path: Pointer to "struct path". |
| 383 | * @type: Name of filesystem type. Maybe NULL. |
| 384 | * @flags: Mount options. |
| 385 | * @data: Optional data. Maybe NULL. |
| 386 | * |
| 387 | * Returns 0 on success, negative value otherwise. |
| 388 | */ |
Al Viro | 8a04c43 | 2016-03-25 14:52:53 -0400 | [diff] [blame] | 389 | static int tomoyo_sb_mount(const char *dev_name, const struct path *path, |
Al Viro | 808d4e3 | 2012-10-11 11:42:01 -0400 | [diff] [blame] | 390 | const char *type, unsigned long flags, void *data) |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 391 | { |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 392 | return tomoyo_mount_permission(dev_name, path, type, flags, data); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 393 | } |
| 394 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 395 | /** |
| 396 | * tomoyo_sb_umount - Target for security_sb_umount(). |
| 397 | * |
| 398 | * @mnt: Pointer to "struct vfsmount". |
| 399 | * @flags: Unmount options. |
| 400 | * |
| 401 | * Returns 0 on success, negative value otherwise. |
| 402 | */ |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 403 | static int tomoyo_sb_umount(struct vfsmount *mnt, int flags) |
| 404 | { |
Kees Cook | 8291798 | 2017-03-29 16:52:58 -0700 | [diff] [blame] | 405 | struct path path = { .mnt = mnt, .dentry = mnt->mnt_root }; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 406 | |
Tetsuo Handa | 97fb35e | 2011-07-08 13:25:53 +0900 | [diff] [blame] | 407 | return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 408 | } |
| 409 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 410 | /** |
| 411 | * tomoyo_sb_pivotroot - Target for security_sb_pivotroot(). |
| 412 | * |
| 413 | * @old_path: Pointer to "struct path". |
| 414 | * @new_path: Pointer to "struct path". |
| 415 | * |
| 416 | * Returns 0 on success, negative value otherwise. |
| 417 | */ |
Al Viro | 3b73b68 | 2016-03-25 15:31:19 -0400 | [diff] [blame] | 418 | static int tomoyo_sb_pivotroot(const struct path *old_path, const struct path *new_path) |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 419 | { |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 420 | return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path); |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 421 | } |
| 422 | |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 423 | /** |
| 424 | * tomoyo_socket_listen - Check permission for listen(). |
| 425 | * |
| 426 | * @sock: Pointer to "struct socket". |
| 427 | * @backlog: Backlog parameter. |
| 428 | * |
| 429 | * Returns 0 on success, negative value otherwise. |
| 430 | */ |
| 431 | static int tomoyo_socket_listen(struct socket *sock, int backlog) |
| 432 | { |
| 433 | return tomoyo_socket_listen_permission(sock); |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * tomoyo_socket_connect - Check permission for connect(). |
| 438 | * |
| 439 | * @sock: Pointer to "struct socket". |
| 440 | * @addr: Pointer to "struct sockaddr". |
| 441 | * @addr_len: Size of @addr. |
| 442 | * |
| 443 | * Returns 0 on success, negative value otherwise. |
| 444 | */ |
| 445 | static int tomoyo_socket_connect(struct socket *sock, struct sockaddr *addr, |
| 446 | int addr_len) |
| 447 | { |
| 448 | return tomoyo_socket_connect_permission(sock, addr, addr_len); |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * tomoyo_socket_bind - Check permission for bind(). |
| 453 | * |
| 454 | * @sock: Pointer to "struct socket". |
| 455 | * @addr: Pointer to "struct sockaddr". |
| 456 | * @addr_len: Size of @addr. |
| 457 | * |
| 458 | * Returns 0 on success, negative value otherwise. |
| 459 | */ |
| 460 | static int tomoyo_socket_bind(struct socket *sock, struct sockaddr *addr, |
| 461 | int addr_len) |
| 462 | { |
| 463 | return tomoyo_socket_bind_permission(sock, addr, addr_len); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * tomoyo_socket_sendmsg - Check permission for sendmsg(). |
| 468 | * |
| 469 | * @sock: Pointer to "struct socket". |
| 470 | * @msg: Pointer to "struct msghdr". |
| 471 | * @size: Size of message. |
| 472 | * |
| 473 | * Returns 0 on success, negative value otherwise. |
| 474 | */ |
| 475 | static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg, |
| 476 | int size) |
| 477 | { |
| 478 | return tomoyo_socket_sendmsg_permission(sock, msg, size); |
| 479 | } |
| 480 | |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 481 | struct lsm_blob_sizes tomoyo_blob_sizes __lsm_ro_after_init = { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 482 | .lbs_task = sizeof(struct tomoyo_task), |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 483 | }; |
| 484 | |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 485 | /** |
| 486 | * tomoyo_task_alloc - Target for security_task_alloc(). |
| 487 | * |
ChenXiaoSong | 98eaa63 | 2021-06-10 15:49:00 +0800 | [diff] [blame] | 488 | * @task: Pointer to "struct task_struct". |
| 489 | * @clone_flags: clone() flags. |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 490 | * |
| 491 | * Returns 0. |
| 492 | */ |
| 493 | static int tomoyo_task_alloc(struct task_struct *task, |
| 494 | unsigned long clone_flags) |
| 495 | { |
| 496 | struct tomoyo_task *old = tomoyo_task(current); |
| 497 | struct tomoyo_task *new = tomoyo_task(task); |
| 498 | |
| 499 | new->domain_info = old->domain_info; |
| 500 | atomic_inc(&new->domain_info->users); |
| 501 | new->old_domain_info = NULL; |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * tomoyo_task_free - Target for security_task_free(). |
| 507 | * |
| 508 | * @task: Pointer to "struct task_struct". |
| 509 | */ |
| 510 | static void tomoyo_task_free(struct task_struct *task) |
| 511 | { |
| 512 | struct tomoyo_task *s = tomoyo_task(task); |
| 513 | |
| 514 | if (s->domain_info) { |
| 515 | atomic_dec(&s->domain_info->users); |
| 516 | s->domain_info = NULL; |
| 517 | } |
| 518 | if (s->old_domain_info) { |
| 519 | atomic_dec(&s->old_domain_info->users); |
| 520 | s->old_domain_info = NULL; |
| 521 | } |
| 522 | } |
| 523 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 524 | /* |
| 525 | * tomoyo_security_ops is a "struct security_operations" which is used for |
| 526 | * registering TOMOYO. |
| 527 | */ |
James Morris | ca97d93 | 2017-02-15 00:18:51 +1100 | [diff] [blame] | 528 | static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = { |
Casey Schaufler | e20b043 | 2015-05-02 15:11:36 -0700 | [diff] [blame] | 529 | LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare), |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 530 | LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds), |
| 531 | LSM_HOOK_INIT(task_alloc, tomoyo_task_alloc), |
| 532 | LSM_HOOK_INIT(task_free, tomoyo_task_free), |
| 533 | #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER |
Eric W. Biederman | b8bff59 | 2020-03-22 15:46:24 -0500 | [diff] [blame] | 534 | LSM_HOOK_INIT(bprm_creds_for_exec, tomoyo_bprm_creds_for_exec), |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 535 | #endif |
Casey Schaufler | e20b043 | 2015-05-02 15:11:36 -0700 | [diff] [blame] | 536 | LSM_HOOK_INIT(bprm_check_security, tomoyo_bprm_check_security), |
| 537 | LSM_HOOK_INIT(file_fcntl, tomoyo_file_fcntl), |
| 538 | LSM_HOOK_INIT(file_open, tomoyo_file_open), |
| 539 | LSM_HOOK_INIT(path_truncate, tomoyo_path_truncate), |
| 540 | LSM_HOOK_INIT(path_unlink, tomoyo_path_unlink), |
| 541 | LSM_HOOK_INIT(path_mkdir, tomoyo_path_mkdir), |
| 542 | LSM_HOOK_INIT(path_rmdir, tomoyo_path_rmdir), |
| 543 | LSM_HOOK_INIT(path_symlink, tomoyo_path_symlink), |
| 544 | LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod), |
| 545 | LSM_HOOK_INIT(path_link, tomoyo_path_link), |
| 546 | LSM_HOOK_INIT(path_rename, tomoyo_path_rename), |
| 547 | LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr), |
| 548 | LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl), |
| 549 | LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod), |
| 550 | LSM_HOOK_INIT(path_chown, tomoyo_path_chown), |
| 551 | LSM_HOOK_INIT(path_chroot, tomoyo_path_chroot), |
| 552 | LSM_HOOK_INIT(sb_mount, tomoyo_sb_mount), |
| 553 | LSM_HOOK_INIT(sb_umount, tomoyo_sb_umount), |
| 554 | LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot), |
| 555 | LSM_HOOK_INIT(socket_bind, tomoyo_socket_bind), |
| 556 | LSM_HOOK_INIT(socket_connect, tomoyo_socket_connect), |
| 557 | LSM_HOOK_INIT(socket_listen, tomoyo_socket_listen), |
| 558 | LSM_HOOK_INIT(socket_sendmsg, tomoyo_socket_sendmsg), |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 559 | }; |
| 560 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 561 | /* Lock for GC. */ |
Lai Jiangshan | 505f14f | 2013-03-16 00:50:53 +0800 | [diff] [blame] | 562 | DEFINE_SRCU(tomoyo_ss); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 563 | |
Casey Schaufler | 43fc460 | 2018-09-21 17:18:07 -0700 | [diff] [blame] | 564 | int tomoyo_enabled __lsm_ro_after_init = 1; |
| 565 | |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 566 | /** |
| 567 | * tomoyo_init - Register TOMOYO Linux as a LSM module. |
| 568 | * |
| 569 | * Returns 0. |
| 570 | */ |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 571 | static int __init tomoyo_init(void) |
| 572 | { |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 573 | struct tomoyo_task *s = tomoyo_task(current); |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 574 | |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 575 | /* register ourselves with the security framework */ |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 576 | security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo"); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 577 | pr_info("TOMOYO Linux initialized\n"); |
Tetsuo Handa | 8c6cb98 | 2019-01-19 23:11:40 +0900 | [diff] [blame] | 578 | s->domain_info = &tomoyo_kernel_domain; |
| 579 | atomic_inc(&tomoyo_kernel_domain.users); |
| 580 | s->old_domain_info = NULL; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 581 | tomoyo_mm_init(); |
Casey Schaufler | 43fc460 | 2018-09-21 17:18:07 -0700 | [diff] [blame] | 582 | |
Kentaro Takeda | f743324 | 2009-02-05 17:18:16 +0900 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
Kees Cook | 3d6e5f6 | 2018-10-10 17:18:23 -0700 | [diff] [blame] | 586 | DEFINE_LSM(tomoyo) = { |
Kees Cook | 07aed2f | 2018-10-10 17:18:24 -0700 | [diff] [blame] | 587 | .name = "tomoyo", |
Casey Schaufler | 43fc460 | 2018-09-21 17:18:07 -0700 | [diff] [blame] | 588 | .enabled = &tomoyo_enabled, |
Kees Cook | a5e2fe7 | 2018-10-12 12:07:39 -0700 | [diff] [blame] | 589 | .flags = LSM_FLAG_LEGACY_MAJOR, |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 590 | .blobs = &tomoyo_blob_sizes, |
Kees Cook | 3d6e5f6 | 2018-10-10 17:18:23 -0700 | [diff] [blame] | 591 | .init = tomoyo_init, |
| 592 | }; |