tomoyo.c 15.5 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 13 14 15 16 17 18
/**
 * tomoyo_cred_alloc_blank - Target for security_cred_alloc_blank().
 *
 * @new: Pointer to "struct cred".
 * @gfp: Memory allocation flags.
 *
 * Returns 0.
 */
19 20
static int tomoyo_cred_alloc_blank(struct cred *new, gfp_t gfp)
{
21 22 23
	struct tomoyo_domain_info **blob = tomoyo_cred(new);

	*blob = NULL;
24 25 26
	return 0;
}

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 41 42 43 44 45
	struct tomoyo_domain_info **old_blob = tomoyo_cred(old);
	struct tomoyo_domain_info **new_blob = tomoyo_cred(new);
	struct tomoyo_domain_info *domain;

	domain = *old_blob;
	*new_blob = domain;

46 47
	if (domain)
		atomic_inc(&domain->users);
K
Kentaro Takeda 已提交
48 49 50
	return 0;
}

T
Tetsuo Handa 已提交
51 52 53 54 55 56
/**
 * tomoyo_cred_transfer - Target for security_transfer_creds().
 *
 * @new: Pointer to "struct cred".
 * @old: Pointer to "struct cred".
 */
57 58
static void tomoyo_cred_transfer(struct cred *new, const struct cred *old)
{
59 60 61
	tomoyo_cred_prepare(new, old, 0);
}

T
Tetsuo Handa 已提交
62 63 64 65 66
/**
 * tomoyo_cred_free - Target for security_cred_free().
 *
 * @cred: Pointer to "struct cred".
 */
67 68
static void tomoyo_cred_free(struct cred *cred)
{
69 70 71
	struct tomoyo_domain_info **blob = tomoyo_cred(cred);
	struct tomoyo_domain_info *domain = *blob;

72 73
	if (domain)
		atomic_dec(&domain->users);
74 75
}

T
Tetsuo Handa 已提交
76 77 78 79 80 81 82
/**
 * tomoyo_bprm_set_creds - Target for security_bprm_set_creds().
 *
 * @bprm: Pointer to "struct linux_binprm".
 *
 * Returns 0 on success, negative value otherwise.
 */
K
Kentaro Takeda 已提交
83 84
static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)
{
85 86 87
	struct tomoyo_domain_info **blob;
	struct tomoyo_domain_info *domain;

K
Kentaro Takeda 已提交
88 89 90 91
	/*
	 * Do only if this function is called for the first time of an execve
	 * operation.
	 */
92
	if (bprm->called_set_creds)
K
Kentaro Takeda 已提交
93
		return 0;
94
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
K
Kentaro Takeda 已提交
95 96 97 98 99 100
	/*
	 * 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);
101
#endif
102 103 104 105 106 107
	/*
	 * Release reference to "struct tomoyo_domain_info" stored inside
	 * "bprm->cred->security". New reference to "struct tomoyo_domain_info"
	 * stored inside "bprm->cred->security" will be acquired later inside
	 * tomoyo_find_next_domain().
	 */
108 109 110
	blob = tomoyo_cred(bprm->cred);
	domain = *blob;
	atomic_dec(&domain->users);
K
Kentaro Takeda 已提交
111 112 113 114
	/*
	 * Tell tomoyo_bprm_check_security() is called for the first time of an
	 * execve operation.
	 */
115
	*blob = NULL;
K
Kentaro Takeda 已提交
116 117 118
	return 0;
}

T
Tetsuo Handa 已提交
119 120 121 122 123 124 125
/**
 * 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 已提交
126 127
static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
{
128 129
	struct tomoyo_domain_info **blob;
	struct tomoyo_domain_info *domain;
K
Kentaro Takeda 已提交
130

131 132
	blob = tomoyo_cred(bprm->cred);
	domain = *blob;
K
Kentaro Takeda 已提交
133 134 135 136
	/*
	 * Execute permission is checked against pathname passed to do_execve()
	 * using current domain.
	 */
137 138 139 140 141 142
	if (!domain) {
		const int idx = tomoyo_read_lock();
		const int err = tomoyo_find_next_domain(bprm);
		tomoyo_read_unlock(idx);
		return err;
	}
K
Kentaro Takeda 已提交
143 144 145
	/*
	 * Read permission is checked against interpreters using next domain.
	 */
T
Tetsuo Handa 已提交
146 147
	return tomoyo_check_open_permission(domain, &bprm->file->f_path,
					    O_RDONLY);
K
Kentaro Takeda 已提交
148 149
}

T
Tetsuo Handa 已提交
150 151 152 153 154 155 156 157
/**
 * tomoyo_inode_getattr - Target for security_inode_getattr().
 *
 * @mnt:    Pointer to "struct vfsmount".
 * @dentry: Pointer to "struct dentry".
 *
 * Returns 0 on success, negative value otherwise.
 */
158
static int tomoyo_inode_getattr(const struct path *path)
T
Tetsuo Handa 已提交
159
{
160
	return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
T
Tetsuo Handa 已提交
161 162
}

