diff options
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 54 |
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 | ||
2348 | static int selinux_bprm_set_creds(struct linux_binprm *bprm) | 2368 | static int selinux_bprm_set_creds(struct linux_binprm *bprm) |