selinux: fix overflow and 0 length allocations
authorWilliam Roberts <william.c.roberts@intel.com>
Tue, 30 Aug 2016 16:28:11 +0000 (09:28 -0700)
committerPaul Moore <paul@paul-moore.com>
Tue, 30 Aug 2016 19:45:50 +0000 (15:45 -0400)
Throughout the SELinux LSM, values taken from sepolicy are
used in places where length == 0 or length == <saturated>
matter, find and fix these.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/conditional.c
security/selinux/ss/policydb.c

index 456e1a9..34afead 100644 (file)
@@ -242,6 +242,8 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
                goto err;
 
        len = le32_to_cpu(buf[2]);
+       if (((len == 0) || (len == (u32)-1)))
+               goto err;
 
        rc = -ENOMEM;
        key = kmalloc(len + 1, GFP_KERNEL);
index 4b24385..8c661f0 100644 (file)
@@ -1094,6 +1094,9 @@ static int str_read(char **strp, gfp_t flags, void *fp, u32 len)
        int rc;
        char *str;
 
+       if ((len == 0) || (len == (u32)-1))
+               return -EINVAL;
+
        str = kmalloc(len + 1, flags);
        if (!str)
                return -ENOMEM;