Skip to contentSkip to conversation

selinux: fix overflow and 0 length allocations

PATCH In review [email protected] 2 participants 2 messages Aug 30, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux: fix overflow and 0 length allocations

From: William Roberts <[email protected]>

Throughout the SE Linux LSM, values taken from sepolicy are used in places where length == 0 or length == <saturated> matter, find and fix these.

---
 security/selinux/ss/conditional.c | 2 ++
 security/selinux/ss/policydb.c    | 3 +++
 2 files changed, 5 insertions(+)
security/selinux/ss/conditional.c +2 -0
index 456e1a9..34afead 100644
@@ -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);
security/selinux/ss/policydb.c +3 -0
index 4b24385..8c661f0 100644
@@ -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;
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 11 lines · On Tue, Aug 30, 2016 at 12:28 PM, <[email protected]> wrote:

From: William Roberts <[email protected]>

Throughout the SE Linux LSM, values taken from sepolicy are used in places where length == 0 or length == <saturated> matter, find and fix these.

---
 security/selinux/ss/conditional.c | 2 ++
 security/selinux/ss/policydb.c    | 3 +++
 2 files changed, 5 insertions(+)

Merged after I fixed the "SELinux" bit in the patch description.

Quoted 29 lines
security/selinux/ss/conditional.c +2 -0
index 456e1a9..34afead 100644
@@ -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);
security/selinux/ss/policydb.c +3 -1
index 4b24385..8c661f0 100644
@@ -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;
--

1.9.1

Signature · 2 lines
paul moore
www.paul-moore.com