tomoyo.c 15.7 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
K
Kentaro Takeda 已提交
2 3 4
/*
 * security/tomoyo/tomoyo.c
 *
T
Tetsuo Handa 已提交
5
 * Copyright (C) 2005-2011  NTT DATA CORPORATION
K
Kentaro Takeda 已提交
6 7
 */

C
Casey Schaufler 已提交
8
#include <linux/lsm_hooks.h>
K
Kentaro Takeda 已提交
9 10
#include "common.h"

T
Tetsuo Handa 已提交
11
/**
12
 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
T
Tetsuo Handa 已提交
13
 *
14
 * Returns pointer to "struct tomoyo_domain_info" for current thread.
T
Tetsuo Handa 已提交
15
 */
16
struct tomoyo_domain_info *tomoyo_domain(void)
17
{
18
	struct tomoyo_task *s = tomoyo_task(current);
19

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

T
Tetsuo Handa 已提交
27 28 29 30 31 32 33 34 35
/**
 * tomoyo_cred_prepare - Target for security_prepare_creds().
 *
 * @new: Pointer to "struct cred".
 * @old: Pointer to "struct cred".
 * @gfp: Memory allocation flags.
 *
 * Returns 0.
 */
K
Kentaro Takeda 已提交
36 37 38
static int tomoyo_cred_prepare(struct cred *new, const struct cred *old,
			       gfp_t gfp)
{
39 40
	/* Restore old_domain_info saved by previous execve() request. */
	struct tomoyo_task *s = tomoyo_task(current);
41

42 43 44 45 46
	if (s->old_domain_info && !current->in_execve) {
		atomic_dec(&s->domain_info->users);
		s->domain_info = s->old_domain_info;
		s->old_domain_info = NULL;
	}
K
Kentaro Takeda 已提交
47 48 49
	return 0;
}

T
Tetsuo Handa 已提交
50
/**
51
 * tomoyo_bprm_committed_creds - Target for security_bprm_committed_creds().
T
Tetsuo Handa 已提交
52
 *
53
 * @bprm: Pointer to "struct linux_binprm".
T
Tetsuo Handa 已提交
54
 */
55
static void tomoyo_bprm_committed_creds(struct linux_binprm *bprm)
56
{
57 58
	/* Clear old_domain_info saved by execve() request. */
	struct tomoyo_task *s = tomoyo_task(current);
59

60 61
	atomic_dec(&s->old_domain_info->users);
	s->old_domain_info = NULL;
62 63
}

64
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
T
Tetsuo Handa 已提交
65
/**
C
ChenXiaoSong 已提交
66
 * tomoyo_bprm_creds_for_exec - Target for security_bprm_creds_for_exec().
T
Tetsuo Handa 已提交
67 68 69
 *
 * @bprm: Pointer to "struct linux_binprm".
 *
70
 * Returns 0.
T
Tetsuo Handa 已提交
71
 */
72
static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm)
K
Kentaro Takeda 已提交
73 74 75 76 77 78 79 80 81
{
	/*
	 * Load policy if /sbin/tomoyo-init exists and /sbin/init is requested
	 * for the first time.
	 */
	if (!tomoyo_policy_loaded)
		tomoyo_load_policy(bprm->filename);
	return 0;
}
82
#endif
K
Kentaro Takeda 已提交
83

T
Tetsuo Handa 已提交
84 85 86 87 88 89 90
/**
 * tomoyo_bprm_check_security - Target for security_bprm_check().
 *
 * @bprm: Pointer to "struct linux_binprm".
 *
 * Returns 0 on success, negative value otherwise.
 */
