diff options
| author | Ingo Molnar <mingo@elte.hu> | 2009-03-28 17:27:45 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2009-03-28 17:27:45 -0400 |
| commit | 3fab191002b184e4390aa07c7149c6cc7b638ec7 (patch) | |
| tree | 821382d49e47c19531bfc3bb9e1f8922486374d4 /security/selinux/hooks.c | |
| parent | 93394a761d78503f11d05b1a7b23d5a9ccc8dad2 (diff) | |
| parent | 7c730ccdc1188b97f5c8cb690906242c7ed75c22 (diff) | |
Merge branch 'linus' into x86/core
Diffstat (limited to 'security/selinux/hooks.c')
| -rw-r--r-- | security/selinux/hooks.c | 308 |
1 files changed, 107 insertions, 201 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 00815973d412..7c52ba243c64 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
| @@ -89,7 +89,7 @@ | |||
| 89 | #define XATTR_SELINUX_SUFFIX "selinux" | 89 | #define XATTR_SELINUX_SUFFIX "selinux" |
| 90 | #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX | 90 | #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX |
| 91 | 91 | ||
| 92 | #define NUM_SEL_MNT_OPTS 4 | 92 | #define NUM_SEL_MNT_OPTS 5 |
| 93 | 93 | ||
| 94 | extern unsigned int policydb_loaded_version; | 94 | extern unsigned int policydb_loaded_version; |
| 95 | extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm); | 95 | extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm); |
| @@ -353,6 +353,7 @@ enum { | |||
| 353 | Opt_fscontext = 2, | 353 | Opt_fscontext = 2, |
| 354 | Opt_defcontext = 3, | 354 | Opt_defcontext = 3, |
| 355 | Opt_rootcontext = 4, | 355 | Opt_rootcontext = 4, |
| 356 | Opt_labelsupport = 5, | ||
| 356 | }; | 357 | }; |
| 357 | 358 | ||
| 358 | static const match_table_t tokens = { | 359 | static const match_table_t tokens = { |
| @@ -360,6 +361,7 @@ static const match_table_t tokens = { | |||
| 360 | {Opt_fscontext, FSCONTEXT_STR "%s"}, | 361 | {Opt_fscontext, FSCONTEXT_STR "%s"}, |
| 361 | {Opt_defcontext, DEFCONTEXT_STR "%s"}, | 362 | {Opt_defcontext, DEFCONTEXT_STR "%s"}, |
| 362 | {Opt_rootcontext, ROOTCONTEXT_STR "%s"}, | 363 | {Opt_rootcontext, ROOTCONTEXT_STR "%s"}, |
| 364 | {Opt_labelsupport, LABELSUPP_STR}, | ||
| 363 | {Opt_error, NULL}, | 365 | {Opt_error, NULL}, |
| 364 | }; | 366 | }; |
| 365 | 367 | ||
| @@ -431,7 +433,7 @@ static int sb_finish_set_opts(struct super_block *sb) | |||
| 431 | } | 433 | } |
| 432 | } | 434 | } |
| 433 | 435 | ||
| 434 | sbsec->initialized = 1; | 436 | sbsec->flags |= (SE_SBINITIALIZED | SE_SBLABELSUPP); |
| 435 | 437 | ||
| 436 | if (sbsec->behavior > ARRAY_SIZE(labeling_behaviors)) | 438 | if (sbsec->behavior > ARRAY_SIZE(labeling_behaviors)) |
| 437 | printk(KERN_ERR "SELinux: initialized (dev %s, type %s), unknown behavior\n", | 439 | printk(KERN_ERR "SELinux: initialized (dev %s, type %s), unknown behavior\n", |
| @@ -441,6 +443,12 @@ static int sb_finish_set_opts(struct super_block *sb) | |||
| 441 | sb->s_id, sb->s_type->name, | 443 | sb->s_id, sb->s_type->name, |
| 442 | labeling_behaviors[sbsec->behavior-1]); | 444 | labeling_behaviors[sbsec->behavior-1]); |
| 443 | 445 | ||
| 446 | if (sbsec->behavior == SECURITY_FS_USE_GENFS || | ||
| 447 | sbsec->behavior == SECURITY_FS_USE_MNTPOINT || | ||
| 448 | sbsec->behavior == SECURITY_FS_USE_NONE || | ||
| 449 | sbsec->behavior > ARRAY_SIZE(labeling_behaviors)) | ||
| 450 | sbsec->flags &= ~SE_SBLABELSUPP; | ||
| 451 | |||
| 444 | /* Initialize the root inode. */ | 452 | /* Initialize the root inode. */ |
| 445 | rc = inode_doinit_with_dentry(root_inode, root); | 453 | rc = inode_doinit_with_dentry(root_inode, root); |
| 446 | 454 | ||
| @@ -487,23 +495,22 @@ static int selinux_get_mnt_opts(const struct super_block *sb, | |||
| 487 | 495 | ||
| 488 | security_init_mnt_opts(opts); | 496 | security_init_mnt_opts(opts); |
| 489 | 497 | ||
| 490 | if (!sbsec->initialized) | 498 | if (!(sbsec->flags & SE_SBINITIALIZED)) |
| 491 | return -EINVAL; | 499 | return -EINVAL; |
| 492 | 500 | ||
| 493 | if (!ss_initialized) | 501 | if (!ss_initialized) |
| 494 | return -EINVAL; | 502 | return -EINVAL; |
| 495 | 503 | ||
| 496 | /* | 504 | tmp = sbsec->flags & SE_MNTMASK; |
| 497 | * if we ever use sbsec flags for anything other than tracking mount | ||
| 498 | * settings this is going to need a mask | ||
| 499 | */ | ||
| 500 | tmp = sbsec->flags; | ||
| 501 | /* count the number of mount options for this sb */ | 505 | /* count the number of mount options for this sb */ |
| 502 | for (i = 0; i < 8; i++) { | 506 | for (i = 0; i < 8; i++) { |
| 503 | if (tmp & 0x01) | 507 | if (tmp & 0x01) |
| 504 | opts->num_mnt_opts++; | 508 | opts->num_mnt_opts++; |
| 505 | tmp >>= 1; | 509 | tmp >>= 1; |
| 506 | } | 510 | } |
| 511 | /* Check if the Label support flag is set */ | ||
| 512 | if (sbsec->flags & SE_SBLABELSUPP) | ||
| 513 | opts->num_mnt_opts++; | ||
| 507 | 514 | ||
| 508 | opts->mnt_opts = kcalloc(opts->num_mnt_opts, sizeof(char *), GFP_ATOMIC); | 515 | opts->mnt_opts = kcalloc(opts->num_mnt_opts, sizeof(char *), GFP_ATOMIC); |
| 509 | if (!opts->mnt_opts) { | 516 | if (!opts->mnt_opts) { |
| @@ -549,6 +556,10 @@ static int selinux_get_mnt_opts(const struct super_block *sb, | |||
| 549 | opts->mnt_opts[i] = context; | 556 | opts->mnt_opts[i] = context; |
| 550 | opts->mnt_opts_flags[i++] = ROOTCONTEXT_MNT; | 557 | opts->mnt_opts_flags[i++] = ROOTCONTEXT_MNT; |
| 551 | } | 558 | } |
| 559 | if (sbsec->flags & SE_SBLABELSUPP) { | ||
| 560 | opts->mnt_opts[i] = NULL; | ||
| 561 | opts->mnt_opts_flags[i++] = SE_SBLABELSUPP; | ||
| 562 | } | ||
| 552 | 563 | ||
| 553 | BUG_ON(i != opts->num_mnt_opts); | 564 | BUG_ON(i != opts->num_mnt_opts); |
| 554 | 565 | ||
| @@ -562,8 +573,10 @@ out_free: | |||
| 562 | static int bad_option(struct superblock_security_struct *sbsec, char flag, | 573 | static int bad_option(struct superblock_security_struct *sbsec, char flag, |
| 563 | u32 old_sid, u32 new_sid) | 574 | u32 old_sid, u32 new_sid) |
| 564 | { | 575 | { |
| 576 | char mnt_flags = sbsec->flags & SE_MNTMASK; | ||
| 577 | |||
| 565 | /* check if the old mount command had the same options */ | 578 | /* check if the old mount command had the same options */ |
| 566 | if (sbsec->initialized) | 579 | if (sbsec->flags & SE_SBINITIALIZED) |
| 567 | if (!(sbsec->flags & flag) || | 580 | if (!(sbsec->flags & flag) || |
| 568 | (old_sid != new_sid)) | 581 | (old_sid != new_sid)) |
| 569 | return 1; | 582 | return 1; |
| @@ -571,8 +584,8 @@ static int bad_option(struct superblock_security_struct *sbsec, char flag, | |||
| 571 | /* check if we were passed the same options twice, | 584 | /* check if we were passed the same options twice, |
| 572 | * aka someone passed context=a,context=b | 585 | * aka someone passed context=a,context=b |
| 573 | */ | 586 | */ |
| 574 | if (!sbsec->initialized) | 587 | if (!(sbsec->flags & SE_SBINITIALIZED)) |
| 575 | if (sbsec->flags & flag) | 588 | if (mnt_flags & flag) |
| 576 | return 1; | 589 | return 1; |
| 577 | return 0; | 590 | return 0; |
| 578 | } | 591 | } |
| @@ -626,7 +639,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
| 626 | * this sb does not set any security options. (The first options | 639 | * this sb does not set any security options. (The first options |
| 627 | * will be used for both mounts) | 640 | * will be used for both mounts) |
| 628 | */ | 641 | */ |
| 629 | if (sbsec->initialized && (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA) | 642 | if ((sbsec->flags & SE_SBINITIALIZED) && (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA) |
| 630 | && (num_opts == 0)) | 643 | && (num_opts == 0)) |
| 631 | goto out; | 644 | goto out; |
| 632 | 645 | ||
| @@ -637,6 +650,9 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
| 637 | */ | 650 | */ |
| 638 | for (i = 0; i < num_opts; i++) { | 651 | for (i = 0; i < num_opts; i++) { |
| 639 | u32 sid; | 652 | u32 sid; |
| 653 | |||
| 654 | if (flags[i] == SE_SBLABELSUPP) | ||
| 655 | continue; | ||
| 640 | rc = security_context_to_sid(mount_options[i], | 656 | rc = security_context_to_sid(mount_options[i], |
| 641 | strlen(mount_options[i]), &sid); | 657 | strlen(mount_options[i]), &sid); |
| 642 | if (rc) { | 658 | if (rc) { |
| @@ -690,19 +706,19 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
| 690 | } | 706 | } |
| 691 | } | 707 | } |
| 692 | 708 | ||
| 693 | if (sbsec->initialized) { | 709 | if (sbsec->flags & SE_SBINITIALIZED) { |
| 694 | /* previously mounted with options, but not on this attempt? */ | 710 | /* previously mounted with options, but not on this attempt? */ |
| 695 | if (sbsec->flags && !num_opts) | 711 | if ((sbsec->flags & SE_MNTMASK) && !num_opts) |
| 696 | goto out_double_mount; | 712 | goto out_double_mount; |
| 697 | rc = 0; | 713 | rc = 0; |
| 698 | goto out; | 714 | goto out; |
| 699 | } | 715 | } |
| 700 | 716 | ||
| 701 | if (strcmp(sb->s_type->name, "proc") == 0) | 717 | if (strcmp(sb->s_type->name, "proc") == 0) |
| 702 | sbsec->proc = 1; | 718 | sbsec->flags |= SE_SBPROC; |
| 703 | 719 | ||
| 704 | /* Determine the labeling behavior to use for this filesystem type. */ | 720 | /* Determine the labeling behavior to use for this filesystem type. */ |
| 705 | rc = security_fs_use(sbsec->proc ? "proc" : sb->s_type->name, &sbsec->behavior, &sbsec->sid); | 721 | rc = security_fs_use((sbsec->flags & SE_SBPROC) ? "proc" : sb->s_type->name, &sbsec->behavior, &sbsec->sid); |
| 706 | if (rc) { | 722 | if (rc) { |
| 707 | printk(KERN_WARNING "%s: security_fs_use(%s) returned %d\n", | 723 | printk(KERN_WARNING "%s: security_fs_use(%s) returned %d\n", |
| 708 | __func__, sb->s_type->name, rc); | 724 | __func__, sb->s_type->name, rc); |
| @@ -806,10 +822,10 @@ static void selinux_sb_clone_mnt_opts(const struct super_block *oldsb, | |||
| 806 | } | 822 | } |
| 807 | 823 | ||
| 808 | /* how can we clone if the old one wasn't set up?? */ | 824 | /* how can we clone if the old one wasn't set up?? */ |
| 809 | BUG_ON(!oldsbsec->initialized); | 825 | BUG_ON(!(oldsbsec->flags & SE_SBINITIALIZED)); |
| 810 | 826 | ||
| 811 | /* if fs is reusing a sb, just let its options stand... */ | 827 | /* if fs is reusing a sb, just let its options stand... */ |
| 812 | if (newsbsec->initialized) | 828 | if (newsbsec->flags & SE_SBINITIALIZED) |
| 813 | return; | 829 | return; |
| 814 | 830 | ||
| 815 | mutex_lock(&newsbsec->lock); | 831 | mutex_lock(&newsbsec->lock); |
| @@ -917,7 +933,8 @@ static int selinux_parse_opts_str(char *options, | |||
| 917 | goto out_err; | 933 | goto out_err; |
| 918 | } | 934 | } |
| 919 | break; | 935 | break; |
| 920 | 936 | case Opt_labelsupport: | |
| 937 | break; | ||
| 921 | default: | 938 | default: |
| 922 | rc = -EINVAL; | 939 | rc = -EINVAL; |
| 923 | printk(KERN_WARNING "SELinux: unknown mount option\n"); | 940 | printk(KERN_WARNING "SELinux: unknown mount option\n"); |
| @@ -999,7 +1016,12 @@ static void selinux_write_opts(struct seq_file *m, | |||
| 999 | char *prefix; | 1016 | char *prefix; |
| 1000 | 1017 | ||
| 1001 | for (i = 0; i < opts->num_mnt_opts; i++) { | 1018 | for (i = 0; i < opts->num_mnt_opts; i++) { |
| 1002 | char *has_comma = strchr(opts->mnt_opts[i], ','); | 1019 | char *has_comma; |
| 1020 | |||
| 1021 | if (opts->mnt_opts[i]) | ||
| 1022 | has_comma = strchr(opts->mnt_opts[i], ','); | ||
| 1023 | else | ||
| 1024 | has_comma = NULL; | ||
| 1003 | 1025 | ||
| 1004 | switch (opts->mnt_opts_flags[i]) { | 1026 | switch (opts->mnt_opts_flags[i]) { |
| 1005 | case CONTEXT_MNT: | 1027 | case CONTEXT_MNT: |
| @@ -1014,6 +1036,10 @@ static void selinux_write_opts(struct seq_file *m, | |||
| 1014 | case DEFCONTEXT_MNT: | 1036 | case DEFCONTEXT_MNT: |
| 1015 | prefix = DEFCONTEXT_STR; | 1037 | prefix = DEFCONTEXT_STR; |
| 1016 | break; | 1038 | break; |
| 1039 | case SE_SBLABELSUPP: | ||
| 1040 | seq_putc(m, ','); | ||
| 1041 | seq_puts(m, LABELSUPP_STR); | ||
| 1042 | continue; | ||
| 1017 | default: | 1043 | default: |
| 1018 | BUG(); | 1044 | BUG(); |
| 1019 | }; | 1045 | }; |
| @@ -1209,7 +1235,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent | |||
| 1209 | goto out_unlock; | 1235 | goto out_unlock; |
| 1210 | 1236 | ||
| 1211 | sbsec = inode->i_sb->s_security; | 1237 | sbsec = inode->i_sb->s_security; |
| 1212 | if (!sbsec->initialized) { | 1238 | if (!(sbsec->flags & SE_SBINITIALIZED)) { |
| 1213 | /* Defer initialization until selinux_complete_init, | 1239 | /* Defer initialization until selinux_complete_init, |
| 1214 | after the initial policy is loaded and the security | 1240 | after the initial policy is loaded and the security |
| 1215 | server is ready to handle calls. */ | 1241 | server is ready to handle calls. */ |
| @@ -1237,19 +1263,26 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent | |||
| 1237 | dentry = d_find_alias(inode); | 1263 | dentry = d_find_alias(inode); |
| 1238 | } | 1264 | } |
| 1239 | if (!dentry) { | 1265 | if (!dentry) { |
| 1240 | printk(KERN_WARNING "SELinux: %s: no dentry for dev=%s " | 1266 | /* |
| 1241 | "ino=%ld\n", __func__, inode->i_sb->s_id, | 1267 | * this is can be hit on boot when a file is accessed |
| 1242 | inode->i_ino); | 1268 | * before the policy is loaded. When we load policy we |
| 1269 | * may find inodes that have no dentry on the | ||
| 1270 | * sbsec->isec_head list. No reason to complain as these | ||
| 1271 | * will get fixed up the next time we go through | ||
| 1272 | * inode_doinit with a dentry, before these inodes could | ||
| 1273 | * be used again by userspace. | ||
| 1274 | */ | ||
| 1243 | goto out_unlock; | 1275 | goto out_unlock; |
| 1244 | } | 1276 | } |
| 1245 | 1277 | ||
| 1246 | len = INITCONTEXTLEN; | 1278 | len = INITCONTEXTLEN; |
| 1247 | context = kmalloc(len, GFP_NOFS); | 1279 | context = kmalloc(len+1, GFP_NOFS); |
| 1248 | if (!context) { | 1280 | if (!context) { |
| 1249 | rc = -ENOMEM; | 1281 | rc = -ENOMEM; |
| 1250 | dput(dentry); | 1282 | dput(dentry); |
| 1251 | goto out_unlock; | 1283 | goto out_unlock; |
| 1252 | } | 1284 | } |
| 1285 | context[len] = '\0'; | ||
| 1253 | rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX, | 1286 | rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX, |
| 1254 | context, len); | 1287 | context, len); |
| 1255 | if (rc == -ERANGE) { | 1288 | if (rc == -ERANGE) { |
| @@ -1262,12 +1295,13 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent | |||
| 1262 | } | 1295 | } |
| 1263 | kfree(context); | 1296 | kfree(context); |
| 1264 | len = rc; | 1297 | len = rc; |
| 1265 | context = kmalloc(len, GFP_NOFS); | 1298 | context = kmalloc(len+1, GFP_NOFS); |
| 1266 | if (!context) { | 1299 | if (!context) { |
| 1267 | rc = -ENOMEM; | 1300 | rc = -ENOMEM; |
| 1268 | dput(dentry); | 1301 | dput(dentry); |
| 1269 | goto out_unlock; | 1302 | goto out_unlock; |
| 1270 | } | 1303 | } |
| 1304 | context[len] = '\0'; | ||
| 1271 | rc = inode->i_op->getxattr(dentry, | 1305 | rc = inode->i_op->getxattr(dentry, |
| 1272 | XATTR_NAME_SELINUX, | 1306 | XATTR_NAME_SELINUX, |
| 1273 | context, len); | 1307 | context, len); |
| @@ -1289,10 +1323,19 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent | |||
| 1289 | sbsec->def_sid, | 1323 | sbsec->def_sid, |
| 1290 | GFP_NOFS); | 1324 | GFP_NOFS); |
| 1291 | if (rc) { | 1325 | if (rc) { |
| 1292 | printk(KERN_WARNING "SELinux: %s: context_to_sid(%s) " | 1326 | char *dev = inode->i_sb->s_id; |
| 1293 | "returned %d for dev=%s ino=%ld\n", | 1327 | unsigned long ino = inode->i_ino; |
| 1294 | __func__, context, -rc, | 1328 | |
| 1295 | inode->i_sb->s_id, inode->i_ino); | 1329 | if (rc == -EINVAL) { |
| 1330 | if (printk_ratelimit()) | ||
| 1331 | printk(KERN_NOTICE "SELinux: inode=%lu on dev=%s was found to have an invalid " | ||
| 1332 | "context=%s. This indicates you may need to relabel the inode or the " | ||
| 1333 | "filesystem in question.\n", ino, dev, context); | ||
| 1334 | } else { | ||
| 1335 | printk(KERN_WARNING "SELinux: %s: context_to_sid(%s) " | ||
| 1336 | "returned %d for dev=%s ino=%ld\n", | ||
| 1337 | __func__, context, -rc, dev, ino); | ||
| 1338 | } | ||
| 1296 | kfree(context); | 1339 | kfree(context); |
| 1297 | /* Leave with the unlabeled SID */ | 1340 | /* Leave with the unlabeled SID */ |
| 1298 | rc = 0; | 1341 | rc = 0; |
| @@ -1326,7 +1369,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent | |||
| 1326 | /* Default to the fs superblock SID. */ | 1369 | /* Default to the fs superblock SID. */ |
| 1327 | isec->sid = sbsec->sid; | 1370 | isec->sid = sbsec->sid; |
| 1328 | 1371 | ||
| 1329 | if (sbsec->proc && !S_ISLNK(inode->i_mode)) { | 1372 | if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) { |
| 1330 | struct proc_inode *proci = PROC_I(inode); | 1373 | struct proc_inode *proci = PROC_I(inode); |
| 1331 | if (proci->pde) { | 1374 | if (proci->pde) { |
| 1332 | isec->sclass = inode_mode_to_security_class(inode->i_mode); | 1375 | isec->sclass = inode_mode_to_security_class(inode->i_mode); |
| @@ -1587,7 +1630,7 @@ static int may_create(struct inode *dir, | |||
| 1587 | if (rc) | 1630 | if (rc) |
| 1588 | return rc; | 1631 | return rc; |
| 1589 | 1632 | ||
| 1590 | if (!newsid || sbsec->behavior == SECURITY_FS_USE_MNTPOINT) { | 1633 | if (!newsid || !(sbsec->flags & SE_SBLABELSUPP)) { |
| 1591 | rc = security_transition_sid(sid, dsec->sid, tclass, &newsid); | 1634 | rc = security_transition_sid(sid, dsec->sid, tclass, &newsid); |
| 1592 | if (rc) | 1635 | if (rc) |
| 1593 | return rc; | 1636 | return rc; |
| @@ -1801,6 +1844,8 @@ static inline u32 open_file_to_av(struct file *file) | |||
| 1801 | av |= FIFO_FILE__OPEN; | 1844 | av |= FIFO_FILE__OPEN; |
| 1802 | else if (S_ISDIR(mode)) | 1845 | else if (S_ISDIR(mode)) |
| 1803 | av |= DIR__OPEN; | 1846 | av |= DIR__OPEN; |
| 1847 | else if (S_ISSOCK(mode)) | ||
| 1848 | av |= SOCK_FILE__OPEN; | ||
| 1804 | else | 1849 | else |
| 1805 | printk(KERN_ERR "SELinux: WARNING: inside %s with " | 1850 | printk(KERN_ERR "SELinux: WARNING: inside %s with " |
| 1806 | "unknown mode:%o\n", __func__, mode); | 1851 | "unknown mode:%o\n", __func__, mode); |
| @@ -1815,7 +1860,7 @@ static int selinux_ptrace_may_access(struct task_struct *child, | |||
| 1815 | { | 1860 | { |
| 1816 | int rc; | 1861 | int rc; |
| 1817 | 1862 | ||
| 1818 | rc = secondary_ops->ptrace_may_access(child, mode); | 1863 | rc = cap_ptrace_may_access(child, mode); |
| 1819 | if (rc) | 1864 | if (rc) |
| 1820 | return rc; | 1865 | return rc; |
| 1821 | 1866 | ||
| @@ -1832,7 +1877,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) | |||
| 1832 | { | 1877 | { |
| 1833 | int rc; | 1878 | int rc; |
| 1834 | 1879 | ||
| 1835 | rc = secondary_ops->ptrace_traceme(parent); | 1880 | rc = cap_ptrace_traceme(parent); |
| 1836 | if (rc) | 1881 | if (rc) |
| 1837 | return rc; | 1882 | return rc; |
| 1838 | 1883 | ||
| @@ -1848,7 +1893,7 @@ static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, | |||
| 1848 | if (error) | 1893 | if (error) |
| 1849 | return error; | 1894 | return error; |
| 1850 | 1895 | ||
| 1851 | return secondary_ops->capget(target, effective, inheritable, permitted); | 1896 | return cap_capget(target, effective, inheritable, permitted); |
| 1852 | } | 1897 | } |
| 1853 | 1898 | ||
| 1854 | static int selinux_capset(struct cred *new, const struct cred *old, | 1899 | static int selinux_capset(struct cred *new, const struct cred *old, |
| @@ -1858,7 +1903,7 @@ static int selinux_capset(struct cred *new, const struct cred *old, | |||
| 1858 | { | 1903 | { |
| 1859 | int error; | 1904 | int error; |
| 1860 | 1905 | ||
| 1861 | error = secondary_ops->capset(new, old, | 1906 | error = cap_capset(new, old, |
| 1862 | effective, inheritable, permitted); | 1907 | effective, inheritable, permitted); |
| 1863 | if (error) | 1908 | if (error) |
| 1864 | return error; | 1909 | return error; |
| @@ -1866,12 +1911,22 @@ static int selinux_capset(struct cred *new, const struct cred *old, | |||
| 1866 | return cred_has_perm(old, new, PROCESS__SETCAP); | 1911 | return cred_has_perm(old, new, PROCESS__SETCAP); |
| 1867 | } | 1912 | } |
| 1868 | 1913 | ||
| 1914 | /* | ||
| 1915 | * (This comment used to live with the selinux_task_setuid hook, | ||
| 1916 | * which was removed). | ||
| 1917 | * | ||
| 1918 | * Since setuid only affects the current process, and since the SELinux | ||
| 1919 | * controls are not based on the Linux identity attributes, SELinux does not | ||
| 1920 | * need to control this operation. However, SELinux does control the use of | ||
| 1921 | * the CAP_SETUID and CAP_SETGID capabilities using the capable hook. | ||
| 1922 | */ | ||
| 1923 | |||
| 1869 | static int selinux_capable(struct task_struct *tsk, const struct cred *cred, | 1924 | static int selinux_capable(struct task_struct *tsk, const struct cred *cred, |
| 1870 | int cap, int audit) | 1925 | int cap, int audit) |
| 1871 | { | 1926 | { |
| 1872 | int rc; | 1927 | int rc; |
| 1873 | 1928 | ||
| 1874 | rc = secondary_ops->capable(tsk, cred, cap, audit); | 1929 | rc = cap_capable(tsk, cred, cap, audit); |
| 1875 | if (rc) | 1930 | if (rc) |
| 1876 | return rc; | 1931 | return rc; |
| 1877 | 1932 | ||
| @@ -1997,7 +2052,7 @@ static int selinux_syslog(int type) | |||
| 1997 | { | 2052 | { |
| 1998 | int rc; | 2053 | int rc; |
| 1999 | 2054 | ||
| 2000 | rc = secondary_ops->syslog(type); | 2055 | rc = cap_syslog(type); |
| 2001 | if (rc) | 2056 | if (rc) |
| 2002 | return rc; | 2057 | return rc; |
| 2003 | 2058 | ||
| @@ -2028,10 +2083,6 @@ static int selinux_syslog(int type) | |||
| 2028 | * mapping. 0 means there is enough memory for the allocation to | 2083 | * mapping. 0 means there is enough memory for the allocation to |
| 2029 | * succeed and -ENOMEM implies there is not. | 2084 | * succeed and -ENOMEM implies there is not. |
| 2030 | * | 2085 | * |
| 2031 | * Note that secondary_ops->capable and task_has_perm_noaudit return 0 | ||
| 2032 | * if the capability is granted, but __vm_enough_memory requires 1 if | ||
| 2033 | * the capability is granted. | ||
| 2034 | * | ||
| 2035 | * Do not audit the selinux permission check, as this is applied to all | 2086 | * Do not audit the selinux permission check, as this is applied to all |
| 2036 | * processes that allocate mappings. | 2087 | * processes that allocate mappings. |
| 2037 | */ | 2088 | */ |
| @@ -2058,7 +2109,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) | |||
| 2058 | struct inode *inode = bprm->file->f_path.dentry->d_inode; | 2109 | struct inode *inode = bprm->file->f_path.dentry->d_inode; |
| 2059 | int rc; | 2110 | int rc; |
| 2060 | 2111 | ||
| 2061 | rc = secondary_ops->bprm_set_creds(bprm); | 2112 | rc = cap_bprm_set_creds(bprm); |
| 2062 | if (rc) | 2113 | if (rc) |
| 2063 | return rc; | 2114 | return rc; |
| 2064 | 2115 | ||
| @@ -2156,11 +2207,6 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) | |||
| 2156 | return 0; | 2207 | return 0; |
| 2157 | } | 2208 | } |
| 2158 | 2209 | ||
| 2159 | static int selinux_bprm_check_security(struct linux_binprm *bprm) | ||
| 2160 | { | ||
| 2161 | return secondary_ops->bprm_check_security(bprm); | ||
| 2162 | } | ||
| 2163 | |||
| 2164 | static int selinux_bprm_secureexec(struct linux_binprm *bprm) | 2210 | static int selinux_bprm_secureexec(struct linux_binprm *bprm) |
| 2165 | { | 2211 | { |
| 2166 | const struct cred *cred = current_cred(); | 2212 | const struct cred *cred = current_cred(); |
| @@ -2180,7 +2226,7 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) | |||
| 2180 | PROCESS__NOATSECURE, NULL); | 2226 | PROCESS__NOATSECURE, NULL); |
| 2181 | } | 2227 | } |
| 2182 | 2228 | ||
| 2183 | return (atsecure || secondary_ops->bprm_secureexec(bprm)); | 2229 | return (atsecure || cap_bprm_secureexec(bprm)); |
| 2184 | } | 2230 | } |
| 2185 | 2231 | ||
| 2186 | extern struct vfsmount *selinuxfs_mount; | 2232 | extern struct vfsmount *selinuxfs_mount; |
| @@ -2290,8 +2336,6 @@ static void selinux_bprm_committing_creds(struct linux_binprm *bprm) | |||
| 2290 | struct rlimit *rlim, *initrlim; | 2336 | struct rlimit *rlim, *initrlim; |
| 2291 | int rc, i; | 2337 | int rc, i; |
| 2292 | 2338 | ||
| 2293 | secondary_ops->bprm_committing_creds(bprm); | ||
| 2294 | |||
| 2295 | new_tsec = bprm->cred->security; | 2339 | new_tsec = bprm->cred->security; |
| 2296 | if (new_tsec->sid == new_tsec->osid) | 2340 | if (new_tsec->sid == new_tsec->osid) |
| 2297 | return; | 2341 | return; |
| @@ -2337,8 +2381,6 @@ static void selinux_bprm_committed_creds(struct linux_binprm *bprm) | |||
| 2337 | int rc, i; | 2381 | int rc, i; |
| 2338 | unsigned long flags; | 2382 | unsigned long flags; |
| 2339 | 2383 | ||
| 2340 | secondary_ops->bprm_committed_creds(bprm); | ||
| 2341 | |||
| 2342 | osid = tsec->osid; | 2384 | osid = tsec->osid; |
| 2343 | sid = tsec->sid; | 2385 | sid = tsec->sid; |
| 2344 | 2386 | ||
| @@ -2400,7 +2442,8 @@ static inline int selinux_option(char *option, int len) | |||
| 2400 | return (match_prefix(CONTEXT_STR, sizeof(CONTEXT_STR)-1, option, len) || | 2442 | return (match_prefix(CONTEXT_STR, sizeof(CONTEXT_STR)-1, option, len) || |
| 2401 | match_prefix(FSCONTEXT_STR, sizeof(FSCONTEXT_STR)-1, option, len) || | 2443 | match_prefix(FSCONTEXT_STR, sizeof(FSCONTEXT_STR)-1, option, len) || |
| 2402 | match_prefix(DEFCONTEXT_STR, sizeof(DEFCONTEXT_STR)-1, option, len) || | 2444 | match_prefix(DEFCONTEXT_STR, sizeof(DEFCONTEXT_STR)-1, option, len) || |
| 2403 | match_prefix(ROOTCONTEXT_STR, sizeof(ROOTCONTEXT_STR)-1, option, len)); | 2445 | match_prefix(ROOTCONTEXT_STR, sizeof(ROOTCONTEXT_STR)-1, option, len) || |
| 2446 | match_prefix(LABELSUPP_STR, sizeof(LABELSUPP_STR)-1, option, len)); | ||
| 2404 | } | 2447 | } |
| 2405 | 2448 | ||
| 2406 | static inline void take_option(char **to, char *from, int *first, int len) | 2449 | static inline void take_option(char **to, char *from, int *first, int len) |
| @@ -2513,11 +2556,6 @@ static int selinux_mount(char *dev_name, | |||
| 2513 | void *data) | 2556 | void *data) |
| 2514 | { | 2557 | { |
| 2515 | const struct cred *cred = current_cred(); | 2558 | const struct cred *cred = current_cred(); |
| 2516 | int rc; | ||
| 2517 | |||
| 2518 | rc = secondary_ops->sb_mount(dev_name, path, type, flags, data); | ||
| 2519 | if (rc) | ||
| 2520 | return rc; | ||
| 2521 | 2559 | ||
| 2522 | if (flags & MS_REMOUNT) | 2560 | if (flags & MS_REMOUNT) |
| 2523 | return superblock_has_perm(cred, path->mnt->mnt_sb, | 2561 | return superblock_has_perm(cred, path->mnt->mnt_sb, |
| @@ -2530,11 +2568,6 @@ static int selinux_mount(char *dev_name, | |||
| 2530 | static int selinux_umount(struct vfsmount *mnt, int flags) | 2568 | static int selinux_umount(struct vfsmount *mnt, int flags) |
| 2531 | { | 2569 | { |
| 2532 | const struct cred *cred = current_cred(); | 2570 | const struct cred *cred = current_cred(); |
| 2533 | int rc; | ||
| 2534 | |||
| 2535 | rc = secondary_ops->sb_umount(mnt, flags); | ||
| 2536 | if (rc) | ||
| 2537 | return rc; | ||
| 2538 | 2571 | ||
| 2539 | return superblock_has_perm(cred, mnt->mnt_sb, | 2572 | return superblock_has_perm(cred, mnt->mnt_sb, |
| 2540 | FILESYSTEM__UNMOUNT, NULL); | 2573 | FILESYSTEM__UNMOUNT, NULL); |
| @@ -2570,7 +2603,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, | |||
| 2570 | sid = tsec->sid; | 2603 | sid = tsec->sid; |
| 2571 | newsid = tsec->create_sid; | 2604 | newsid = tsec->create_sid; |
| 2572 | 2605 | ||
| 2573 | if (!newsid || sbsec->behavior == SECURITY_FS_USE_MNTPOINT) { | 2606 | if (!newsid || !(sbsec->flags & SE_SBLABELSUPP)) { |
| 2574 | rc = security_transition_sid(sid, dsec->sid, | 2607 | rc = security_transition_sid(sid, dsec->sid, |
| 2575 | inode_mode_to_security_class(inode->i_mode), | 2608 | inode_mode_to_security_class(inode->i_mode), |
| 2576 | &newsid); | 2609 | &newsid); |
| @@ -2585,14 +2618,14 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, | |||
| 2585 | } | 2618 | } |
| 2586 | 2619 | ||
| 2587 | /* Possibly defer initialization to selinux_complete_init. */ | 2620 | /* Possibly defer initialization to selinux_complete_init. */ |
| 2588 | if (sbsec->initialized) { | 2621 | if (sbsec->flags & SE_SBINITIALIZED) { |
| 2589 | struct inode_security_struct *isec = inode->i_security; | 2622 | struct inode_security_struct *isec = inode->i_security; |
| 2590 | isec->sclass = inode_mode_to_security_class(inode->i_mode); | 2623 | isec->sclass = inode_mode_to_security_class(inode->i_mode); |
| 2591 | isec->sid = newsid; | 2624 | isec->sid = newsid; |
| 2592 | isec->initialized = 1; | 2625 | isec->initialized = 1; |
| 2593 | } | 2626 | } |
| 2594 | 2627 | ||
| 2595 | if (!ss_initialized || sbsec->behavior == SECURITY_FS_USE_MNTPOINT) | 2628 | if (!ss_initialized || !(sbsec->flags & SE_SBLABELSUPP)) |
| 2596 | return -EOPNOTSUPP; | 2629 | return -EOPNOTSUPP; |
| 2597 | 2630 | ||
| 2598 | if (name) { | 2631 | if (name) { |
| @@ -2622,21 +2655,11 @@ static int selinux_inode_create(struct inode *dir, struct dentry *dentry, int ma | |||
| 2622 | 2655 | ||
| 2623 | static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) | 2656 | static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) |
| 2624 | { | 2657 | { |
| 2625 | int rc; | ||
| 2626 | |||
| 2627 | rc = secondary_ops->inode_link(old_dentry, dir, new_dentry); | ||
| 2628 | if (rc) | ||
| 2629 | return rc; | ||
| 2630 | return may_link(dir, old_dentry, MAY_LINK); | 2658 | return may_link(dir, old_dentry, MAY_LINK); |
| 2631 | } | 2659 | } |
| 2632 | 2660 | ||
| 2633 | static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry) | 2661 | static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry) |
| 2634 | { | 2662 | { |
| 2635 | int rc; | ||
| 2636 | |||
| 2637 | rc = secondary_ops->inode_unlink(dir, dentry); | ||
| 2638 | if (rc) | ||
| 2639 | return rc; | ||
| 2640 | return may_link(dir, dentry, MAY_UNLINK); | 2663 | return may_link(dir, dentry, MAY_UNLINK); |
| 2641 | } | 2664 | } |
| 2642 | 2665 | ||
| @@ -2657,12 +2680,6 @@ static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry) | |||
| 2657 | 2680 | ||
| 2658 | static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) | 2681 | static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) |
| 2659 | { | 2682 | { |
| 2660 | int rc; | ||
| 2661 | |||
| 2662 | rc = secondary_ops->inode_mknod(dir, dentry, mode, dev); | ||
| 2663 | if (rc) | ||
| 2664 | return rc; | ||
| 2665 | |||
| 2666 | return may_create(dir, dentry, inode_mode_to_security_class(mode)); | 2683 | return may_create(dir, dentry, inode_mode_to_security_class(mode)); |
| 2667 | } | 2684 | } |
| 2668 | 2685 | ||
| @@ -2682,22 +2699,13 @@ static int selinux_inode_readlink(struct dentry *dentry) | |||
| 2682 | static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *nameidata) | 2699 | static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *nameidata) |
| 2683 | { | 2700 | { |
| 2684 | const struct cred *cred = current_cred(); | 2701 | const struct cred *cred = current_cred(); |
| 2685 | int rc; | ||
| 2686 | 2702 | ||
| 2687 | rc = secondary_ops->inode_follow_link(dentry, nameidata); | ||
| 2688 | if (rc) | ||
| 2689 | return rc; | ||
| 2690 | return dentry_has_perm(cred, NULL, dentry, FILE__READ); | 2703 | return dentry_has_perm(cred, NULL, dentry, FILE__READ); |
| 2691 | } | 2704 | } |
| 2692 | 2705 | ||
| 2693 | static int selinux_inode_permission(struct inode *inode, int mask) | 2706 | static int selinux_inode_permission(struct inode *inode, int mask) |
| 2694 | { | 2707 | { |
| 2695 | const struct cred *cred = current_cred(); | 2708 | const struct cred *cred = current_cred(); |
| 2696 | int rc; | ||
| 2697 | |||
| 2698 | rc = secondary_ops->inode_permission(inode, mask); | ||
| 2699 | if (rc) | ||
| 2700 | return rc; | ||
| 2701 | 2709 | ||
| 2702 | if (!mask) { | 2710 | if (!mask) { |
| 2703 | /* No permission to check. Existence test. */ | 2711 | /* No permission to check. Existence test. */ |
| @@ -2711,11 +2719,6 @@ static int selinux_inode_permission(struct inode *inode, int mask) | |||
| 2711 | static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) | 2719 | static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) |
| 2712 | { | 2720 | { |
| 2713 | const struct cred *cred = current_cred(); | 2721 | const struct cred *cred = current_cred(); |
| 2714 | int rc; | ||
| 2715 | |||
| 2716 | rc = secondary_ops->inode_setattr(dentry, iattr); | ||
| 2717 | if (rc) | ||
| 2718 | return rc; | ||
| 2719 | 2722 | ||
| 2720 | if (iattr->ia_valid & ATTR_FORCE) | 2723 | if (iattr->ia_valid & ATTR_FORCE) |
| 2721 | return 0; | 2724 | return 0; |
| @@ -2769,7 +2772,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, | |||
| 2769 | return selinux_inode_setotherxattr(dentry, name); | 2772 | return selinux_inode_setotherxattr(dentry, name); |
| 2770 | 2773 | ||
| 2771 | sbsec = inode->i_sb->s_security; | 2774 | sbsec = inode->i_sb->s_security; |
| 2772 | if (sbsec->behavior == SECURITY_FS_USE_MNTPOINT) | 2775 | if (!(sbsec->flags & SE_SBLABELSUPP)) |
| 2773 | return -EOPNOTSUPP; | 2776 | return -EOPNOTSUPP; |
| 2774 | 2777 | ||
| 2775 | if (!is_owner_or_cap(inode)) | 2778 | if (!is_owner_or_cap(inode)) |
| @@ -2931,16 +2934,6 @@ static int selinux_inode_listsecurity(struct inode *inode, char *buffer, size_t | |||
| 2931 | return len; | 2934 | return len; |
| 2932 | } | 2935 | } |
| 2933 | 2936 | ||
| 2934 | static int selinux_inode_need_killpriv(struct dentry *dentry) | ||
| 2935 | { | ||
| 2936 | return secondary_ops->inode_need_killpriv(dentry); | ||
| 2937 | } | ||
| 2938 | |||
| 2939 | static int selinux_inode_killpriv(struct dentry *dentry) | ||
| 2940 | { | ||
| 2941 | return secondary_ops->inode_killpriv(dentry); | ||
| 2942 | } | ||
| 2943 | |||
| 2944 | static void selinux_inode_getsecid(const struct inode *inode, u32 *secid) | 2937 | static void selinux_inode_getsecid(const struct inode *inode, u32 *secid) |
| 2945 | { | 2938 | { |
| 2946 | struct inode_security_struct *isec = inode->i_security; | 2939 | struct inode_security_struct *isec = inode->i_security; |
| @@ -3078,18 +3071,13 @@ static int selinux_file_mprotect(struct vm_area_struct *vma, | |||
| 3078 | unsigned long prot) | 3071 | unsigned long prot) |
| 3079 | { | 3072 | { |
| 3080 | const struct cred *cred = current_cred(); | 3073 | const struct cred *cred = current_cred(); |
| 3081 | int rc; | ||
| 3082 | |||
| 3083 | rc = secondary_ops->file_mprotect(vma, reqprot, prot); | ||
| 3084 | if (rc) | ||
| 3085 | return rc; | ||
| 3086 | 3074 | ||
| 3087 | if (selinux_checkreqprot) | 3075 | if (selinux_checkreqprot) |
| 3088 | prot = reqprot; | 3076 | prot = reqprot; |
| 3089 | 3077 | ||
| 3090 | #ifndef CONFIG_PPC32 | 3078 | #ifndef CONFIG_PPC32 |
| 3091 | if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { | 3079 | if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { |
| 3092 | rc = 0; | 3080 | int rc = 0; |
| 3093 | if (vma->vm_start >= vma->vm_mm->start_brk && | 3081 | if (vma->vm_start >= vma->vm_mm->start_brk && |
| 3094 | vma->vm_end <= vma->vm_mm->brk) { | 3082 | vma->vm_end <= vma->vm_mm->brk) { |
| 3095 | rc = cred_has_perm(cred, cred, PROCESS__EXECHEAP); | 3083 | rc = cred_has_perm(cred, cred, PROCESS__EXECHEAP); |
| @@ -3239,12 +3227,6 @@ static int selinux_dentry_open(struct file *file, const struct cred *cred) | |||
| 3239 | 3227 | ||
| 3240 | static int selinux_task_create(unsigned long clone_flags) | 3228 | static int selinux_task_create(unsigned long clone_flags) |
| 3241 | { | 3229 | { |
| 3242 | int rc; | ||
| 3243 | |||
| 3244 | rc = secondary_ops->task_create(clone_flags); | ||
| 3245 | if (rc) | ||
| 3246 | return rc; | ||
| 3247 | |||
| 3248 | return current_has_perm(current, PROCESS__FORK); | 3230 | return current_has_perm(current, PROCESS__FORK); |
| 3249 | } | 3231 | } |
| 3250 | 3232 | ||
| @@ -3278,14 +3260,6 @@ static int selinux_cred_prepare(struct cred *new, const struct cred *old, | |||
| 3278 | } | 3260 | } |
| 3279 | 3261 | ||
| 3280 | /* | 3262 | /* |
| 3281 | * commit new credentials | ||
| 3282 | */ | ||
| 3283 | static void selinux_cred_commit(struct cred *new, const struct cred *old) | ||
| 3284 | { | ||
| 3285 | secondary_ops->cred_commit(new, old); | ||
| 3286 | } | ||
| 3287 | |||
| 3288 | /* | ||
| 3289 | * set the security data for a kernel service | 3263 | * set the security data for a kernel service |
| 3290 | * - all the creation contexts are set to unlabelled | 3264 | * - all the creation contexts are set to unlabelled |
| 3291 | */ | 3265 | */ |
| @@ -3329,29 +3303,6 @@ static int selinux_kernel_create_files_as(struct cred *new, struct inode *inode) | |||
| 3329 | return 0; | 3303 | return 0; |
| 3330 | } | 3304 | } |
| 3331 | 3305 | ||
| 3332 | static int selinux_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags) | ||
| 3333 | { | ||
| 3334 | /* Since setuid only affects the current process, and | ||
| 3335 | since the SELinux controls are not based on the Linux | ||
| 3336 | identity attributes, SELinux does not need to control | ||
| 3337 | this operation. However, SELinux does control the use | ||
| 3338 | of the CAP_SETUID and CAP_SETGID capabilities using the | ||
| 3339 | capable hook. */ | ||
| 3340 | return 0; | ||
| 3341 | } | ||
| 3342 | |||
| 3343 | static int selinux_task_fix_setuid(struct cred *new, const struct cred *old, | ||
| 3344 | int flags) | ||
| 3345 | { | ||
| 3346 | return secondary_ops->task_fix_setuid(new, old, flags); | ||
| 3347 | } | ||
| 3348 | |||
| 3349 | static int selinux_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags) | ||
| 3350 | { | ||
| 3351 | /* See the comment for setuid above. */ | ||
| 3352 | return 0; | ||
| 3353 | } | ||
| 3354 | |||
| 3355 | static int selinux_task_setpgid(struct task_struct *p, pid_t pgid) | 3306 | static int selinux_task_setpgid(struct task_struct *p, pid_t pgid) |
| 3356 | { | 3307 | { |
| 3357 | return current_has_perm(p, PROCESS__SETPGID); | 3308 | return current_has_perm(p, PROCESS__SETPGID); |
| @@ -3372,17 +3323,11 @@ static void selinux_task_getsecid(struct task_struct *p, u32 *secid) | |||
| 3372 | *secid = task_sid(p); | 3323 | *secid = task_sid(p); |
| 3373 | } | 3324 | } |
| 3374 | 3325 | ||
| 3375 | static int selinux_task_setgroups(struct group_info *group_info) | ||
| 3376 | { | ||
| 3377 | /* See the comment for setuid above. */ | ||
| 3378 | return 0; | ||
| 3379 | } | ||
| 3380 | |||
| 3381 | static int selinux_task_setnice(struct task_struct *p, int nice) | 3326 | static int selinux_task_setnice(struct task_struct *p, int nice) |
| 3382 | { | 3327 | { |
| 3383 | int rc; | 3328 | int rc; |
| 3384 | 3329 | ||
| 3385 | rc = secondary_ops->task_setnice(p, nice); | 3330 | rc = cap_task_setnice(p, nice); |
| 3386 | if (rc) | 3331 | if (rc) |
| 3387 | return rc; | 3332 | return rc; |
| 3388 | 3333 | ||
| @@ -3393,7 +3338,7 @@ static int selinux_task_setioprio(struct task_struct *p, int ioprio) | |||
| 3393 | { | 3338 | { |
| 3394 | int rc; | 3339 | int rc; |
| 3395 | 3340 | ||
| 3396 | rc = secondary_ops->task_setioprio(p, ioprio); | 3341 | rc = cap_task_setioprio(p, ioprio); |
| 3397 | if (rc) | 3342 | if (rc) |
| 3398 | return rc; | 3343 | return rc; |
| 3399 | 3344 | ||
| @@ -3408,11 +3353,6 @@ static int selinux_task_getioprio(struct task_struct *p) | |||
| 3408 | static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim) | 3353 | static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim) |
| 3409 | { | 3354 | { |
| 3410 | struct rlimit *old_rlim = current->signal->rlim + resource; | 3355 | struct rlimit *old_rlim = current->signal->rlim + resource; |
| 3411 | int rc; | ||
| 3412 | |||
| 3413 | rc = secondary_ops->task_setrlimit(resource, new_rlim); | ||
| 3414 | if (rc) | ||
| 3415 | return rc; | ||
| 3416 | 3356 | ||
| 3417 | /* Control the ability to change the hard limit (whether | 3357 | /* Control the ability to change the hard limit (whether |
| 3418 | lowering or raising it), so that the hard limit can | 3358 | lowering or raising it), so that the hard limit can |
| @@ -3428,7 +3368,7 @@ static int selinux_task_setscheduler(struct task_struct *p, int policy, struct s | |||
| 3428 | { | 3368 | { |
| 3429 | int rc; | 3369 | int rc; |
| 3430 | 3370 | ||
| 3431 | rc = secondary_ops->task_setscheduler(p, policy, lp); | 3371 | rc = cap_task_setscheduler(p, policy, lp); |
| 3432 | if (rc) | 3372 | if (rc) |
| 3433 | return rc; | 3373 | return rc; |
| 3434 | 3374 | ||
| @@ -3451,10 +3391,6 @@ static int selinux_task_kill(struct task_struct *p, struct siginfo *info, | |||
| 3451 | u32 perm; | 3391 | u32 perm; |
| 3452 | int rc; | 3392 | int rc; |
| 3453 | 3393 | ||
| 3454 | rc = secondary_ops->task_kill(p, info, sig, secid); | ||
| 3455 | if (rc) | ||
| 3456 | return rc; | ||
| 3457 | |||
| 3458 | if (!sig) | 3394 | if (!sig) |
| 3459 | perm = PROCESS__SIGNULL; /* null signal; existence test */ | 3395 | perm = PROCESS__SIGNULL; /* null signal; existence test */ |
| 3460 | else | 3396 | else |
| @@ -3467,18 +3403,6 @@ static int selinux_task_kill(struct task_struct *p, struct siginfo *info, | |||
| 3467 | return rc; | 3403 | return rc; |
| 3468 | } | 3404 | } |
| 3469 | 3405 | ||
| 3470 | static int selinux_task_prctl(int option, | ||
| 3471 | unsigned long arg2, | ||
| 3472 | unsigned long arg3, | ||
| 3473 | unsigned long arg4, | ||
| 3474 | unsigned long arg5) | ||
| 3475 | { | ||
| 3476 | /* The current prctl operations do not appear to require | ||
| 3477 | any SELinux controls since they merely observe or modify | ||
| 3478 | the state of the current process. */ | ||
| 3479 | return secondary_ops->task_prctl(option, arg2, arg3, arg4, arg5); | ||
| 3480 | } | ||
| 3481 | |||
| 3482 | static int selinux_task_wait(struct task_struct *p) | 3406 | static int selinux_task_wait(struct task_struct *p) |
| 3483 | { | 3407 | { |
| 3484 | return task_has_perm(p, current, PROCESS__SIGCHLD); | 3408 | return task_has_perm(p, current, PROCESS__SIGCHLD); |
| @@ -4047,10 +3971,6 @@ static int selinux_socket_unix_stream_connect(struct socket *sock, | |||
| 4047 | struct avc_audit_data ad; | 3971 | struct avc_audit_data ad; |
| 4048 | int err; | 3972 | int err; |
| 4049 | 3973 | ||
| 4050 | err = secondary_ops->unix_stream_connect(sock, other, newsk); | ||
| 4051 | if (err) | ||
| 4052 | return err; | ||
| 4053 | |||
| 4054 | isec = SOCK_INODE(sock)->i_security; | 3974 | isec = SOCK_INODE(sock)->i_security; |
| 4055 | other_isec = SOCK_INODE(other)->i_security; | 3975 | other_isec = SOCK_INODE(other)->i_security; |
| 4056 | 3976 | ||
| @@ -4844,7 +4764,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) | |||
| 4844 | { | 4764 | { |
| 4845 | int err; | 4765 | int err; |
| 4846 | 4766 | ||
| 4847 | err = secondary_ops->netlink_send(sk, skb); | 4767 | err = cap_netlink_send(sk, skb); |
| 4848 | if (err) | 4768 | if (err) |
| 4849 | return err; | 4769 | return err; |
| 4850 | 4770 | ||
| @@ -4859,7 +4779,7 @@ static int selinux_netlink_recv(struct sk_buff *skb, int capability) | |||
| 4859 | int err; | 4779 | int err; |
| 4860 | struct avc_audit_data ad; | 4780 | struct avc_audit_data ad; |
| 4861 | 4781 | ||
| 4862 | err = secondary_ops->netlink_recv(skb, capability); | 4782 | err = cap_netlink_recv(skb, capability); |
| 4863 | if (err) | 4783 | if (err) |
| 4864 | return err; | 4784 | return err; |
| 4865 | 4785 | ||
| @@ -5167,11 +5087,6 @@ static int selinux_shm_shmat(struct shmid_kernel *shp, | |||
| 5167 | char __user *shmaddr, int shmflg) | 5087 | char __user *shmaddr, int shmflg) |
| 5168 | { | 5088 | { |
| 5169 | u32 perms; | 5089 | u32 perms; |
| 5170 | int rc; | ||
| 5171 | |||
| 5172 | rc = secondary_ops->shm_shmat(shp, shmaddr, shmflg); | ||
| 5173 | if (rc) | ||
| 5174 | return rc; | ||
| 5175 | 5090 | ||
| 5176 | if (shmflg & SHM_RDONLY) | 5091 | if (shmflg & SHM_RDONLY) |
| 5177 | perms = SHM__READ; | 5092 | perms = SHM__READ; |
| @@ -5581,7 +5496,6 @@ static struct security_operations selinux_ops = { | |||
| 5581 | .netlink_recv = selinux_netlink_recv, | 5496 | .netlink_recv = selinux_netlink_recv, |
| 5582 | 5497 | ||
| 5583 | .bprm_set_creds = selinux_bprm_set_creds, | 5498 | .bprm_set_creds = selinux_bprm_set_creds, |
| 5584 | .bprm_check_security = selinux_bprm_check_security, | ||
| 5585 | .bprm_committing_creds = selinux_bprm_committing_creds, | 5499 | .bprm_committing_creds = selinux_bprm_committing_creds, |
| 5586 | .bprm_committed_creds = selinux_bprm_committed_creds, | 5500 | .bprm_committed_creds = selinux_bprm_committed_creds, |
| 5587 | .bprm_secureexec = selinux_bprm_secureexec, | 5501 | .bprm_secureexec = selinux_bprm_secureexec, |
| @@ -5623,8 +5537,6 @@ static struct security_operations selinux_ops = { | |||
| 5623 | .inode_getsecurity = selinux_inode_getsecurity, | 5537 | .inode_getsecurity = selinux_inode_getsecurity, |
| 5624 | .inode_setsecurity = selinux_inode_setsecurity, | 5538 | .inode_setsecurity = selinux_inode_setsecurity, |
| 5625 | .inode_listsecurity = selinux_inode_listsecurity, | 5539 | .inode_listsecurity = selinux_inode_listsecurity, |
| 5626 | .inode_need_killpriv = selinux_inode_need_killpriv, | ||
| 5627 | .inode_killpriv = selinux_inode_killpriv, | ||
| 5628 | .inode_getsecid = selinux_inode_getsecid, | 5540 | .inode_getsecid = selinux_inode_getsecid, |
| 5629 | 5541 | ||
| 5630 | .file_permission = selinux_file_permission, | 5542 | .file_permission = selinux_file_permission, |
| @@ -5644,17 +5556,12 @@ static struct security_operations selinux_ops = { | |||
| 5644 | .task_create = selinux_task_create, | 5556 | .task_create = selinux_task_create, |
| 5645 | .cred_free = selinux_cred_free, | 5557 | .cred_free = selinux_cred_free, |
| 5646 | .cred_prepare = selinux_cred_prepare, | 5558 | .cred_prepare = selinux_cred_prepare, |
| 5647 | .cred_commit = selinux_cred_commit, | ||
| 5648 | .kernel_act_as = selinux_kernel_act_as, | 5559 | .kernel_act_as = selinux_kernel_act_as, |
| 5649 | .kernel_create_files_as = selinux_kernel_create_files_as, | 5560 | .kernel_create_files_as = selinux_kernel_create_files_as, |
| 5650 | .task_setuid = selinux_task_setuid, | ||
| 5651 | .task_fix_setuid = selinux_task_fix_setuid, | ||
| 5652 | .task_setgid = selinux_task_setgid, | ||
| 5653 | .task_setpgid = selinux_task_setpgid, | 5561 | .task_setpgid = selinux_task_setpgid, |
| 5654 | .task_getpgid = selinux_task_getpgid, | 5562 | .task_getpgid = selinux_task_getpgid, |
| 5655 | .task_getsid = selinux_task_getsid, | 5563 | .task_getsid = selinux_task_getsid, |
| 5656 | .task_getsecid = selinux_task_getsecid, | 5564 | .task_getsecid = selinux_task_getsecid, |
| 5657 | .task_setgroups = selinux_task_setgroups, | ||
| 5658 | .task_setnice = selinux_task_setnice, | 5565 | .task_setnice = selinux_task_setnice, |
| 5659 | .task_setioprio = selinux_task_setioprio, | 5566 | .task_setioprio = selinux_task_setioprio, |
| 5660 | .task_getioprio = selinux_task_getioprio, | 5567 | .task_getioprio = selinux_task_getioprio, |
| @@ -5664,7 +5571,6 @@ static struct security_operations selinux_ops = { | |||
| 5664 | .task_movememory = selinux_task_movememory, | 5571 | .task_movememory = selinux_task_movememory, |
| 5665 | .task_kill = selinux_task_kill, | 5572 | .task_kill = selinux_task_kill, |
| 5666 | .task_wait = selinux_task_wait, | 5573 | .task_wait = selinux_task_wait, |
| 5667 | .task_prctl = selinux_task_prctl, | ||
| 5668 | .task_to_inode = selinux_task_to_inode, | 5574 | .task_to_inode = selinux_task_to_inode, |
| 5669 | 5575 | ||
| 5670 | .ipc_permission = selinux_ipc_permission, | 5576 | .ipc_permission = selinux_ipc_permission, |
