History

Merge branch 'next' into for-linus

James Morris committed 15 years ago

Commit a0029512 parents 521cb40 c15169485 files · +1549 −712Browse files

Unified · Split

85 files
  1. Documentation/keys-request-key.txt +5 −4
  2. Documentation/keys.txt +24 −4
  3. arch/x86/Kconfig +5 −0
  4. fs/btrfs/inode.c +7 −6
  5. fs/btrfs/xattr.c +4 −2
  6. fs/btrfs/xattr.h +2 −1
  7. fs/cachefiles/namei.c +44 −8
  8. fs/ext2/ext2.h +1 −1
  9. fs/ext2/ialloc.c +3 −2
  10. fs/ext2/namei.c +4 −4
  11. fs/ext2/xattr.h +4 −2
  12. fs/ext2/xattr_security.c +3 −2
  13. fs/ext3/ialloc.c +3 −2
  14. fs/ext3/namei.c +4 −4
  15. fs/ext3/xattr.h +2 −2
  16. fs/ext3/xattr_security.c +3 −2
  17. fs/ext4/ialloc.c +1 −1
  18. fs/ext4/xattr.h +2 −2
  19. fs/ext4/xattr_security.c +3 −2
  20. fs/file_table.c +4 −1
  21. fs/gfs2/inode.c +4 −3
  22. fs/jffs2/dir.c +4 −5
  23. fs/jffs2/nodelist.h +1 −1
  24. fs/jffs2/security.c +3 −2
  25. fs/jffs2/write.c +10 −8
  26. fs/jffs2/xattr.h +3 −2
  27. fs/jfs/jfs_xattr.h +3 −2
  28. fs/jfs/namei.c +4 −4
  29. fs/jfs/xattr.c +4 −2
  30. fs/namespace.c +4 −0
  31. fs/ocfs2/namei.c +2 −2
  32. fs/ocfs2/refcounttree.c +2 −1
  33. fs/ocfs2/xattr.c +6 −4
  34. fs/ocfs2/xattr.h +3 −1
  35. fs/open.c +2 −1
  36. fs/proc/proc_sysctl.c +0 −1
  37. fs/reiserfs/namei.c +5 −4
  38. fs/reiserfs/xattr_security.c +2 −1
  39. fs/xfs/linux-2.6/xfs_iops.c +5 −4
  40. include/linux/ext3_fs.h +2 −1
  41. include/linux/fs.h +21 −2
  42. include/linux/ima.h +0 −6
  43. include/linux/key-type.h +13 −1
  44. include/linux/key.h +5 −0
  45. include/linux/keyctl.h +2 −0
  46. include/linux/reiserfs_xattr.h +2 −0
  47. include/linux/security.h +20 −15
  48. include/linux/xattr.h +2 −0
  49. kernel/sysctl.c +0 −5
  50. mm/shmem.c +5 −4
  51. net/rxrpc/ar-key.c +19 −0
  52. scripts/selinux/genheaders/genheaders.c +20 −0
  53. security/apparmor/Makefile +33 −5
  54. security/apparmor/lsm.c +0 −2
  55. security/capability.c +8 −7
  56. security/integrity/ima/ima.h +1 −2
  57. security/integrity/ima/ima_api.c +3 −10
  58. security/integrity/ima/ima_iint.c +0 −5
  59. security/integrity/ima/ima_main.c +16 −120
  60. security/keys/compat.c +50 −0
  61. security/keys/encrypted.c +1 −2
  62. security/keys/internal.h +8 −0
  63. security/keys/key.c +19 −8
  64. security/keys/keyctl.c +134 −9
  65. security/keys/keyring.c +2 −2
  66. security/keys/request_key.c +1 −1
  67. security/keys/trusted.c +1 −2
  68. security/keys/user_defined.c +1 −2
  69. security/security.c +12 −7
  70. security/selinux/hooks.c +188 −162
  71. security/selinux/include/classmap.h +5 −2
  72. security/selinux/include/security.h +5 −3
  73. security/selinux/ss/avtab.h +11 −12
  74. security/selinux/ss/ebitmap.h +0 −1
  75. security/selinux/ss/mls.c +3 −2
  76. security/selinux/ss/mls.h +2 −1
  77. security/selinux/ss/policydb.c +130 −0
  78. security/selinux/ss/policydb.h +13 −1
  79. security/selinux/ss/services.c +55 −18
  80. security/selinux/xfrm.c +1 −1
  81. security/smack/smack.h +6 −11
  82. security/smack/smack_access.c +34 −18
  83. security/smack/smack_lsm.c +244 −43
  84. security/smack/smackfs.c +255 −115
  85. security/tomoyo/file.c +1 −4