T
Tetsuo Handa 已提交
163 164 165 166 167 168 169
/**
 * tomoyo_path_truncate - Target for security_path_truncate().
 *
 * @path: Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
170
static int tomoyo_path_truncate(const struct path *path)
K
Kentaro Takeda 已提交
171
{
T
Tetsuo Handa 已提交
172
	return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL);
K
Kentaro Takeda 已提交
173 174
}

T
Tetsuo Handa 已提交
175 176 177 178 179 180 181 182
/**
 * 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 已提交
183
static int tomoyo_path_unlink(const struct path *parent, struct dentry *dentry)
K
Kentaro Takeda 已提交
184
{
K
Kees Cook 已提交
185
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
186
	return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
K
Kentaro Takeda 已提交
187 188
}

T
Tetsuo Handa 已提交
189 190 191 192 193 194 195 196 197
/**
 * 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.
 */
198
static int tomoyo_path_mkdir(const struct path *parent, struct dentry *dentry,
A
Al Viro 已提交
199
			     umode_t mode)
K
Kentaro Takeda 已提交
200
{
K
Kees Cook 已提交
201
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
202 203
	return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
				       mode & S_IALLUGO);
K
Kentaro Takeda 已提交
204 205
}

T
Tetsuo Handa 已提交
206 207 208 209 210 211 212 213
/**
 * 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 已提交
214
static int tomoyo_path_rmdir(const struct path *parent, struct dentry *dentry)
K
Kentaro Takeda 已提交
215
{
K
Kees Cook 已提交
216
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
217
	return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
K
Kentaro Takeda 已提交
218 219
}

T
Tetsuo Handa 已提交
220 221 222 223 224 225 226 227 228
/**
 * 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.
 */
229
static int tomoyo_path_symlink(const struct path *parent, struct dentry *dentry,
K
Kentaro Takeda 已提交
230 231
			       const char *old_name)
{
K
Kees Cook 已提交
232
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
233
	return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
K
Kentaro Takeda 已提交
234 235
}

T
Tetsuo Handa 已提交
236 237 238 239 240 241 242 243 244 245
/**
 * 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.
 */
246
static int tomoyo_path_mknod(const struct path *parent, struct dentry *dentry,
A
Al Viro 已提交
247
			     umode_t mode, unsigned int dev)
K
Kentaro Takeda 已提交
248
{
K
Kees Cook 已提交
249
	struct path path = { .mnt = parent->mnt, .dentry = dentry };
T
Tetsuo Handa 已提交
250
	int type = TOMOYO_TYPE_CREATE;
251
	const unsigned int perm = mode & S_IALLUGO;
K
Kentaro Takeda 已提交
252 253 254

	switch (mode & S_IFMT) {
	case S_IFCHR:
T
Tetsuo Handa 已提交
255
		type = TOMOYO_TYPE_MKCHAR;
K
Kentaro Takeda 已提交
256 257
		break;
	case S_IFBLK:
T
Tetsuo Handa 已提交
258
		type = TOMOYO_TYPE_MKBLOCK;
K
Kentaro Takeda 已提交
259
		break;
260 261 262
	default:
		goto no_dev;
	}
T
Tetsuo Handa 已提交
263
	return tomoyo_mkdev_perm(type, &path, perm, dev);
264 265
 no_dev:
	switch (mode & S_IFMT) {
K
Kentaro Takeda 已提交
266
	case S_IFIFO:
T
Tetsuo Handa 已提交
267
		type = TOMOYO_TYPE_MKFIFO;
K
Kentaro Takeda 已提交
268 269
		break;
	case S_IFSOCK:
T
Tetsuo Handa 已提交
270
		type = TOMOYO_TYPE_MKSOCK;
K
Kentaro Takeda 已提交
271 272
		break;
	}
273
	return tomoyo_path_number_perm(type, &path, perm);
K
Kentaro Takeda 已提交
274 275
}

T
Tetsuo Handa 已提交
276 277 278 279 280 281 282 283 284
/**
 * 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 已提交
285
static int tomoyo_path_link(struct dentry *old_dentry, const struct path *new_dir,
K
Kentaro Takeda 已提交
286 287
			    struct dentry *new_dentry)
{
K
Kees Cook 已提交
288 289
	struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
	struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
290
	return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
K
Kentaro Takeda 已提交
291 292
}

T
Tetsuo Handa 已提交
293 294 295 296 297 298 299 300 301 302
/**
 * 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".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
303
static int tomoyo_path_rename(const struct path *old_parent,
K
Kentaro Takeda 已提交
304
			      struct dentry *old_dentry,
A
Al Viro 已提交
305
			      const struct path *new_parent,
K
Kentaro Takeda 已提交
306 307
			      struct dentry *new_dentry)
{
K
Kees Cook 已提交
308 309
	struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
	struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
310
	return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
K
Kentaro Takeda 已提交
311 312
}

T
Tetsuo Handa 已提交
313 314 315 316 317 318 319 320 321
/**
 * 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 已提交
322 323 324
static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
			     unsigned long arg)
{
T
Tetsuo Handa 已提交
325 326 327 328
	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 已提交
329 330
}

T
Tetsuo Handa 已提交
331
/**
332
 * tomoyo_file_open - Target for security_file_open().
T
Tetsuo Handa 已提交
333 334 335 336 337 338
 *
 * @f:    Pointer to "struct file".
 * @cred: Pointer to "struct cred".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
339
static int tomoyo_file_open(struct file *f)
K
Kentaro Takeda 已提交
340 341 342 343 344 345 346 347
{
	int flags = f->f_flags;
	/* Don't check read permission here if called from do_execve(). */
	if (current->in_execve)
		return 0;
	return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, flags);
}

