]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
selinux: fix kernel BUG on prlimit(..., NULL, NULL)
authorStephen Smalley <sds@tycho.nsa.gov>
Tue, 28 Feb 2017 14:35:08 +0000 (09:35 -0500)
committerJames Morris <james.l.morris@oracle.com>
Sun, 5 Mar 2017 23:44:16 +0000 (10:44 +1100)
commit 79bcf325e6b32b3c ("prlimit,security,selinux: add a security hook
for prlimit") introduced a security hook for prlimit() and implemented it
for SELinux.  However, if prlimit() is called with NULL arguments for both
the new limit and the old limit, then the hook is called with 0 for the
read/write flags, since the prlimit() will neither read nor write the
process' limits.  This would in turn lead to calling avc_has_perm() with 0
for the requested permissions, which triggers a BUG_ON() in
avc_has_perm_noaudit() since the kernel should never be invoking
avc_has_perm() with no permissions.  Fix this in the SELinux hook by
returning immediately if the flags are 0.  Arguably prlimit64() itself
ought to return immediately if both old_rlim and new_rlim are NULL since
it is effectively a no-op in that case.

Reported by the lkp-robot based on trinity testing.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
security/selinux/hooks.c

index 870d24ecc2decf043e08dd8060aae0dbe0f16f91..3ba5ce1f4e05a2e59a1d9c283ac6d6f648b2d77e 100644 (file)
@@ -3925,6 +3925,8 @@ int selinux_task_prlimit(const struct cred *cred, const struct cred *tcred,
 {
        u32 av = 0;
 
+       if (!flags)
+               return 0;
        if (flags & LSM_PRLIMIT_WRITE)
                av |= PROCESS__SETRLIMIT;
        if (flags & LSM_PRLIMIT_READ)