Documentation/keys-request-key.txt+5−4
@@ -127,14 +127,15 @@ This is because process A's keyrings can't simply be attached to · 126 unmodified lines
127127 of them, and (b) it requires the same UID/GID/Groups all the way through.
128128
129129
130−======================
131−NEGATIVE INSTANTIATION
132−======================
130+====================================
131+NEGATIVE INSTANTIATION AND REJECTION
132+====================================
133133
134134 Rather than instantiating a key, it is possible for the possessor of an
135135 authorisation key to negatively instantiate a key that's under construction.
136136 This is a short duration placeholder that causes any attempt at re-requesting
137−the key whilst it exists to fail with error ENOKEY.
137+the key whilst it exists to fail with error ENOKEY if negated or the specified
138+error if rejected.
138139
139140 This is provided to prevent excessive repeated spawning of /sbin/request-key
140141 processes for a key that will never be obtainable.
Documentation/keys.txt+24−4
@@ -637,6 +637,9 @@ The keyctl syscall functions are: · 636 unmodified lines
637637 long keyctl(KEYCTL_INSTANTIATE, key_serial_t key,
638638 const void *payload, size_t plen,
639639 key_serial_t keyring);
640+ long keyctl(KEYCTL_INSTANTIATE_IOV, key_serial_t key,
641+ const struct iovec *payload_iov, unsigned ioc,
642+ key_serial_t keyring);
640643
641644 If the kernel calls back to userspace to complete the instantiation of a
642645 key, userspace should use this call to supply data for the key before the
@@ -652,11 +655,16 @@ The keyctl syscall functions are: · 9 unmodified lines
652655
653656 The payload and plen arguments describe the payload data as for add_key().
654657
658+ The payload_iov and ioc arguments describe the payload data in an iovec
659+ array instead of a single buffer.
660+
655661
656662 (*) Negatively instantiate a partially constructed key.
657663
658664 long keyctl(KEYCTL_NEGATE, key_serial_t key,
659665 unsigned timeout, key_serial_t keyring);
666+ long keyctl(KEYCTL_REJECT, key_serial_t key,
667+ unsigned timeout, unsigned error, key_serial_t keyring);
660668
661669 If the kernel calls back to userspace to complete the instantiation of a
662670 key, userspace should use this call mark the key as negative before the
@@ -669,6 +677,10 @@ The keyctl syscall functions are: · 6 unmodified lines
669677 that keyring, however all the constraints applying in KEYCTL_LINK apply in
670678 this case too.
671679
680+ If the key is rejected, future searches for it will return the specified
681+ error code until the rejected key expires. Negating the key is the same
682+ as rejecting the key with ENOKEY as the error code.
683+
672684
673685 (*) Set the default request-key destination keyring.
674686
@@ -1062,6 +1074,13 @@ The structure has a number of fields, some of which are mandatory: · 387 unmodified lines
10621074 viable.
10631075
10641076
1077+ (*) int (*vet_description)(const char *description);
1078+
1079+ This optional method is called to vet a key description. If the key type
1080+ doesn't approve of the key description, it may return an error, otherwise
1081+ it should return 0.
1082+
1083+
10651084 (*) int (*instantiate)(struct key *key, const void *data, size_t datalen);
10661085
10671086 This method is called to attach a payload to a key during construction.
@@ -1231,10 +1250,11 @@ hand the request off to (perhaps a path held in placed in another key by, for · 163 unmodified lines
12311250 example, the KDE desktop manager).
12321251
12331252 The program (or whatever it calls) should finish construction of the key by
1234−calling KEYCTL_INSTANTIATE, which also permits it to cache the key in one of
1235−the keyrings (probably the session ring) before returning. Alternatively, the
1236−key can be marked as negative with KEYCTL_NEGATE; this also permits the key to
1237−be cached in one of the keyrings.
1253+calling KEYCTL_INSTANTIATE or KEYCTL_INSTANTIATE_IOV, which also permits it to
1254+cache the key in one of the keyrings (probably the session ring) before
1255+returning. Alternatively, the key can be marked as negative with KEYCTL_NEGATE
1256+or KEYCTL_REJECT; this also permits the key to be cached in one of the
1257+keyrings.
12381258
12391259 If it returns with the key remaining in the unconstructed state, the key will
12401260 be marked as being negative, it will be added to the session keyring, and an
arch/x86/Kconfig+5−0
@@ -2138,6 +2138,11 @@ config SYSVIPC_COMPAT · 2137 unmodified lines
21382138 def_bool y
21392139 depends on COMPAT && SYSVIPC
21402140
2141+config KEYS_COMPAT
2142+ bool
2143+ depends on COMPAT && KEYS
2144+ default y
2145+
21412146 endmenu
21422147
21432148
fs/btrfs/inode.c+7−6
@@ -90,13 +90,14 @@ static noinline int cow_file_range(struct inode *inode, · 89 unmodified lines
9090 unsigned long *nr_written, int unlock);
9191
9292 static int btrfs_init_inode_security(struct btrfs_trans_handle *trans,
93− struct inode *inode, struct inode *dir)
93+ struct inode *inode, struct inode *dir,
94+ const struct qstr *qstr)
9495 {
9596 int err;
9697
9798 err = btrfs_init_acl(trans, inode, dir);
9899 if (!err)
99− err = btrfs_xattr_security_init(trans, inode, dir);
100+ err = btrfs_xattr_security_init(trans, inode, dir, qstr);
100101 return err;
101102 }
102103
@@ -4704,7 +4705,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, · 4601 unmodified lines
47044705 if (IS_ERR(inode))
47054706 goto out_unlock;
47064707
4707− err = btrfs_init_inode_security(trans, inode, dir);
4708+ err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
47084709 if (err) {
47094710 drop_inode = 1;
47104711 goto out_unlock;
@@ -4765,7 +4766,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, · 54 unmodified lines
47654766 if (IS_ERR(inode))
47664767 goto out_unlock;
47674768
4768− err = btrfs_init_inode_security(trans, inode, dir);
4769+ err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
47694770 if (err) {
47704771 drop_inode = 1;
47714772 goto out_unlock;
@@ -4894,7 +4895,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) · 122 unmodified lines
48944895
48954896 drop_on_err = 1;
48964897
4897− err = btrfs_init_inode_security(trans, inode, dir);
4898+ err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
48984899 if (err)
48994900 goto out_fail;
49004901
@@ -7106,7 +7107,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, · 2205 unmodified lines
71067107 if (IS_ERR(inode))
71077108 goto out_unlock;
71087109
7109− err = btrfs_init_inode_security(trans, inode, dir);
7110+ err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
71107111 if (err) {
71117112 drop_inode = 1;
71127113 goto out_unlock;
fs/btrfs/xattr.c+4−2
@@ -370,7 +370,8 @@ int btrfs_removexattr(struct dentry *dentry, const char *name) · 369 unmodified lines
370370 }
371371
372372 int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
373− struct inode *inode, struct inode *dir)
373+ struct inode *inode, struct inode *dir,
374+ const struct qstr *qstr)
374375 {
375376 int err;
376377 size_t len;
@@ -378,7 +379,8 @@ int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, · 1 unmodified line
378379 char *suffix;
379380 char *name;
380381
381− err = security_inode_init_security(inode, dir, &suffix, &value, &len);
382+ err = security_inode_init_security(inode, dir, qstr, &suffix, &value,
383+ &len);
382384 if (err) {
383385 if (err == -EOPNOTSUPP)
384386 return 0;
fs/btrfs/xattr.h+2−1
@@ -37,6 +37,7 @@ extern int btrfs_setxattr(struct dentry *dentry, const char *name, · 36 unmodified lines
3737 extern int btrfs_removexattr(struct dentry *dentry, const char *name);
3838
3939 extern int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
40− struct inode *inode, struct inode *dir);
40+ struct inode *inode, struct inode *dir,
41+ const struct qstr *qstr);
4142
4243 #endif /* __XATTR__ */
fs/cachefiles/namei.c+44−8
@@ -275,6 +275,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache, · 274 unmodified lines
275275 bool preemptive)
276276 {
277277 struct dentry *grave, *trap;
278+ struct path path, path_to_graveyard;
278279 char nbuffer[8 + 8 + 1];
279280 int ret;
280281
@@ -287,10 +288,18 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache, · 6 unmodified lines
287288 /* non-directories can just be unlinked */
288289 if (!S_ISDIR(rep->d_inode->i_mode)) {
289290 _debug("unlink stale object");
290− ret = vfs_unlink(dir->d_inode, rep);
291291
292− if (preemptive)
293− cachefiles_mark_object_buried(cache, rep);
292+ path.mnt = cache->mnt;
293+ path.dentry = dir;
294+ ret = security_path_unlink(&path, rep);
295+ if (ret < 0) {
296+ cachefiles_io_error(cache, "Unlink security error");
297+ } else {
298+ ret = vfs_unlink(dir->d_inode, rep);
299+
300+ if (preemptive)
301+ cachefiles_mark_object_buried(cache, rep);
302+ }
294303
295304 mutex_unlock(&dir->d_inode->i_mutex);
296305
@@ -379,12 +388,23 @@ try_again: · 82 unmodified lines
379388 }
380389
381390 /* attempt the rename */
382− ret = vfs_rename(dir->d_inode, rep, cache->graveyard->d_inode, grave);
383− if (ret != 0 && ret != -ENOMEM)
384− cachefiles_io_error(cache, "Rename failed with error %d", ret);
391+ path.mnt = cache->mnt;
392+ path.dentry = dir;
393+ path_to_graveyard.mnt = cache->mnt;
394+ path_to_graveyard.dentry = cache->graveyard;
395+ ret = security_path_rename(&path, rep, &path_to_graveyard, grave);
396+ if (ret < 0) {
397+ cachefiles_io_error(cache, "Rename security error %d", ret);
398+ } else {
399+ ret = vfs_rename(dir->d_inode, rep,
400+ cache->graveyard->d_inode, grave);
401+ if (ret != 0 && ret != -ENOMEM)
402+ cachefiles_io_error(cache,
403+ "Rename failed with error %d", ret);
385404
386− if (preemptive)
387− cachefiles_mark_object_buried(cache, rep);
405+ if (preemptive)
406+ cachefiles_mark_object_buried(cache, rep);
407+ }
388408
389409 unlock_rename(cache->graveyard, dir);
390410 dput(grave);
@@ -448,6 +468,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent, · 57 unmodified lines
448468 {
449469 struct cachefiles_cache *cache;
450470 struct dentry *dir, *next = NULL;
471+ struct path path;
451472 unsigned long start;
452473 const char *name;
453474 int ret, nlen;
@@ -458,6 +479,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent, · 4 unmodified lines
458479
459480 cache = container_of(parent->fscache.cache,
460481 struct cachefiles_cache, cache);
482+ path.mnt = cache->mnt;
461483
462484 ASSERT(parent->dentry);
463485 ASSERT(parent->dentry->d_inode);
@@ -511,6 +533,10 @@ lookup_again: · 47 unmodified lines
511533 if (ret < 0)
512534 goto create_error;
513535
536+ path.dentry = dir;
537+ ret = security_path_mkdir(&path, next, 0);
538+ if (ret < 0)
539+ goto create_error;
514540 start = jiffies;
515541 ret = vfs_mkdir(dir->d_inode, next, 0);
516542 cachefiles_hist(cachefiles_mkdir_histogram, start);
@@ -536,6 +562,10 @@ lookup_again: · 19 unmodified lines
536562 if (ret < 0)
537563 goto create_error;
538564
565+ path.dentry = dir;
566+ ret = security_path_mknod(&path, next, S_IFREG, 0);
567+ if (ret < 0)
568+ goto create_error;
539569 start = jiffies;
540570 ret = vfs_create(dir->d_inode, next, S_IFREG, NULL);
541571 cachefiles_hist(cachefiles_create_histogram, start);
@@ -692,6 +722,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, · 150 unmodified lines
692722 {
693723 struct dentry *subdir;
694724 unsigned long start;
725+ struct path path;
695726 int ret;
696727
697728 _enter(",,%s", dirname);
@@ -719,6 +750,11 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, · 21 unmodified lines
719750
720751 _debug("attempt mkdir");
721752
753+ path.mnt = cache->mnt;
754+ path.dentry = dir;
755+ ret = security_path_mkdir(&path, subdir, 0700);
756+ if (ret < 0)
757+ goto mkdir_error;
722758 ret = vfs_mkdir(dir->d_inode, subdir, 0700);
723759 if (ret < 0)
724760 goto mkdir_error;
fs/ext2/ext2.h+1−1
@@ -110,7 +110,7 @@ extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **); · 109 unmodified lines
110110 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
111111
112112 /* ialloc.c */
113−extern struct inode * ext2_new_inode (struct inode *, int);
113+extern struct inode * ext2_new_inode (struct inode *, int, const struct qstr *);
114114 extern void ext2_free_inode (struct inode *);
115115 extern unsigned long ext2_count_free_inodes (struct super_block *);
116116 extern void ext2_check_inodes_bitmap (struct super_block *);
fs/ext2/ialloc.c+3−2
@@ -429,7 +429,8 @@ found: · 428 unmodified lines
429429 return group;
430430 }
431431
432−struct inode *ext2_new_inode(struct inode *dir, int mode)
432+struct inode *ext2_new_inode(struct inode *dir, int mode,
433+ const struct qstr *qstr)
433434 {
434435 struct super_block *sb;
435436 struct buffer_head *bitmap_bh = NULL;
@@ -585,7 +586,7 @@ got: · 149 unmodified lines
585586 if (err)
586587 goto fail_free_drop;
587588
588− err = ext2_init_security(inode,dir);
589+ err = ext2_init_security(inode, dir, qstr);
589590 if (err)
590591 goto fail_free_drop;
591592
fs/ext2/namei.c+4−4
@@ -104,7 +104,7 @@ static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, st · 103 unmodified lines
104104
105105 dquot_initialize(dir);
106106
107− inode = ext2_new_inode(dir, mode);
107+ inode = ext2_new_inode(dir, mode, &dentry->d_name);
108108 if (IS_ERR(inode))
109109 return PTR_ERR(inode);
110110
@@ -133,7 +133,7 @@ static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_ · 22 unmodified lines
133133
134134 dquot_initialize(dir);
135135
136− inode = ext2_new_inode (dir, mode);
136+ inode = ext2_new_inode (dir, mode, &dentry->d_name);
137137 err = PTR_ERR(inode);
138138 if (!IS_ERR(inode)) {
139139 init_special_inode(inode, inode->i_mode, rdev);
@@ -159,7 +159,7 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry, · 19 unmodified lines
159159
160160 dquot_initialize(dir);
161161
162− inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO);
162+ inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO, &dentry->d_name);
163163 err = PTR_ERR(inode);
164164 if (IS_ERR(inode))
165165 goto out;
@@ -230,7 +230,7 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode) · 64 unmodified lines
230230
231231 inode_inc_link_count(dir);
232232
233− inode = ext2_new_inode (dir, S_IFDIR | mode);
233+ inode = ext2_new_inode(dir, S_IFDIR | mode, &dentry->d_name);
234234 err = PTR_ERR(inode);
235235 if (IS_ERR(inode))
236236 goto out_dir;
fs/ext2/xattr.h+4−2
@@ -116,9 +116,11 @@ exit_ext2_xattr(void) · 115 unmodified lines
116116 # endif /* CONFIG_EXT2_FS_XATTR */
117117
118118 #ifdef CONFIG_EXT2_FS_SECURITY
119−extern int ext2_init_security(struct inode *inode, struct inode *dir);
119+extern int ext2_init_security(struct inode *inode, struct inode *dir,
120+ const struct qstr *qstr);
120121 #else
121−static inline int ext2_init_security(struct inode *inode, struct inode *dir)
122+static inline int ext2_init_security(struct inode *inode, struct inode *dir,
123+ const struct qstr *qstr)
122124 {
123125 return 0;
124126 }
fs/ext2/xattr_security.c+3−2
@@ -47,14 +47,15 @@ ext2_xattr_security_set(struct dentry *dentry, const char *name, · 46 unmodified lines
4747 }
4848
4949 int
50−ext2_init_security(struct inode *inode, struct inode *dir)
50+ext2_init_security(struct inode *inode, struct inode *dir,
51+ const struct qstr *qstr)
5152 {
5253 int err;
5354 size_t len;
5455 void *value;
5556 char *name;
5657
57− err = security_inode_init_security(inode, dir, &name, &value, &len);
58+ err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
5859 if (err) {
5960 if (err == -EOPNOTSUPP)
6061 return 0;
fs/ext3/ialloc.c+3−2
@@ -404,7 +404,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent) · 403 unmodified lines
404404 * For other inodes, search forward from the parent directory's block
405405 * group to find a free inode.
406406 */
407−struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
407+struct inode *ext3_new_inode(handle_t *handle, struct inode * dir,
408+ const struct qstr *qstr, int mode)
408409 {
409410 struct super_block *sb;
410411 struct buffer_head *bitmap_bh = NULL;
@@ -589,7 +590,7 @@ got: · 178 unmodified lines
589590 if (err)
590591 goto fail_free_drop;
591592
592− err = ext3_init_security(handle,inode, dir);
593+ err = ext3_init_security(handle, inode, dir, qstr);
593594 if (err)
594595 goto fail_free_drop;
595596
fs/ext3/namei.c+4−4
@@ -1710,7 +1710,7 @@ retry: · 1709 unmodified lines
17101710 if (IS_DIRSYNC(dir))
17111711 handle->h_sync = 1;
17121712
1713− inode = ext3_new_inode (handle, dir, mode);
1713+ inode = ext3_new_inode (handle, dir, &dentry->d_name, mode);
17141714 err = PTR_ERR(inode);
17151715 if (!IS_ERR(inode)) {
17161716 inode->i_op = &ext3_file_inode_operations;
@@ -1746,7 +1746,7 @@ retry: · 29 unmodified lines
17461746 if (IS_DIRSYNC(dir))
17471747 handle->h_sync = 1;
17481748
1749− inode = ext3_new_inode (handle, dir, mode);
1749+ inode = ext3_new_inode (handle, dir, &dentry->d_name, mode);
17501750 err = PTR_ERR(inode);
17511751 if (!IS_ERR(inode)) {
17521752 init_special_inode(inode, inode->i_mode, rdev);
@@ -1784,7 +1784,7 @@ retry: · 31 unmodified lines
17841784 if (IS_DIRSYNC(dir))
17851785 handle->h_sync = 1;
17861786
1787− inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
1787+ inode = ext3_new_inode (handle, dir, &dentry->d_name, S_IFDIR | mode);
17881788 err = PTR_ERR(inode);
17891789 if (IS_ERR(inode))
17901790 goto out_stop;
@@ -2206,7 +2206,7 @@ retry: · 415 unmodified lines
22062206 if (IS_DIRSYNC(dir))
22072207 handle->h_sync = 1;
22082208
2209− inode = ext3_new_inode (handle, dir, S_IFLNK|S_IRWXUGO);
2209+ inode = ext3_new_inode (handle, dir, &dentry->d_name, S_IFLNK|S_IRWXUGO);
22102210 err = PTR_ERR(inode);
22112211 if (IS_ERR(inode))
22122212 goto out_stop;
fs/ext3/xattr.h+2−2
@@ -128,10 +128,10 @@ exit_ext3_xattr(void) · 127 unmodified lines
128128
129129 #ifdef CONFIG_EXT3_FS_SECURITY
130130 extern int ext3_init_security(handle_t *handle, struct inode *inode,
131− struct inode *dir);
131+ struct inode *dir, const struct qstr *qstr);
132132 #else
133133 static inline int ext3_init_security(handle_t *handle, struct inode *inode,
134− struct inode *dir)
134+ struct inode *dir, const struct qstr *qstr)
135135 {
136136 return 0;
137137 }
fs/ext3/xattr_security.c+3−2
@@ -49,14 +49,15 @@ ext3_xattr_security_set(struct dentry *dentry, const char *name, · 48 unmodified lines
4949 }
5050
5151 int
52−ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
52+ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
53+ const struct qstr *qstr)
5354 {
5455 int err;
5556 size_t len;
5657 void *value;
5758 char *name;
5859
59− err = security_inode_init_security(inode, dir, &name, &value, &len);
60+ err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
6061 if (err) {
6162 if (err == -EOPNOTSUPP)
6263 return 0;
fs/ext4/ialloc.c+1−1
@@ -1042,7 +1042,7 @@ got: · 1041 unmodified lines
10421042 if (err)
10431043 goto fail_free_drop;
10441044
1045− err = ext4_init_security(handle, inode, dir);
1045+ err = ext4_init_security(handle, inode, dir, qstr);
10461046 if (err)
10471047 goto fail_free_drop;
10481048
fs/ext4/xattr.h+2−2
@@ -145,10 +145,10 @@ ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize, · 144 unmodified lines
145145
146146 #ifdef CONFIG_EXT4_FS_SECURITY
147147 extern int ext4_init_security(handle_t *handle, struct inode *inode,
148− struct inode *dir);
148+ struct inode *dir, const struct qstr *qstr);
149149 #else
150150 static inline int ext4_init_security(handle_t *handle, struct inode *inode,
151− struct inode *dir)
151+ struct inode *dir, const struct qstr *qstr)
152152 {
153153 return 0;
154154 }
fs/ext4/xattr_security.c+3−2
@@ -49,14 +49,15 @@ ext4_xattr_security_set(struct dentry *dentry, const char *name, · 48 unmodified lines
4949 }
5050
5151 int
52−ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
52+ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
53+ const struct qstr *qstr)
5354 {
5455 int err;
5556 size_t len;
5657 void *value;
5758 char *name;
5859
59− err = security_inode_init_security(inode, dir, &name, &value, &len);
60+ err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
6061 if (err) {
6162 if (err == -EOPNOTSUPP)
6263 return 0;
fs/file_table.c+4−1
@@ -190,7 +190,8 @@ struct file *alloc_file(struct path *path, fmode_t mode, · 189 unmodified lines
190190 file_take_write(file);
191191 WARN_ON(mnt_clone_write(path->mnt));
192192 }
193− ima_counts_get(file);
193+ if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
194+ i_readcount_inc(path->dentry->d_inode);
194195 return file;
195196 }
196197 EXPORT_SYMBOL(alloc_file);
@@ -251,6 +252,8 @@ static void __fput(struct file *file) · 54 unmodified lines
251252 fops_put(file->f_op);
252253 put_pid(file->f_owner.pid);
253254 file_sb_list_del(file);
255+ if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
256+ i_readcount_dec(inode);
254257 if (file->f_mode & FMODE_WRITE)
255258 drop_file_write_access(file);
256259 file->f_path.dentry = NULL;
fs/gfs2/inode.c+4−3
@@ -763,14 +763,15 @@ fail: · 762 unmodified lines
763763 return error;
764764 }
765765
766−static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip)
766+static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip,
767+ const struct qstr *qstr)
767768 {
768769 int err;
769770 size_t len;
770771 void *value;
771772 char *name;
772773
773− err = security_inode_init_security(&ip->i_inode, &dip->i_inode,
774+ err = security_inode_init_security(&ip->i_inode, &dip->i_inode, qstr,
774775 &name, &value, &len);
775776
776777 if (err) {
@@ -854,7 +855,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, · 77 unmodified lines
854855 if (error)
855856 goto fail_gunlock2;
856857
857− error = gfs2_security_init(dip, GFS2_I(inode));
858+ error = gfs2_security_init(dip, GFS2_I(inode), name);
858859 if (error)
859860 goto fail_gunlock2;
860861
fs/jffs2/dir.c+4−5
@@ -215,8 +215,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode, · 214 unmodified lines
215215 no chance of AB-BA deadlock involving its f->sem). */
216216 mutex_unlock(&f->sem);
217217
218− ret = jffs2_do_create(c, dir_f, f, ri,
219− dentry->d_name.name, dentry->d_name.len);
218+ ret = jffs2_do_create(c, dir_f, f, ri, &dentry->d_name);
220219 if (ret)
221220 goto fail;
222221
@@ -386,7 +385,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char · 163 unmodified lines
386385
387386 jffs2_complete_reservation(c);
388387
389− ret = jffs2_init_security(inode, dir_i);
388+ ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
390389 if (ret)
391390 goto fail;
392391
@@ -530,7 +529,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode) · 137 unmodified lines
530529
531530 jffs2_complete_reservation(c);
532531
533− ret = jffs2_init_security(inode, dir_i);
532+ ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
534533 if (ret)
535534 goto fail;
536535
@@ -703,7 +702,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de · 166 unmodified lines
703702
704703 jffs2_complete_reservation(c);
705704
706− ret = jffs2_init_security(inode, dir_i);
705+ ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
707706 if (ret)
708707 goto fail;
709708
fs/jffs2/nodelist.h+1−1
@@ -401,7 +401,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, · 400 unmodified lines
401401 struct jffs2_raw_inode *ri, unsigned char *buf,
402402 uint32_t offset, uint32_t writelen, uint32_t *retlen);
403403 int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f,
404− struct jffs2_raw_inode *ri, const char *name, int namelen);
404+ struct jffs2_raw_inode *ri, const struct qstr *qstr);
405405 int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name,
406406 int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
407407 int jffs2_do_link(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino,
fs/jffs2/security.c+3−2
@@ -23,14 +23,15 @@ · 22 unmodified lines
2323 #include "nodelist.h"
2424
2525 /* ---- Initial Security Label Attachment -------------- */
26−int jffs2_init_security(struct inode *inode, struct inode *dir)
26+int jffs2_init_security(struct inode *inode, struct inode *dir,
27+ const struct qstr *qstr)
2728 {
2829 int rc;
2930 size_t len;
3031 void *value;
3132 char *name;
3233
33− rc = security_inode_init_security(inode, dir, &name, &value, &len);
34+ rc = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
3435 if (rc) {
3536 if (rc == -EOPNOTSUPP)
3637 return 0;
fs/jffs2/write.c+10−8
@@ -424,7 +424,9 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, · 423 unmodified lines
424424 return ret;
425425 }
426426
427−int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen)
427+int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
428+ struct jffs2_inode_info *f, struct jffs2_raw_inode *ri,
429+ const struct qstr *qstr)
428430 {
429431 struct jffs2_raw_dirent *rd;
430432 struct jffs2_full_dnode *fn;
@@ -466,15 +468,15 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str · 35 unmodified lines
466468 mutex_unlock(&f->sem);
467469 jffs2_complete_reservation(c);
468470
469− ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode);
471+ ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode, qstr);
470472 if (ret)
471473 return ret;
472474 ret = jffs2_init_acl_post(&f->vfs_inode);
473475 if (ret)
474476 return ret;
475477
476− ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
477− ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
478+ ret = jffs2_reserve_space(c, sizeof(*rd)+qstr->len, &alloclen,
479+ ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(qstr->len));
478480
479481 if (ret) {
480482 /* Eep. */
@@ -493,19 +495,19 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str · 12 unmodified lines
493495
494496 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
495497 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
496− rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
498+ rd->totlen = cpu_to_je32(sizeof(*rd) + qstr->len);
497499 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
498500
499501 rd->pino = cpu_to_je32(dir_f->inocache->ino);
500502 rd->version = cpu_to_je32(++dir_f->highest_version);
501503 rd->ino = ri->ino;
502504 rd->mctime = ri->ctime;
503− rd->nsize = namelen;
505+ rd->nsize = qstr->len;
504506 rd->type = DT_REG;
505507 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
506− rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
508+ rd->name_crc = cpu_to_je32(crc32(0, qstr->name, qstr->len));
507509
508− fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
510+ fd = jffs2_write_dirent(c, dir_f, rd, qstr->name, qstr->len, ALLOC_NORMAL);
509511
510512 jffs2_free_raw_dirent(rd);
511513
fs/jffs2/xattr.h+3−2
@@ -121,10 +121,11 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t); · 120 unmodified lines
121121 #endif /* CONFIG_JFFS2_FS_XATTR */
122122
123123 #ifdef CONFIG_JFFS2_FS_SECURITY
124−extern int jffs2_init_security(struct inode *inode, struct inode *dir);
124+extern int jffs2_init_security(struct inode *inode, struct inode *dir,
125+ const struct qstr *qstr);
125126 extern const struct xattr_handler jffs2_security_xattr_handler;
126127 #else
127−#define jffs2_init_security(inode,dir) (0)
128+#define jffs2_init_security(inode,dir,qstr) (0)
128129 #endif /* CONFIG_JFFS2_FS_SECURITY */
129130
130131 #endif /* _JFFS2_FS_XATTR_H_ */
fs/jfs/jfs_xattr.h+3−2
@@ -62,10 +62,11 @@ extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); · 61 unmodified lines
6262 extern int jfs_removexattr(struct dentry *, const char *);
6363
6464 #ifdef CONFIG_JFS_SECURITY
65−extern int jfs_init_security(tid_t, struct inode *, struct inode *);
65+extern int jfs_init_security(tid_t, struct inode *, struct inode *,
66+ const struct qstr *);
6667 #else
6768 static inline int jfs_init_security(tid_t tid, struct inode *inode,
68− struct inode *dir)
69+ struct inode *dir, const struct qstr *qstr)
6970 {
7071 return 0;
7172 }
fs/jfs/namei.c+4−4
@@ -115,7 +115,7 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode, · 114 unmodified lines
115115 if (rc)
116116 goto out3;
117117
118− rc = jfs_init_security(tid, ip, dip);
118+ rc = jfs_init_security(tid, ip, dip, &dentry->d_name);
119119 if (rc) {
120120 txAbort(tid, 0);
121121 goto out3;
@@ -253,7 +253,7 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode) · 131 unmodified lines
253253 if (rc)
254254 goto out3;
255255
256− rc = jfs_init_security(tid, ip, dip);
256+ rc = jfs_init_security(tid, ip, dip, &dentry->d_name);
257257 if (rc) {
258258 txAbort(tid, 0);
259259 goto out3;
@@ -932,7 +932,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry, · 672 unmodified lines
932932 mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT);
933933 mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
934934
935− rc = jfs_init_security(tid, ip, dip);
935+ rc = jfs_init_security(tid, ip, dip, &dentry->d_name);
936936 if (rc)
937937 goto out3;
938938
@@ -1395,7 +1395,7 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry, · 456 unmodified lines
13951395 if (rc)
13961396 goto out3;
13971397
1398− rc = jfs_init_security(tid, ip, dir);
1398+ rc = jfs_init_security(tid, ip, dir, &dentry->d_name);
13991399 if (rc) {
14001400 txAbort(tid, 0);
14011401 goto out3;
fs/jfs/xattr.c+4−2
@@ -1091,7 +1091,8 @@ int jfs_removexattr(struct dentry *dentry, const char *name) · 1090 unmodified lines
10911091 }
10921092
10931093 #ifdef CONFIG_JFS_SECURITY
1094−int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir)
1094+int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir,
1095+ const struct qstr *qstr)
10951096 {
10961097 int rc;
10971098 size_t len;
@@ -1099,7 +1100,8 @@ int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir) · 1 unmodified line
10991100 char *suffix;
11001101 char *name;
11011102
1102− rc = security_inode_init_security(inode, dir, &suffix, &value, &len);
1103+ rc = security_inode_init_security(inode, dir, qstr, &suffix, &value,
1104+ &len);
11031105 if (rc) {
11041106 if (rc == -EOPNOTSUPP)
11051107 return 0;
fs/namespace.c+4−0
@@ -1767,6 +1767,10 @@ static int do_remount(struct path *path, int flags, int mnt_flags, · 1766 unmodified lines
17671767 if (path->dentry != path->mnt->mnt_root)
17681768 return -EINVAL;
17691769
1770+ err = security_sb_remount(sb, data);
1771+ if (err)
1772+ return err;
1773+
17701774 down_write(&sb->s_umount);
17711775 if (flags & MS_BIND)
17721776 err = change_mount_flags(path->mnt, flags);
fs/ocfs2/namei.c+2−2
@@ -293,7 +293,7 @@ static int ocfs2_mknod(struct inode *dir, · 292 unmodified lines
293293 }
294294
295295 /* get security xattr */
296− status = ocfs2_init_security_get(inode, dir, &si);
296+ status = ocfs2_init_security_get(inode, dir, &dentry->d_name, &si);
297297 if (status) {
298298 if (status == -EOPNOTSUPP)
299299 si.enable = 0;
@@ -1665,7 +1665,7 @@ static int ocfs2_symlink(struct inode *dir, · 1365 unmodified lines
16651665 }
16661666
16671667 /* get security xattr */
1668− status = ocfs2_init_security_get(inode, dir, &si);
1668+ status = ocfs2_init_security_get(inode, dir, &dentry->d_name, &si);
16691669 if (status) {
16701670 if (status == -EOPNOTSUPP)
16711671 si.enable = 0;
fs/ocfs2/refcounttree.c+2−1
@@ -4328,7 +4328,8 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir, · 4327 unmodified lines
43284328
43294329 /* If the security isn't preserved, we need to re-initialize them. */
43304330 if (!preserve) {
4331− error = ocfs2_init_security_and_acl(dir, new_orphan_inode);
4331+ error = ocfs2_init_security_and_acl(dir, new_orphan_inode,
4332+ &new_dentry->d_name);
43324333 if (error)
43334334 mlog_errno(error);
43344335 }
fs/ocfs2/xattr.c+6−4
@@ -7185,7 +7185,8 @@ out: · 7184 unmodified lines
71857185 * must not hold any lock expect i_mutex.
71867186 */
71877187 int ocfs2_init_security_and_acl(struct inode *dir,
7188− struct inode *inode)
7188+ struct inode *inode,
7189+ const struct qstr *qstr)
71897190 {
71907191 int ret = 0;
71917192 struct buffer_head *dir_bh = NULL;
@@ -7193,7 +7194,7 @@ int ocfs2_init_security_and_acl(struct inode *dir, · 1 unmodified line
71937194 .enable = 1,
71947195 };
71957196
7196− ret = ocfs2_init_security_get(inode, dir, &si);
7197+ ret = ocfs2_init_security_get(inode, dir, qstr, &si);
71977198 if (!ret) {
71987199 ret = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
71997200 si.name, si.value, si.value_len,
@@ -7261,13 +7262,14 @@ static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name, · 61 unmodified lines
72617262
72627263 int ocfs2_init_security_get(struct inode *inode,
72637264 struct inode *dir,
7265+ const struct qstr *qstr,
72647266 struct ocfs2_security_xattr_info *si)
72657267 {
72667268 /* check whether ocfs2 support feature xattr */
72677269 if (!ocfs2_supports_xattr(OCFS2_SB(dir->i_sb)))
72687270 return -EOPNOTSUPP;
7269− return security_inode_init_security(inode, dir, &si->name, &si->value,
7270− &si->value_len);
7271+ return security_inode_init_security(inode, dir, qstr, &si->name,
7272+ &si->value, &si->value_len);
72717273 }
72727274
72737275 int ocfs2_init_security_set(handle_t *handle,
fs/ocfs2/xattr.h+3−1
@@ -57,6 +57,7 @@ int ocfs2_has_inline_xattr_value_outside(struct inode *inode, · 56 unmodified lines
5757 struct ocfs2_dinode *di);
5858 int ocfs2_xattr_remove(struct inode *, struct buffer_head *);
5959 int ocfs2_init_security_get(struct inode *, struct inode *,
60+ const struct qstr *,
6061 struct ocfs2_security_xattr_info *);
6162 int ocfs2_init_security_set(handle_t *, struct inode *,
6263 struct buffer_head *,
@@ -94,5 +95,6 @@ int ocfs2_reflink_xattrs(struct inode *old_inode, · 31 unmodified lines
9495 struct buffer_head *new_bh,
9596 bool preserve_security);
9697 int ocfs2_init_security_and_acl(struct inode *dir,
97− struct inode *inode);
98+ struct inode *inode,
99+ const struct qstr *qstr);
98100 #endif /* OCFS2_XATTR_H */
fs/open.c+2−1
@@ -701,7 +701,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, · 700 unmodified lines
701701 if (error)
702702 goto cleanup_all;
703703 }
704− ima_counts_get(f);
704+ if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
705+ i_readcount_inc(inode);
705706
706707 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
707708
fs/proc/proc_sysctl.c+0−1
@@ -32,7 +32,6 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, · 31 unmodified lines
3232 ei->sysctl_entry = table;
3333
3434 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
35− inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */
3635 inode->i_mode = table->mode;
3736 if (!table->child) {
3837 inode->i_mode |= S_IFREG;
fs/reiserfs/namei.c+5−4
@@ -593,7 +593,7 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode, · 592 unmodified lines
593593 new_inode_init(inode, dir, mode);
594594
595595 jbegin_count += reiserfs_cache_default_acl(dir);
596− retval = reiserfs_security_init(dir, inode, &security);
596+ retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
597597 if (retval < 0) {
598598 drop_new_inode(inode);
599599 return retval;
@@ -667,7 +667,7 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode, · 67 unmodified lines
667667 new_inode_init(inode, dir, mode);
668668
669669 jbegin_count += reiserfs_cache_default_acl(dir);
670− retval = reiserfs_security_init(dir, inode, &security);
670+ retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
671671 if (retval < 0) {
672672 drop_new_inode(inode);
673673 return retval;
@@ -747,7 +747,7 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) · 73 unmodified lines
747747 new_inode_init(inode, dir, mode);
748748
749749 jbegin_count += reiserfs_cache_default_acl(dir);
750− retval = reiserfs_security_init(dir, inode, &security);
750+ retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
751751 if (retval < 0) {
752752 drop_new_inode(inode);
753753 return retval;
@@ -1032,7 +1032,8 @@ static int reiserfs_symlink(struct inode *parent_dir, · 278 unmodified lines
10321032 }
10331033 new_inode_init(inode, parent_dir, mode);
10341034
1035− retval = reiserfs_security_init(parent_dir, inode, &security);
1035+ retval = reiserfs_security_init(parent_dir, inode, &dentry->d_name,
1036+ &security);
10361037 if (retval < 0) {
10371038 drop_new_inode(inode);
10381039 return retval;
fs/reiserfs/xattr_security.c+2−1
@@ -54,6 +54,7 @@ static size_t security_list(struct dentry *dentry, char *list, size_t list_len, · 53 unmodified lines
5454 * of blocks needed for the transaction. If successful, reiserfs_security
5555 * must be released using reiserfs_security_free when the caller is done. */
5656 int reiserfs_security_init(struct inode *dir, struct inode *inode,
57+ const struct qstr *qstr,
5758 struct reiserfs_security_handle *sec)
5859 {
5960 int blocks = 0;
@@ -65,7 +66,7 @@ int reiserfs_security_init(struct inode *dir, struct inode *inode, · 5 unmodified lines
6566 if (IS_PRIVATE(dir))
6667 return 0;
6768
68− error = security_inode_init_security(inode, dir, &sec->name,
69+ error = security_inode_init_security(inode, dir, qstr, &sec->name,
6970 &sec->value, &sec->length);
7071 if (error) {
7172 if (error == -EOPNOTSUPP)
fs/xfs/linux-2.6/xfs_iops.c+5−4
@@ -102,7 +102,8 @@ xfs_mark_inode_dirty( · 101 unmodified lines
102102 STATIC int
103103 xfs_init_security(
104104 struct inode *inode,
105− struct inode *dir)
105+ struct inode *dir,
106+ const struct qstr *qstr)
106107 {
107108 struct xfs_inode *ip = XFS_I(inode);
108109 size_t length;
@@ -110,7 +111,7 @@ xfs_init_security( · 1 unmodified line
110111 unsigned char *name;
111112 int error;
112113
113− error = security_inode_init_security(inode, dir, (char **)&name,
114+ error = security_inode_init_security(inode, dir, qstr, (char **)&name,
114115 &value, &length);
115116 if (error) {
116117 if (error == -EOPNOTSUPP)
@@ -194,7 +195,7 @@ xfs_vn_mknod( · 77 unmodified lines
194195
195196 inode = VFS_I(ip);
196197
197− error = xfs_init_security(inode, dir);
198+ error = xfs_init_security(inode, dir, &dentry->d_name);
198199 if (unlikely(error))
199200 goto out_cleanup_inode;
200201
@@ -367,7 +368,7 @@ xfs_vn_symlink( · 166 unmodified lines
367368
368369 inode = VFS_I(cip);
369370
370− error = xfs_init_security(inode, dir);
371+ error = xfs_init_security(inode, dir, &dentry->d_name);
371372 if (unlikely(error))
372373 goto out_cleanup_inode;
373374
include/linux/ext3_fs.h+2−1
@@ -884,7 +884,8 @@ extern int ext3fs_dirhash(const char *name, int len, struct · 883 unmodified lines
884884 dx_hash_info *hinfo);
885885
886886 /* ialloc.c */
887−extern struct inode * ext3_new_inode (handle_t *, struct inode *, int);
887+extern struct inode * ext3_new_inode (handle_t *, struct inode *,
888+ const struct qstr *, int);
888889 extern void ext3_free_inode (handle_t *, struct inode *);
889890 extern struct inode * ext3_orphan_get (struct super_block *, unsigned long);
890891 extern unsigned long ext3_count_free_inodes (struct super_block *);
include/linux/fs.h+21−2
@@ -798,8 +798,7 @@ struct inode { · 797 unmodified lines
798798 #endif
799799
800800 #ifdef CONFIG_IMA
801− /* protected by i_lock */
802− unsigned int i_readcount; /* struct files open RO */
801+ atomic_t i_readcount; /* struct files open RO */
803802 #endif
804803 atomic_t i_writecount;
805804 #ifdef CONFIG_SECURITY
@@ -2200,6 +2199,26 @@ static inline void allow_write_access(struct file *file) · 1394 unmodified lines
22002199 if (file)
22012200 atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
22022201 }
2202+#ifdef CONFIG_IMA
2203+static inline void i_readcount_dec(struct inode *inode)
2204+{
2205+ BUG_ON(!atomic_read(&inode->i_readcount));
2206+ atomic_dec(&inode->i_readcount);
2207+}
2208+static inline void i_readcount_inc(struct inode *inode)
2209+{
2210+ atomic_inc(&inode->i_readcount);
2211+}
2212+#else
2213+static inline void i_readcount_dec(struct inode *inode)
2214+{
2215+ return;
2216+}
2217+static inline void i_readcount_inc(struct inode *inode)
2218+{
2219+ return;
2220+}
2221+#endif
22032222 extern int do_pipe_flags(int *, int);
22042223 extern struct file *create_read_pipe(struct file *f, int flags);
22052224 extern struct file *create_write_pipe(int flags);
include/linux/ima.h+0−6
@@ -20,7 +20,6 @@ extern void ima_inode_free(struct inode *inode); · 19 unmodified lines
2020 extern int ima_file_check(struct file *file, int mask);
2121 extern void ima_file_free(struct file *file);
2222 extern int ima_file_mmap(struct file *file, unsigned long prot);
23−extern void ima_counts_get(struct file *file);
2423
2524 #else
2625 static inline int ima_bprm_check(struct linux_binprm *bprm)
@@ -53,10 +52,5 @@ static inline int ima_file_mmap(struct file *file, unsigned long prot) · 26 unmodified lines
5352 return 0;
5453 }
5554
56−static inline void ima_counts_get(struct file *file)
57−{
58− return;
59−}
60−
6155 #endif /* CONFIG_IMA_H */
6256 #endif /* _LINUX_IMA_H */
include/linux/key-type.h+13−1
@@ -41,6 +41,9 @@ struct key_type { · 40 unmodified lines
4141 */
4242 size_t def_datalen;
4343
44+ /* vet a description */
45+ int (*vet_description)(const char *description);
46+
4447 /* instantiate a key of this type
4548 * - this method should call key_payload_reserve() to determine if the
4649 * user's quota will hold the payload
@@ -102,11 +105,20 @@ extern int key_instantiate_and_link(struct key *key, · 55 unmodified lines
102105 size_t datalen,
103106 struct key *keyring,
104107 struct key *instkey);
105−extern int key_negate_and_link(struct key *key,
108+extern int key_reject_and_link(struct key *key,
106109 unsigned timeout,
110+ unsigned error,
107111 struct key *keyring,
108112 struct key *instkey);
109113 extern void complete_request_key(struct key_construction *cons, int error);
110114
115+static inline int key_negate_and_link(struct key *key,
116+ unsigned timeout,
117+ struct key *keyring,
118+ struct key *instkey)
119+{
120+ return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey);
121+}
122+
111123 #endif /* CONFIG_KEYS */
112124 #endif /* _LINUX_KEY_TYPE_H */
include/linux/key.h+5−0
@@ -170,6 +170,7 @@ struct key { · 169 unmodified lines
170170 struct list_head link;
171171 unsigned long x[2];
172172 void *p[2];
173+ int reject_error;
173174 } type_data;
174175
175176 /* key data
@@ -275,6 +276,10 @@ static inline key_serial_t key_serial(struct key *key) · 99 unmodified lines
275276 return key ? key->serial : 0;
276277 }
277278
279+#define rcu_dereference_key(KEY) \
280+ (rcu_dereference_protected((KEY)->payload.rcudata, \
281+ rwsem_is_locked(&((struct key *)(KEY))->sem)))
282+
278283 #ifdef CONFIG_SYSCTL
279284 extern ctl_table key_sysctls[];
280285 #endif
include/linux/keyctl.h+2−0
@@ -53,5 +53,7 @@ · 52 unmodified lines
5353 #define KEYCTL_ASSUME_AUTHORITY 16 /* assume request_key() authorisation */
5454 #define KEYCTL_GET_SECURITY 17 /* get key security label */
5555 #define KEYCTL_SESSION_TO_PARENT 18 /* apply session keyring to parent process */
56+#define KEYCTL_REJECT 19 /* reject a partially constructed key */
57+#define KEYCTL_INSTANTIATE_IOV 20 /* instantiate a partially constructed key */
5658
5759 #endif /* _LINUX_KEYCTL_H */
include/linux/reiserfs_xattr.h+2−0
@@ -63,6 +63,7 @@ extern const struct xattr_handler reiserfs_xattr_trusted_handler; · 62 unmodified lines
6363 extern const struct xattr_handler reiserfs_xattr_security_handler;
6464 #ifdef CONFIG_REISERFS_FS_SECURITY
6565 int reiserfs_security_init(struct inode *dir, struct inode *inode,
66+ const struct qstr *qstr,
6667 struct reiserfs_security_handle *sec);
6768 int reiserfs_security_write(struct reiserfs_transaction_handle *th,
6869 struct inode *inode,
@@ -130,6 +131,7 @@ static inline void reiserfs_init_xattr_rwsem(struct inode *inode) · 61 unmodified lines
130131 #ifndef CONFIG_REISERFS_FS_SECURITY
131132 static inline int reiserfs_security_init(struct inode *dir,
132133 struct inode *inode,
134+ const struct qstr *qstr,
133135 struct reiserfs_security_handle *sec)
134136 {
135137 return 0;
include/linux/security.h+20−15
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <linux/fs.h>
2626 #include <linux/fsnotify.h>
2727 #include <linux/binfmts.h>
28+#include <linux/dcache.h>
2829 #include <linux/signal.h>
2930 #include <linux/resource.h>
3031 #include <linux/sem.h>
@@ -267,6 +268,12 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · 236 unmodified lines
267268 * @orig the original mount data copied from userspace.
268269 * @copy copied data which will be passed to the security module.
269270 * Returns 0 if the copy was successful.
271+ * @sb_remount:
272+ * Extracts security system specifc mount options and verifys no changes
273+ * are being made to those options.
274+ * @sb superblock being remounted
275+ * @data contains the filesystem-specific data.
276+ * Return 0 if permission is granted.
270277 * @sb_umount:
271278 * Check permission before the @mnt file system is unmounted.
272279 * @mnt contains the mounted file system.
@@ -315,6 +322,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · 42 unmodified lines
315322 * then it should return -EOPNOTSUPP to skip this processing.
316323 * @inode contains the inode structure of the newly created inode.
317324 * @dir contains the inode structure of the parent directory.
325+ * @qstr contains the last path component of the new object
318326 * @name will be set to the allocated name suffix (e.g. selinux).
319327 * @value will be set to the allocated attribute value.
320328 * @len will be set to the length of the value.
@@ -1257,12 +1265,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · 936 unmodified lines
12571265 * @cap contains the capability <include/linux/capability.h>.
12581266 * @audit: Whether to write an audit message or not
12591267 * Return 0 if the capability is granted for @tsk.
1260− * @sysctl:
1261− * Check permission before accessing the @table sysctl variable in the
1262− * manner specified by @op.
1263− * @table contains the ctl_table structure for the sysctl variable.
1264− * @op contains the operation (001 = search, 002 = write, 004 = read).
1265− * Return 0 if permission is granted.
12661268 * @syslog:
12671269 * Check permission before accessing the kernel message ring or changing
12681270 * logging to the console.
@@ -1383,7 +1385,6 @@ struct security_operations { · 114 unmodified lines
13831385 const kernel_cap_t *permitted);
13841386 int (*capable) (struct task_struct *tsk, const struct cred *cred,
13851387 int cap, int audit);
1386− int (*sysctl) (struct ctl_table *table, int op);
13871388 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
13881389 int (*quota_on) (struct dentry *dentry);
13891390 int (*syslog) (int type);
@@ -1399,6 +1400,7 @@ struct security_operations { · 9 unmodified lines
13991400 int (*sb_alloc_security) (struct super_block *sb);
14001401 void (*sb_free_security) (struct super_block *sb);
14011402 int (*sb_copy_data) (char *orig, char *copy);
1403+ int (*sb_remount) (struct super_block *sb, void *data);
14021404 int (*sb_kern_mount) (struct super_block *sb, int flags, void *data);
14031405 int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
14041406 int (*sb_statfs) (struct dentry *dentry);
@@ -1435,7 +1437,8 @@ struct security_operations { · 30 unmodified lines
14351437 int (*inode_alloc_security) (struct inode *inode);
14361438 void (*inode_free_security) (struct inode *inode);
14371439 int (*inode_init_security) (struct inode *inode, struct inode *dir,
1438− char **name, void **value, size_t *len);
1440+ const struct qstr *qstr, char **name,
1441+ void **value, size_t *len);
14391442 int (*inode_create) (struct inode *dir,
14401443 struct dentry *dentry, int mode);
14411444 int (*inode_link) (struct dentry *old_dentry,
@@ -1665,7 +1668,6 @@ int security_capset(struct cred *new, const struct cred *old, · 223 unmodified lines
16651668 int security_capable(const struct cred *cred, int cap);
16661669 int security_real_capable(struct task_struct *tsk, int cap);
16671670 int security_real_capable_noaudit(struct task_struct *tsk, int cap);
1668−int security_sysctl(struct ctl_table *table, int op);
16691671 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
16701672 int security_quota_on(struct dentry *dentry);
16711673 int security_syslog(int type);
@@ -1681,6 +1683,7 @@ int security_bprm_secureexec(struct linux_binprm *bprm); · 9 unmodified lines
16811683 int security_sb_alloc(struct super_block *sb);
16821684 void security_sb_free(struct super_block *sb);
16831685 int security_sb_copy_data(char *orig, char *copy);
1686+int security_sb_remount(struct super_block *sb, void *data);
16841687 int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
16851688 int security_sb_show_options(struct seq_file *m, struct super_block *sb);
16861689 int security_sb_statfs(struct dentry *dentry);
@@ -1696,7 +1699,8 @@ int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts); · 9 unmodified lines
16961699 int security_inode_alloc(struct inode *inode);
16971700 void security_inode_free(struct inode *inode);
16981701 int security_inode_init_security(struct inode *inode, struct inode *dir,
1699− char **name, void **value, size_t *len);
1702+ const struct qstr *qstr, char **name,
1703+ void **value, size_t *len);
17001704 int security_inode_create(struct inode *dir, struct dentry *dentry, int mode);
17011705 int security_inode_link(struct dentry *old_dentry, struct inode *dir,
17021706 struct dentry *new_dentry);
@@ -1883,11 +1887,6 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap) · 180 unmodified lines
18831887 return ret;
18841888 }
18851889
1886−static inline int security_sysctl(struct ctl_table *table, int op)
1887−{
1888− return 0;
1889−}
1890−
18911890 static inline int security_quotactl(int cmds, int type, int id,
18921891 struct super_block *sb)
18931892 {
@@ -1964,6 +1963,11 @@ static inline int security_sb_copy_data(char *orig, char *copy) · 70 unmodified lines
19641963 return 0;
19651964 }
19661965
1966+static inline int security_sb_remount(struct super_block *sb, void *data)
1967+{
1968+ return 0;
1969+}
1970+
19671971 static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
19681972 {
19691973 return 0;
@@ -2023,6 +2027,7 @@ static inline void security_inode_free(struct inode *inode) · 53 unmodified lines
20232027
20242028 static inline int security_inode_init_security(struct inode *inode,
20252029 struct inode *dir,
2030+ const struct qstr *qstr,
20262031 char **name,
20272032 void **value,
20282033 size_t *len)
include/linux/xattr.h+2−0
@@ -42,11 +42,13 @@ · 41 unmodified lines
4242 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
4343 #define XATTR_SMACK_EXEC "SMACK64EXEC"
4444 #define XATTR_SMACK_TRANSMUTE "SMACK64TRANSMUTE"
45+#define XATTR_SMACK_MMAP "SMACK64MMAP"
4546 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
4647 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
4748 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
4849 #define XATTR_NAME_SMACKEXEC XATTR_SECURITY_PREFIX XATTR_SMACK_EXEC
4950 #define XATTR_NAME_SMACKTRANSMUTE XATTR_SECURITY_PREFIX XATTR_SMACK_TRANSMUTE
51+#define XATTR_NAME_SMACKMMAP XATTR_SECURITY_PREFIX XATTR_SMACK_MMAP
5052
5153 #define XATTR_CAPS_SUFFIX "capability"
5254 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
kernel/sysctl.c+0−5
@@ -1690,13 +1690,8 @@ static int test_perm(int mode, int op) · 1689 unmodified lines
16901690
16911691 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
16921692 {
1693− int error;
16941693 int mode;
16951694
1696− error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1697− if (error)
1698− return error;
1699−
17001695 if (root->permissions)
17011696 mode = root->permissions(root, current->nsproxy, table);
17021697 else
mm/shmem.c+5−4
@@ -1843,8 +1843,9 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) · 1842 unmodified lines
18431843
18441844 inode = shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE);
18451845 if (inode) {
1846− error = security_inode_init_security(inode, dir, NULL, NULL,
1847− NULL);
1846+ error = security_inode_init_security(inode, dir,
1847+ &dentry->d_name, NULL,
1848+ NULL, NULL);
18481849 if (error) {
18491850 if (error != -EOPNOTSUPP) {
18501851 iput(inode);
@@ -1983,8 +1984,8 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s · 132 unmodified lines
19831984 if (!inode)
19841985 return -ENOSPC;
19851986
1986− error = security_inode_init_security(inode, dir, NULL, NULL,
1987− NULL);
1987+ error = security_inode_init_security(inode, dir, &dentry->d_name, NULL,
1988+ NULL, NULL);
19881989 if (error) {
19891990 if (error != -EOPNOTSUPP) {
19901991 iput(inode);
net/rxrpc/ar-key.c+19−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <keys/user-type.h>
2626 #include "ar-internal.h"
2727
28+static int rxrpc_vet_description_s(const char *);
2829 static int rxrpc_instantiate(struct key *, const void *, size_t);
2930 static int rxrpc_instantiate_s(struct key *, const void *, size_t);
3031 static void rxrpc_destroy(struct key *);
@@ -52,12 +53,30 @@ EXPORT_SYMBOL(key_type_rxrpc); · 21 unmodified lines
5253 */
5354 struct key_type key_type_rxrpc_s = {
5455 .name = "rxrpc_s",
56+ .vet_description = rxrpc_vet_description_s,
5557 .instantiate = rxrpc_instantiate_s,
5658 .match = user_match,
5759 .destroy = rxrpc_destroy_s,
5860 .describe = rxrpc_describe,
5961 };
6062
63+/*
64+ * Vet the description for an RxRPC server key
65+ */
66+static int rxrpc_vet_description_s(const char *desc)
67+{
68+ unsigned long num;
69+ char *p;
70+
71+ num = simple_strtoul(desc, &p, 10);
72+ if (*p != ':' || num > 65535)
73+ return -EINVAL;
74+ num = simple_strtoul(p + 1, &p, 10);
75+ if (*p || num < 1 || num > 255)
76+ return -EINVAL;
77+ return 0;
78+}
79+
6180 /*
6281 * parse an RxKAD type XDR format token
6382 * - the caller guarantees we have at least 4 words
scripts/selinux/genheaders/genheaders.c+20−0
@@ -43,6 +43,8 @@ int main(int argc, char *argv[]) · 42 unmodified lines
4343 int i, j, k;
4444 int isids_len;
4545 FILE *fout;
46+ const char *needle = "SOCKET";
47+ char *substr;
4648
4749 progname = argv[0];
4850
@@ -88,6 +90,24 @@ int main(int argc, char *argv[]) · 39 unmodified lines
8890 fprintf(fout, "%2d\n", i);
8991 }
9092 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
93+ fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
94+ fprintf(fout, "{\n");
95+ fprintf(fout, "\tbool sock = false;\n\n");
96+ fprintf(fout, "\tswitch (kern_tclass) {\n");
97+ for (i = 0; secclass_map[i].name; i++) {
98+ struct security_class_mapping *map = &secclass_map[i];
99+ substr = strstr(map->name, needle);
100+ if (substr && strcmp(substr, needle) == 0)
101+ fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
102+ }
103+ fprintf(fout, "\t\tsock = true;\n");
104+ fprintf(fout, "\t\tbreak;\n");
105+ fprintf(fout, "\tdefault:\n");
106+ fprintf(fout, "\t\tbreak;\n");
107+ fprintf(fout, "\t}\n\n");
108+ fprintf(fout, "\treturn sock;\n");
109+ fprintf(fout, "}\n");
110+
91111 fprintf(fout, "\n#endif\n");
92112 fclose(fout);
93113
security/apparmor/Makefile+33−5
@@ -6,19 +6,47 @@ apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \ · 5 unmodified lines
66 path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
77 resource.o sid.o file.o
88
9−clean-files: capability_names.h af_names.h
9+clean-files := capability_names.h rlim_names.h
1010
11+
12+# Build a lower case string table of capability names
13+# Transforms lines from
14+# #define CAP_DAC_OVERRIDE 1
15+# to
16+# [1] = "dac_override",
1117 quiet_cmd_make-caps = GEN $@
12−cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ; sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2] = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@
18+cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ;\
19+ sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
20+ -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
21+ echo "};" >> $@
22+
1323
24+# Build a lower case string table of rlimit names.
25+# Transforms lines from
26+# #define RLIMIT_STACK 3 /* max stack size */
27+# to
28+# [RLIMIT_STACK] = "stack",
29+#
30+# and build a second integer table (with the second sed cmd), that maps
31+# RLIMIT defines to the order defined in asm-generic/resource.h Thi is
32+# required by policy load to map policy ordering of RLIMITs to internal
33+# ordering for architectures that redefine an RLIMIT.
34+# Transforms lines from
35+# #define RLIMIT_STACK 3 /* max stack size */
36+# to
37+# RLIMIT_STACK,
1438 quiet_cmd_make-rlim = GEN $@
15−cmd_make-rlim = echo "static const char *rlim_names[] = {" > $@ ; sed -n --e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+RLIMIT_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/[\\2] = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@ ; echo "static const int rlim_map[] = {" >> $@ ; sed -n -e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+\\(RLIMIT_[A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/\\1,/p" $< >> $@ ; echo "};" >> $@
39+cmd_make-rlim = echo "static const char *rlim_names[] = {" > $@ ;\
40+ sed $< >> $@ -r -n \
41+ -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
42+ echo "};" >> $@ ;\
43+ echo "static const int rlim_map[] = {" >> $@ ;\
44+ sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
45+ echo "};" >> $@
1646
1747 $(obj)/capability.o : $(obj)/capability_names.h
1848 $(obj)/resource.o : $(obj)/rlim_names.h
1949 $(obj)/capability_names.h : $(srctree)/include/linux/capability.h
2050 $(call cmd,make-caps)
21−$(obj)/af_names.h : $(srctree)/include/linux/socket.h
22− $(call cmd,make-af)
2351 $(obj)/rlim_names.h : $(srctree)/include/asm-generic/resource.h
2452 $(call cmd,make-rlim)
security/apparmor/lsm.c+0−2
@@ -693,11 +693,9 @@ static struct kernel_param_ops param_ops_aalockpolicy = { · 692 unmodified lines
693693
694694 static int param_set_audit(const char *val, struct kernel_param *kp);
695695 static int param_get_audit(char *buffer, struct kernel_param *kp);
696−#define param_check_audit(name, p) __param_check(name, p, int)
697696
698697 static int param_set_mode(const char *val, struct kernel_param *kp);
699698 static int param_get_mode(char *buffer, struct kernel_param *kp);
700−#define param_check_mode(name, p) __param_check(name, p, int)
701699
702700 /* Flag values, also controllable via /sys/module/apparmor/parameters
703701 * We define special types as we want to do additional mediation.
security/capability.c+8−7
@@ -12,11 +12,6 @@ · 11 unmodified lines
1212
1313 #include <linux/security.h>
1414
15−static int cap_sysctl(ctl_table *table, int op)
16−{
17− return 0;
18−}
19−
2015 static int cap_syslog(int type)
2116 {
2217 return 0;
@@ -59,6 +54,11 @@ static int cap_sb_copy_data(char *orig, char *copy) · 36 unmodified lines
5954 return 0;
6055 }
6156
57+static int cap_sb_remount(struct super_block *sb, void *data)
58+{
59+ return 0;
60+}
61+
6262 static int cap_sb_kern_mount(struct super_block *sb, int flags, void *data)
6363 {
6464 return 0;
@@ -118,7 +118,8 @@ static void cap_inode_free_security(struct inode *inode) · 53 unmodified lines
118118 }
119119
120120 static int cap_inode_init_security(struct inode *inode, struct inode *dir,
121− char **name, void **value, size_t *len)
121+ const struct qstr *qstr, char **name,
122+ void **value, size_t *len)
122123 {
123124 return -EOPNOTSUPP;
124125 }
@@ -880,7 +881,6 @@ void __init security_fixup_ops(struct security_operations *ops) · 755 unmodified lines
880881 set_to_cap_if_null(ops, capable);
881882 set_to_cap_if_null(ops, quotactl);
882883 set_to_cap_if_null(ops, quota_on);
883− set_to_cap_if_null(ops, sysctl);
884884 set_to_cap_if_null(ops, syslog);
885885 set_to_cap_if_null(ops, settime);
886886 set_to_cap_if_null(ops, vm_enough_memory);
@@ -892,6 +892,7 @@ void __init security_fixup_ops(struct security_operations *ops) · 5 unmodified lines
892892 set_to_cap_if_null(ops, sb_alloc_security);
893893 set_to_cap_if_null(ops, sb_free_security);
894894 set_to_cap_if_null(ops, sb_copy_data);
895+ set_to_cap_if_null(ops, sb_remount);
895896 set_to_cap_if_null(ops, sb_kern_mount);
896897 set_to_cap_if_null(ops, sb_show_options);
897898 set_to_cap_if_null(ops, sb_statfs);
security/integrity/ima/ima.h+1−2
@@ -110,8 +110,7 @@ struct ima_iint_cache { · 109 unmodified lines
110110 };
111111
112112 /* LIM API function definitions */
113−int ima_must_measure(struct ima_iint_cache *iint, struct inode *inode,
114− int mask, int function);
113+int ima_must_measure(struct inode *inode, int mask, int function);
115114 int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file);
116115 void ima_store_measurement(struct ima_iint_cache *iint, struct file *file,
117116 const unsigned char *filename);
security/integrity/ima/ima_api.c+3−10
@@ -105,20 +105,13 @@ err_out: · 104 unmodified lines
105105 * mask: contains the permission mask
106106 * fsmagic: hex value
107107 *
108− * Must be called with iint->mutex held.
109− *
110− * Return 0 to measure. Return 1 if already measured.
111− * For matching a DONT_MEASURE policy, no policy, or other
112− * error, return an error code.
108+ * Return 0 to measure. For matching a DONT_MEASURE policy, no policy,
109+ * or other error, return an error code.
113110 */
114−int ima_must_measure(struct ima_iint_cache *iint, struct inode *inode,
115− int mask, int function)
111+int ima_must_measure(struct inode *inode, int mask, int function)
116112 {
117113 int must_measure;
118114
119− if (iint && iint->flags & IMA_MEASURED)
120− return 1;
121−
122115 must_measure = ima_match_policy(inode, function, mask);
123116 return must_measure ? 0 : -EACCES;
124117 }
security/integrity/ima/ima_iint.c+0−5
@@ -137,11 +137,6 @@ void ima_inode_free(struct inode *inode) · 136 unmodified lines
137137 {
138138 struct ima_iint_cache *iint;
139139
140− if (inode->i_readcount)
141− printk(KERN_INFO "%s: readcount: %u\n", __func__, inode->i_readcount);
142−
143− inode->i_readcount = 0;
144−
145140 if (!IS_IMA(inode))
146141 return;
147142
security/integrity/ima/ima_main.c+16−120
@@ -36,67 +36,17 @@ static int __init hash_setup(char *str) · 35 unmodified lines
3636 }
3737 __setup("ima_hash=", hash_setup);
3838
39−struct ima_imbalance {
40− struct hlist_node node;
41− unsigned long fsmagic;
42−};
43−
44−/*
45− * ima_limit_imbalance - emit one imbalance message per filesystem type
46− *
47− * Maintain list of filesystem types that do not measure files properly.
48− * Return false if unknown, true if known.
49− */
50−static bool ima_limit_imbalance(struct file *file)
51−{
52− static DEFINE_SPINLOCK(ima_imbalance_lock);
53− static HLIST_HEAD(ima_imbalance_list);
54−
55− struct super_block *sb = file->f_dentry->d_sb;
56− struct ima_imbalance *entry;
57− struct hlist_node *node;
58− bool found = false;
59−
60− rcu_read_lock();
61− hlist_for_each_entry_rcu(entry, node, &ima_imbalance_list, node) {
62− if (entry->fsmagic == sb->s_magic) {
63− found = true;
64− break;
65− }
66− }
67− rcu_read_unlock();
68− if (found)
69− goto out;
70−
71− entry = kmalloc(sizeof(*entry), GFP_NOFS);
72− if (!entry)
73− goto out;
74− entry->fsmagic = sb->s_magic;
75− spin_lock(&ima_imbalance_lock);
76− /*
77− * we could have raced and something else might have added this fs
78− * to the list, but we don't really care
79− */
80− hlist_add_head_rcu(&entry->node, &ima_imbalance_list);
81− spin_unlock(&ima_imbalance_lock);
82− printk(KERN_INFO "IMA: unmeasured files on fsmagic: %lX\n",
83− entry->fsmagic);
84−out:
85− return found;
86−}
87−
8839 /*
89− * ima_counts_get - increment file counts
40+ * ima_rdwr_violation_check
9041 *
91− * Maintain read/write counters for all files, but only
92− * invalidate the PCR for measured files:
42+ * Only invalidate the PCR for measured files:
9343 * - Opening a file for write when already open for read,
9444 * results in a time of measure, time of use (ToMToU) error.
9545 * - Opening a file for read when already open for write,
9646 * could result in a file measurement error.
9747 *
9848 */
99−void ima_counts_get(struct file *file)
49+static void ima_rdwr_violation_check(struct file *file)
10050 {
10151 struct dentry *dentry = file->f_path.dentry;
10252 struct inode *inode = dentry->d_inode;
@@ -104,32 +54,25 @@ void ima_counts_get(struct file *file) · 1 unmodified line
10454 int rc;
10555 bool send_tomtou = false, send_writers = false;
10656
107− if (!S_ISREG(inode->i_mode))
57+ if (!S_ISREG(inode->i_mode) || !ima_initialized)
10858 return;
10959
110− spin_lock(&inode->i_lock);
111−
112− if (!ima_initialized)
113− goto out;
60+ mutex_lock(&inode->i_mutex); /* file metadata: permissions, xattr */
11461
11562 if (mode & FMODE_WRITE) {
116− if (inode->i_readcount && IS_IMA(inode))
63+ if (atomic_read(&inode->i_readcount) && IS_IMA(inode))
11764 send_tomtou = true;
11865 goto out;
11966 }
12067
121− rc = ima_must_measure(NULL, inode, MAY_READ, FILE_CHECK);
68+ rc = ima_must_measure(inode, MAY_READ, FILE_CHECK);
12269 if (rc < 0)
12370 goto out;
12471
12572 if (atomic_read(&inode->i_writecount) > 0)
12673 send_writers = true;
12774 out:
128− /* remember the vfs deals with i_writecount */
129− if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
130− inode->i_readcount++;
131−
132− spin_unlock(&inode->i_lock);
75+ mutex_unlock(&inode->i_mutex);
13376
13477 if (send_tomtou)
13578 ima_add_violation(inode, dentry->d_name.name, "invalid_pcr",
@@ -139,71 +82,25 @@ out: · 3 unmodified lines
13982 "open_writers");
14083 }
14184
142−/*
143− * Decrement ima counts
144− */
145−static void ima_dec_counts(struct inode *inode, struct file *file)
146−{
147− mode_t mode = file->f_mode;
148−
149− assert_spin_locked(&inode->i_lock);
150−
151− if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
152− if (unlikely(inode->i_readcount == 0)) {
153− if (!ima_limit_imbalance(file)) {
154− printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
155− __func__, inode->i_readcount);
156− dump_stack();
157− }
158− return;
159− }
160− inode->i_readcount--;
161− }
162−}
163−
16485 static void ima_check_last_writer(struct ima_iint_cache *iint,
16586 struct inode *inode,
16687 struct file *file)
16788 {
16889 mode_t mode = file->f_mode;
16990
170− BUG_ON(!mutex_is_locked(&iint->mutex));
171− assert_spin_locked(&inode->i_lock);
172−
91+ mutex_lock(&iint->mutex);
17392 if (mode & FMODE_WRITE &&
17493 atomic_read(&inode->i_writecount) == 1 &&
17594 iint->version != inode->i_version)
17695 iint->flags &= ~IMA_MEASURED;
177−}
178−
179−static void ima_file_free_iint(struct ima_iint_cache *iint, struct inode *inode,
180− struct file *file)
181−{
182− mutex_lock(&iint->mutex);
183− spin_lock(&inode->i_lock);
184−
185− ima_dec_counts(inode, file);
186− ima_check_last_writer(iint, inode, file);
187−
188− spin_unlock(&inode->i_lock);
18996 mutex_unlock(&iint->mutex);
19097 }
19198
192−static void ima_file_free_noiint(struct inode *inode, struct file *file)
193−{
194− spin_lock(&inode->i_lock);
195−
196− ima_dec_counts(inode, file);
197−
198− spin_unlock(&inode->i_lock);
199−}
200−
20199 /**
202100 * ima_file_free - called on __fput()
203101 * @file: pointer to file structure being freed
204102 *
205− * Flag files that changed, based on i_version;
206− * and decrement the i_readcount.
103+ * Flag files that changed, based on i_version
207104 */
208105 void ima_file_free(struct file *file)
209106 {
@@ -214,12 +111,10 @@ void ima_file_free(struct file *file) · 4 unmodified lines
214111 return;
215112
216113 iint = ima_iint_find(inode);
114+ if (!iint)
115+ return;
217116
218− if (iint)
219− ima_file_free_iint(iint, inode, file);
220− else
221− ima_file_free_noiint(inode, file);
222−
117+ ima_check_last_writer(iint, inode, file);
223118 }
224119
225120 static int process_measurement(struct file *file, const unsigned char *filename,
@@ -232,7 +127,7 @@ static int process_measurement(struct file *file, const unsigned char *filename, · 6 unmodified lines
232127 if (!ima_initialized || !S_ISREG(inode->i_mode))
233128 return 0;
234129
235− rc = ima_must_measure(NULL, inode, mask, function);
130+ rc = ima_must_measure(inode, mask, function);
236131 if (rc != 0)
237132 return rc;
238133 retry:
@@ -246,7 +141,7 @@ retry: · 7 unmodified lines
246141
247142 mutex_lock(&iint->mutex);
248143
249− rc = ima_must_measure(iint, inode, mask, function);
144+ rc = iint->flags & IMA_MEASURED ? 1 : 0;
250145 if (rc != 0)
251146 goto out;
252147
@@ -317,6 +212,7 @@ int ima_file_check(struct file *file, int mask) · 64 unmodified lines
317212 {
318213 int rc;
319214
215+ ima_rdwr_violation_check(file);
320216 rc = process_measurement(file, file->f_dentry->d_name.name,
321217 mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
322218 FILE_CHECK);
security/keys/compat.c+50−0
@@ -12,8 +12,51 @@ · 11 unmodified lines
1212 #include <linux/syscalls.h>
1313 #include <linux/keyctl.h>
1414 #include <linux/compat.h>
15+#include <linux/slab.h>
1516 #include "internal.h"
1617
18+/*
19+ * Instantiate a key with the specified compatibility multipart payload and
20+ * link the key into the destination keyring if one is given.
21+ *
22+ * The caller must have the appropriate instantiation permit set for this to
23+ * work (see keyctl_assume_authority). No other permissions are required.
24+ *
25+ * If successful, 0 will be returned.
26+ */
27+long compat_keyctl_instantiate_key_iov(
28+ key_serial_t id,
29+ const struct compat_iovec __user *_payload_iov,
30+ unsigned ioc,
31+ key_serial_t ringid)
32+{
33+ struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
34+ long ret;
35+
36+ if (_payload_iov == 0 || ioc == 0)
37+ goto no_payload;
38+
39+ ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc,
40+ ARRAY_SIZE(iovstack),
41+ iovstack, &iov);
42+ if (ret < 0)
43+ return ret;
44+ if (ret == 0)
45+ goto no_payload_free;
46+
47+ ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
48+
49+ if (iov != iovstack)
50+ kfree(iov);
51+ return ret;
52+
53+no_payload_free:
54+ if (iov != iovstack)
55+ kfree(iov);
56+no_payload:
57+ return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
58+}
59+
1760 /*
1861 * The key control system call, 32-bit compatibility version for 64-bit archs
1962 *
@@ -85,6 +128,13 @@ asmlinkage long compat_sys_keyctl(u32 option, · 65 unmodified lines
85128 case KEYCTL_SESSION_TO_PARENT:
86129 return keyctl_session_to_parent();
87130
131+ case KEYCTL_REJECT:
132+ return keyctl_reject_key(arg2, arg3, arg4, arg5);
133+
134+ case KEYCTL_INSTANTIATE_IOV:
135+ return compat_keyctl_instantiate_key_iov(
136+ arg2, compat_ptr(arg3), arg4, arg5);
137+
88138 default:
89139 return -EOPNOTSUPP;
90140 }
security/keys/encrypted.c+1−2
@@ -765,8 +765,7 @@ static long encrypted_read(const struct key *key, char __user *buffer, · 764 unmodified lines
765765 size_t asciiblob_len;
766766 int ret;
767767
768− epayload = rcu_dereference_protected(key->payload.data,
769− rwsem_is_locked(&((struct key *)key)->sem));
768+ epayload = rcu_dereference_key(key);
770769
771770 /* returns the hex encoded iv, encrypted-data, and hmac as ascii */
772771 asciiblob_len = epayload->datablob_len + ivsize + 1
security/keys/internal.h+8−0
@@ -214,6 +214,14 @@ extern long keyctl_assume_authority(key_serial_t); · 213 unmodified lines
214214 extern long keyctl_get_security(key_serial_t keyid, char __user *buffer,
215215 size_t buflen);
216216 extern long keyctl_session_to_parent(void);
217+extern long keyctl_reject_key(key_serial_t, unsigned, unsigned, key_serial_t);
218+extern long keyctl_instantiate_key_iov(key_serial_t,
219+ const struct iovec __user *,
220+ unsigned, key_serial_t);
221+
222+extern long keyctl_instantiate_key_common(key_serial_t,
223+ const struct iovec __user *,
224+ unsigned, size_t, key_serial_t);
217225
218226 /*
219227 * Debugging key validation
security/keys/key.c+19−8
@@ -249,6 +249,14 @@ struct key *key_alloc(struct key_type *type, const char *desc, · 248 unmodified lines
249249 if (!desc || !*desc)
250250 goto error;
251251
252+ if (type->vet_description) {
253+ ret = type->vet_description(desc);
254+ if (ret < 0) {
255+ key = ERR_PTR(ret);
256+ goto error;
257+ }
258+ }
259+
252260 desclen = strlen(desc) + 1;
253261 quotalen = desclen + type->def_datalen;
254262
@@ -503,26 +511,29 @@ int key_instantiate_and_link(struct key *key, · 248 unmodified lines
503511 EXPORT_SYMBOL(key_instantiate_and_link);
504512
505513 /**
506− * key_negate_and_link - Negatively instantiate a key and link it into the keyring.
514+ * key_reject_and_link - Negatively instantiate a key and link it into the keyring.
507515 * @key: The key to instantiate.
508516 * @timeout: The timeout on the negative key.
517+ * @error: The error to return when the key is hit.
509518 * @keyring: Keyring to create a link in on success (or NULL).
510519 * @authkey: The authorisation token permitting instantiation.
511520 *
512521 * Negatively instantiate a key that's in the uninstantiated state and, if
513− * successful, set its timeout and link it in to the destination keyring if one
514− * is supplied. The key and any links to the key will be automatically garbage
515− * collected after the timeout expires.
522+ * successful, set its timeout and stored error and link it in to the
523+ * destination keyring if one is supplied. The key and any links to the key
524+ * will be automatically garbage collected after the timeout expires.
516525 *
517526 * Negative keys are used to rate limit repeated request_key() calls by causing
518− * them to return -ENOKEY until the negative key expires.
527+ * them to return the stored error code (typically ENOKEY) until the negative
528+ * key expires.
519529 *
520530 * If successful, 0 is returned, the authorisation token is revoked and anyone
521531 * waiting for the key is woken up. If the key was already instantiated,
522532 * -EBUSY will be returned.
523533 */
524−int key_negate_and_link(struct key *key,
534+int key_reject_and_link(struct key *key,
525535 unsigned timeout,
536+ unsigned error,
526537 struct key *keyring,
527538 struct key *authkey)
528539 {
@@ -548,6 +559,7 @@ int key_negate_and_link(struct key *key, · 19 unmodified lines
548559 atomic_inc(&key->user->nikeys);
549560 set_bit(KEY_FLAG_NEGATIVE, &key->flags);
550561 set_bit(KEY_FLAG_INSTANTIATED, &key->flags);
562+ key->type_data.reject_error = -error;
551563 now = current_kernel_time();
552564 key->expiry = now.tv_sec + timeout;
553565 key_schedule_gc(key->expiry + key_gc_delay);
@@ -577,8 +589,7 @@ int key_negate_and_link(struct key *key, · 23 unmodified lines
577589
578590 return ret == 0 ? link_ret : ret;
579591 }
580−
581−EXPORT_SYMBOL(key_negate_and_link);
592+EXPORT_SYMBOL(key_reject_and_link);
582593
583594 /*
584595 * Garbage collect keys in process context so that we don't have to disable
security/keys/keyctl.c+134−9
@@ -912,6 +912,21 @@ static int keyctl_change_reqkey_auth(struct key *key) · 911 unmodified lines
912912 return commit_creds(new);
913913 }
914914
915+/*
916+ * Copy the iovec data from userspace
917+ */
918+static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
919+ unsigned ioc)
920+{
921+ for (; ioc > 0; ioc--) {
922+ if (copy_from_user(buffer, iov->iov_base, iov->iov_len) != 0)
923+ return -EFAULT;
924+ buffer += iov->iov_len;
925+ iov++;
926+ }
927+ return 0;
928+}
929+
915930 /*
916931 * Instantiate a key with the specified payload and link the key into the
917932 * destination keyring if one is given.
@@ -921,10 +936,11 @@ static int keyctl_change_reqkey_auth(struct key *key) · 3 unmodified lines
921936 *
922937 * If successful, 0 will be returned.
923938 */
924−long keyctl_instantiate_key(key_serial_t id,
925− const void __user *_payload,
926− size_t plen,
927− key_serial_t ringid)
939+long keyctl_instantiate_key_common(key_serial_t id,
940+ const struct iovec *payload_iov,
941+ unsigned ioc,
942+ size_t plen,
943+ key_serial_t ringid)
928944 {
929945 const struct cred *cred = current_cred();
930946 struct request_key_auth *rka;
@@ -953,7 +969,7 @@ long keyctl_instantiate_key(key_serial_t id, · 22 unmodified lines
953969 /* pull the payload in if one was supplied */
954970 payload = NULL;
955971
956− if (_payload) {
972+ if (payload_iov) {
957973 ret = -ENOMEM;
958974 payload = kmalloc(plen, GFP_KERNEL);
959975 if (!payload) {
@@ -965,8 +981,8 @@ long keyctl_instantiate_key(key_serial_t id, · 5 unmodified lines
965981 goto error;
966982 }
967983
968− ret = -EFAULT;
969− if (copy_from_user(payload, _payload, plen) != 0)
984+ ret = copy_from_user_iovec(payload, payload_iov, ioc);
985+ if (ret < 0)
970986 goto error2;
971987 }
972988
@@ -996,6 +1012,72 @@ error: · 23 unmodified lines
9961012 return ret;
9971013 }
9981014
1015+/*
1016+ * Instantiate a key with the specified payload and link the key into the
1017+ * destination keyring if one is given.
1018+ *
1019+ * The caller must have the appropriate instantiation permit set for this to
1020+ * work (see keyctl_assume_authority). No other permissions are required.
1021+ *
1022+ * If successful, 0 will be returned.
1023+ */
1024+long keyctl_instantiate_key(key_serial_t id,
1025+ const void __user *_payload,
1026+ size_t plen,
1027+ key_serial_t ringid)
1028+{
1029+ if (_payload && plen) {
1030+ struct iovec iov[1] = {
1031+ [0].iov_base = (void __user *)_payload,
1032+ [0].iov_len = plen
1033+ };
1034+
1035+ return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
1036+ }
1037+
1038+ return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
1039+}
1040+
1041+/*
1042+ * Instantiate a key with the specified multipart payload and link the key into
1043+ * the destination keyring if one is given.
1044+ *
1045+ * The caller must have the appropriate instantiation permit set for this to
1046+ * work (see keyctl_assume_authority). No other permissions are required.
1047+ *
1048+ * If successful, 0 will be returned.
1049+ */
1050+long keyctl_instantiate_key_iov(key_serial_t id,
1051+ const struct iovec __user *_payload_iov,
1052+ unsigned ioc,
1053+ key_serial_t ringid)
1054+{
1055+ struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
1056+ long ret;
1057+
1058+ if (_payload_iov == 0 || ioc == 0)
1059+ goto no_payload;
1060+
1061+ ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc,
1062+ ARRAY_SIZE(iovstack), iovstack, &iov);
1063+ if (ret < 0)
1064+ return ret;
1065+ if (ret == 0)
1066+ goto no_payload_free;
1067+
1068+ ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
1069+
1070+ if (iov != iovstack)
1071+ kfree(iov);
1072+ return ret;
1073+
1074+no_payload_free:
1075+ if (iov != iovstack)
1076+ kfree(iov);
1077+no_payload:
1078+ return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
1079+}
1080+
9991081 /*
10001082 * Negatively instantiate the key with the given timeout (in seconds) and link
10011083 * the key into the destination keyring if one is given.
@@ -1012,13 +1094,43 @@ error: · 10 unmodified lines
10121094 * If successful, 0 will be returned.
10131095 */
10141096 long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
1097+{
1098+ return keyctl_reject_key(id, timeout, ENOKEY, ringid);
1099+}
1100+
1101+/*
1102+ * Negatively instantiate the key with the given timeout (in seconds) and error
1103+ * code and link the key into the destination keyring if one is given.
1104+ *
1105+ * The caller must have the appropriate instantiation permit set for this to
1106+ * work (see keyctl_assume_authority). No other permissions are required.
1107+ *
1108+ * The key and any links to the key will be automatically garbage collected
1109+ * after the timeout expires.
1110+ *
1111+ * Negative keys are used to rate limit repeated request_key() calls by causing
1112+ * them to return the specified error code until the negative key expires.
1113+ *
1114+ * If successful, 0 will be returned.
1115+ */
1116+long keyctl_reject_key(key_serial_t id, unsigned timeout, unsigned error,
1117+ key_serial_t ringid)
10151118 {
10161119 const struct cred *cred = current_cred();
10171120 struct request_key_auth *rka;
10181121 struct key *instkey, *dest_keyring;
10191122 long ret;
10201123
1021− kenter("%d,%u,%d", id, timeout, ringid);
1124+ kenter("%d,%u,%u,%d", id, timeout, error, ringid);
1125+
1126+ /* must be a valid error code and mustn't be a kernel special */
1127+ if (error <= 0 ||
1128+ error >= MAX_ERRNO ||
1129+ error == ERESTARTSYS ||
1130+ error == ERESTARTNOINTR ||
1131+ error == ERESTARTNOHAND ||
1132+ error == ERESTART_RESTARTBLOCK)
1133+ return -EINVAL;
10221134
10231135 /* the appropriate instantiation authorisation key must have been
10241136 * assumed before calling this */
@@ -1038,7 +1150,7 @@ long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) · 13 unmodified lines
10381150 goto error;
10391151
10401152 /* instantiate the key and link it into a keyring */
1041− ret = key_negate_and_link(rka->target_key, timeout,
1153+ ret = key_reject_and_link(rka->target_key, timeout, error,
10421154 dest_keyring, instkey);
10431155
10441156 key_put(dest_keyring);
@@ -1492,6 +1604,19 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, · 447 unmodified lines
14921604 case KEYCTL_SESSION_TO_PARENT:
14931605 return keyctl_session_to_parent();
14941606
1607+ case KEYCTL_REJECT:
1608+ return keyctl_reject_key((key_serial_t) arg2,
1609+ (unsigned) arg3,
1610+ (unsigned) arg4,
1611+ (key_serial_t) arg5);
1612+
1613+ case KEYCTL_INSTANTIATE_IOV:
1614+ return keyctl_instantiate_key_iov(
1615+ (key_serial_t) arg2,
1616+ (const struct iovec __user *) arg3,
1617+ (unsigned) arg4,
1618+ (key_serial_t) arg5);
1619+
14951620 default:
14961621 return -EOPNOTSUPP;
14971622 }
security/keys/keyring.c+2−2
@@ -352,7 +352,7 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref, · 351 unmodified lines
352352 goto error_2;
353353 if (key->expiry && now.tv_sec >= key->expiry)
354354 goto error_2;
355− key_ref = ERR_PTR(-ENOKEY);
355+ key_ref = ERR_PTR(key->type_data.reject_error);
356356 if (kflags & (1 << KEY_FLAG_NEGATIVE))
357357 goto error_2;
358358 goto found;
@@ -401,7 +401,7 @@ descend: · 42 unmodified lines
401401
402402 /* we set a different error code if we pass a negative key */
403403 if (kflags & (1 << KEY_FLAG_NEGATIVE)) {
404− err = -ENOKEY;
404+ err = key->type_data.reject_error;
405405 continue;
406406 }
407407
security/keys/request_key.c+1−1
@@ -585,7 +585,7 @@ int wait_for_key_construction(struct key *key, bool intr) · 584 unmodified lines
585585 if (ret < 0)
586586 return ret;
587587 if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
588− return -ENOKEY;
588+ return key->type_data.reject_error;
589589 return key_validate(key);
590590 }
591591 EXPORT_SYMBOL(wait_for_key_construction);
security/keys/trusted.c+1−2
@@ -1076,8 +1076,7 @@ static long trusted_read(const struct key *key, char __user *buffer, · 1075 unmodified lines
10761076 char *bufp;
10771077 int i;
10781078
1079− p = rcu_dereference_protected(key->payload.data,
1080− rwsem_is_locked(&((struct key *)key)->sem));
1079+ p = rcu_dereference_key(key);
10811080 if (!p)
10821081 return -EINVAL;
10831082 if (!buffer || buflen <= 0)
security/keys/user_defined.c+1−2
@@ -184,8 +184,7 @@ long user_read(const struct key *key, char __user *buffer, size_t buflen) · 183 unmodified lines
184184 struct user_key_payload *upayload;
185185 long ret;
186186
187− upayload = rcu_dereference_protected(
188− key->payload.data, rwsem_is_locked(&((struct key *)key)->sem));
187+ upayload = rcu_dereference_key(key);
189188 ret = upayload->datalen;
190189
191190 /* we can return the data as is */
security/security.c+12−7
@@ -181,11 +181,6 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap) · 180 unmodified lines
181181 return ret;
182182 }
183183
184−int security_sysctl(struct ctl_table *table, int op)
185−{
186− return security_ops->sysctl(table, op);
187−}
188−
189184 int security_quotactl(int cmds, int type, int id, struct super_block *sb)
190185 {
191186 return security_ops->quotactl(cmds, type, id, sb);
@@ -271,6 +266,11 @@ int security_sb_copy_data(char *orig, char *copy) · 79 unmodified lines
271266 }
272267 EXPORT_SYMBOL(security_sb_copy_data);
273268
269+int security_sb_remount(struct super_block *sb, void *data)
270+{
271+ return security_ops->sb_remount(sb, data);
272+}
273+
274274 int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
275275 {
276276 return security_ops->sb_kern_mount(sb, flags, data);
@@ -335,11 +335,13 @@ void security_inode_free(struct inode *inode) · 58 unmodified lines
335335 }
336336
337337 int security_inode_init_security(struct inode *inode, struct inode *dir,
338− char **name, void **value, size_t *len)
338+ const struct qstr *qstr, char **name,
339+ void **value, size_t *len)
339340 {
340341 if (unlikely(IS_PRIVATE(inode)))
341342 return -EOPNOTSUPP;
342− return security_ops->inode_init_security(inode, dir, name, value, len);
343+ return security_ops->inode_init_security(inode, dir, qstr, name, value,
344+ len);
343345 }
344346 EXPORT_SYMBOL(security_inode_init_security);
345347
@@ -359,6 +361,7 @@ int security_path_mkdir(struct path *dir, struct dentry *dentry, int mode) · 13 unmodified lines
359361 return 0;
360362 return security_ops->path_mkdir(dir, dentry, mode);
361363 }
364+EXPORT_SYMBOL(security_path_mkdir);
362365
363366 int security_path_rmdir(struct path *dir, struct dentry *dentry)
364367 {
@@ -373,6 +376,7 @@ int security_path_unlink(struct path *dir, struct dentry *dentry) · 8 unmodified lines
373376 return 0;
374377 return security_ops->path_unlink(dir, dentry);
375378 }
379+EXPORT_SYMBOL(security_path_unlink);
376380
377381 int security_path_symlink(struct path *dir, struct dentry *dentry,
378382 const char *old_name)
@@ -399,6 +403,7 @@ int security_path_rename(struct path *old_dir, struct dentry *old_dentry, · 20 unmodified lines
399403 return security_ops->path_rename(old_dir, old_dentry, new_dir,
400404 new_dentry);
401405 }
406+EXPORT_SYMBOL(security_path_rename);
402407
403408 int security_path_truncate(struct path *path)
404409 {
security/selinux/hooks.c+188−162
@@ -24,9 +24,11 @@ · 23 unmodified lines
2424 */
2525
2626 #include <linux/init.h>
27+#include <linux/kd.h>
2728 #include <linux/kernel.h>
2829 #include <linux/tracehook.h>
2930 #include <linux/errno.h>
31+#include <linux/ext2_fs.h>
3032 #include <linux/sched.h>
3133 #include <linux/security.h>
3234 #include <linux/xattr.h>
@@ -36,14 +38,15 @@ · 3 unmodified lines
3638 #include <linux/mman.h>
3739 #include <linux/slab.h>
3840 #include <linux/pagemap.h>
41+#include <linux/proc_fs.h>
3942 #include <linux/swap.h>
4043 #include <linux/spinlock.h>
4144 #include <linux/syscalls.h>
45+#include <linux/dcache.h>
4246 #include <linux/file.h>
4347 #include <linux/fdtable.h>
4448 #include <linux/namei.h>
4549 #include <linux/mount.h>
46−#include <linux/proc_fs.h>
4750 #include <linux/netfilter_ipv4.h>
4851 #include <linux/netfilter_ipv6.h>
4952 #include <linux/tty.h>
@@ -70,7 +73,6 @@ · 20 unmodified lines
7073 #include <net/ipv6.h>
7174 #include <linux/hugetlb.h>
7275 #include <linux/personality.h>
73−#include <linux/sysctl.h>
7476 #include <linux/audit.h>
7577 #include <linux/string.h>
7678 #include <linux/selinux.h>
@@ -1120,39 +1122,35 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc · 1043 unmodified lines
11201122 }
11211123
11221124 #ifdef CONFIG_PROC_FS
1123−static int selinux_proc_get_sid(struct proc_dir_entry *de,
1125+static int selinux_proc_get_sid(struct dentry *dentry,
11241126 u16 tclass,
11251127 u32 *sid)
11261128 {
1127− int buflen, rc;
1128− char *buffer, *path, *end;
1129+ int rc;
1130+ char *buffer, *path;
11291131
11301132 buffer = (char *)__get_free_page(GFP_KERNEL);
11311133 if (!buffer)
11321134 return -ENOMEM;
11331135
1134− buflen = PAGE_SIZE;
1135− end = buffer+buflen;
1136− *--end = '\0';
1137− buflen--;
1138− path = end-1;
1139− *path = '/';
1140− while (de && de != de->parent) {
1141− buflen -= de->namelen + 1;
1142− if (buflen < 0)
1143− break;
1144− end -= de->namelen;
1145− memcpy(end, de->name, de->namelen);
1146− *--end = '/';
1147− path = end;
1148− de = de->parent;
1136+ path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
1137+ if (IS_ERR(path))
1138+ rc = PTR_ERR(path);
1139+ else {
1140+ /* each process gets a /proc/PID/ entry. Strip off the
1141+ * PID part to get a valid selinux labeling.
1142+ * e.g. /proc/1/net/rpc/nfs -> /net/rpc/nfs */
1143+ while (path[1] >= '0' && path[1] <= '9') {
1144+ path[1] = '/';
1145+ path++;
1146+ }
1147+ rc = security_genfs_sid("proc", path, tclass, sid);
11491148 }
1150− rc = security_genfs_sid("proc", path, tclass, sid);
11511149 free_page((unsigned long)buffer);
11521150 return rc;
11531151 }
11541152 #else
1155−static int selinux_proc_get_sid(struct proc_dir_entry *de,
1153+static int selinux_proc_get_sid(struct dentry *dentry,
11561154 u16 tclass,
11571155 u32 *sid)
11581156 {
@@ -1300,10 +1298,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent · 141 unmodified lines
13001298
13011299 /* Try to obtain a transition SID. */
13021300 isec->sclass = inode_mode_to_security_class(inode->i_mode);
1303− rc = security_transition_sid(isec->task_sid,
1304− sbsec->sid,
1305− isec->sclass,
1306− &sid);
1301+ rc = security_transition_sid(isec->task_sid, sbsec->sid,
1302+ isec->sclass, NULL, &sid);
13071303 if (rc)
13081304 goto out_unlock;
13091305 isec->sid = sid;
@@ -1316,10 +1312,9 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent · 6 unmodified lines
13161312 isec->sid = sbsec->sid;
13171313
13181314 if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
1319− struct proc_inode *proci = PROC_I(inode);
1320− if (proci->pde) {
1315+ if (opt_dentry) {
13211316 isec->sclass = inode_mode_to_security_class(inode->i_mode);
1322− rc = selinux_proc_get_sid(proci->pde,
1317+ rc = selinux_proc_get_sid(opt_dentry,
13231318 isec->sclass,
13241319 &sid);
13251320 if (rc)
@@ -1578,7 +1573,7 @@ static int may_create(struct inode *dir, · 252 unmodified lines
15781573 return rc;
15791574
15801575 if (!newsid || !(sbsec->flags & SE_SBLABELSUPP)) {
1581− rc = security_transition_sid(sid, dsec->sid, tclass, &newsid);
1576+ rc = security_transition_sid(sid, dsec->sid, tclass, NULL, &newsid);
15821577 if (rc)
15831578 return rc;
15841579 }
@@ -1862,82 +1857,6 @@ static int selinux_capable(struct task_struct *tsk, const struct cred *cred, · 277 unmodified lines
18621857 return task_has_capability(tsk, cred, cap, audit);
18631858 }
18641859
1865−static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
1866−{
1867− int buflen, rc;
1868− char *buffer, *path, *end;
1869−
1870− rc = -ENOMEM;
1871− buffer = (char *)__get_free_page(GFP_KERNEL);
1872− if (!buffer)
1873− goto out;
1874−
1875− buflen = PAGE_SIZE;
1876− end = buffer+buflen;
1877− *--end = '\0';
1878− buflen--;
1879− path = end-1;
1880− *path = '/';
1881− while (table) {
1882− const char *name = table->procname;
1883− size_t namelen = strlen(name);
1884− buflen -= namelen + 1;
1885− if (buflen < 0)
1886− goto out_free;
1887− end -= namelen;
1888− memcpy(end, name, namelen);
1889− *--end = '/';
1890− path = end;
1891− table = table->parent;
1892− }
1893− buflen -= 4;
1894− if (buflen < 0)
1895− goto out_free;
1896− end -= 4;
1897− memcpy(end, "/sys", 4);
1898− path = end;
1899− rc = security_genfs_sid("proc", path, tclass, sid);
1900−out_free:
1901− free_page((unsigned long)buffer);
1902−out:
1903− return rc;
1904−}
1905−
1906−static int selinux_sysctl(ctl_table *table, int op)
1907−{
1908− int error = 0;
1909− u32 av;
1910− u32 tsid, sid;
1911− int rc;
1912−
1913− sid = current_sid();
1914−
1915− rc = selinux_sysctl_get_sid(table, (op == 0001) ?
1916− SECCLASS_DIR : SECCLASS_FILE, &tsid);
1917− if (rc) {
1918− /* Default to the well-defined sysctl SID. */
1919− tsid = SECINITSID_SYSCTL;
1920− }
1921−
1922− /* The op values are "defined" in sysctl.c, thereby creating
1923− * a bad coupling between this module and sysctl.c */
1924− if (op == 001) {
1925− error = avc_has_perm(sid, tsid,
1926− SECCLASS_DIR, DIR__SEARCH, NULL);
1927− } else {
1928− av = 0;
1929− if (op & 004)
1930− av |= FILE__READ;
1931− if (op & 002)
1932− av |= FILE__WRITE;
1933− if (av)
1934− error = avc_has_perm(sid, tsid,
1935− SECCLASS_FILE, av, NULL);
1936− }
1937−
1938− return error;
1939−}
1940−
19411860 static int selinux_quotactl(int cmds, int type, int id, struct super_block *sb)
19421861 {
19431862 const struct cred *cred = current_cred();
@@ -2060,7 +1979,8 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) · 116 unmodified lines
20601979 } else {
20611980 /* Check for a default transition on this program. */
20621981 rc = security_transition_sid(old_tsec->sid, isec->sid,
2063− SECCLASS_PROCESS, &new_tsec->sid);
1982+ SECCLASS_PROCESS, NULL,
1983+ &new_tsec->sid);
20641984 if (rc)
20651985 return rc;
20661986 }
@@ -2443,6 +2363,91 @@ out: · 376 unmodified lines
24432363 return rc;
24442364 }
24452365
2366+static int selinux_sb_remount(struct super_block *sb, void *data)
2367+{
2368+ int rc, i, *flags;
2369+ struct security_mnt_opts opts;
2370+ char *secdata, **mount_options;
2371+ struct superblock_security_struct *sbsec = sb->s_security;
2372+
2373+ if (!(sbsec->flags & SE_SBINITIALIZED))
2374+ return 0;
2375+
2376+ if (!data)
2377+ return 0;
2378+
2379+ if (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA)
2380+ return 0;
2381+
2382+ security_init_mnt_opts(&opts);
2383+ secdata = alloc_secdata();
2384+ if (!secdata)
2385+ return -ENOMEM;
2386+ rc = selinux_sb_copy_data(data, secdata);
2387+ if (rc)
2388+ goto out_free_secdata;
2389+
2390+ rc = selinux_parse_opts_str(secdata, &opts);
2391+ if (rc)
2392+ goto out_free_secdata;
2393+
2394+ mount_options = opts.mnt_opts;
2395+ flags = opts.mnt_opts_flags;
2396+
2397+ for (i = 0; i < opts.num_mnt_opts; i++) {
2398+ u32 sid;
2399+ size_t len;
2400+
2401+ if (flags[i] == SE_SBLABELSUPP)
2402+ continue;
2403+ len = strlen(mount_options[i]);
2404+ rc = security_context_to_sid(mount_options[i], len, &sid);
2405+ if (rc) {
2406+ printk(KERN_WARNING "SELinux: security_context_to_sid"
2407+ "(%s) failed for (dev %s, type %s) errno=%d\n",
2408+ mount_options[i], sb->s_id, sb->s_type->name, rc);
2409+ goto out_free_opts;
2410+ }
2411+ rc = -EINVAL;
2412+ switch (flags[i]) {
2413+ case FSCONTEXT_MNT:
2414+ if (bad_option(sbsec, FSCONTEXT_MNT, sbsec->sid, sid))
2415+ goto out_bad_option;
2416+ break;
2417+ case CONTEXT_MNT:
2418+ if (bad_option(sbsec, CONTEXT_MNT, sbsec->mntpoint_sid, sid))
2419+ goto out_bad_option;
2420+ break;
2421+ case ROOTCONTEXT_MNT: {
2422+ struct inode_security_struct *root_isec;
2423+ root_isec = sb->s_root->d_inode->i_security;
2424+
2425+ if (bad_option(sbsec, ROOTCONTEXT_MNT, root_isec->sid, sid))
2426+ goto out_bad_option;
2427+ break;
2428+ }
2429+ case DEFCONTEXT_MNT:
2430+ if (bad_option(sbsec, DEFCONTEXT_MNT, sbsec->def_sid, sid))
2431+ goto out_bad_option;
2432+ break;
2433+ default:
2434+ goto out_free_opts;
2435+ }
2436+ }
2437+
2438+ rc = 0;
2439+out_free_opts:
2440+ security_free_mnt_opts(&opts);
2441+out_free_secdata:
2442+ free_secdata(secdata);
2443+ return rc;
2444+out_bad_option:
2445+ printk(KERN_WARNING "SELinux: unable to change security options "
2446+ "during remount (dev %s, type=%s)\n", sb->s_id,
2447+ sb->s_type->name);
2448+ goto out_free_opts;
2449+}
2450+
24462451 static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
24472452 {
24482453 const struct cred *cred = current_cred();
@@ -2509,8 +2514,8 @@ static void selinux_inode_free_security(struct inode *inode) · 60 unmodified lines
25092514 }
25102515
25112516 static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
2512− char **name, void **value,
2513− size_t *len)
2517+ const struct qstr *qstr, char **name,
2518+ void **value, size_t *len)
25142519 {
25152520 const struct task_security_struct *tsec = current_security();
25162521 struct inode_security_struct *dsec;
@@ -2531,7 +2536,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, · 14 unmodified lines
25312536 else if (!newsid || !(sbsec->flags & SE_SBLABELSUPP)) {
25322537 rc = security_transition_sid(sid, dsec->sid,
25332538 inode_mode_to_security_class(inode->i_mode),
2534− &newsid);
2539+ qstr, &newsid);
25352540 if (rc) {
25362541 printk(KERN_WARNING "%s: "
25372542 "security_transition_sid failed, rc=%d (dev=%s "
@@ -2932,16 +2937,47 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd, · 394 unmodified lines
29322937 unsigned long arg)
29332938 {
29342939 const struct cred *cred = current_cred();
2935− u32 av = 0;
2940+ int error = 0;
29362941
2937− if (_IOC_DIR(cmd) & _IOC_WRITE)
2938− av |= FILE__WRITE;
2939− if (_IOC_DIR(cmd) & _IOC_READ)
2940− av |= FILE__READ;
2941− if (!av)
2942− av = FILE__IOCTL;
2942+ switch (cmd) {
2943+ case FIONREAD:
2944+ /* fall through */
2945+ case FIBMAP:
2946+ /* fall through */
2947+ case FIGETBSZ:
2948+ /* fall through */
2949+ case EXT2_IOC_GETFLAGS:
2950+ /* fall through */
2951+ case EXT2_IOC_GETVERSION:
2952+ error = file_has_perm(cred, file, FILE__GETATTR);
2953+ break;
2954+
2955+ case EXT2_IOC_SETFLAGS:
2956+ /* fall through */
2957+ case EXT2_IOC_SETVERSION:
2958+ error = file_has_perm(cred, file, FILE__SETATTR);
2959+ break;
2960+
2961+ /* sys_ioctl() checks */
2962+ case FIONBIO:
2963+ /* fall through */
2964+ case FIOASYNC:
2965+ error = file_has_perm(cred, file, 0);
2966+ break;
29432967
2944− return file_has_perm(cred, file, av);
2968+ case KDSKBENT:
2969+ case KDSKBSENT:
2970+ error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG,
2971+ SECURITY_CAP_AUDIT);
2972+ break;
2973+
2974+ /* default case assumes that the command will go
2975+ * to the file's ioctl() function.
2976+ */
2977+ default:
2978+ error = file_has_perm(cred, file, FILE__IOCTL);
2979+ }
2980+ return error;
29452981 }
29462982
29472983 static int default_noexec;
@@ -3644,9 +3680,16 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid) · 696 unmodified lines
36443680
36453681 /* socket security operations */
36463682
3647−static u32 socket_sockcreate_sid(const struct task_security_struct *tsec)
3683+static int socket_sockcreate_sid(const struct task_security_struct *tsec,
3684+ u16 secclass, u32 *socksid)
36483685 {
3649− return tsec->sockcreate_sid ? : tsec->sid;
3686+ if (tsec->sockcreate_sid > SECSID_NULL) {
3687+ *socksid = tsec->sockcreate_sid;
3688+ return 0;
3689+ }
3690+
3691+ return security_transition_sid(tsec->sid, tsec->sid, secclass, NULL,
3692+ socksid);
36503693 }
36513694
36523695 static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
@@ -3670,12 +3713,16 @@ static int selinux_socket_create(int family, int type, · 17 unmodified lines
36703713 const struct task_security_struct *tsec = current_security();
36713714 u32 newsid;
36723715 u16 secclass;
3716+ int rc;
36733717
36743718 if (kern)
36753719 return 0;
36763720
3677− newsid = socket_sockcreate_sid(tsec);
36783721 secclass = socket_type_to_security_class(family, type, protocol);
3722+ rc = socket_sockcreate_sid(tsec, secclass, &newsid);
3723+ if (rc)
3724+ return rc;
3725+
36793726 return avc_has_perm(tsec->sid, newsid, secclass, SOCKET__CREATE, NULL);
36803727 }
36813728
@@ -3687,12 +3734,16 @@ static int selinux_socket_post_create(struct socket *sock, int family, · 5 unmodified lines
36873734 struct sk_security_struct *sksec;
36883735 int err = 0;
36893736
3737+ isec->sclass = socket_type_to_security_class(family, type, protocol);
3738+
36903739 if (kern)
36913740 isec->sid = SECINITSID_KERNEL;
3692− else
3693− isec->sid = socket_sockcreate_sid(tsec);
3741+ else {
3742+ err = socket_sockcreate_sid(tsec, isec->sclass, &(isec->sid));
3743+ if (err)
3744+ return err;
3745+ }
36943746
3695− isec->sclass = socket_type_to_security_class(family, type, protocol);
36963747 isec->initialized = 1;
36973748
36983749 if (sock->sk) {
@@ -4002,7 +4053,6 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, · 303 unmodified lines
40024053 {
40034054 int err = 0;
40044055 struct sk_security_struct *sksec = sk->sk_security;
4005− u32 peer_sid;
40064056 u32 sk_sid = sksec->sid;
40074057 struct common_audit_data ad;
40084058 char *addrp;
@@ -4021,20 +4071,10 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, · 12 unmodified lines
40214071 return err;
40224072 }
40234073
4024− if (selinux_policycap_netpeer) {
4025− err = selinux_skb_peerlbl_sid(skb, family, &peer_sid);
4026− if (err)
4027− return err;
4028− err = avc_has_perm(sk_sid, peer_sid,
4029− SECCLASS_PEER, PEER__RECV, &ad);
4030− if (err)
4031− selinux_netlbl_err(skb, err, 0);
4032− } else {
4033− err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, &ad);
4034− if (err)
4035− return err;
4036− err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, &ad);
4037− }
4074+ err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, &ad);
4075+ if (err)
4076+ return err;
4077+ err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, &ad);
40384078
40394079 return err;
40404080 }
@@ -4529,9 +4569,8 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, · 488 unmodified lines
45294569 SECCLASS_PACKET, PACKET__SEND, &ad))
45304570 return NF_DROP_ERR(-ECONNREFUSED);
45314571
4532− if (selinux_policycap_netpeer)
4533− if (selinux_xfrm_postroute_last(sksec->sid, skb, &ad, proto))
4534− return NF_DROP_ERR(-ECONNREFUSED);
4572+ if (selinux_xfrm_postroute_last(sksec->sid, skb, &ad, proto))
4573+ return NF_DROP_ERR(-ECONNREFUSED);
45354574
45364575 return NF_ACCEPT;
45374576 }
@@ -4574,27 +4613,14 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex, · 36 unmodified lines
45744613 * from the sending socket, otherwise use the kernel's sid */
45754614 sk = skb->sk;
45764615 if (sk == NULL) {
4577− switch (family) {
4578− case PF_INET:
4579− if (IPCB(skb)->flags & IPSKB_FORWARDED)
4580− secmark_perm = PACKET__FORWARD_OUT;
4581− else
4582− secmark_perm = PACKET__SEND;
4583− break;
4584− case PF_INET6:
4585− if (IP6CB(skb)->flags & IP6SKB_FORWARDED)
4586− secmark_perm = PACKET__FORWARD_OUT;
4587− else
4588− secmark_perm = PACKET__SEND;
4589− break;
4590− default:
4591− return NF_DROP_ERR(-ECONNREFUSED);
4592− }
4593− if (secmark_perm == PACKET__FORWARD_OUT) {
4616+ if (skb->skb_iif) {
4617+ secmark_perm = PACKET__FORWARD_OUT;
45944618 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid))
45954619 return NF_DROP;
4596− } else
4620+ } else {
4621+ secmark_perm = PACKET__SEND;
45974622 peer_sid = SECINITSID_KERNEL;
4623+ }
45984624 } else {
45994625 struct sk_security_struct *sksec = sk->sk_security;
46004626 peer_sid = sksec->sid;
@@ -4848,7 +4874,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, · 247 unmodified lines
48484874 * message queue this message will be stored in
48494875 */
48504876 rc = security_transition_sid(sid, isec->sid, SECCLASS_MSG,
4851− &msec->sid);
4877+ NULL, &msec->sid);
48524878 if (rc)
48534879 return rc;
48544880 }
@@ -5402,7 +5428,6 @@ static struct security_operations selinux_ops = { · 547 unmodified lines
54025428 .ptrace_traceme = selinux_ptrace_traceme,
54035429 .capget = selinux_capget,
54045430 .capset = selinux_capset,
5405− .sysctl = selinux_sysctl,
54065431 .capable = selinux_capable,
54075432 .quotactl = selinux_quotactl,
54085433 .quota_on = selinux_quota_on,
@@ -5420,6 +5445,7 @@ static struct security_operations selinux_ops = { · 11 unmodified lines
54205445 .sb_alloc_security = selinux_sb_alloc_security,
54215446 .sb_free_security = selinux_sb_free_security,
54225447 .sb_copy_data = selinux_sb_copy_data,
5448+ .sb_remount = selinux_sb_remount,
54235449 .sb_kern_mount = selinux_sb_kern_mount,
54245450 .sb_show_options = selinux_sb_show_options,
54255451 .sb_statfs = selinux_sb_statfs,
security/selinux/include/classmap.h+5−2
@@ -12,6 +12,10 @@ · 11 unmodified lines
1212 #define COMMON_IPC_PERMS "create", "destroy", "getattr", "setattr", "read", \
1313 "write", "associate", "unix_read", "unix_write"
1414
15+/*
16+ * Note: The name for any socket class should be suffixed by "socket",
17+ * and doesn't contain more than one substr of "socket".
18+ */
1519 struct security_class_mapping secclass_map[] = {
1620 { "security",
1721 { "compute_av", "compute_create", "compute_member",
@@ -132,8 +136,7 @@ struct security_class_mapping secclass_map[] = { · 114 unmodified lines
132136 { "appletalk_socket",
133137 { COMMON_SOCK_PERMS, NULL } },
134138 { "packet",
135− { "send", "recv", "relabelto", "flow_in", "flow_out",
136− "forward_in", "forward_out", NULL } },
139+ { "send", "recv", "relabelto", "forward_in", "forward_out", NULL } },
137140 { "key",
138141 { "view", "read", "write", "search", "link", "setattr", "create",
139142 NULL } },
security/selinux/include/security.h+5−3
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #ifndef _SELINUX_SECURITY_H_
99 #define _SELINUX_SECURITY_H_
1010
11+#include <linux/dcache.h>
1112 #include <linux/magic.h>
1213 #include <linux/types.h>
1314 #include "flask.h"
@@ -28,13 +29,14 @@ · 14 unmodified lines
2829 #define POLICYDB_VERSION_POLCAP 22
2930 #define POLICYDB_VERSION_PERMISSIVE 23
3031 #define POLICYDB_VERSION_BOUNDARY 24
32+#define POLICYDB_VERSION_FILENAME_TRANS 25
3133
3234 /* Range of policy versions we understand*/
3335 #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
3436 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
3537 #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
3638 #else
37−#define POLICYDB_VERSION_MAX POLICYDB_VERSION_BOUNDARY
39+#define POLICYDB_VERSION_MAX POLICYDB_VERSION_FILENAME_TRANS
3840 #endif
3941
4042 /* Mask for just the mount related flags */
@@ -106,8 +108,8 @@ void security_compute_av(u32 ssid, u32 tsid, · 65 unmodified lines
106108 void security_compute_av_user(u32 ssid, u32 tsid,
107109 u16 tclass, struct av_decision *avd);
108110
109−int security_transition_sid(u32 ssid, u32 tsid,
110− u16 tclass, u32 *out_sid);
111+int security_transition_sid(u32 ssid, u32 tsid, u16 tclass,
112+ const struct qstr *qstr, u32 *out_sid);
111113
112114 int security_transition_sid_user(u32 ssid, u32 tsid,
113115 u16 tclass, u32 *out_sid);
security/selinux/ss/avtab.h+11−12
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 *
1515 * Copyright (C) 2003 Tresys Technology, LLC
1616 * This program is free software; you can redistribute it and/or modify
17− * it under the terms of the GNU General Public License as published by
17+ * it under the terms of the GNU General Public License as published by
1818 * the Free Software Foundation, version 2.
1919 *
2020 * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
@@ -27,16 +27,16 @@ struct avtab_key { · 6 unmodified lines
2727 u16 source_type; /* source type */
2828 u16 target_type; /* target type */
2929 u16 target_class; /* target object class */
30−#define AVTAB_ALLOWED 1
31−#define AVTAB_AUDITALLOW 2
32−#define AVTAB_AUDITDENY 4
33−#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
34−#define AVTAB_TRANSITION 16
35−#define AVTAB_MEMBER 32
36−#define AVTAB_CHANGE 64
37−#define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
38−#define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
39−#define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
30+#define AVTAB_ALLOWED 0x0001
31+#define AVTAB_AUDITALLOW 0x0002
32+#define AVTAB_AUDITDENY 0x0004
33+#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
34+#define AVTAB_TRANSITION 0x0010
35+#define AVTAB_MEMBER 0x0020
36+#define AVTAB_CHANGE 0x0040
37+#define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
38+#define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
39+#define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
4040 u16 specified; /* what field is specified */
4141 };
4242
@@ -86,7 +86,6 @@ void avtab_cache_destroy(void); · 43 unmodified lines
8686
8787 #define MAX_AVTAB_HASH_BITS 11
8888 #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
89−#define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1)
9089
9190 #endif /* _SS_AVTAB_H_ */
9291
security/selinux/ss/ebitmap.h+0−1
@@ -36,7 +36,6 @@ struct ebitmap { · 35 unmodified lines
3636 };
3737
3838 #define ebitmap_length(e) ((e)->highbit)
39−#define ebitmap_startbit(e) ((e)->node ? (e)->node->startbit : 0)
4039
4140 static inline unsigned int ebitmap_start_positive(struct ebitmap *e,
4241 struct ebitmap_node **n)
security/selinux/ss/mls.c+3−2
@@ -512,7 +512,8 @@ int mls_compute_sid(struct context *scontext, · 511 unmodified lines
512512 struct context *tcontext,
513513 u16 tclass,
514514 u32 specified,
515− struct context *newcontext)
515+ struct context *newcontext,
516+ bool sock)
516517 {
517518 struct range_trans rtr;
518519 struct mls_range *r;
@@ -531,7 +532,7 @@ int mls_compute_sid(struct context *scontext, · 12 unmodified lines
531532 return mls_range_set(newcontext, r);
532533 /* Fallthrough */
533534 case AVTAB_CHANGE:
534− if (tclass == policydb.process_class)
535+ if ((tclass == policydb.process_class) || (sock == true))
535536 /* Use the process MLS attributes. */
536537 return mls_context_cpy(newcontext, scontext);
537538 else
security/selinux/ss/mls.h+2−1
@@ -49,7 +49,8 @@ int mls_compute_sid(struct context *scontext, · 48 unmodified lines
4949 struct context *tcontext,
5050 u16 tclass,
5151 u32 specified,
52− struct context *newcontext);
52+ struct context *newcontext,
53+ bool sock);
5354
5455 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
5556 struct context *usercon);
security/selinux/ss/policydb.c+130−0
@@ -123,6 +123,11 @@ static struct policydb_compat_info policydb_compat[] = { · 122 unmodified lines
123123 .sym_num = SYM_NUM,
124124 .ocon_num = OCON_NUM,
125125 },
126+ {
127+ .version = POLICYDB_VERSION_FILENAME_TRANS,
128+ .sym_num = SYM_NUM,
129+ .ocon_num = OCON_NUM,
130+ },
126131 };
127132
128133 static struct policydb_compat_info *policydb_lookup_compat(int version)
@@ -704,6 +709,7 @@ void policydb_destroy(struct policydb *p) · 575 unmodified lines
704709 int i;
705710 struct role_allow *ra, *lra = NULL;
706711 struct role_trans *tr, *ltr = NULL;
712+ struct filename_trans *ft, *nft;
707713
708714 for (i = 0; i < SYM_NUM; i++) {
709715 cond_resched();
@@ -781,6 +787,15 @@ void policydb_destroy(struct policydb *p) · 71 unmodified lines
781787 }
782788 flex_array_free(p->type_attr_map_array);
783789 }
790+
791+ ft = p->filename_trans;
792+ while (ft) {
793+ nft = ft->next;
794+ kfree(ft->name);
795+ kfree(ft);
796+ ft = nft;
797+ }
798+
784799 ebitmap_destroy(&p->policycaps);
785800 ebitmap_destroy(&p->permissive_map);
786801
@@ -1788,6 +1803,76 @@ out: · 1001 unmodified lines
17881803 return rc;
17891804 }
17901805
1806+static int filename_trans_read(struct policydb *p, void *fp)
1807+{
1808+ struct filename_trans *ft, *last;
1809+ u32 nel, len;
1810+ char *name;
1811+ __le32 buf[4];
1812+ int rc, i;
1813+
1814+ if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
1815+ return 0;
1816+
1817+ rc = next_entry(buf, fp, sizeof(u32));
1818+ if (rc)
1819+ goto out;
1820+ nel = le32_to_cpu(buf[0]);
1821+
1822+ printk(KERN_ERR "%s: nel=%d\n", __func__, nel);
1823+
1824+ last = p->filename_trans;
1825+ while (last && last->next)
1826+ last = last->next;
1827+
1828+ for (i = 0; i < nel; i++) {
1829+ rc = -ENOMEM;
1830+ ft = kzalloc(sizeof(*ft), GFP_KERNEL);
1831+ if (!ft)
1832+ goto out;
1833+
1834+ /* add it to the tail of the list */
1835+ if (!last)
1836+ p->filename_trans = ft;
1837+ else
1838+ last->next = ft;
1839+ last = ft;
1840+
1841+ /* length of the path component string */
1842+ rc = next_entry(buf, fp, sizeof(u32));
1843+ if (rc)
1844+ goto out;
1845+ len = le32_to_cpu(buf[0]);
1846+
1847+ rc = -ENOMEM;
1848+ name = kmalloc(len + 1, GFP_KERNEL);
1849+ if (!name)
1850+ goto out;
1851+
1852+ ft->name = name;
1853+
1854+ /* path component string */
1855+ rc = next_entry(name, fp, len);
1856+ if (rc)
1857+ goto out;
1858+ name[len] = 0;
1859+
1860+ printk(KERN_ERR "%s: ft=%p ft->name=%p ft->name=%s\n", __func__, ft, ft->name, ft->name);
1861+
1862+ rc = next_entry(buf, fp, sizeof(u32) * 4);
1863+ if (rc)
1864+ goto out;
1865+
1866+ ft->stype = le32_to_cpu(buf[0]);
1867+ ft->ttype = le32_to_cpu(buf[1]);
1868+ ft->tclass = le32_to_cpu(buf[2]);
1869+ ft->otype = le32_to_cpu(buf[3]);
1870+ }
1871+ rc = 0;
1872+out:
1873+ return rc;
1874+}
1875+
17911876 static int genfs_read(struct policydb *p, void *fp)
17921877 {
17931878 int i, j, rc;
@@ -2251,6 +2336,10 @@ int policydb_read(struct policydb *p, void *fp) · 457 unmodified lines
22512336 lra = ra;
22522337 }
22532338
2339+ rc = filename_trans_read(p, fp);
2340+ if (rc)
2341+ goto bad;
2342+
22542343 rc = policydb_index(p);
22552344 if (rc)
22562345 goto bad;
@@ -3025,6 +3114,43 @@ static int range_write(struct policydb *p, void *fp) · 768 unmodified lines
30253114 return 0;
30263115 }
30273116
3117+static int filename_trans_write(struct policydb *p, void *fp)
3118+{
3119+ struct filename_trans *ft;
3120+ u32 len, nel = 0;
3121+ __le32 buf[4];
3122+ int rc;
3123+
3124+ for (ft = p->filename_trans; ft; ft = ft->next)
3125+ nel++;
3126+
3127+ buf[0] = cpu_to_le32(nel);
3128+ rc = put_entry(buf, sizeof(u32), 1, fp);
3129+ if (rc)
3130+ return rc;
3131+
3132+ for (ft = p->filename_trans; ft; ft = ft->next) {
3133+ len = strlen(ft->name);
3134+ buf[0] = cpu_to_le32(len);
3135+ rc = put_entry(buf, sizeof(u32), 1, fp);
3136+ if (rc)
3137+ return rc;
3138+
3139+ rc = put_entry(ft->name, sizeof(char), len, fp);
3140+ if (rc)
3141+ return rc;
3142+
3143+ buf[0] = ft->stype;
3144+ buf[1] = ft->ttype;
3145+ buf[2] = ft->tclass;
3146+ buf[3] = ft->otype;
3147+
3148+ rc = put_entry(buf, sizeof(u32), 4, fp);
3149+ if (rc)
3150+ return rc;
3151+ }
3152+ return 0;
3153+}
30283154 /*
30293155 * Write the configuration data in a policy database
30303156 * structure to a policy database binary representation
@@ -3135,6 +3261,10 @@ int policydb_write(struct policydb *p, void *fp) · 104 unmodified lines
31353261 if (rc)
31363262 return rc;
31373263
3264+ rc = filename_trans_write(p, fp);
3265+ if (rc)
3266+ return rc;
3267+
31383268 rc = ocontext_write(p, info, fp);
31393269 if (rc)
31403270 return rc;
security/selinux/ss/policydb.h+13−1
@@ -77,6 +77,15 @@ struct role_trans { · 76 unmodified lines
7777 struct role_trans *next;
7878 };
7979
80+struct filename_trans {
81+ struct filename_trans *next;
82+ u32 stype; /* current process */
83+ u32 ttype; /* parent dir context */
84+ u16 tclass; /* class of new object */
85+ const char *name; /* last path component */
86+ u32 otype; /* expected of new object */
87+};
88+
8089 struct role_allow {
8190 u32 role; /* current role */
8291 u32 new_role; /* new role */
@@ -217,6 +226,9 @@ struct policydb { · 134 unmodified lines
217226 /* role transitions */
218227 struct role_trans *role_tr;
219228
229+ /* file transitions with the last path component */
230+ struct filename_trans *filename_trans;
231+
220232 /* bools indexed by (value - 1) */
221233 struct cond_bool_datum **bool_val_to_struct;
222234 /* type enforcement conditional access vectors and transitions */
@@ -302,7 +314,7 @@ static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes) · 79 unmodified lines
302314 return 0;
303315 }
304316
305−static inline int put_entry(void *buf, size_t bytes, int num, struct policy_file *fp)
317+static inline int put_entry(const void *buf, size_t bytes, int num, struct policy_file *fp)
306318 {
307319 size_t len = bytes * num;
308320
security/selinux/ss/services.c+55−18
@@ -201,6 +201,21 @@ static u16 unmap_class(u16 tclass) · 200 unmodified lines
201201 return tclass;
202202 }
203203
204+/*
205+ * Get kernel value for class from its policy value
206+ */
207+static u16 map_class(u16 pol_value)
208+{
209+ u16 i;
210+
211+ for (i = 1; i < current_mapping_size; i++) {
212+ if (current_mapping[i].value == pol_value)
213+ return i;
214+ }
215+
216+ return pol_value;
217+}
218+
204219 static void map_decision(u16 tclass, struct av_decision *avd,
205220 int allow_unknown)
206221 {
@@ -1343,10 +1358,27 @@ out: · 1136 unmodified lines
13431358 return -EACCES;
13441359 }
13451360
1361+static void filename_compute_type(struct policydb *p, struct context *newcontext,
1362+ u32 scon, u32 tcon, u16 tclass,
1363+ const struct qstr *qstr)
1364+{
1365+ struct filename_trans *ft;
1366+ for (ft = p->filename_trans; ft; ft = ft->next) {
1367+ if (ft->stype == scon &&
1368+ ft->ttype == tcon &&
1369+ ft->tclass == tclass &&
1370+ !strcmp(ft->name, qstr->name)) {
1371+ newcontext->type = ft->otype;
1372+ return;
1373+ }
1374+ }
1375+}
1376+
13461377 static int security_compute_sid(u32 ssid,
13471378 u32 tsid,
13481379 u16 orig_tclass,
13491380 u32 specified,
1381+ const struct qstr *qstr,
13501382 u32 *out_sid,
13511383 bool kern)
13521384 {
@@ -1357,6 +1389,7 @@ static int security_compute_sid(u32 ssid, · 4 unmodified lines
13571389 struct avtab_node *node;
13581390 u16 tclass;
13591391 int rc = 0;
1392+ bool sock;
13601393
13611394 if (!ss_initialized) {
13621395 switch (orig_tclass) {
@@ -1374,10 +1407,13 @@ static int security_compute_sid(u32 ssid, · 11 unmodified lines
13741407
13751408 read_lock(&policy_rwlock);
13761409
1377− if (kern)
1410+ if (kern) {
13781411 tclass = unmap_class(orig_tclass);
1379− else
1412+ sock = security_is_socket_class(orig_tclass);
1413+ } else {
13801414 tclass = orig_tclass;
1415+ sock = security_is_socket_class(map_class(tclass));
1416+ }
13811417
13821418 scontext = sidtab_search(&sidtab, ssid);
13831419 if (!scontext) {
@@ -1408,7 +1444,7 @@ static int security_compute_sid(u32 ssid, · 24 unmodified lines
14081444 }
14091445
14101446 /* Set the role and type to default values. */
1411− if (tclass == policydb.process_class) {
1447+ if ((tclass == policydb.process_class) || (sock == true)) {
14121448 /* Use the current role and type of process. */
14131449 newcontext.role = scontext->role;
14141450 newcontext.type = scontext->type;
@@ -1442,6 +1478,11 @@ static int security_compute_sid(u32 ssid, · 27 unmodified lines
14421478 newcontext.type = avdatum->data;
14431479 }
14441480
1481+ /* if we have a qstr this is a file trans check so check those rules */
1482+ if (qstr)
1483+ filename_compute_type(&policydb, &newcontext, scontext->type,
1484+ tcontext->type, tclass, qstr);
1485+
14451486 /* Check for class-specific changes. */
14461487 if (tclass == policydb.process_class) {
14471488 if (specified & AVTAB_TRANSITION) {
@@ -1460,7 +1501,8 @@ static int security_compute_sid(u32 ssid, · 12 unmodified lines
14601501
14611502 /* Set the MLS attributes.
14621503 This is done last because it may allocate memory. */
1463− rc = mls_compute_sid(scontext, tcontext, tclass, specified, &newcontext);
1504+ rc = mls_compute_sid(scontext, tcontext, tclass, specified,
1505+ &newcontext, sock);
14641506 if (rc)
14651507 goto out_unlock;
14661508
@@ -1495,22 +1537,17 @@ out: · 28 unmodified lines
14951537 * if insufficient memory is available, or %0 if the new SID was
14961538 * computed successfully.
14971539 */
1498−int security_transition_sid(u32 ssid,
1499− u32 tsid,
1500− u16 tclass,
1501− u32 *out_sid)
1540+int security_transition_sid(u32 ssid, u32 tsid, u16 tclass,
1541+ const struct qstr *qstr, u32 *out_sid)
15021542 {
15031543 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION,
1504− out_sid, true);
1544+ qstr, out_sid, true);
15051545 }
15061546
1507−int security_transition_sid_user(u32 ssid,
1508− u32 tsid,
1509− u16 tclass,
1510− u32 *out_sid)
1547+int security_transition_sid_user(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid)
15111548 {
15121549 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION,
1513− out_sid, false);
1550+ NULL, out_sid, false);
15141551 }
15151552
15161553 /**
@@ -1531,8 +1568,8 @@ int security_member_sid(u32 ssid, · 14 unmodified lines
15311568 u16 tclass,
15321569 u32 *out_sid)
15331570 {
1534− return security_compute_sid(ssid, tsid, tclass, AVTAB_MEMBER, out_sid,
1535− false);
1571+ return security_compute_sid(ssid, tsid, tclass, AVTAB_MEMBER, NULL,
1572+ out_sid, false);
15361573 }
15371574
15381575 /**
@@ -1553,8 +1590,8 @@ int security_change_sid(u32 ssid, · 14 unmodified lines
15531590 u16 tclass,
15541591 u32 *out_sid)
15551592 {
1556− return security_compute_sid(ssid, tsid, tclass, AVTAB_CHANGE, out_sid,
1557− false);
1593+ return security_compute_sid(ssid, tsid, tclass, AVTAB_CHANGE, NULL,
1594+ out_sid, false);
15581595 }
15591596
15601597 /* Clone the SID into the new SID table. */
security/selinux/xfrm.c+1−1
@@ -208,7 +208,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp, · 207 unmodified lines
208208 if (!uctx)
209209 goto not_from_user;
210210
211− if (uctx->ctx_doi != XFRM_SC_ALG_SELINUX)
211+ if (uctx->ctx_alg != XFRM_SC_ALG_SELINUX)
212212 return -EINVAL;
213213
214214 str_len = uctx->ctx_len;
security/smack/smack.h+6−11
@@ -52,13 +52,16 @@ struct socket_smack { · 51 unmodified lines
5252 struct inode_smack {
5353 char *smk_inode; /* label of the fso */
5454 char *smk_task; /* label of the task */
55+ char *smk_mmap; /* label of the mmap domain */
5556 struct mutex smk_lock; /* initialization lock */
5657 int smk_flags; /* smack inode flags */
5758 };
5859
5960 struct task_smack {
60− char *smk_task; /* label used for access control */
61− char *smk_forked; /* label when forked */
61+ char *smk_task; /* label for access control */
62+ char *smk_forked; /* label when forked */
63+ struct list_head smk_rules; /* per task access rules */
64+ struct mutex smk_rules_lock; /* lock for the rules */
6265 };
6366
6467 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
@@ -151,12 +154,6 @@ struct smack_known { · 86 unmodified lines
151154 */
152155 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
153156
154−/*
155− * A limit on the number of entries in the lists
156− * makes some of the list administration easier.
157− */
158−#define SMACK_LIST_MAX 10000
159−
160157 /*
161158 * CIPSO defaults.
162159 */
@@ -174,9 +171,7 @@ struct smack_known { · 11 unmodified lines
174171 /*
175172 * Just to make the common cases easier to deal with
176173 */
177−#define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
178174 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
179−#define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
180175 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
181176 #define MAY_NOT 0
182177
@@ -202,7 +197,7 @@ struct inode_smack *new_inode_smack(char *); · 19 unmodified lines
202197 /*
203198 * These functions are in smack_access.c
204199 */
205−int smk_access_entry(char *, char *);
200+int smk_access_entry(char *, char *, struct list_head *);
206201 int smk_access(char *, char *, int, struct smk_audit_info *);
207202 int smk_curacc(char *, u32, struct smk_audit_info *);
208203 int smack_to_cipso(const char *, struct smack_cipso *);
security/smack/smack_access.c+34−18
@@ -70,10 +70,11 @@ int log_policy = SMACK_AUDIT_DENIED; · 69 unmodified lines
7070 * smk_access_entry - look up matching access rule
7171 * @subject_label: a pointer to the subject's Smack label
7272 * @object_label: a pointer to the object's Smack label
73+ * @rule_list: the list of rules to search
7374 *
7475 * This function looks up the subject/object pair in the
75− * access rule list and returns pointer to the matching rule if found,
76− * NULL otherwise.
76+ * access rule list and returns the access mode. If no
77+ * entry is found returns -ENOENT.
7778 *
7879 * NOTE:
7980 * Even though Smack labels are usually shared on smack_list
@@ -85,13 +86,13 @@ int log_policy = SMACK_AUDIT_DENIED; · 5 unmodified lines
8586 * will be on the list, so checking the pointers may be a worthwhile
8687 * optimization.
8788 */
88−int smk_access_entry(char *subject_label, char *object_label)
89+int smk_access_entry(char *subject_label, char *object_label,
90+ struct list_head *rule_list)
8991 {
90− u32 may = MAY_NOT;
92+ int may = -ENOENT;
9193 struct smack_rule *srp;
9294
93− rcu_read_lock();
94− list_for_each_entry_rcu(srp, &smack_rule_list, list) {
95+ list_for_each_entry_rcu(srp, rule_list, list) {
9596 if (srp->smk_subject == subject_label ||
9697 strcmp(srp->smk_subject, subject_label) == 0) {
9798 if (srp->smk_object == object_label ||
@@ -101,7 +102,6 @@ int smk_access_entry(char *subject_label, char *object_label) · 3 unmodified lines
101102 }
102103 }
103104 }
104− rcu_read_unlock();
105105
106106 return may;
107107 }
@@ -129,7 +129,7 @@ int smk_access_entry(char *subject_label, char *object_label) · 21 unmodified lines
129129 int smk_access(char *subject_label, char *object_label, int request,
130130 struct smk_audit_info *a)
131131 {
132− u32 may = MAY_NOT;
132+ int may = MAY_NOT;
133133 int rc = 0;
134134
135135 /*
@@ -181,13 +181,14 @@ int smk_access(char *subject_label, char *object_label, int request, · 45 unmodified lines
181181 * Beyond here an explicit relationship is required.
182182 * If the requested access is contained in the available
183183 * access (e.g. read is included in readwrite) it's
184− * good.
185− */
186− may = smk_access_entry(subject_label, object_label);
187− /*
188− * This is a bit map operation.
184+ * good. A negative response from smk_access_entry()
185+ * indicates there is no entry for this pair.
189186 */
190− if ((request & may) == request)
187+ rcu_read_lock();
188+ may = smk_access_entry(subject_label, object_label, &smack_rule_list);
189+ rcu_read_unlock();
190+
191+ if (may > 0 && (request & may) == request)
191192 goto out_audit;
192193
193194 rc = -EACCES;
@@ -212,12 +213,27 @@ out_audit: · 18 unmodified lines
212213 */
213214 int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
214215 {
216+ struct task_smack *tsp = current_security();
217+ char *sp = smk_of_task(tsp);
218+ int may;
215219 int rc;
216− char *sp = smk_of_current();
217220
221+ /*
222+ * Check the global rule list
223+ */
218224 rc = smk_access(sp, obj_label, mode, NULL);
219− if (rc == 0)
220− goto out_audit;
225+ if (rc == 0) {
226+ /*
227+ * If there is an entry in the task's rule list
228+ * it can further restrict access.
229+ */
230+ may = smk_access_entry(sp, obj_label, &tsp->smk_rules);
231+ if (may < 0)
232+ goto out_audit;
233+ if ((mode & may) == mode)
234+ goto out_audit;
235+ rc = -EACCES;
236+ }
221237
222238 /*
223239 * Return if a specific label has been designated as the
@@ -228,7 +244,7 @@ int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a) · 4 unmodified lines
228244 goto out_audit;
229245
230246 if (capable(CAP_MAC_OVERRIDE))
231− return 0;
247+ rc = 0;
232248
233249 out_audit:
234250 #ifdef CONFIG_AUDIT
security/smack/smack_lsm.c+244−43
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #include <net/cipso_ipv4.h>
3434 #include <linux/audit.h>
3535 #include <linux/magic.h>
36+#include <linux/dcache.h>
3637 #include "smack.h"
3738
3839 #define task_security(task) (task_cred_xxx((task), security))
@@ -84,6 +85,56 @@ struct inode_smack *new_inode_smack(char *smack) · 45 unmodified lines
8485 return isp;
8586 }
8687
88+/**
89+ * new_task_smack - allocate a task security blob
90+ * @smack: a pointer to the Smack label to use in the blob
91+ *
92+ * Returns the new blob or NULL if there's no memory available
93+ */
94+static struct task_smack *new_task_smack(char *task, char *forked, gfp_t gfp)
95+{
96+ struct task_smack *tsp;
97+
98+ tsp = kzalloc(sizeof(struct task_smack), gfp);
99+ if (tsp == NULL)
100+ return NULL;
101+
102+ tsp->smk_task = task;
103+ tsp->smk_forked = forked;
104+ INIT_LIST_HEAD(&tsp->smk_rules);
105+ mutex_init(&tsp->smk_rules_lock);
106+
107+ return tsp;
108+}
109+
110+/**
111+ * smk_copy_rules - copy a rule set
112+ * @nhead - new rules header pointer
113+ * @ohead - old rules header pointer
114+ *
115+ * Returns 0 on success, -ENOMEM on error
116+ */
117+static int smk_copy_rules(struct list_head *nhead, struct list_head *ohead,
118+ gfp_t gfp)
119+{
120+ struct smack_rule *nrp;
121+ struct smack_rule *orp;
122+ int rc = 0;
123+
124+ INIT_LIST_HEAD(nhead);
125+
126+ list_for_each_entry_rcu(orp, ohead, list) {
127+ nrp = kzalloc(sizeof(struct smack_rule), gfp);
128+ if (nrp == NULL) {
129+ rc = -ENOMEM;
130+ break;
131+ }
132+ *nrp = *orp;
133+ list_add_rcu(&nrp->list, nhead);
134+ }
135+ return rc;
136+}
137+
87138 /*
88139 * LSM hooks.
89140 * We he, that is fun!
@@ -102,23 +153,17 @@ static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode) · 12 unmodified lines
102153 {
103154 int rc;
104155 struct smk_audit_info ad;
105− char *sp, *tsp;
156+ char *tsp;
106157
107158 rc = cap_ptrace_access_check(ctp, mode);
108159 if (rc != 0)
109160 return rc;
110161
111− sp = smk_of_current();
112162 tsp = smk_of_task(task_security(ctp));
113163 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
114164 smk_ad_setfield_u_tsk(&ad, ctp);
115165
116− /* we won't log here, because rc can be overriden */
117− rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
118− if (rc != 0 && capable(CAP_MAC_OVERRIDE))
119− rc = 0;
120−
121− smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
166+ rc = smk_curacc(tsp, MAY_READWRITE, &ad);
122167 return rc;
123168 }
124169
@@ -134,23 +179,17 @@ static int smack_ptrace_traceme(struct task_struct *ptp) · 9 unmodified lines
134179 {
135180 int rc;
136181 struct smk_audit_info ad;
137− char *sp, *tsp;
182+ char *tsp;
138183
139184 rc = cap_ptrace_traceme(ptp);
140185 if (rc != 0)
141186 return rc;
142187
188+ tsp = smk_of_task(task_security(ptp));
143189 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
144190 smk_ad_setfield_u_tsk(&ad, ptp);
145191
146− sp = smk_of_current();
147− tsp = smk_of_task(task_security(ptp));
148− /* we won't log here, because rc can be overriden */
149− rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
150− if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
151− rc = 0;
152−
153− smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
192+ rc = smk_curacc(tsp, MAY_READWRITE, &ad);
154193 return rc;
155194 }
156195
@@ -463,6 +502,7 @@ static void smack_inode_free_security(struct inode *inode) · 306 unmodified lines
463502 * smack_inode_init_security - copy out the smack from an inode
464503 * @inode: the inode
465504 * @dir: unused
505+ * @qstr: unused
466506 * @name: where to put the attribute name
467507 * @value: where to put the attribute value
468508 * @len: where to put the length of the attribute
@@ -470,11 +510,12 @@ static void smack_inode_free_security(struct inode *inode) · 1 unmodified line
470510 * Returns 0 if it all works out, -ENOMEM if there's no memory
471511 */
472512 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
473− char **name, void **value, size_t *len)
513+ const struct qstr *qstr, char **name,
514+ void **value, size_t *len)
474515 {
475516 char *isp = smk_of_inode(inode);
476517 char *dsp = smk_of_inode(dir);
477− u32 may;
518+ int may;
478519
479520 if (name) {
480521 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
@@ -483,14 +524,17 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, · 2 unmodified lines
483524 }
484525
485526 if (value) {
486− may = smk_access_entry(smk_of_current(), dsp);
527+ rcu_read_lock();
528+ may = smk_access_entry(smk_of_current(), dsp, &smack_rule_list);
529+ rcu_read_unlock();
487530
488531 /*
489532 * If the access rule allows transmutation and
490533 * the directory requests transmutation then
491534 * by all means transmute.
492535 */
493− if (((may & MAY_TRANSMUTE) != 0) && smk_inode_transmutable(dir))
536+ if (may > 0 && ((may & MAY_TRANSMUTE) != 0) &&
537+ smk_inode_transmutable(dir))
494538 isp = dsp;
495539
496540 *value = kstrdup(isp, GFP_KERNEL);
@@ -716,7 +760,8 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name, · 219 unmodified lines
716760 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
717761 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
718762 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0 ||
719− strcmp(name, XATTR_NAME_SMACKEXEC) == 0) {
763+ strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
764+ strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
720765 if (!capable(CAP_MAC_ADMIN))
721766 rc = -EPERM;
722767 /*
@@ -773,6 +818,12 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name, · 50 unmodified lines
773818 isp->smk_task = nsp;
774819 else
775820 isp->smk_task = smack_known_invalid.smk_known;
821+ } else if (strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
822+ nsp = smk_import(value, size);
823+ if (nsp != NULL)
824+ isp->smk_mmap = nsp;
825+ else
826+ isp->smk_mmap = smack_known_invalid.smk_known;
776827 } else if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0)
777828 isp->smk_flags |= SMK_INODE_TRANSMUTE;
778829
@@ -815,7 +866,8 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name) · 36 unmodified lines
815866 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
816867 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0 ||
817868 strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
818− strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
869+ strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0 ||
870+ strcmp(name, XATTR_NAME_SMACKMMAP)) {
819871 if (!capable(CAP_MAC_ADMIN))
820872 rc = -EPERM;
821873 } else
@@ -829,6 +881,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name) · 7 unmodified lines
829881 if (rc == 0) {
830882 isp = dentry->d_inode->i_security;
831883 isp->smk_task = NULL;
884+ isp->smk_mmap = NULL;
832885 }
833886
834887 return rc;
@@ -1059,6 +1112,126 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd, · 224 unmodified lines
10591112 return rc;
10601113 }
10611114
1115+/**
1116+ * smack_file_mmap :
1117+ * Check permissions for a mmap operation. The @file may be NULL, e.g.
1118+ * if mapping anonymous memory.
1119+ * @file contains the file structure for file to map (may be NULL).
1120+ * @reqprot contains the protection requested by the application.
1121+ * @prot contains the protection that will be applied by the kernel.
1122+ * @flags contains the operational flags.
1123+ * Return 0 if permission is granted.
1124+ */
1125+static int smack_file_mmap(struct file *file,
1126+ unsigned long reqprot, unsigned long prot,
1127+ unsigned long flags, unsigned long addr,
1128+ unsigned long addr_only)
1129+{
1130+ struct smack_rule *srp;
1131+ struct task_smack *tsp;
1132+ char *sp;
1133+ char *msmack;
1134+ char *osmack;
1135+ struct inode_smack *isp;
1136+ struct dentry *dp;
1137+ int may;
1138+ int mmay;
1139+ int tmay;
1140+ int rc;
1141+
1142+ /* do DAC check on address space usage */
1143+ rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
1144+ if (rc || addr_only)
1145+ return rc;
1146+
1147+ if (file == NULL || file->f_dentry == NULL)
1148+ return 0;
1149+
1150+ dp = file->f_dentry;
1151+
1152+ if (dp->d_inode == NULL)
1153+ return 0;
1154+
1155+ isp = dp->d_inode->i_security;
1156+ if (isp->smk_mmap == NULL)
1157+ return 0;
1158+ msmack = isp->smk_mmap;
1159+
1160+ tsp = current_security();
1161+ sp = smk_of_current();
1162+ rc = 0;
1163+
1164+ rcu_read_lock();
1165+ /*
1166+ * For each Smack rule associated with the subject
1167+ * label verify that the SMACK64MMAP also has access
1168+ * to that rule's object label.
1169+ *
1170+ * Because neither of the labels comes
1171+ * from the networking code it is sufficient
1172+ * to compare pointers.
1173+ */
1174+ list_for_each_entry_rcu(srp, &smack_rule_list, list) {
1175+ if (srp->smk_subject != sp)
1176+ continue;
1177+
1178+ osmack = srp->smk_object;
1179+ /*
1180+ * Matching labels always allows access.
1181+ */
1182+ if (msmack == osmack)
1183+ continue;
1184+ /*
1185+ * If there is a matching local rule take
1186+ * that into account as well.
1187+ */
1188+ may = smk_access_entry(srp->smk_subject, osmack,
1189+ &tsp->smk_rules);
1190+ if (may == -ENOENT)
1191+ may = srp->smk_access;
1192+ else
1193+ may &= srp->smk_access;
1194+ /*
1195+ * If may is zero the SMACK64MMAP subject can't
1196+ * possibly have less access.
1197+ */
1198+ if (may == 0)
1199+ continue;
1200+
1201+ /*
1202+ * Fetch the global list entry.
1203+ * If there isn't one a SMACK64MMAP subject
1204+ * can't have as much access as current.
1205+ */
1206+ mmay = smk_access_entry(msmack, osmack, &smack_rule_list);
1207+ if (mmay == -ENOENT) {
1208+ rc = -EACCES;
1209+ break;
1210+ }
1211+ /*
1212+ * If there is a local entry it modifies the
1213+ * potential access, too.
1214+ */
1215+ tmay = smk_access_entry(msmack, osmack, &tsp->smk_rules);
1216+ if (tmay != -ENOENT)
1217+ mmay &= tmay;
1218+
1219+ /*
1220+ * If there is any access available to current that is
1221+ * not available to a SMACK64MMAP subject
1222+ * deny access.
1223+ */
1224+ if ((may | mmay) != mmay) {
1225+ rc = -EACCES;
1226+ break;
1227+ }
1228+ }
1229+
1230+ rcu_read_unlock();
1231+
1232+ return rc;
1233+}
1234+
10621235 /**
10631236 * smack_file_set_fowner - set the file security blob value
10641237 * @file: object in question
@@ -1095,6 +1268,7 @@ static int smack_file_send_sigiotask(struct task_struct *tsk, · 30 unmodified lines
10951268 * struct fown_struct is never outside the context of a struct file
10961269 */
10971270 file = container_of(fown, struct file, f_owner);
1271+
10981272 /* we don't log here as rc can be overriden */
10991273 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
11001274 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
@@ -1145,9 +1319,14 @@ static int smack_file_receive(struct file *file) · 44 unmodified lines
11451319 */
11461320 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
11471321 {
1148− cred->security = kzalloc(sizeof(struct task_smack), gfp);
1149− if (cred->security == NULL)
1322+ struct task_smack *tsp;
1323+
1324+ tsp = new_task_smack(NULL, NULL, gfp);
1325+ if (tsp == NULL)
11501326 return -ENOMEM;
1327+
1328+ cred->security = tsp;
1329+
11511330 return 0;
11521331 }
11531332
@@ -1156,13 +1335,24 @@ static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp) · 2 unmodified lines
11561335 * smack_cred_free - "free" task-level security credentials
11571336 * @cred: the credentials in question
11581337 *
1159− * Smack isn't using copies of blobs. Everyone
1160− * points to an immutable list. The blobs never go away.
1161− * There is no leak here.
11621338 */
11631339 static void smack_cred_free(struct cred *cred)
11641340 {
1165− kfree(cred->security);
1341+ struct task_smack *tsp = cred->security;
1342+ struct smack_rule *rp;
1343+ struct list_head *l;
1344+ struct list_head *n;
1345+
1346+ if (tsp == NULL)
1347+ return;
1348+ cred->security = NULL;
1349+
1350+ list_for_each_safe(l, n, &tsp->smk_rules) {
1351+ rp = list_entry(l, struct smack_rule, list);
1352+ list_del(&rp->list);
1353+ kfree(rp);
1354+ }
1355+ kfree(tsp);
11661356 }
11671357
11681358 /**
@@ -1178,13 +1368,16 @@ static int smack_cred_prepare(struct cred *new, const struct cred *old, · 9 unmodified lines
11781368 {
11791369 struct task_smack *old_tsp = old->security;
11801370 struct task_smack *new_tsp;
1371+ int rc;
11811372
1182− new_tsp = kzalloc(sizeof(struct task_smack), gfp);
1373+ new_tsp = new_task_smack(old_tsp->smk_task, old_tsp->smk_task, gfp);
11831374 if (new_tsp == NULL)
11841375 return -ENOMEM;
11851376
1186− new_tsp->smk_task = old_tsp->smk_task;
1187− new_tsp->smk_forked = old_tsp->smk_task;
1377+ rc = smk_copy_rules(&new_tsp->smk_rules, &old_tsp->smk_rules, gfp);
1378+ if (rc != 0)
1379+ return rc;
1380+
11881381 new->security = new_tsp;
11891382 return 0;
11901383 }
@@ -1203,6 +1396,11 @@ static void smack_cred_transfer(struct cred *new, const struct cred *old) · 12 unmodified lines
12031396
12041397 new_tsp->smk_task = old_tsp->smk_task;
12051398 new_tsp->smk_forked = old_tsp->smk_task;
1399+ mutex_init(&new_tsp->smk_rules_lock);
1400+ INIT_LIST_HEAD(&new_tsp->smk_rules);
1401+
1402+
1403+ /* cbs copy rule list */
12061404 }
12071405
12081406 /**
@@ -2419,6 +2617,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) · 1210 unmodified lines
24192617 }
24202618 }
24212619 isp->smk_task = smk_fetch(XATTR_NAME_SMACKEXEC, inode, dp);
2620+ isp->smk_mmap = smk_fetch(XATTR_NAME_SMACKMMAP, inode, dp);
24222621
24232622 dput(dp);
24242623 break;
@@ -2478,6 +2677,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value) · 53 unmodified lines
24782677 static int smack_setprocattr(struct task_struct *p, char *name,
24792678 void *value, size_t size)
24802679 {
2680+ int rc;
24812681 struct task_smack *tsp;
24822682 struct task_smack *oldtsp;
24832683 struct cred *new;
@@ -2513,13 +2713,16 @@ static int smack_setprocattr(struct task_struct *p, char *name, · 29 unmodified lines
25132713 new = prepare_creds();
25142714 if (new == NULL)
25152715 return -ENOMEM;
2516− tsp = kzalloc(sizeof(struct task_smack), GFP_KERNEL);
2716+
2717+ tsp = new_task_smack(newsmack, oldtsp->smk_forked, GFP_KERNEL);
25172718 if (tsp == NULL) {
25182719 kfree(new);
25192720 return -ENOMEM;
25202721 }
2521− tsp->smk_task = newsmack;
2522− tsp->smk_forked = oldtsp->smk_forked;
2722+ rc = smk_copy_rules(&tsp->smk_rules, &oldtsp->smk_rules, GFP_KERNEL);
2723+ if (rc != 0)
2724+ return rc;
2725+
25232726 new->security = tsp;
25242727 commit_creds(new);
25252728 return size;
@@ -3221,6 +3424,7 @@ struct security_operations smack_ops = { · 695 unmodified lines
32213424 .file_ioctl = smack_file_ioctl,
32223425 .file_lock = smack_file_lock,
32233426 .file_fcntl = smack_file_fcntl,
3427+ .file_mmap = smack_file_mmap,
32243428 .file_set_fowner = smack_file_set_fowner,
32253429 .file_send_sigiotask = smack_file_send_sigiotask,
32263430 .file_receive = smack_file_receive,
@@ -3334,23 +3538,20 @@ static __init int smack_init(void) · 107 unmodified lines
33343538 struct cred *cred;
33353539 struct task_smack *tsp;
33363540
3337− tsp = kzalloc(sizeof(struct task_smack), GFP_KERNEL);
3541+ if (!security_module_enable(&smack_ops))
3542+ return 0;
3543+
3544+ tsp = new_task_smack(smack_known_floor.smk_known,
3545+ smack_known_floor.smk_known, GFP_KERNEL);
33383546 if (tsp == NULL)
33393547 return -ENOMEM;
33403548
3341− if (!security_module_enable(&smack_ops)) {
3342− kfree(tsp);
3343− return 0;
3344− }
3345−
33463549 printk(KERN_INFO "Smack: Initializing.\n");
33473550
33483551 /*
33493552 * Set the security state for the initial task.
33503553 */
33513554 cred = (struct cred *) current->cred;
3352− tsp->smk_forked = smack_known_floor.smk_known;
3353− tsp->smk_task = smack_known_floor.smk_known;
33543555 cred->security = tsp;
33553556
33563557 /* initialize the smack_know_list */
security/smack/smackfs.c+255−115
@@ -43,6 +43,7 @@ enum smk_inos { · 42 unmodified lines
4343 SMK_NETLBLADDR = 8, /* single label hosts */
4444 SMK_ONLYCAP = 9, /* the only "capable" label */
4545 SMK_LOGGING = 10, /* logging */
46+ SMK_LOAD_SELF = 11, /* task specific rules */
4647 };
4748
4849 /*
@@ -135,104 +136,30 @@ static void smk_netlabel_audit_set(struct netlbl_audit *nap) · 86 unmodified lines
135136 #define SMK_NETLBLADDRMIN 9
136137 #define SMK_NETLBLADDRMAX 42
137138
138−/*
139− * Seq_file read operations for /smack/load
140− */
141−
142−static void *load_seq_start(struct seq_file *s, loff_t *pos)
143−{
144− if (*pos == SEQ_READ_FINISHED)
145− return NULL;
146− if (list_empty(&smack_rule_list))
147− return NULL;
148− return smack_rule_list.next;
149−}
150−
151−static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
152−{
153− struct list_head *list = v;
154−
155− if (list_is_last(list, &smack_rule_list)) {
156− *pos = SEQ_READ_FINISHED;
157− return NULL;
158− }
159− return list->next;
160−}
161−
162−static int load_seq_show(struct seq_file *s, void *v)
163−{
164− struct list_head *list = v;
165− struct smack_rule *srp =
166− list_entry(list, struct smack_rule, list);
167−
168− seq_printf(s, "%s %s", (char *)srp->smk_subject,
169− (char *)srp->smk_object);
170−
171− seq_putc(s, ' ');
172−
173− if (srp->smk_access & MAY_READ)
174− seq_putc(s, 'r');
175− if (srp->smk_access & MAY_WRITE)
176− seq_putc(s, 'w');
177− if (srp->smk_access & MAY_EXEC)
178− seq_putc(s, 'x');
179− if (srp->smk_access & MAY_APPEND)
180− seq_putc(s, 'a');
181− if (srp->smk_access & MAY_TRANSMUTE)
182− seq_putc(s, 't');
183− if (srp->smk_access == 0)
184− seq_putc(s, '-');
185−
186− seq_putc(s, '\n');
187−
188− return 0;
189−}
190−
191−static void load_seq_stop(struct seq_file *s, void *v)
192−{
193− /* No-op */
194−}
195−
196−static const struct seq_operations load_seq_ops = {
197− .start = load_seq_start,
198− .next = load_seq_next,
199− .show = load_seq_show,
200− .stop = load_seq_stop,
201−};
202−
203−/**
204− * smk_open_load - open() for /smack/load
205− * @inode: inode structure representing file
206− * @file: "load" file pointer
207− *
208− * For reading, use load_seq_* seq_file reading operations.
209− */
210−static int smk_open_load(struct inode *inode, struct file *file)
211−{
212− return seq_open(file, &load_seq_ops);
213−}
214−
215139 /**
216140 * smk_set_access - add a rule to the rule list
217141 * @srp: the new rule to add
142+ * @rule_list: the list of rules
143+ * @rule_lock: the rule list lock
218144 *
219145 * Looks through the current subject/object/access list for
220146 * the subject/object pair and replaces the access that was
221147 * there. If the pair isn't found add it with the specified
222148 * access.
223149 *
150+ * Returns 1 if a rule was found to exist already, 0 if it is new
224151 * Returns 0 if nothing goes wrong or -ENOMEM if it fails
225152 * during the allocation of the new pair to add.
226153 */
227−static int smk_set_access(struct smack_rule *srp)
154+static int smk_set_access(struct smack_rule *srp, struct list_head *rule_list,
155+ struct mutex *rule_lock)
228156 {
229157 struct smack_rule *sp;
230− int ret = 0;
231− int found;
232− mutex_lock(&smack_list_lock);
158+ int found = 0;
233159
234− found = 0;
235− list_for_each_entry_rcu(sp, &smack_rule_list, list) {
160+ mutex_lock(rule_lock);
161+
162+ list_for_each_entry_rcu(sp, rule_list, list) {
236163 if (sp->smk_subject == srp->smk_subject &&
237164 sp->smk_object == srp->smk_object) {
238165 found = 1;
@@ -241,19 +168,21 @@ static int smk_set_access(struct smack_rule *srp) · 2 unmodified lines
241168 }
242169 }
243170 if (found == 0)
244− list_add_rcu(&srp->list, &smack_rule_list);
171+ list_add_rcu(&srp->list, rule_list);
245172
246− mutex_unlock(&smack_list_lock);
173+ mutex_unlock(rule_lock);
247174
248− return ret;
175+ return found;
249176 }
250177
251178 /**
252− * smk_write_load - write() for /smack/load
179+ * smk_write_load_list - write() for any /smack/load
253180 * @file: file pointer, not actually used
254181 * @buf: where to get the data from
255182 * @count: bytes sent
256183 * @ppos: where to start - must be 0
184+ * @rule_list: the list of rules to write to
185+ * @rule_lock: lock for the rule list
257186 *
258187 * Get one smack access rule from above.
259188 * The format is exactly:
@@ -263,21 +192,19 @@ static int smk_set_access(struct smack_rule *srp) · 3 unmodified lines
263192 *
264193 * writes must be SMK_LABELLEN+SMK_LABELLEN+SMK_ACCESSLEN bytes.
265194 */
266−static ssize_t smk_write_load(struct file *file, const char __user *buf,
267− size_t count, loff_t *ppos)
195+static ssize_t smk_write_load_list(struct file *file, const char __user *buf,
196+ size_t count, loff_t *ppos,
197+ struct list_head *rule_list,
198+ struct mutex *rule_lock)
268199 {
269200 struct smack_rule *rule;
270201 char *data;
271202 int rc = -EINVAL;
272203
273204 /*
274− * Must have privilege.
275205 * No partial writes.
276206 * Enough data must be present.
277207 */
278− if (!capable(CAP_MAC_ADMIN))
279− return -EPERM;
280−
281208 if (*ppos != 0)
282209 return -EINVAL;
283210 /*
@@ -372,11 +299,13 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf, · 88 unmodified lines
372299 goto out_free_rule;
373300 }
374301
375− rc = smk_set_access(rule);
376−
377− if (!rc)
378− rc = count;
379− goto out;
302+ rc = count;
303+ /*
304+ * smk_set_access returns true if there was already a rule
305+ * for the subject/object pair, and false if it was new.
306+ */
307+ if (!smk_set_access(rule, rule_list, rule_lock))
308+ goto out;
380309
381310 out_free_rule:
382311 kfree(rule);
@@ -385,6 +314,108 @@ out: · 2 unmodified lines
385314 return rc;
386315 }
387316
317+
318+/*
319+ * Seq_file read operations for /smack/load
320+ */
321+
322+static void *load_seq_start(struct seq_file *s, loff_t *pos)
323+{
324+ if (*pos == SEQ_READ_FINISHED)
325+ return NULL;
326+ if (list_empty(&smack_rule_list))
327+ return NULL;
328+ return smack_rule_list.next;
329+}
330+
331+static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
332+{
333+ struct list_head *list = v;
334+
335+ if (list_is_last(list, &smack_rule_list)) {
336+ *pos = SEQ_READ_FINISHED;
337+ return NULL;
338+ }
339+ return list->next;
340+}
341+
342+static int load_seq_show(struct seq_file *s, void *v)
343+{
344+ struct list_head *list = v;
345+ struct smack_rule *srp =
346+ list_entry(list, struct smack_rule, list);
347+
348+ seq_printf(s, "%s %s", (char *)srp->smk_subject,
349+ (char *)srp->smk_object);
350+
351+ seq_putc(s, ' ');
352+
353+ if (srp->smk_access & MAY_READ)
354+ seq_putc(s, 'r');
355+ if (srp->smk_access & MAY_WRITE)
356+ seq_putc(s, 'w');
357+ if (srp->smk_access & MAY_EXEC)
358+ seq_putc(s, 'x');
359+ if (srp->smk_access & MAY_APPEND)
360+ seq_putc(s, 'a');
361+ if (srp->smk_access & MAY_TRANSMUTE)
362+ seq_putc(s, 't');
363+ if (srp->smk_access == 0)
364+ seq_putc(s, '-');
365+
366+ seq_putc(s, '\n');
367+
368+ return 0;
369+}
370+
371+static void load_seq_stop(struct seq_file *s, void *v)
372+{
373+ /* No-op */
374+}
375+
376+static const struct seq_operations load_seq_ops = {
377+ .start = load_seq_start,
378+ .next = load_seq_next,
379+ .show = load_seq_show,
380+ .stop = load_seq_stop,
381+};
382+
383+/**
384+ * smk_open_load - open() for /smack/load
385+ * @inode: inode structure representing file
386+ * @file: "load" file pointer
387+ *
388+ * For reading, use load_seq_* seq_file reading operations.
389+ */
390+static int smk_open_load(struct inode *inode, struct file *file)
391+{
392+ return seq_open(file, &load_seq_ops);
393+}
394+
395+/**
396+ * smk_write_load - write() for /smack/load
397+ * @file: file pointer, not actually used
398+ * @buf: where to get the data from
399+ * @count: bytes sent
400+ * @ppos: where to start - must be 0
401+ *
402+ */
403+static ssize_t smk_write_load(struct file *file, const char __user *buf,
404+ size_t count, loff_t *ppos)
405+{
406+
407+ /*
408+ * Must have privilege.
409+ * No partial writes.
410+ * Enough data must be present.
411+ */
412+ if (!capable(CAP_MAC_ADMIN))
413+ return -EPERM;
414+
415+ return smk_write_load_list(file, buf, count, ppos, &smack_rule_list,
416+ &smack_list_lock);
417+}
418+
388419 static const struct file_operations smk_load_ops = {
389420 .open = smk_open_load,
390421 .read = seq_read,
@@ -1288,6 +1319,112 @@ static const struct file_operations smk_logging_ops = { · 897 unmodified lines
12881319 .write = smk_write_logging,
12891320 .llseek = default_llseek,
12901321 };
1322+
1323+/*
1324+ * Seq_file read operations for /smack/load-self
1325+ */
1326+
1327+static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
1328+{
1329+ struct task_smack *tsp = current_security();
1330+
1331+ if (*pos == SEQ_READ_FINISHED)
1332+ return NULL;
1333+ if (list_empty(&tsp->smk_rules))
1334+ return NULL;
1335+ return tsp->smk_rules.next;
1336+}
1337+
1338+static void *load_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
1339+{
1340+ struct task_smack *tsp = current_security();
1341+ struct list_head *list = v;
1342+
1343+ if (list_is_last(list, &tsp->smk_rules)) {
1344+ *pos = SEQ_READ_FINISHED;
1345+ return NULL;
1346+ }
1347+ return list->next;
1348+}
1349+
1350+static int load_self_seq_show(struct seq_file *s, void *v)
1351+{
1352+ struct list_head *list = v;
1353+ struct smack_rule *srp =
1354+ list_entry(list, struct smack_rule, list);
1355+
1356+ seq_printf(s, "%s %s", (char *)srp->smk_subject,
1357+ (char *)srp->smk_object);
1358+
1359+ seq_putc(s, ' ');
1360+
1361+ if (srp->smk_access & MAY_READ)
1362+ seq_putc(s, 'r');
1363+ if (srp->smk_access & MAY_WRITE)
1364+ seq_putc(s, 'w');
1365+ if (srp->smk_access & MAY_EXEC)
1366+ seq_putc(s, 'x');
1367+ if (srp->smk_access & MAY_APPEND)
1368+ seq_putc(s, 'a');
1369+ if (srp->smk_access & MAY_TRANSMUTE)
1370+ seq_putc(s, 't');
1371+ if (srp->smk_access == 0)
1372+ seq_putc(s, '-');
1373+
1374+ seq_putc(s, '\n');
1375+
1376+ return 0;
1377+}
1378+
1379+static void load_self_seq_stop(struct seq_file *s, void *v)
1380+{
1381+ /* No-op */
1382+}
1383+
1384+static const struct seq_operations load_self_seq_ops = {
1385+ .start = load_self_seq_start,
1386+ .next = load_self_seq_next,
1387+ .show = load_self_seq_show,
1388+ .stop = load_self_seq_stop,
1389+};
1390+
1391+
1392+/**
1393+ * smk_open_load_self - open() for /smack/load-self
1394+ * @inode: inode structure representing file
1395+ * @file: "load" file pointer
1396+ *
1397+ * For reading, use load_seq_* seq_file reading operations.
1398+ */
1399+static int smk_open_load_self(struct inode *inode, struct file *file)
1400+{
1401+ return seq_open(file, &load_self_seq_ops);
1402+}
1403+
1404+/**
1405+ * smk_write_load_self - write() for /smack/load-self
1406+ * @file: file pointer, not actually used
1407+ * @buf: where to get the data from
1408+ * @count: bytes sent
1409+ * @ppos: where to start - must be 0
1410+ *
1411+ */
1412+static ssize_t smk_write_load_self(struct file *file, const char __user *buf,
1413+ size_t count, loff_t *ppos)
1414+{
1415+ struct task_smack *tsp = current_security();
1416+
1417+ return smk_write_load_list(file, buf, count, ppos, &tsp->smk_rules,
1418+ &tsp->smk_rules_lock);
1419+}
1420+
1421+static const struct file_operations smk_load_self_ops = {
1422+ .open = smk_open_load_self,
1423+ .read = seq_read,
1424+ .llseek = seq_lseek,
1425+ .write = smk_write_load_self,
1426+ .release = seq_release,
1427+};
12911428 /**
12921429 * smk_fill_super - fill the /smackfs superblock
12931430 * @sb: the empty superblock
@@ -1304,23 +1441,26 @@ static int smk_fill_super(struct super_block *sb, void *data, int silent) · 10 unmodified lines
13041441 struct inode *root_inode;
13051442
13061443 static struct tree_descr smack_files[] = {
1307− [SMK_LOAD] =
1308− {"load", &smk_load_ops, S_IRUGO|S_IWUSR},
1309− [SMK_CIPSO] =
1310− {"cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
1311− [SMK_DOI] =
1312− {"doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
1313− [SMK_DIRECT] =
1314− {"direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
1315− [SMK_AMBIENT] =
1316− {"ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
1317− [SMK_NETLBLADDR] =
1318− {"netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR},
1319− [SMK_ONLYCAP] =
1320− {"onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
1321− [SMK_LOGGING] =
1322− {"logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
1323− /* last one */ {""}
1444+ [SMK_LOAD] = {
1445+ "load", &smk_load_ops, S_IRUGO|S_IWUSR},
1446+ [SMK_CIPSO] = {
1447+ "cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
1448+ [SMK_DOI] = {
1449+ "doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
1450+ [SMK_DIRECT] = {
1451+ "direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
1452+ [SMK_AMBIENT] = {
1453+ "ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
1454+ [SMK_NETLBLADDR] = {
1455+ "netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR},
1456+ [SMK_ONLYCAP] = {
1457+ "onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
1458+ [SMK_LOGGING] = {
1459+ "logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
1460+ [SMK_LOAD_SELF] = {
1461+ "load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
1462+ /* last one */
1463+ {""}
13241464 };
13251465
13261466 rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
security/tomoyo/file.c+1−4
@@ -927,7 +927,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, · 926 unmodified lines
927927 struct path *path, const int flag)
928928 {
929929 const u8 acc_mode = ACC_MODE(flag);
930− int error = -ENOMEM;
930+ int error = 0;
931931 struct tomoyo_path_info buf;
932932 struct tomoyo_request_info r;
933933 int idx;
@@ -938,9 +938,6 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, · 4 unmodified lines
938938 buf.name = NULL;
939939 r.mode = TOMOYO_CONFIG_DISABLED;
940940 idx = tomoyo_read_lock();
941− if (!tomoyo_get_realpath(&buf, path))
942− goto out;
943− error = 0;
944941 /*
945942 * If the filename is specified by "deny_rewrite" keyword,
946943 * we need to check "allow_rewrite" permission when the filename is not

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t