K
Kentaro Takeda 已提交
91 92
static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
{
93
	struct tomoyo_task *s = tomoyo_task(current);
K
Kentaro Takeda 已提交
94 95

	/*
96
	 * Execute permission is checked against pathname passed to execve()
K
Kentaro Takeda 已提交
97 98
	 * using current domain.
	 */
99
	if (!s->old_domain_info) {
100 101
		const int idx = tomoyo_read_lock();
		const int err = tomoyo_find_next_domain(bprm);
T
Tetsuo Handa 已提交
102

103 104 105
		tomoyo_read_unlock(idx);
		return err;
	}
K
Kentaro Takeda 已提交
106 107 108
	/*
	 * Read permission is checked against interpreters using next domain.
	 */
109 110
	return tomoyo_check_open_permission(s->domain_info,
					    &bprm->file->f_path, O_RDONLY);
K
Kentaro Takeda 已提交
111 112
}

T
Tetsuo Handa 已提交
113 114 115
/**
 * tomoyo_inode_getattr - Target for security_inode_getattr().
 *
C
ChenXiaoSong 已提交
116
 * @path: Pointer to "struct path".
T
Tetsuo Handa 已提交
117 118 119
 *
 * Returns 0 on success, negative value otherwise.
 */
120
static int tomoyo_inode_getattr(const struct path *path)
T
Tetsuo Handa 已提交
121
{
122
	return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
T
Tetsuo Handa 已提交
123 124
}

T
Tetsuo Handa 已提交
125 126 127 128 129 130 131
/**
 * tomoyo_path_truncate - Target for security_path_truncate().
 *
 * @path: Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
132
static int tomoyo_path_truncate(const struct path *path)
K
Kentaro Takeda 已提交
133
{
T
Tetsuo Handa 已提交
134
	return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL);
K
Kentaro Takeda 已提交
135 136
}

T
Tetsuo Handa 已提交
137 138 139 140 141 142 143 144
/**
 * tomoyo_path_unlink - Target for security_path_unlink().
 *
 * @parent: Pointer to "struct path".
 * @dentry: Pointer to "struct dentry".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
145
static int tomoyo_path_unlink(const struct path *parent, struct dentry *dentry)
K
Kentaro Takeda 已提交
146
{
K
Kees Cook 已提交
147
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
148

T
Tetsuo Handa 已提交
149
	return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
K
Kentaro Takeda 已提交
150 151
}

T
Tetsuo Handa 已提交
152 153 154 155 156 157 158 159 160
/**
 * tomoyo_path_mkdir - Target for security_path_mkdir().
 *
 * @parent: Pointer to "struct path".
 * @dentry: Pointer to "struct dentry".
 * @mode:   DAC permission mode.
 *
 * Returns 0 on success, negative value otherwise.
 */
161
static int tomoyo_path_mkdir(const struct path *parent, struct dentry *dentry,
A
Al Viro 已提交
162
			     umode_t mode)
K
Kentaro Takeda 已提交
163
{
K
Kees Cook 已提交
164
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
165

166 167
	return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
				       mode & S_IALLUGO);
K
Kentaro Takeda 已提交
168 169
}

T
Tetsuo Handa 已提交
170 171 172 173 174 175 176 177
/**
 * tomoyo_path_rmdir - Target for security_path_rmdir().
 *
 * @parent: Pointer to "struct path".
 * @dentry: Pointer to "struct dentry".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
178
static int tomoyo_path_rmdir(const struct path *parent, struct dentry *dentry)
K
Kentaro Takeda 已提交
179
{
K
Kees Cook 已提交
180
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
181

T
Tetsuo Handa 已提交
182
	return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
K
Kentaro Takeda 已提交
183 184
}

T
Tetsuo Handa 已提交
185 186 187 188 189 190 191 192 193
/**
 * tomoyo_path_symlink - Target for security_path_symlink().
 *
 * @parent:   Pointer to "struct path".
 * @dentry:   Pointer to "struct dentry".
 * @old_name: Symlink's content.
 *
 * Returns 0 on success, negative value otherwise.
 */