T
Tetsuo Handa 已提交
348 349 350 351 352 353 354 355 356
/**
 * 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.
 */
357 358 359
static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
			     unsigned long arg)
{
360
	return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
361 362
}

T
Tetsuo Handa 已提交
363 364 365
/**
 * tomoyo_path_chmod - Target for security_path_chmod().
 *
366 367
 * @path: Pointer to "struct path".
 * @mode: DAC permission mode.
T
Tetsuo Handa 已提交
368 369 370
 *
 * Returns 0 on success, negative value otherwise.
 */
371
static int tomoyo_path_chmod(const struct path *path, umode_t mode)
372
{
373
	return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, path,
374
				       mode & S_IALLUGO);
375 376
}

T
Tetsuo Handa 已提交
377 378 379 380 381 382 383 384 385
/**
 * 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.
 */
386
static int tomoyo_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
387 388
{
	int error = 0;
389 390 391 392 393 394
	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));
395 396 397
	return error;
}

T
Tetsuo Handa 已提交
398 399 400 401 402 403 404
/**
 * tomoyo_path_chroot - Target for security_path_chroot().
 *
 * @path: Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
A
Al Viro 已提交
405
static int tomoyo_path_chroot(const struct path *path)
406
{
T
Tetsuo Handa 已提交
407
	return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL);
408 409
}

T
Tetsuo Handa 已提交
410 411 412 413 414 415 416 417 418 419 420
/**
 * 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 已提交
421
static int tomoyo_sb_mount(const char *dev_name, const struct path *path,
A
Al Viro 已提交
422
			   const char *type, unsigned long flags, void *data)
423
{
T
Tetsuo Handa 已提交
424
	return tomoyo_mount_permission(dev_name, path, type, flags, data);
425 426
}

T
Tetsuo Handa 已提交
427 428 429 430 431 432 433 434
/**
 * tomoyo_sb_umount - Target for security_sb_umount().
 *
 * @mnt:   Pointer to "struct vfsmount".
 * @flags: Unmount options.
 *
 * Returns 0 on success, negative value otherwise.
 */
435 436
static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
{
K
Kees Cook 已提交
437
	struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
T
Tetsuo Handa 已提交
438
	return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
439 440
}

T
Tetsuo Handa 已提交
441 442 443 444 445 446 447 448
/**
 * 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 已提交
449
static int tomoyo_sb_pivotroot(const struct path *old_path, const struct path *new_path)
450
{
451
	return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
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 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
/**
 * 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);
}

512 513 514 515
struct lsm_blob_sizes tomoyo_blob_sizes __lsm_ro_after_init = {
	.lbs_cred = sizeof(struct tomoyo_domain_info *),
};

516 517 518 519
/*
 * tomoyo_security_ops is a "struct security_operations" which is used for
 * registering TOMOYO.
 */
520
static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = {
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
	LSM_HOOK_INIT(cred_alloc_blank, tomoyo_cred_alloc_blank),
	LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),
	LSM_HOOK_INIT(cred_transfer, tomoyo_cred_transfer),
	LSM_HOOK_INIT(cred_free, tomoyo_cred_free),
	LSM_HOOK_INIT(bprm_set_creds, tomoyo_bprm_set_creds),
	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 已提交
549 550
};

551
/* Lock for GC. */
552
DEFINE_SRCU(tomoyo_ss);
553

554 555
int tomoyo_enabled __lsm_ro_after_init = 1;

T
Tetsuo Handa 已提交
556 557 558 559 560
/**
 * tomoyo_init - Register TOMOYO Linux as a LSM module.
 *
 * Returns 0.
 */
K
Kentaro Takeda 已提交
561 562 563
static int __init tomoyo_init(void)
{
	struct cred *cred = (struct cred *) current_cred();
564
	struct tomoyo_domain_info **blob;
K
Kentaro Takeda 已提交
565 566

	/* register ourselves with the security framework */
567
	security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
K
Kentaro Takeda 已提交
568
	printk(KERN_INFO "TOMOYO Linux initialized\n");
569
	lsm_early_cred(cred);
570 571
	blob = tomoyo_cred(cred);
	*blob = &tomoyo_kernel_domain;
572
	tomoyo_mm_init();
573

K
Kentaro Takeda 已提交
574 575 576
	return 0;
}

577
DEFINE_LSM(tomoyo) = {
578
	.name = "tomoyo",
579
	.enabled = &tomoyo_enabled,
580
	.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
581
	.blobs = &tomoyo_blob_sizes,
582 583
	.init = tomoyo_init,
};