aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-12 16:21:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-12 16:21:00 -0400
commit7f85565a3f7194b966de71926471d69788b6b9c3 (patch)
tree95f93ab1d18dc1121cd5ec71309c7e6cb4dedc7b /security/selinux/hooks.c
parent680352bda57e3dbf21cddf6a5e23aff7e294fb31 (diff)
parent0c3014f22dec0e1d14c8298551bfb6434638bdd9 (diff)
Merge tag 'selinux-pr-20170831' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: "A relatively quiet period for SELinux, 11 patches with only two/three having any substantive changes. These noteworthy changes include another tweak to the NNP/nosuid handling, per-file labeling for cgroups, and an object class fix for AF_UNIX/SOCK_RAW sockets; the rest of the changes are minor tweaks or administrative updates (Stephen's email update explains the file explosion in the diffstat). Everything passes the selinux-testsuite" [ Also a couple of small patches from the security tree from Tetsuo Handa for Tomoyo and LSM cleanup. The separation of security policy updates wasn't all that clean - Linus ] * tag 'selinux-pr-20170831' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: constify nf_hook_ops selinux: allow per-file labeling for cgroupfs lsm_audit: update my email address selinux: update my email address MAINTAINERS: update the NetLabel and Labeled Networking information selinux: use GFP_NOWAIT in the AVC kmem_caches selinux: Generalize support for NNP/nosuid SELinux domain transitions selinux: genheaders should fail if too many permissions are defined selinux: update the selinux info in MAINTAINERS credits: update Paul Moore's info selinux: Assign proper class to PF_UNIX/SOCK_RAW sockets tomoyo: Update URLs in Documentation/admin-guide/LSM/tomoyo.rst LSM: Remove security_task_create() hook.
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index ad3b0f53ede0..f5d304736852 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * This file contains the SELinux hook function implementations. 4 * This file contains the SELinux hook function implementations.
5 * 5 *
6 * Authors: Stephen Smalley, <sds@epoch.ncsc.mil> 6 * Authors: Stephen Smalley, <sds@tycho.nsa.gov>
7 * Chris Vance, <cvance@nai.com> 7 * Chris Vance, <cvance@nai.com>
8 * Wayne Salamon, <wsalamon@nai.com> 8 * Wayne Salamon, <wsalamon@nai.com>
9 * James Morris <jmorris@redhat.com> 9 * James Morris <jmorris@redhat.com>
@@ -815,7 +815,9 @@ static int selinux_set_mnt_opts(struct super_block *sb,
815 if (!strcmp(sb->s_type->name, "debugfs") || 815 if (!strcmp(sb->s_type->name, "debugfs") ||
816 !strcmp(sb->s_type->name, "tracefs") || 816 !strcmp(sb->s_type->name, "tracefs") ||
817 !strcmp(sb->s_type->name, "sysfs") || 817 !strcmp(sb->s_type->name, "sysfs") ||
818 !strcmp(sb->s_type->name, "pstore")) 818 !strcmp(sb->s_type->name, "pstore") ||
819 !strcmp(sb->s_type->name, "cgroup") ||
820 !strcmp(sb->s_type->name, "cgroup2"))
819 sbsec->flags |= SE_SBGENFS; 821 sbsec->flags |= SE_SBGENFS;
820 822
821 if (!sbsec->behavior) { 823 if (!sbsec->behavior) {
@@ -1303,6 +1305,7 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc
1303 case SOCK_SEQPACKET: 1305 case SOCK_SEQPACKET:
1304 return SECCLASS_UNIX_STREAM_SOCKET; 1306 return SECCLASS_UNIX_STREAM_SOCKET;
1305 case SOCK_DGRAM: 1307 case SOCK_DGRAM:
1308 case SOCK_RAW:
1306 return SECCLASS_UNIX_DGRAM_SOCKET; 1309 return SECCLASS_UNIX_DGRAM_SOCKET;
1307 } 1310 }
1308 break; 1311 break;
@@ -2317,6 +2320,7 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm,
2317 int nnp = (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS); 2320 int nnp = (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS);
2318 int nosuid = !mnt_may_suid(bprm->file->f_path.mnt); 2321 int nosuid = !mnt_may_suid(bprm->file->f_path.mnt);
2319 int rc; 2322 int rc;
2323 u32 av;
2320 2324
2321 if (!nnp && !nosuid) 2325 if (!nnp && !nosuid)
2322 return 0; /* neither NNP nor nosuid */ 2326 return 0; /* neither NNP nor nosuid */
@@ -2325,24 +2329,40 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm,
2325 return 0; /* No change in credentials */ 2329 return 0; /* No change in credentials */
2326 2330
2327 /* 2331 /*
2328 * The only transitions we permit under NNP or nosuid 2332 * If the policy enables the nnp_nosuid_transition policy capability,
2329 * are transitions to bounded SIDs, i.e. SIDs that are 2333 * then we permit transitions under NNP or nosuid if the
2330 * guaranteed to only be allowed a subset of the permissions 2334 * policy allows the corresponding permission between
2331 * of the current SID. 2335 * the old and new contexts.
2332 */ 2336 */
2333 rc = security_bounded_transition(old_tsec->sid, new_tsec->sid); 2337 if (selinux_policycap_nnp_nosuid_transition) {
2334 if (rc) { 2338 av = 0;
2335 /*
2336 * On failure, preserve the errno values for NNP vs nosuid.
2337 * NNP: Operation not permitted for caller.
2338 * nosuid: Permission denied to file.
2339 */
2340 if (nnp) 2339 if (nnp)
2341 return -EPERM; 2340 av |= PROCESS2__NNP_TRANSITION;
2342 else 2341 if (nosuid)
2343 return -EACCES; 2342 av |= PROCESS2__NOSUID_TRANSITION;
2343 rc = avc_has_perm(old_tsec->sid, new_tsec->sid,
2344 SECCLASS_PROCESS2, av, NULL);
2345 if (!rc)
2346 return 0;
2344 } 2347 }
2345 return 0; 2348
2349 /*
2350 * We also permit NNP or nosuid transitions to bounded SIDs,
2351 * i.e. SIDs that are guaranteed to only be allowed a subset
2352 * of the permissions of the current SID.
2353 */
2354 rc = security_bounded_transition(old_tsec->sid, new_tsec->sid);
2355 if (!rc)
2356 return 0;
2357
2358 /*
2359 * On failure, preserve the errno values for NNP vs nosuid.
2360 * NNP: Operation not permitted for caller.
2361 * nosuid: Permission denied to file.
2362 */
2363 if (nnp)
2364 return -EPERM;
2365 return -EACCES;
2346} 2366}
2347 2367
2348static int selinux_bprm_set_creds(struct linux_binprm *bprm) 2368static int selinux_bprm_set_creds(struct linux_binprm *bprm)