194
static int tomoyo_path_symlink(const struct path *parent, struct dentry *dentry,
K
Kentaro Takeda 已提交
195 196
			       const char *old_name)
{
K
Kees Cook 已提交
197
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
198

T
Tetsuo Handa 已提交
199
	return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
K
Kentaro Takeda 已提交
200 201
}

T
Tetsuo Handa 已提交
202 203 204 205 206 207 208 209 210 211
/**
 * tomoyo_path_mknod - Target for security_path_mknod().
 *
 * @parent: Pointer to "struct path".
 * @dentry: Pointer to "struct dentry".
 * @mode:   DAC permission mode.
 * @dev:    Device attributes.
 *
 * Returns 0 on success, negative value otherwise.
 */
212
static int tomoyo_path_mknod(const struct path *parent, struct dentry *dentry,
A
Al Viro 已提交
213
			     umode_t mode, unsigned int dev)
K
Kentaro Takeda 已提交
214
{
K
Kees Cook 已提交
215
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
216
	int type = TOMOYO_TYPE_CREATE;
217
	const unsigned int perm = mode & S_IALLUGO;
K
Kentaro Takeda 已提交
218 219 220

	switch (mode & S_IFMT) {
	case S_IFCHR:
T
Tetsuo Handa 已提交
221
		type = TOMOYO_TYPE_MKCHAR;
K
Kentaro Takeda 已提交
222 223
		break;
	case S_IFBLK:
T
Tetsuo Handa 已提交
224
		type = TOMOYO_TYPE_MKBLOCK;
K
Kentaro Takeda 已提交
225
		break;
226 227 228
	default:
		goto no_dev;
	}
T
Tetsuo Handa 已提交
229
	return tomoyo_mkdev_perm(type, &path, perm, dev);
230 231
 no_dev:
	switch (mode & S_IFMT) {
K
Kentaro Takeda 已提交
232
	case S_IFIFO:
T
Tetsuo Handa 已提交
233
		type = TOMOYO_TYPE_MKFIFO;
K
Kentaro Takeda 已提交
234 235
		break;
	case S_IFSOCK:
T
Tetsuo Handa 已提交
236
		type = TOMOYO_TYPE_MKSOCK;
K
Kentaro Takeda 已提交
237 238
		break;
	}
239
	return tomoyo_path_number_perm(type, &path, perm);
K
Kentaro Takeda 已提交
240 241
}

T
Tetsuo Handa 已提交
242 243 244 245 246 247 248 249 250
/**
 * tomoyo_path_link - Target for security_path_link().
 *
 * @old_dentry: Pointer to "struct dentry".
 * @new_dir:    Pointer to "struct path".
 * @new_dentry: Pointer to "struct dentry".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
251
static int tomoyo_path_link(struct dentry *old_dentry, const struct path *new_dir,
K
Kentaro Takeda 已提交
252 253
			    struct dentry *new_dentry)
{
K
Kees Cook 已提交
254 255
	struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
	struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
T
Tetsuo Handa 已提交
256

257
	return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
K
Kentaro Takeda 已提交
258 259
}

T
Tetsuo Handa 已提交
260 261 262 263 264 265 266
/**
 * tomoyo_path_rename - Target for security_path_rename().
 *
 * @old_parent: Pointer to "struct path".
 * @old_dentry: Pointer to "struct dentry".
 * @new_parent: Pointer to "struct path".
 * @new_dentry: Pointer to "struct dentry".
267
 * @flags: Rename options.
T
Tetsuo Handa 已提交
268 269 270
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
271
static int tomoyo_path_rename(const struct path *old_parent,
K
Kentaro Takeda 已提交
272
			      struct dentry *old_dentry,
A
Al Viro 已提交
273
			      const struct path *new_parent,
274 275
			      struct dentry *new_dentry,
			      const unsigned int flags)
K
Kentaro Takeda 已提交
276
{
K
Kees Cook 已提交
277 278
	struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
	struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
T
Tetsuo Handa 已提交
279

280 281 282 283 284 285 286
	if (flags & RENAME_EXCHANGE) {
		const int err = tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path2,
				&path1);

		if (err)
			return err;
	}
287
	return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
K
Kentaro Takeda 已提交
288 289
}

T
Tetsuo Handa 已提交
290 291 292 293 294 295 296 297 298
/**
 * tomoyo_file_fcntl - Target for security_file_fcntl().
 *
 * @file: Pointer to "struct file".
 * @cmd:  Command for fcntl().
 * @arg:  Argument for @cmd.
 *
 * Returns 0 on success, negative value otherwise.
 */
