blob: 620d37c159a3948fd85faa70db3acc326a7ba281 [file] [log] [blame]
Kentaro Takedaf7433242009-02-05 17:18:16 +09001/*
2 * security/tomoyo/tomoyo.c
3 *
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +09004 * Copyright (C) 2005-2011 NTT DATA CORPORATION
Kentaro Takedaf7433242009-02-05 17:18:16 +09005 */
6
7#include <linux/security.h>
8#include "common.h"
Kentaro Takedaf7433242009-02-05 17:18:16 +09009
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +090010/**
11 * tomoyo_cred_alloc_blank - Target for security_cred_alloc_blank().
12 *
13 * @new: Pointer to "struct cred".
14 * @gfp: Memory allocation flags.
15 *
16 * Returns 0.
17 */
David Howellsee18d642009-09-02 09:14:21 +010018static int tomoyo_cred_alloc_blank(struct cred *new, gfp_t gfp)
19{
20 new->security = NULL;
21 return 0;
22}
23
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +090024/**
25 * tomoyo_cred_prepare - Target for security_prepare_creds().
26 *
27 * @new: Pointer to "struct cred".
28 * @old: Pointer to "struct cred".
29 * @gfp: Memory allocation flags.
30 *
31 * Returns 0.
32 */
Kentaro Takedaf7433242009-02-05 17:18:16 +090033static int tomoyo_cred_prepare(struct cred *new, const struct cred *old,
34 gfp_t gfp)
35{
Tetsuo Handaec8e6a42010-02-11 09:43:20 +090036 struct tomoyo_domain_info *domain = old->security;
37 new->security = domain;
38 if (domain)
39 atomic_inc(&domain->users);
Kentaro Takedaf7433242009-02-05 17:18:16 +090040 return 0;
41}
42
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +090043/**
44 * tomoyo_cred_transfer - Target for security_transfer_creds().
45 *
46 * @new: Pointer to "struct cred".
47 * @old: Pointer to "struct cred".
48 */
David Howellsee18d642009-09-02 09:14:21 +010049static void tomoyo_cred_transfer(struct cred *new, const struct cred *old)
50{
Tetsuo Handaec8e6a42010-02-11 09:43:20 +090051 tomoyo_cred_prepare(new, old, 0);
52}
53
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +090054/**
55 * tomoyo_cred_free - Target for security_cred_free().
56 *
57 * @cred: Pointer to "struct cred".
58 */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +090059static void tomoyo_cred_free(struct cred *cred)
60{
61 struct tomoyo_domain_info *domain = cred->security;
62 if (domain)
63 atomic_dec(&domain->users);
David Howellsee18d642009-09-02 09:14:21 +010064}
65
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +090066/**
67 * tomoyo_bprm_set_creds - Target for security_bprm_set_creds().
68 *
69 * @bprm: Pointer to "struct linux_binprm".
70 *
71 * Returns 0 on success, negative value otherwise.
72 */
Kentaro Takedaf7433242009-02-05 17:18:16 +090073static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)
74{
Herton Ronaldo Krzesinskib1338d12009-05-26 12:15:53 +090075 int rc;
76
77 rc = cap_bprm_set_creds(bprm);
78 if (rc)
79 return rc;
80
Kentaro Takedaf7433242009-02-05 17:18:16 +090081 /*
82 * Do only if this function is called for the first time of an execve
83 * operation.
84 */
85 if (bprm->cred_prepared)
86 return 0;
Tetsuo Handa7986cf22011-06-29 13:07:52 +090087#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
Kentaro Takedaf7433242009-02-05 17:18:16 +090088 /*
89 * Load policy if /sbin/tomoyo-init exists and /sbin/init is requested
90 * for the first time.
91 */
92 if (!tomoyo_policy_loaded)
93 tomoyo_load_policy(bprm->filename);
Tetsuo Handa7986cf22011-06-29 13:07:52 +090094#endif
Kentaro Takedaf7433242009-02-05 17:18:16 +090095 /*
Tetsuo Handaec8e6a42010-02-11 09:43:20 +090096 * Release reference to "struct tomoyo_domain_info" stored inside
97 * "bprm->cred->security". New reference to "struct tomoyo_domain_info"
98 * stored inside "bprm->cred->security" will be acquired later inside
99 * tomoyo_find_next_domain().
100 */
101 atomic_dec(&((struct tomoyo_domain_info *)
102 bprm->cred->security)->users);
103 /*
Kentaro Takedaf7433242009-02-05 17:18:16 +0900104 * Tell tomoyo_bprm_check_security() is called for the first time of an
105 * execve operation.
106 */
107 bprm->cred->security = NULL;
108 return 0;
109}
110
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900111/**
112 * tomoyo_bprm_check_security - Target for security_bprm_check().
113 *
114 * @bprm: Pointer to "struct linux_binprm".
115 *
116 * Returns 0 on success, negative value otherwise.
117 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900118static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
119{
120 struct tomoyo_domain_info *domain = bprm->cred->security;
121
122 /*
123 * Execute permission is checked against pathname passed to do_execve()
124 * using current domain.
125 */
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900126 if (!domain) {
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900127 const int idx = tomoyo_read_lock();
128 const int err = tomoyo_find_next_domain(bprm);
129 tomoyo_read_unlock(idx);
130 return err;
131 }
Kentaro Takedaf7433242009-02-05 17:18:16 +0900132 /*
133 * Read permission is checked against interpreters using next domain.
Kentaro Takedaf7433242009-02-05 17:18:16 +0900134 */
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900135 return tomoyo_check_open_permission(domain, &bprm->file->f_path,
136 O_RDONLY);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900137}
138
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900139/**
140 * tomoyo_inode_getattr - Target for security_inode_getattr().
141 *
142 * @mnt: Pointer to "struct vfsmount".
143 * @dentry: Pointer to "struct dentry".
144 *
145 * Returns 0 on success, negative value otherwise.
146 */
Tetsuo Handa7c759642011-06-26 23:15:31 +0900147static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
148{
149 struct path path = { mnt, dentry };
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900150 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
Tetsuo Handa7c759642011-06-26 23:15:31 +0900151}
152
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900153/**
154 * tomoyo_path_truncate - Target for security_path_truncate().
155 *
156 * @path: Pointer to "struct path".
157 *
158 * Returns 0 on success, negative value otherwise.
159 */
Tetsuo Handaea0d3ab2010-06-02 13:24:43 +0900160static int tomoyo_path_truncate(struct path *path)
Kentaro Takedaf7433242009-02-05 17:18:16 +0900161{
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900162 return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900163}
164
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900165/**
166 * tomoyo_path_unlink - Target for security_path_unlink().
167 *
168 * @parent: Pointer to "struct path".
169 * @dentry: Pointer to "struct dentry".
170 *
171 * Returns 0 on success, negative value otherwise.
172 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900173static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
174{
175 struct path path = { parent->mnt, dentry };
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900176 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900177}
178
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900179/**
180 * tomoyo_path_mkdir - Target for security_path_mkdir().
181 *
182 * @parent: Pointer to "struct path".
183 * @dentry: Pointer to "struct dentry".
184 * @mode: DAC permission mode.
185 *
186 * Returns 0 on success, negative value otherwise.
187 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900188static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
Al Viro4572bef2011-11-21 14:56:21 -0500189 umode_t mode)
Kentaro Takedaf7433242009-02-05 17:18:16 +0900190{
191 struct path path = { parent->mnt, dentry };
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900192 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
193 mode & S_IALLUGO);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900194}
195
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900196/**
197 * tomoyo_path_rmdir - Target for security_path_rmdir().
198 *
199 * @parent: Pointer to "struct path".
200 * @dentry: Pointer to "struct dentry".
201 *
202 * Returns 0 on success, negative value otherwise.
203 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900204static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
205{
206 struct path path = { parent->mnt, dentry };
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900207 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900208}
209
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900210/**
211 * tomoyo_path_symlink - Target for security_path_symlink().
212 *
213 * @parent: Pointer to "struct path".
214 * @dentry: Pointer to "struct dentry".
215 * @old_name: Symlink's content.
216 *
217 * Returns 0 on success, negative value otherwise.
218 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900219static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
220 const char *old_name)
221{
222 struct path path = { parent->mnt, dentry };
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900223 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900224}
225
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900226/**
227 * tomoyo_path_mknod - Target for security_path_mknod().
228 *
229 * @parent: Pointer to "struct path".
230 * @dentry: Pointer to "struct dentry".
231 * @mode: DAC permission mode.
232 * @dev: Device attributes.
233 *
234 * Returns 0 on success, negative value otherwise.
235 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900236static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
Al Viro04fc66e2011-11-21 14:58:38 -0500237 umode_t mode, unsigned int dev)
Kentaro Takedaf7433242009-02-05 17:18:16 +0900238{
239 struct path path = { parent->mnt, dentry };
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900240 int type = TOMOYO_TYPE_CREATE;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900241 const unsigned int perm = mode & S_IALLUGO;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900242
243 switch (mode & S_IFMT) {
244 case S_IFCHR:
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900245 type = TOMOYO_TYPE_MKCHAR;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900246 break;
247 case S_IFBLK:
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900248 type = TOMOYO_TYPE_MKBLOCK;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900249 break;
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900250 default:
251 goto no_dev;
252 }
Tetsuo Handa75093152010-06-16 16:23:55 +0900253 return tomoyo_mkdev_perm(type, &path, perm, dev);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900254 no_dev:
255 switch (mode & S_IFMT) {
Kentaro Takedaf7433242009-02-05 17:18:16 +0900256 case S_IFIFO:
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900257 type = TOMOYO_TYPE_MKFIFO;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900258 break;
259 case S_IFSOCK:
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900260 type = TOMOYO_TYPE_MKSOCK;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900261 break;
262 }
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900263 return tomoyo_path_number_perm(type, &path, perm);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900264}
265
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900266/**
267 * tomoyo_path_link - Target for security_path_link().
268 *
269 * @old_dentry: Pointer to "struct dentry".
270 * @new_dir: Pointer to "struct path".
271 * @new_dentry: Pointer to "struct dentry".
272 *
273 * Returns 0 on success, negative value otherwise.
274 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900275static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
276 struct dentry *new_dentry)
277{
278 struct path path1 = { new_dir->mnt, old_dentry };
279 struct path path2 = { new_dir->mnt, new_dentry };
Tetsuo Handa97d69312010-02-16 09:46:15 +0900280 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900281}
282
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900283/**
284 * tomoyo_path_rename - Target for security_path_rename().
285 *
286 * @old_parent: Pointer to "struct path".
287 * @old_dentry: Pointer to "struct dentry".
288 * @new_parent: Pointer to "struct path".
289 * @new_dentry: Pointer to "struct dentry".
290 *
291 * Returns 0 on success, negative value otherwise.
292 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900293static int tomoyo_path_rename(struct path *old_parent,
294 struct dentry *old_dentry,
295 struct path *new_parent,
296 struct dentry *new_dentry)
297{
298 struct path path1 = { old_parent->mnt, old_dentry };
299 struct path path2 = { new_parent->mnt, new_dentry };
Tetsuo Handa97d69312010-02-16 09:46:15 +0900300 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
Kentaro Takedaf7433242009-02-05 17:18:16 +0900301}
302
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900303/**
304 * tomoyo_file_fcntl - Target for security_file_fcntl().
305 *
306 * @file: Pointer to "struct file".
307 * @cmd: Command for fcntl().
308 * @arg: Argument for @cmd.
309 *
310 * Returns 0 on success, negative value otherwise.
311 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900312static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
313 unsigned long arg)
314{
Tetsuo Handa7c759642011-06-26 23:15:31 +0900315 if (!(cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND)))
316 return 0;
317 return tomoyo_check_open_permission(tomoyo_domain(), &file->f_path,
318 O_WRONLY | (arg & O_APPEND));
Kentaro Takedaf7433242009-02-05 17:18:16 +0900319}
320
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900321/**
322 * tomoyo_dentry_open - Target for security_dentry_open().
323 *
324 * @f: Pointer to "struct file".
325 * @cred: Pointer to "struct cred".
326 *
327 * Returns 0 on success, negative value otherwise.
328 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900329static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
330{
331 int flags = f->f_flags;
Kentaro Takedaf7433242009-02-05 17:18:16 +0900332 /* Don't check read permission here if called from do_execve(). */
333 if (current->in_execve)
334 return 0;
335 return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, flags);
336}
337
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900338/**
339 * tomoyo_file_ioctl - Target for security_file_ioctl().
340 *
341 * @file: Pointer to "struct file".
342 * @cmd: Command for ioctl().
343 * @arg: Argument for @cmd.
344 *
345 * Returns 0 on success, negative value otherwise.
346 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900347static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
348 unsigned long arg)
349{
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900350 return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900351}
352
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900353/**
354 * tomoyo_path_chmod - Target for security_path_chmod().
355 *
Al Virocdcf1162011-12-08 10:51:53 -0500356 * @path: Pointer to "struct path".
357 * @mode: DAC permission mode.
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900358 *
359 * Returns 0 on success, negative value otherwise.
360 */
Al Virocdcf1162011-12-08 10:51:53 -0500361static int tomoyo_path_chmod(struct path *path, umode_t mode)
Tetsuo Handa937bf612009-12-02 21:09:48 +0900362{
Al Virocdcf1162011-12-08 10:51:53 -0500363 return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, path,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900364 mode & S_IALLUGO);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900365}
366
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900367/**
368 * tomoyo_path_chown - Target for security_path_chown().
369 *
370 * @path: Pointer to "struct path".
371 * @uid: Owner ID.
372 * @gid: Group ID.
373 *
374 * Returns 0 on success, negative value otherwise.
375 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900376static int tomoyo_path_chown(struct path *path, uid_t uid, gid_t gid)
377{
378 int error = 0;
379 if (uid != (uid_t) -1)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900380 error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path, uid);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900381 if (!error && gid != (gid_t) -1)
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900382 error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path, gid);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900383 return error;
384}
385
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900386/**
387 * tomoyo_path_chroot - Target for security_path_chroot().
388 *
389 * @path: Pointer to "struct path".
390 *
391 * Returns 0 on success, negative value otherwise.
392 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900393static int tomoyo_path_chroot(struct path *path)
394{
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900395 return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900396}
397
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900398/**
399 * tomoyo_sb_mount - Target for security_sb_mount().
400 *
401 * @dev_name: Name of device file. Maybe NULL.
402 * @path: Pointer to "struct path".
403 * @type: Name of filesystem type. Maybe NULL.
404 * @flags: Mount options.
405 * @data: Optional data. Maybe NULL.
406 *
407 * Returns 0 on success, negative value otherwise.
408 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900409static int tomoyo_sb_mount(char *dev_name, struct path *path,
410 char *type, unsigned long flags, void *data)
411{
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900412 return tomoyo_mount_permission(dev_name, path, type, flags, data);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900413}
414
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900415/**
416 * tomoyo_sb_umount - Target for security_sb_umount().
417 *
418 * @mnt: Pointer to "struct vfsmount".
419 * @flags: Unmount options.
420 *
421 * Returns 0 on success, negative value otherwise.
422 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900423static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
424{
425 struct path path = { mnt, mnt->mnt_root };
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900426 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900427}
428
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900429/**
430 * tomoyo_sb_pivotroot - Target for security_sb_pivotroot().
431 *
432 * @old_path: Pointer to "struct path".
433 * @new_path: Pointer to "struct path".
434 *
435 * Returns 0 on success, negative value otherwise.
436 */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900437static int tomoyo_sb_pivotroot(struct path *old_path, struct path *new_path)
438{
Tetsuo Handa97d69312010-02-16 09:46:15 +0900439 return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
Tetsuo Handa937bf612009-12-02 21:09:48 +0900440}
441
Tetsuo Handa059d84d2011-09-10 15:23:54 +0900442/**
443 * tomoyo_socket_listen - Check permission for listen().
444 *
445 * @sock: Pointer to "struct socket".
446 * @backlog: Backlog parameter.
447 *
448 * Returns 0 on success, negative value otherwise.
449 */
450static int tomoyo_socket_listen(struct socket *sock, int backlog)
451{
452 return tomoyo_socket_listen_permission(sock);
453}
454
455/**
456 * tomoyo_socket_connect - Check permission for connect().
457 *
458 * @sock: Pointer to "struct socket".
459 * @addr: Pointer to "struct sockaddr".
460 * @addr_len: Size of @addr.
461 *
462 * Returns 0 on success, negative value otherwise.
463 */
464static int tomoyo_socket_connect(struct socket *sock, struct sockaddr *addr,
465 int addr_len)
466{
467 return tomoyo_socket_connect_permission(sock, addr, addr_len);
468}
469
470/**
471 * tomoyo_socket_bind - Check permission for bind().
472 *
473 * @sock: Pointer to "struct socket".
474 * @addr: Pointer to "struct sockaddr".
475 * @addr_len: Size of @addr.
476 *
477 * Returns 0 on success, negative value otherwise.
478 */
479static int tomoyo_socket_bind(struct socket *sock, struct sockaddr *addr,
480 int addr_len)
481{
482 return tomoyo_socket_bind_permission(sock, addr, addr_len);
483}
484
485/**
486 * tomoyo_socket_sendmsg - Check permission for sendmsg().
487 *
488 * @sock: Pointer to "struct socket".
489 * @msg: Pointer to "struct msghdr".
490 * @size: Size of message.
491 *
492 * Returns 0 on success, negative value otherwise.
493 */
494static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
495 int size)
496{
497 return tomoyo_socket_sendmsg_permission(sock, msg, size);
498}
499
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900500/*
501 * tomoyo_security_ops is a "struct security_operations" which is used for
502 * registering TOMOYO.
503 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900504static struct security_operations tomoyo_security_ops = {
505 .name = "tomoyo",
David Howellsee18d642009-09-02 09:14:21 +0100506 .cred_alloc_blank = tomoyo_cred_alloc_blank,
Kentaro Takedaf7433242009-02-05 17:18:16 +0900507 .cred_prepare = tomoyo_cred_prepare,
David Howellsee18d642009-09-02 09:14:21 +0100508 .cred_transfer = tomoyo_cred_transfer,
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900509 .cred_free = tomoyo_cred_free,
Kentaro Takedaf7433242009-02-05 17:18:16 +0900510 .bprm_set_creds = tomoyo_bprm_set_creds,
511 .bprm_check_security = tomoyo_bprm_check_security,
Kentaro Takedaf7433242009-02-05 17:18:16 +0900512 .file_fcntl = tomoyo_file_fcntl,
513 .dentry_open = tomoyo_dentry_open,
514 .path_truncate = tomoyo_path_truncate,
515 .path_unlink = tomoyo_path_unlink,
516 .path_mkdir = tomoyo_path_mkdir,
517 .path_rmdir = tomoyo_path_rmdir,
518 .path_symlink = tomoyo_path_symlink,
519 .path_mknod = tomoyo_path_mknod,
520 .path_link = tomoyo_path_link,
521 .path_rename = tomoyo_path_rename,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900522 .inode_getattr = tomoyo_inode_getattr,
Tetsuo Handa937bf612009-12-02 21:09:48 +0900523 .file_ioctl = tomoyo_file_ioctl,
524 .path_chmod = tomoyo_path_chmod,
525 .path_chown = tomoyo_path_chown,
526 .path_chroot = tomoyo_path_chroot,
527 .sb_mount = tomoyo_sb_mount,
528 .sb_umount = tomoyo_sb_umount,
529 .sb_pivotroot = tomoyo_sb_pivotroot,
Tetsuo Handa059d84d2011-09-10 15:23:54 +0900530 .socket_bind = tomoyo_socket_bind,
531 .socket_connect = tomoyo_socket_connect,
532 .socket_listen = tomoyo_socket_listen,
533 .socket_sendmsg = tomoyo_socket_sendmsg,
Kentaro Takedaf7433242009-02-05 17:18:16 +0900534};
535
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900536/* Lock for GC. */
537struct srcu_struct tomoyo_ss;
538
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900539/**
540 * tomoyo_init - Register TOMOYO Linux as a LSM module.
541 *
542 * Returns 0.
543 */
Kentaro Takedaf7433242009-02-05 17:18:16 +0900544static int __init tomoyo_init(void)
545{
546 struct cred *cred = (struct cred *) current_cred();
547
548 if (!security_module_enable(&tomoyo_security_ops))
549 return 0;
550 /* register ourselves with the security framework */
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900551 if (register_security(&tomoyo_security_ops) ||
552 init_srcu_struct(&tomoyo_ss))
Kentaro Takedaf7433242009-02-05 17:18:16 +0900553 panic("Failure registering TOMOYO Linux");
554 printk(KERN_INFO "TOMOYO Linux initialized\n");
555 cred->security = &tomoyo_kernel_domain;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900556 tomoyo_mm_init();
Kentaro Takedaf7433242009-02-05 17:18:16 +0900557 return 0;
558}
559
560security_initcall(tomoyo_init);