Blame view

security/tomoyo/tomoyo.c 14.7 KB
f74332437   Kentaro Takeda   LSM adapter funct...
1
2
3
  /*
   * security/tomoyo/tomoyo.c
   *
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
4
   * Copyright (C) 2005-2011  NTT DATA CORPORATION
f74332437   Kentaro Takeda   LSM adapter funct...
5
6
7
8
   */
  
  #include <linux/security.h>
  #include "common.h"
f74332437   Kentaro Takeda   LSM adapter funct...
9

0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
10
11
12
13
14
15
16
17
  /**
   * tomoyo_cred_alloc_blank - Target for security_cred_alloc_blank().
   *
   * @new: Pointer to "struct cred".
   * @gfp: Memory allocation flags.
   *
   * Returns 0.
   */
ee18d64c1   David Howells   KEYS: Add a keyct...
18
19
20
21
22
  static int tomoyo_cred_alloc_blank(struct cred *new, gfp_t gfp)
  {
  	new->security = NULL;
  	return 0;
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
23
24
25
26
27
28
29
30
31
  /**
   * tomoyo_cred_prepare - Target for security_prepare_creds().
   *
   * @new: Pointer to "struct cred".
   * @old: Pointer to "struct cred".
   * @gfp: Memory allocation flags.
   *
   * Returns 0.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
32
33
34
  static int tomoyo_cred_prepare(struct cred *new, const struct cred *old,
  			       gfp_t gfp)
  {
ec8e6a4e0   Tetsuo Handa   TOMOYO: Add refco...
35
36
37
38
  	struct tomoyo_domain_info *domain = old->security;
  	new->security = domain;
  	if (domain)
  		atomic_inc(&domain->users);
f74332437   Kentaro Takeda   LSM adapter funct...
39
40
  	return 0;
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
41
42
43
44
45
46
  /**
   * tomoyo_cred_transfer - Target for security_transfer_creds().
   *
   * @new: Pointer to "struct cred".
   * @old: Pointer to "struct cred".
   */
ee18d64c1   David Howells   KEYS: Add a keyct...
47
48
  static void tomoyo_cred_transfer(struct cred *new, const struct cred *old)
  {
ec8e6a4e0   Tetsuo Handa   TOMOYO: Add refco...
49
50
  	tomoyo_cred_prepare(new, old, 0);
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
51
52
53
54
55
  /**
   * tomoyo_cred_free - Target for security_cred_free().
   *
   * @cred: Pointer to "struct cred".
   */
ec8e6a4e0   Tetsuo Handa   TOMOYO: Add refco...
56
57
58
59
60
  static void tomoyo_cred_free(struct cred *cred)
  {
  	struct tomoyo_domain_info *domain = cred->security;
  	if (domain)
  		atomic_dec(&domain->users);
ee18d64c1   David Howells   KEYS: Add a keyct...
61
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
62
63
64
65
66
67
68
  /**
   * tomoyo_bprm_set_creds - Target for security_bprm_set_creds().
   *
   * @bprm: Pointer to "struct linux_binprm".
   *
   * Returns 0 on success, negative value otherwise.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
69
70
  static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)
  {
b1338d199   Herton Ronaldo Krzesinski   tomoyo: add missi...
71
72
73
74
75
  	int rc;
  
  	rc = cap_bprm_set_creds(bprm);
  	if (rc)
  		return rc;
f74332437   Kentaro Takeda   LSM adapter funct...
76
77
78
79
80
81
  	/*
  	 * Do only if this function is called for the first time of an execve
  	 * operation.
  	 */
  	if (bprm->cred_prepared)
  		return 0;
7986cf28b   Tetsuo Handa   TOMOYO: Fix build...
82
  #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
f74332437   Kentaro Takeda   LSM adapter funct...
83
84
85
86
87
88
  	/*
  	 * 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);
7986cf28b   Tetsuo Handa   TOMOYO: Fix build...
89
  #endif
f74332437   Kentaro Takeda   LSM adapter funct...
90
  	/*
ec8e6a4e0   Tetsuo Handa   TOMOYO: Add refco...
91
92
93
94
95
96
97
98
  	 * 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().
  	 */
  	atomic_dec(&((struct tomoyo_domain_info *)
  		     bprm->cred->security)->users);
  	/*
f74332437   Kentaro Takeda   LSM adapter funct...
99
100
101
102
103
104
  	 * Tell tomoyo_bprm_check_security() is called for the first time of an
  	 * execve operation.
  	 */
  	bprm->cred->security = NULL;
  	return 0;
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
105
106
107
108
109
110
111
  /**
   * tomoyo_bprm_check_security - Target for security_bprm_check().
   *
   * @bprm: Pointer to "struct linux_binprm".
   *
   * Returns 0 on success, negative value otherwise.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
112
113
114
115
116
117
118
119
  static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
  {
  	struct tomoyo_domain_info *domain = bprm->cred->security;
  
  	/*
  	 * Execute permission is checked against pathname passed to do_execve()
  	 * using current domain.
  	 */
fdb8ebb72   Tetsuo Handa   TOMOYO: Use RCU p...
120
  	if (!domain) {
fdb8ebb72   Tetsuo Handa   TOMOYO: Use RCU p...
121
122
123
124
125
  		const int idx = tomoyo_read_lock();
  		const int err = tomoyo_find_next_domain(bprm);
  		tomoyo_read_unlock(idx);
  		return err;
  	}
f74332437   Kentaro Takeda   LSM adapter funct...
126
127
  	/*
  	 * Read permission is checked against interpreters using next domain.
f74332437   Kentaro Takeda   LSM adapter funct...
128
  	 */
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
129
130
  	return tomoyo_check_open_permission(domain, &bprm->file->f_path,
  					    O_RDONLY);
f74332437   Kentaro Takeda   LSM adapter funct...
131
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
132
133
134
135
136
137
138
139
  /**
   * 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.
   */
7c75964f4   Tetsuo Handa   TOMOYO: Cleanup p...
140
141
142
  static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
  {
  	struct path path = { mnt, dentry };
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
143
  	return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
7c75964f4   Tetsuo Handa   TOMOYO: Cleanup p...
144
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
145
146
147
148
149
150
151
  /**
   * tomoyo_path_truncate - Target for security_path_truncate().
   *
   * @path: Pointer to "struct path".
   *
   * Returns 0 on success, negative value otherwise.
   */
ea0d3ab23   Tetsuo Handa   LSM: Remove unuse...
152
  static int tomoyo_path_truncate(struct path *path)
f74332437   Kentaro Takeda   LSM adapter funct...
153
  {
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
154
  	return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path, NULL);
f74332437   Kentaro Takeda   LSM adapter funct...
155
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
156
157
158
159
160
161
162
163
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
164
165
166
  static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
  {
  	struct path path = { parent->mnt, dentry };
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
167
  	return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
f74332437   Kentaro Takeda   LSM adapter funct...
168
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
169
170
171
172
173
174
175
176
177
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
178
179
180
181
  static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
  			     int mode)
  {
  	struct path path = { parent->mnt, dentry };
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
182
183
  	return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
  				       mode & S_IALLUGO);
f74332437   Kentaro Takeda   LSM adapter funct...
184
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
185
186
187
188
189
190
191
192
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
193
194
195
  static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
  {
  	struct path path = { parent->mnt, dentry };
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
196
  	return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
f74332437   Kentaro Takeda   LSM adapter funct...
197
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
198
199
200
201
202
203
204
205
206
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
207
208
209
210
  static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
  			       const char *old_name)
  {
  	struct path path = { parent->mnt, dentry };
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
211
  	return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
f74332437   Kentaro Takeda   LSM adapter funct...
212
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
213
214
215
216
217
218
219
220
221
222
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
223
224
225
226
  static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
  			     int mode, unsigned int dev)
  {
  	struct path path = { parent->mnt, dentry };
7ef612331   Tetsuo Handa   TOMOYO: Use short...
227
  	int type = TOMOYO_TYPE_CREATE;
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
228
  	const unsigned int perm = mode & S_IALLUGO;
f74332437   Kentaro Takeda   LSM adapter funct...
229
230
231
  
  	switch (mode & S_IFMT) {
  	case S_IFCHR:
7ef612331   Tetsuo Handa   TOMOYO: Use short...
232
  		type = TOMOYO_TYPE_MKCHAR;
f74332437   Kentaro Takeda   LSM adapter funct...
233
234
  		break;
  	case S_IFBLK:
7ef612331   Tetsuo Handa   TOMOYO: Use short...
235
  		type = TOMOYO_TYPE_MKBLOCK;
f74332437   Kentaro Takeda   LSM adapter funct...
236
  		break;
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
237
238
239
  	default:
  		goto no_dev;
  	}
75093152a   Tetsuo Handa   TOMOYO: Rename sy...
240
  	return tomoyo_mkdev_perm(type, &path, perm, dev);
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
241
242
   no_dev:
  	switch (mode & S_IFMT) {
f74332437   Kentaro Takeda   LSM adapter funct...
243
  	case S_IFIFO:
7ef612331   Tetsuo Handa   TOMOYO: Use short...
244
  		type = TOMOYO_TYPE_MKFIFO;
f74332437   Kentaro Takeda   LSM adapter funct...
245
246
  		break;
  	case S_IFSOCK:
7ef612331   Tetsuo Handa   TOMOYO: Use short...
247
  		type = TOMOYO_TYPE_MKSOCK;
f74332437   Kentaro Takeda   LSM adapter funct...
248
249
  		break;
  	}
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
250
  	return tomoyo_path_number_perm(type, &path, perm);
f74332437   Kentaro Takeda   LSM adapter funct...
251
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
252
253
254
255
256
257
258
259
260
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
261
262
263
264
265
  static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
  			    struct dentry *new_dentry)
  {
  	struct path path1 = { new_dir->mnt, old_dentry };
  	struct path path2 = { new_dir->mnt, new_dentry };
97d6931ea   Tetsuo Handa   TOMOYO: Remove un...
266
  	return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
f74332437   Kentaro Takeda   LSM adapter funct...
267
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
268
269
270
271
272
273
274
275
276
277
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
278
279
280
281
282
283
284
  static int tomoyo_path_rename(struct path *old_parent,
  			      struct dentry *old_dentry,
  			      struct path *new_parent,
  			      struct dentry *new_dentry)
  {
  	struct path path1 = { old_parent->mnt, old_dentry };
  	struct path path2 = { new_parent->mnt, new_dentry };
97d6931ea   Tetsuo Handa   TOMOYO: Remove un...
285
  	return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
f74332437   Kentaro Takeda   LSM adapter funct...
286
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
287
288
289
290
291
292
293
294
295
  /**
   * 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.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
296
297
298
  static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
  			     unsigned long arg)
  {
7c75964f4   Tetsuo Handa   TOMOYO: Cleanup p...
299
300
301
302
  	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));
f74332437   Kentaro Takeda   LSM adapter funct...
303
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
304
305
306
307
308
309
310
311
  /**
   * tomoyo_dentry_open - Target for security_dentry_open().
   *
   * @f:    Pointer to "struct file".
   * @cred: Pointer to "struct cred".
   *
   * Returns 0 on success, negative value otherwise.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
312
313
314
  static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
  {
  	int flags = f->f_flags;
f74332437   Kentaro Takeda   LSM adapter funct...
315
316
317
318
319
  	/* 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);
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
320
321
322
323
324
325
326
327
328
  /**
   * 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.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
329
330
331
  static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
  			     unsigned long arg)
  {
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
332
  	return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
333
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
334
335
336
337
338
339
340
341
342
  /**
   * tomoyo_path_chmod - Target for security_path_chmod().
   *
   * @dentry: Pointer to "struct dentry".
   * @mnt:    Pointer to "struct vfsmount".
   * @mode:   DAC permission mode.
   *
   * Returns 0 on success, negative value otherwise.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
343
344
345
346
  static int tomoyo_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
  			     mode_t mode)
  {
  	struct path path = { mnt, dentry };
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
347
348
  	return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, &path,
  				       mode & S_IALLUGO);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
349
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
350
351
352
353
354
355
356
357
358
  /**
   * 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.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
359
360
361
362
  static int tomoyo_path_chown(struct path *path, uid_t uid, gid_t gid)
  {
  	int error = 0;
  	if (uid != (uid_t) -1)
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
363
  		error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path, uid);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
364
  	if (!error && gid != (gid_t) -1)
a1f9bb6a3   Tetsuo Handa   TOMOYO: Split fil...
365
  		error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path, gid);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
366
367
  	return error;
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
368
369
370
371
372
373
374
  /**
   * tomoyo_path_chroot - Target for security_path_chroot().
   *
   * @path: Pointer to "struct path".
   *
   * Returns 0 on success, negative value otherwise.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
375
376
  static int tomoyo_path_chroot(struct path *path)
  {
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
377
  	return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path, NULL);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
378
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
379
380
381
382
383
384
385
386
387
388
389
  /**
   * 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.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
390
391
392
  static int tomoyo_sb_mount(char *dev_name, struct path *path,
  			   char *type, unsigned long flags, void *data)
  {
2106ccd97   Tetsuo Handa   TOMOYO: Add mount...
393
  	return tomoyo_mount_permission(dev_name, path, type, flags, data);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
394
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
395
396
397
398
399
400
401
402
  /**
   * tomoyo_sb_umount - Target for security_sb_umount().
   *
   * @mnt:   Pointer to "struct vfsmount".
   * @flags: Unmount options.
   *
   * Returns 0 on success, negative value otherwise.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
403
404
405
  static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
  {
  	struct path path = { mnt, mnt->mnt_root };
97fb35e41   Tetsuo Handa   TOMOYO: Enable co...
406
  	return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
407
  }
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
408
409
410
411
412
413
414
415
  /**
   * 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.
   */
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
416
417
  static int tomoyo_sb_pivotroot(struct path *old_path, struct path *new_path)
  {
97d6931ea   Tetsuo Handa   TOMOYO: Remove un...
418
  	return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
419
  }
059d84dbb   Tetsuo Handa   TOMOYO: Add socke...
420
421
422
423
424
425
426
427
428
429
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
  /**
   * 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);
  }
c3fa109a5   Tetsuo Handa   TOMOYO: Add descr...
477
478
479
480
  /*
   * tomoyo_security_ops is a "struct security_operations" which is used for
   * registering TOMOYO.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
481
482
  static struct security_operations tomoyo_security_ops = {
  	.name                = "tomoyo",
ee18d64c1   David Howells   KEYS: Add a keyct...
483
  	.cred_alloc_blank    = tomoyo_cred_alloc_blank,
f74332437   Kentaro Takeda   LSM adapter funct...
484
  	.cred_prepare        = tomoyo_cred_prepare,
ee18d64c1   David Howells   KEYS: Add a keyct...
485
  	.cred_transfer	     = tomoyo_cred_transfer,
ec8e6a4e0   Tetsuo Handa   TOMOYO: Add refco...
486
  	.cred_free           = tomoyo_cred_free,
f74332437   Kentaro Takeda   LSM adapter funct...
487
488
  	.bprm_set_creds      = tomoyo_bprm_set_creds,
  	.bprm_check_security = tomoyo_bprm_check_security,
f74332437   Kentaro Takeda   LSM adapter funct...
489
490
491
492
493
494
495
496
497
498
  	.file_fcntl          = tomoyo_file_fcntl,
  	.dentry_open         = tomoyo_dentry_open,
  	.path_truncate       = tomoyo_path_truncate,
  	.path_unlink         = tomoyo_path_unlink,
  	.path_mkdir          = tomoyo_path_mkdir,
  	.path_rmdir          = tomoyo_path_rmdir,
  	.path_symlink        = tomoyo_path_symlink,
  	.path_mknod          = tomoyo_path_mknod,
  	.path_link           = tomoyo_path_link,
  	.path_rename         = tomoyo_path_rename,
7c75964f4   Tetsuo Handa   TOMOYO: Cleanup p...
499
  	.inode_getattr       = tomoyo_inode_getattr,
937bf6133   Tetsuo Handa   TOMOYO: Add rest ...
500
501
502
503
504
505
506
  	.file_ioctl          = tomoyo_file_ioctl,
  	.path_chmod          = tomoyo_path_chmod,
  	.path_chown          = tomoyo_path_chown,
  	.path_chroot         = tomoyo_path_chroot,
  	.sb_mount            = tomoyo_sb_mount,
  	.sb_umount           = tomoyo_sb_umount,
  	.sb_pivotroot        = tomoyo_sb_pivotroot,
059d84dbb   Tetsuo Handa   TOMOYO: Add socke...
507
508
509
510
  	.socket_bind         = tomoyo_socket_bind,
  	.socket_connect      = tomoyo_socket_connect,
  	.socket_listen       = tomoyo_socket_listen,
  	.socket_sendmsg      = tomoyo_socket_sendmsg,
f74332437   Kentaro Takeda   LSM adapter funct...
511
  };
fdb8ebb72   Tetsuo Handa   TOMOYO: Use RCU p...
512
513
  /* Lock for GC. */
  struct srcu_struct tomoyo_ss;
0f2a55d5b   Tetsuo Handa   TOMOYO: Update ke...
514
515
516
517
518
  /**
   * tomoyo_init - Register TOMOYO Linux as a LSM module.
   *
   * Returns 0.
   */
f74332437   Kentaro Takeda   LSM adapter funct...
519
520
521
522
523
524
525
  static int __init tomoyo_init(void)
  {
  	struct cred *cred = (struct cred *) current_cred();
  
  	if (!security_module_enable(&tomoyo_security_ops))
  		return 0;
  	/* register ourselves with the security framework */
fdb8ebb72   Tetsuo Handa   TOMOYO: Use RCU p...
526
527
  	if (register_security(&tomoyo_security_ops) ||
  	    init_srcu_struct(&tomoyo_ss))
f74332437   Kentaro Takeda   LSM adapter funct...
528
529
530
531
  		panic("Failure registering TOMOYO Linux");
  	printk(KERN_INFO "TOMOYO Linux initialized
  ");
  	cred->security = &tomoyo_kernel_domain;
c3ef1500e   Tetsuo Handa   TOMOYO: Split fil...
532
  	tomoyo_mm_init();
f74332437   Kentaro Takeda   LSM adapter funct...
533
534
535
536
  	return 0;
  }
  
  security_initcall(tomoyo_init);