K
Kentaro Takeda 已提交
299 300 301
static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
			     unsigned long arg)
{
T
Tetsuo Handa 已提交
302 303 304 305
	if (!(cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND)))
		return 0;
	return tomoyo_check_open_permission(tomoyo_domain(), &file->f_path,
					    O_WRONLY | (arg & O_APPEND));
K
Kentaro Takeda 已提交
306 307
}

T
Tetsuo Handa 已提交
308
/**
309
 * tomoyo_file_open - Target for security_file_open().
T
Tetsuo Handa 已提交
310
 *
C
ChenXiaoSong 已提交
311
 * @f: Pointer to "struct file".
T
Tetsuo Handa 已提交
312 313 314
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
315
static int tomoyo_file_open(struct file *f)
K
Kentaro Takeda 已提交
316
{
317
	/* Don't check read permission here if called from execve(). */
K
Kentaro Takeda 已提交
318 319
	if (current->in_execve)
		return 0;
T
Tetsuo Handa 已提交
320 321
	return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path,
					    f->f_flags);
K
Kentaro Takeda 已提交
322 323
}

T
Tetsuo Handa 已提交
324 325 326 327 328 329 330 331 332
/**
 * tomoyo_file_ioctl - Target for security_file_ioctl().
 *
 * @file: Pointer to "struct file".
 * @cmd:  Command for ioctl().
 * @arg:  Argument for @cmd.
 *
 * Returns 0 on success, negative value otherwise.
 */
333 334 335
static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
			     unsigned long arg)
{
336
	return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
337 338
}

T
Tetsuo Handa 已提交
339 340 341
/**
 * tomoyo_path_chmod - Target for security_path_chmod().
 *
342 343
 * @path: Pointer to "struct path".
 * @mode: DAC permission mode.
T
Tetsuo Handa 已提交
344 345 346
 *
 * Returns 0 on success, negative value otherwise.
 */
347
static int tomoyo_path_chmod(const struct path *path, umode_t mode)
348
{
349
	return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, path,
350
				       mode & S_IALLUGO);
351 352
}

T
Tetsuo Handa 已提交
353 354 355 356 357 358 359 360 361
/**
 * tomoyo_path_chown - Target for security_path_chown().
 *
 * @path: Pointer to "struct path".
 * @uid:  Owner ID.
 * @gid:  Group ID.
 *
 * Returns 0 on success, negative value otherwise.
 */
362
static int tomoyo_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
363 364
{
	int error = 0;
T
Tetsuo Handa 已提交
365

366 367 368 369 370 371
	if (uid_valid(uid))
		error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path,
						from_kuid(&init_user_ns, uid));
	if (!error && gid_valid(gid))
		error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path,
						from_kgid(&init_user_ns, gid));
372 373 374
	return error;
}

