security: Create file_truncate hook from path_truncate hook
[linux-block.git] / security / tomoyo / tomoyo.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
f7433243
KT
2/*
3 * security/tomoyo/tomoyo.c
4 *
0f2a55d5 5 * Copyright (C) 2005-2011 NTT DATA CORPORATION
f7433243
KT
6 */
7
3c4ed7bd 8#include <linux/lsm_hooks.h>
f7433243 9#include "common.h"
f7433243 10
0f2a55d5 11/**
8c6cb983 12 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
0f2a55d5 13 *
8c6cb983 14 * Returns pointer to "struct tomoyo_domain_info" for current thread.
0f2a55d5 15 */
8c6cb983 16struct tomoyo_domain_info *tomoyo_domain(void)
ee18d64c 17{
8c6cb983 18 struct tomoyo_task *s = tomoyo_task(current);
43fc4609 19
8c6cb983
TH
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;
ee18d64c
DH
25}
26
0f2a55d5
TH
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 */
f7433243
KT
36static int tomoyo_cred_prepare(struct cred *new, const struct cred *old,
37 gfp_t gfp)
38{
8c6cb983
TH
39 /* Restore old_domain_info saved by previous execve() request. */
40 struct tomoyo_task *s = tomoyo_task(current);
43fc4609 41
8c6cb983
TH
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 }
f7433243
KT
47 return 0;
48}
49
0f2a55d5 50/**
8c6cb983 51 * tomoyo_bprm_committed_creds - Target for security_bprm_committed_creds().
0f2a55d5 52 *
8c6cb983 53 * @bprm: Pointer to "struct linux_binprm".
0f2a55d5 54 */
8c6cb983 55static void tomoyo_bprm_committed_creds(struct linux_binprm *bprm)
ec8e6a4e 56{
8c6cb983
TH
57 /* Clear old_domain_info saved by execve() request. */
58 struct tomoyo_task *s = tomoyo_task(current);
43fc4609 59
8c6cb983
TH
60 atomic_dec(&s->old_domain_info->users);
61 s->old_domain_info = NULL;
ee18d64c
DH
62}
63
8c6cb983 64#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
0f2a55d5 65/**
98eaa63e 66 * tomoyo_bprm_creds_for_exec - Target for security_bprm_creds_for_exec().
0f2a55d5
TH
67 *
68 * @bprm: Pointer to "struct linux_binprm".
69 *
8c6cb983 70 * Returns 0.
0f2a55d5 71 */
b8bff599 72static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm)
f7433243 73{
f7433243
KT
74 /*
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);
f7433243
KT
80 return 0;
81}
8c6cb983 82#endif
f7433243 83
0f2a55d5
TH
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 */
f7433243
KT
91static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
92{
8c6cb983 93 struct tomoyo_task *s = tomoyo_task(current);
f7433243
KT
94
95 /*
be619f7f 96 * Execute permission is checked against pathname passed to execve()
f7433243
KT
97 * using current domain.
98 */
8c6cb983 99 if (!s->old_domain_info) {
fdb8ebb7
TH
100 const int idx = tomoyo_read_lock();
101 const int err = tomoyo_find_next_domain(bprm);
cdcf6723 102
fdb8ebb7
TH
103 tomoyo_read_unlock(idx);
104 return err;
105 }
f7433243
KT
106 /*
107 * Read permission is checked against interpreters using next domain.
f7433243 108 */
8c6cb983
TH
109 return tomoyo_check_open_permission(s->domain_info,
110 &bprm->file->f_path, O_RDONLY);
f7433243
KT
111}
112
0f2a55d5
TH
113/**
114 * tomoyo_inode_getattr - Target for security_inode_getattr().
115 *
98eaa63e 116 * @path: Pointer to "struct path".
0f2a55d5
TH
117 *
118 * Returns 0 on success, negative value otherwise.
119 */
3f7036a0 120static int tomoyo_inode_getattr(const struct path *path)
7c75964f 121{
3f7036a0 122 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
7c75964f
TH
123}
124
0f2a55d5
TH
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 */
81f4c506 132static int tomoyo_path_truncate(const struct path *path)
f7433243 133{
97fb35e4 134 return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL);
f7433243
KT
135}
136
3350607d
GN
137/**
138 * tomoyo_file_truncate - Target for security_file_truncate().
139 *
140 * @file: Pointer to "struct file".
141 *
142 * Returns 0 on success, negative value otherwise.
143 */
144static int tomoyo_file_truncate(struct file *file)
145{
146 return tomoyo_path_truncate(&file->f_path);
147}
148
0f2a55d5
TH
149/**
150 * tomoyo_path_unlink - Target for security_path_unlink().
151 *
152 * @parent: Pointer to "struct path".
153 * @dentry: Pointer to "struct dentry".
154 *
155 * Returns 0 on success, negative value otherwise.
156 */
989f74e0 157static int tomoyo_path_unlink(const struct path *parent, struct dentry *dentry)
f7433243 158{
8291798d 159 struct path path = { .mnt = parent->mnt, .dentry = dentry };
cdcf6723 160
97fb35e4 161 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
f7433243
KT
162}
163
0f2a55d5
TH
164/**
165 * tomoyo_path_mkdir - Target for security_path_mkdir().
166 *
167 * @parent: Pointer to "struct path".
168 * @dentry: Pointer to "struct dentry".
169 * @mode: DAC permission mode.
170 *
171 * Returns 0 on success, negative value otherwise.
172 */
d3607752 173static int tomoyo_path_mkdir(const struct path *parent, struct dentry *dentry,
4572befe 174 umode_t mode)
f7433243 175{
8291798d 176 struct path path = { .mnt = parent->mnt, .dentry = dentry };
cdcf6723 177
a1f9bb6a
TH
178 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
179 mode & S_IALLUGO);
f7433243
KT
180}
181
0f2a55d5
TH
182/**
183 * tomoyo_path_rmdir - Target for security_path_rmdir().
184 *
185 * @parent: Pointer to "struct path".
186 * @dentry: Pointer to "struct dentry".
187 *
188 * Returns 0 on success, negative value otherwise.
189 */
989f74e0 190static int tomoyo_path_rmdir(const struct path *parent, struct dentry *dentry)
f7433243 191{
8291798d 192 struct path path = { .mnt = parent->mnt, .dentry = dentry };
cdcf6723 193
97fb35e4 194 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
f7433243
KT
195}
196
0f2a55d5
TH
197/**
198 * tomoyo_path_symlink - Target for security_path_symlink().
199 *
200 * @parent: Pointer to "struct path".
201 * @dentry: Pointer to "struct dentry".
202 * @old_name: Symlink's content.
203 *
204 * Returns 0 on success, negative value otherwise.
205 */
d3607752 206static int tomoyo_path_symlink(const struct path *parent, struct dentry *dentry,
f7433243
KT
207 const char *old_name)
208{
8291798d 209 struct path path = { .mnt = parent->mnt, .dentry = dentry };
cdcf6723 210
97fb35e4 211 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
f7433243
KT
212}
213
0f2a55d5
TH
214/**
215 * tomoyo_path_mknod - Target for security_path_mknod().
216 *
217 * @parent: Pointer to "struct path".
218 * @dentry: Pointer to "struct dentry".
219 * @mode: DAC permission mode.
220 * @dev: Device attributes.
221 *
222 * Returns 0 on success, negative value otherwise.
223 */
d3607752 224static int tomoyo_path_mknod(const struct path *parent, struct dentry *dentry,
04fc66e7 225 umode_t mode, unsigned int dev)
f7433243 226{
8291798d 227 struct path path = { .mnt = parent->mnt, .dentry = dentry };
7ef61233 228 int type = TOMOYO_TYPE_CREATE;
a1f9bb6a 229 const unsigned int perm = mode & S_IALLUGO;
f7433243
KT
230
231 switch (mode & S_IFMT) {
232 case S_IFCHR:
7ef61233 233 type = TOMOYO_TYPE_MKCHAR;
f7433243
KT
234 break;
235 case S_IFBLK:
7ef61233 236 type = TOMOYO_TYPE_MKBLOCK;
f7433243 237 break;
a1f9bb6a
TH
238 default:
239 goto no_dev;
240 }
75093152 241 return tomoyo_mkdev_perm(type, &path, perm, dev);
a1f9bb6a
TH
242 no_dev:
243 switch (mode & S_IFMT) {
f7433243 244 case S_IFIFO:
7ef61233 245 type = TOMOYO_TYPE_MKFIFO;
f7433243
KT
246 break;
247 case S_IFSOCK:
7ef61233 248 type = TOMOYO_TYPE_MKSOCK;
f7433243
KT
249 break;
250 }
a1f9bb6a 251 return tomoyo_path_number_perm(type, &path, perm);
f7433243
KT
252}
253
0f2a55d5
TH
254/**
255 * tomoyo_path_link - Target for security_path_link().
256 *
257 * @old_dentry: Pointer to "struct dentry".
258 * @new_dir: Pointer to "struct path".
259 * @new_dentry: Pointer to "struct dentry".
260 *
261 * Returns 0 on success, negative value otherwise.
262 */
3ccee46a 263static int tomoyo_path_link(struct dentry *old_dentry, const struct path *new_dir,
f7433243
KT
264 struct dentry *new_dentry)
265{
8291798d
KC
266 struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
267 struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
cdcf6723 268
97d6931e 269 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
f7433243
KT
270}
271
0f2a55d5
TH
272/**
273 * tomoyo_path_rename - Target for security_path_rename().
274 *
275 * @old_parent: Pointer to "struct path".
276 * @old_dentry: Pointer to "struct dentry".
277 * @new_parent: Pointer to "struct path".
278 * @new_dentry: Pointer to "struct dentry".
100f59d9 279 * @flags: Rename options.
0f2a55d5
TH
280 *
281 * Returns 0 on success, negative value otherwise.
282 */
3ccee46a 283static int tomoyo_path_rename(const struct path *old_parent,
f7433243 284 struct dentry *old_dentry,
3ccee46a 285 const struct path *new_parent,
100f59d9
MS
286 struct dentry *new_dentry,
287 const unsigned int flags)
f7433243 288{
8291798d
KC
289 struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
290 struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
cdcf6723 291
100f59d9
MS
292 if (flags & RENAME_EXCHANGE) {
293 const int err = tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path2,
294 &path1);
295
296 if (err)
297 return err;
298 }
97d6931e 299 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
f7433243
KT
300}
301
0f2a55d5
TH
302/**
303 * tomoyo_file_fcntl - Target for security_file_fcntl().
304 *
305 * @file: Pointer to "struct file".
306 * @cmd: Command for fcntl().
307 * @arg: Argument for @cmd.
308 *
309 * Returns 0 on success, negative value otherwise.
310 */
f7433243
KT
311static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
312 unsigned long arg)
313{
7c75964f
TH
314 if (!(cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND)))
315 return 0;
316 return tomoyo_check_open_permission(tomoyo_domain(), &file->f_path,
317 O_WRONLY | (arg & O_APPEND));
f7433243
KT
318}
319
0f2a55d5 320/**
83d49856 321 * tomoyo_file_open - Target for security_file_open().
0f2a55d5 322 *
98eaa63e 323 * @f: Pointer to "struct file".
0f2a55d5
TH
324 *
325 * Returns 0 on success, negative value otherwise.
326 */
94817692 327static int tomoyo_file_open(struct file *f)
f7433243 328{
be619f7f 329 /* Don't check read permission here if called from execve(). */
f7433243
KT
330 if (current->in_execve)
331 return 0;
cdcf6723
TH
332 return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path,
333 f->f_flags);
f7433243
KT
334}
335
0f2a55d5
TH
336/**
337 * tomoyo_file_ioctl - Target for security_file_ioctl().
338 *
339 * @file: Pointer to "struct file".
340 * @cmd: Command for ioctl().
341 * @arg: Argument for @cmd.
342 *
343 * Returns 0 on success, negative value otherwise.
344 */
937bf613
TH
345static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
346 unsigned long arg)
347{
a1f9bb6a 348 return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
937bf613
TH
349}
350
0f2a55d5
TH
351/**
352 * tomoyo_path_chmod - Target for security_path_chmod().
353 *
cdcf116d
AV
354 * @path: Pointer to "struct path".
355 * @mode: DAC permission mode.
0f2a55d5
TH
356 *
357 * Returns 0 on success, negative value otherwise.
358 */
be01f9f2 359static int tomoyo_path_chmod(const struct path *path, umode_t mode)
937bf613 360{
cdcf116d 361 return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, path,
a1f9bb6a 362 mode & S_IALLUGO);
937bf613
TH
363}
364
0f2a55d5
TH
365/**
366 * tomoyo_path_chown - Target for security_path_chown().
367 *
368 * @path: Pointer to "struct path".
369 * @uid: Owner ID.
370 * @gid: Group ID.
371 *
372 * Returns 0 on success, negative value otherwise.
373 */
7fd25dac 374static int tomoyo_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
937bf613
TH
375{
376 int error = 0;
cdcf6723 377
d2b31ca6
EB
378 if (uid_valid(uid))
379 error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path,
380 from_kuid(&init_user_ns, uid));
381 if (!error && gid_valid(gid))
382 error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path,
383 from_kgid(&init_user_ns, gid));
937bf613
TH
384 return error;
385}
386
0f2a55d5
TH
387/**
388 * tomoyo_path_chroot - Target for security_path_chroot().
389 *
390 * @path: Pointer to "struct path".
391 *
392 * Returns 0 on success, negative value otherwise.
393 */
77b286c0 394static int tomoyo_path_chroot(const struct path *path)
937bf613 395{
97fb35e4 396 return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL);
937bf613
TH
397}
398
0f2a55d5
TH
399/**
400 * tomoyo_sb_mount - Target for security_sb_mount().
401 *
402 * @dev_name: Name of device file. Maybe NULL.
403 * @path: Pointer to "struct path".
404 * @type: Name of filesystem type. Maybe NULL.
405 * @flags: Mount options.
406 * @data: Optional data. Maybe NULL.
407 *
408 * Returns 0 on success, negative value otherwise.
409 */
8a04c43b 410static int tomoyo_sb_mount(const char *dev_name, const struct path *path,
808d4e3c 411 const char *type, unsigned long flags, void *data)
937bf613 412{
2106ccd9 413 return tomoyo_mount_permission(dev_name, path, type, flags, data);
937bf613
TH
414}
415
0f2a55d5
TH
416/**
417 * tomoyo_sb_umount - Target for security_sb_umount().
418 *
419 * @mnt: Pointer to "struct vfsmount".
420 * @flags: Unmount options.
421 *
422 * Returns 0 on success, negative value otherwise.
423 */
937bf613
TH
424static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
425{
8291798d 426 struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
cdcf6723 427
97fb35e4 428 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
937bf613
TH
429}
430
0f2a55d5
TH
431/**
432 * tomoyo_sb_pivotroot - Target for security_sb_pivotroot().
433 *
434 * @old_path: Pointer to "struct path".
435 * @new_path: Pointer to "struct path".
436 *
437 * Returns 0 on success, negative value otherwise.
438 */
3b73b68c 439static int tomoyo_sb_pivotroot(const struct path *old_path, const struct path *new_path)
937bf613 440{
97d6931e 441 return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
937bf613
TH
442}
443
059d84db
TH
444/**
445 * tomoyo_socket_listen - Check permission for listen().
446 *
447 * @sock: Pointer to "struct socket".
448 * @backlog: Backlog parameter.
449 *
450 * Returns 0 on success, negative value otherwise.
451 */
452static int tomoyo_socket_listen(struct socket *sock, int backlog)
453{
454 return tomoyo_socket_listen_permission(sock);
455}
456
457/**
458 * tomoyo_socket_connect - Check permission for connect().
459 *
460 * @sock: Pointer to "struct socket".
461 * @addr: Pointer to "struct sockaddr".
462 * @addr_len: Size of @addr.
463 *
464 * Returns 0 on success, negative value otherwise.
465 */
466static int tomoyo_socket_connect(struct socket *sock, struct sockaddr *addr,
467 int addr_len)
468{
469 return tomoyo_socket_connect_permission(sock, addr, addr_len);
470}
471
472/**
473 * tomoyo_socket_bind - Check permission for bind().
474 *
475 * @sock: Pointer to "struct socket".
476 * @addr: Pointer to "struct sockaddr".
477 * @addr_len: Size of @addr.
478 *
479 * Returns 0 on success, negative value otherwise.
480 */
481static int tomoyo_socket_bind(struct socket *sock, struct sockaddr *addr,
482 int addr_len)
483{
484 return tomoyo_socket_bind_permission(sock, addr, addr_len);
485}
486
487/**
488 * tomoyo_socket_sendmsg - Check permission for sendmsg().
489 *
490 * @sock: Pointer to "struct socket".
491 * @msg: Pointer to "struct msghdr".
492 * @size: Size of message.
493 *
494 * Returns 0 on success, negative value otherwise.
495 */
496static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
497 int size)
498{
499 return tomoyo_socket_sendmsg_permission(sock, msg, size);
500}
501
bbd3662a 502struct lsm_blob_sizes tomoyo_blob_sizes __lsm_ro_after_init = {
8c6cb983 503 .lbs_task = sizeof(struct tomoyo_task),
bbd3662a
CS
504};
505
8c6cb983
TH
506/**
507 * tomoyo_task_alloc - Target for security_task_alloc().
508 *
98eaa63e
C
509 * @task: Pointer to "struct task_struct".
510 * @clone_flags: clone() flags.
8c6cb983
TH
511 *
512 * Returns 0.
513 */
514static int tomoyo_task_alloc(struct task_struct *task,
515 unsigned long clone_flags)
516{
517 struct tomoyo_task *old = tomoyo_task(current);
518 struct tomoyo_task *new = tomoyo_task(task);
519
520 new->domain_info = old->domain_info;
521 atomic_inc(&new->domain_info->users);
522 new->old_domain_info = NULL;
523 return 0;
524}
525
526/**
527 * tomoyo_task_free - Target for security_task_free().
528 *
529 * @task: Pointer to "struct task_struct".
530 */
531static void tomoyo_task_free(struct task_struct *task)
532{
533 struct tomoyo_task *s = tomoyo_task(task);
534
535 if (s->domain_info) {
536 atomic_dec(&s->domain_info->users);
537 s->domain_info = NULL;
538 }
539 if (s->old_domain_info) {
540 atomic_dec(&s->old_domain_info->users);
541 s->old_domain_info = NULL;
542 }
543}
544
c3fa109a
TH
545/*
546 * tomoyo_security_ops is a "struct security_operations" which is used for
547 * registering TOMOYO.
548 */
ca97d939 549static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = {
e20b043a 550 LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),
8c6cb983
TH
551 LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds),
552 LSM_HOOK_INIT(task_alloc, tomoyo_task_alloc),
553 LSM_HOOK_INIT(task_free, tomoyo_task_free),
554#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
b8bff599 555 LSM_HOOK_INIT(bprm_creds_for_exec, tomoyo_bprm_creds_for_exec),
8c6cb983 556#endif
e20b043a
CS
557 LSM_HOOK_INIT(bprm_check_security, tomoyo_bprm_check_security),
558 LSM_HOOK_INIT(file_fcntl, tomoyo_file_fcntl),
559 LSM_HOOK_INIT(file_open, tomoyo_file_open),
3350607d 560 LSM_HOOK_INIT(file_truncate, tomoyo_file_truncate),
e20b043a
CS
561 LSM_HOOK_INIT(path_truncate, tomoyo_path_truncate),
562 LSM_HOOK_INIT(path_unlink, tomoyo_path_unlink),
563 LSM_HOOK_INIT(path_mkdir, tomoyo_path_mkdir),
564 LSM_HOOK_INIT(path_rmdir, tomoyo_path_rmdir),
565 LSM_HOOK_INIT(path_symlink, tomoyo_path_symlink),
566 LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod),
567 LSM_HOOK_INIT(path_link, tomoyo_path_link),
568 LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
569 LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr),
570 LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
571 LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
572 LSM_HOOK_INIT(path_chown, tomoyo_path_chown),
573 LSM_HOOK_INIT(path_chroot, tomoyo_path_chroot),
574 LSM_HOOK_INIT(sb_mount, tomoyo_sb_mount),
575 LSM_HOOK_INIT(sb_umount, tomoyo_sb_umount),
576 LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot),
577 LSM_HOOK_INIT(socket_bind, tomoyo_socket_bind),
578 LSM_HOOK_INIT(socket_connect, tomoyo_socket_connect),
579 LSM_HOOK_INIT(socket_listen, tomoyo_socket_listen),
580 LSM_HOOK_INIT(socket_sendmsg, tomoyo_socket_sendmsg),
f7433243
KT
581};
582
fdb8ebb7 583/* Lock for GC. */
505f14f7 584DEFINE_SRCU(tomoyo_ss);
fdb8ebb7 585
43fc4609
CS
586int tomoyo_enabled __lsm_ro_after_init = 1;
587
0f2a55d5
TH
588/**
589 * tomoyo_init - Register TOMOYO Linux as a LSM module.
590 *
591 * Returns 0.
592 */
f7433243
KT
593static int __init tomoyo_init(void)
594{
8c6cb983 595 struct tomoyo_task *s = tomoyo_task(current);
f7433243 596
f7433243 597 /* register ourselves with the security framework */
d69dece5 598 security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
cdcf6723 599 pr_info("TOMOYO Linux initialized\n");
8c6cb983
TH
600 s->domain_info = &tomoyo_kernel_domain;
601 atomic_inc(&tomoyo_kernel_domain.users);
602 s->old_domain_info = NULL;
c3ef1500 603 tomoyo_mm_init();
43fc4609 604
f7433243
KT
605 return 0;
606}
607
3d6e5f6d 608DEFINE_LSM(tomoyo) = {
07aed2f2 609 .name = "tomoyo",
43fc4609 610 .enabled = &tomoyo_enabled,
a5e2fe7e 611 .flags = LSM_FLAG_LEGACY_MAJOR,
bbd3662a 612 .blobs = &tomoyo_blob_sizes,
3d6e5f6d
KC
613 .init = tomoyo_init,
614};