T
Tetsuo Handa 已提交
375 376 377 378 379 380 381
/**
 * tomoyo_path_chroot - Target for security_path_chroot().
 *
 * @path: Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
382
static int tomoyo_path_chroot(const struct path *path)
383
{
T
Tetsuo Handa 已提交
384
	return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL);
385 386
}

T
Tetsuo Handa 已提交
387 388 389 390 391 392 393 394 395 396 397
/**
 * tomoyo_sb_mount - Target for security_sb_mount().
 *
 * @dev_name: Name of device file. Maybe NULL.
 * @path:     Pointer to "struct path".
 * @type:     Name of filesystem type. Maybe NULL.
 * @flags:    Mount options.
 * @data:     Optional data. Maybe NULL.
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
398
static int tomoyo_sb_mount(const char *dev_name, const struct path *path,
A
Al Viro 已提交
399
			   const char *type, unsigned long flags, void *data)
400
{
T
Tetsuo Handa 已提交
401
	return tomoyo_mount_permission(dev_name, path, type, flags, data);
402 403
}

T
Tetsuo Handa 已提交
404 405 406 407 408 409 410 411
/**
 * tomoyo_sb_umount - Target for security_sb_umount().
 *
 * @mnt:   Pointer to "struct vfsmount".
 * @flags: Unmount options.
 *
 * Returns 0 on success, negative value otherwise.
 */
412 413
static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
{
K
Kees Cook 已提交
414
	struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
T
Tetsuo Handa 已提交
415

T
Tetsuo Handa 已提交
416
	return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
417 418
}

T
Tetsuo Handa 已提交
419 420 421 422 423 424 425 426
/**
 * tomoyo_sb_pivotroot - Target for security_sb_pivotroot().
 *
 * @old_path: Pointer to "struct path".
 * @new_path: Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
427
static int tomoyo_sb_pivotroot(const struct path *old_path, const struct path *new_path)
428
{
429
	return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
430 431
}

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
/**
 * tomoyo_socket_listen - Check permission for listen().
 *
 * @sock:    Pointer to "struct socket".
 * @backlog: Backlog parameter.
 *
 * Returns 0 on success, negative value otherwise.
 */
static int tomoyo_socket_listen(struct socket *sock, int backlog)
{
	return tomoyo_socket_listen_permission(sock);
}

/**
 * tomoyo_socket_connect - Check permission for connect().
 *
 * @sock:     Pointer to "struct socket".
 * @addr:     Pointer to "struct sockaddr".
 * @addr_len: Size of @addr.
 *
 * Returns 0 on success, negative value otherwise.
 */
static int tomoyo_socket_connect(struct socket *sock, struct sockaddr *addr,
				 int addr_len)
{
	return tomoyo_socket_connect_permission(sock, addr, addr_len);
}

/**
 * tomoyo_socket_bind - Check permission for bind().
 *
 * @sock:     Pointer to "struct socket".
 * @addr:     Pointer to "struct sockaddr".
 * @addr_len: Size of @addr.
 *
 * Returns 0 on success, negative value otherwise.
 */
static int tomoyo_socket_bind(struct socket *sock, struct sockaddr *addr,
			      int addr_len)
{
	return tomoyo_socket_bind_permission(sock, addr, addr_len);
}

/**
 * tomoyo_socket_sendmsg - Check permission for sendmsg().
 *
 * @sock: Pointer to "struct socket".
 * @msg:  Pointer to "struct msghdr".
 * @size: Size of message.
 *
 * Returns 0 on success, negative value otherwise.
 */
static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
				 int size)
{
	return tomoyo_socket_sendmsg_permission(sock, msg, size);
}

490
struct lsm_blob_sizes tomoyo_blob_sizes __lsm_ro_after_init = {
491
	.lbs_task = sizeof(struct tomoyo_task),
492 493
};

494 495 496
/**
 * tomoyo_task_alloc - Target for security_task_alloc().
 *
C
ChenXiaoSong 已提交
497 498
 * @task:        Pointer to "struct task_struct".
 * @clone_flags: clone() flags.
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
 *
 * Returns 0.
 */
static int tomoyo_task_alloc(struct task_struct *task,
			     unsigned long clone_flags)
{
	struct tomoyo_task *old = tomoyo_task(current);
	struct tomoyo_task *new = tomoyo_task(task);

	new->domain_info = old->domain_info;
	atomic_inc(&new->domain_info->users);
	new->old_domain_info = NULL;
	return 0;
}

/**
 * tomoyo_task_free - Target for security_task_free().
 *
 * @task: Pointer to "struct task_struct".
 */
static void tomoyo_task_free(struct task_struct *task)
{
	struct tomoyo_task *s = tomoyo_task(task);

	if (s->domain_info) {
		atomic_dec(&s->domain_info->users);
		s->domain_info = NULL;
	}
	if (s->old_domain_info) {
		atomic_dec(&s->old_domain_info->users);
		s->old_domain_info = NULL;
	}
}

533 534 535 536
/*
 * tomoyo_security_ops is a "struct security_operations" which is used for
 * registering TOMOYO.
 */
537
static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = {
538
	LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),
539 540 541 542
	LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds),
	LSM_HOOK_INIT(task_alloc, tomoyo_task_alloc),
	LSM_HOOK_INIT(task_free, tomoyo_task_free),
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
543
	LSM_HOOK_INIT(bprm_creds_for_exec, tomoyo_bprm_creds_for_exec),
544
#endif
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
	LSM_HOOK_INIT(bprm_check_security, tomoyo_bprm_check_security),
	LSM_HOOK_INIT(file_fcntl, tomoyo_file_fcntl),
	LSM_HOOK_INIT(file_open, tomoyo_file_open),
	LSM_HOOK_INIT(path_truncate, tomoyo_path_truncate),
	LSM_HOOK_INIT(path_unlink, tomoyo_path_unlink),
	LSM_HOOK_INIT(path_mkdir, tomoyo_path_mkdir),
	LSM_HOOK_INIT(path_rmdir, tomoyo_path_rmdir),
	LSM_HOOK_INIT(path_symlink, tomoyo_path_symlink),
	LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod),
	LSM_HOOK_INIT(path_link, tomoyo_path_link),
	LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
	LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr),
	LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
	LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
	LSM_HOOK_INIT(path_chown, tomoyo_path_chown),
	LSM_HOOK_INIT(path_chroot, tomoyo_path_chroot),
	LSM_HOOK_INIT(sb_mount, tomoyo_sb_mount),
	LSM_HOOK_INIT(sb_umount, tomoyo_sb_umount),
	LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot),
	LSM_HOOK_INIT(socket_bind, tomoyo_socket_bind),
	LSM_HOOK_INIT(socket_connect, tomoyo_socket_connect),
	LSM_HOOK_INIT(socket_listen, tomoyo_socket_listen),
	LSM_HOOK_INIT(socket_sendmsg, tomoyo_socket_sendmsg),
K
Kentaro Takeda 已提交
568 569
};

570
/* Lock for GC. */
571
DEFINE_SRCU(tomoyo_ss);
572

573 574
int tomoyo_enabled __lsm_ro_after_init = 1;

T
Tetsuo Handa 已提交
575 576 577 578 579
/**
 * tomoyo_init - Register TOMOYO Linux as a LSM module.
 *
 * Returns 0.
 */
K
Kentaro Takeda 已提交
580 581
static int __init tomoyo_init(void)
{
582
	struct tomoyo_task *s = tomoyo_task(current);
K
Kentaro Takeda 已提交
583 584

	/* register ourselves with the security framework */
585
	security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
T
Tetsuo Handa 已提交
586
	pr_info("TOMOYO Linux initialized\n");
587 588 589
	s->domain_info = &tomoyo_kernel_domain;
	atomic_inc(&tomoyo_kernel_domain.users);
	s->old_domain_info = NULL;
590
	tomoyo_mm_init();
591

K
Kentaro Takeda 已提交
592 593 594
	return 0;
}

595
DEFINE_LSM(tomoyo) = {
596
	.name = "tomoyo",
597
	.enabled = &tomoyo_enabled,
598
	.flags = LSM_FLAG_LEGACY_MAJOR,
599
	.blobs = &tomoyo_blob_sizes,
600 601
	.init = tomoyo_init,
};