Skip to contentSkip to conversation

libsepol: Check for embedded NUL when reading from policy file

PATCH In review James Carter 2 participants 3 messages Jul 22 – Jul 24 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Check for embedded NUL when reading from policy file

Check that data read from a policy file does not have an embedded NUL to protect against maliciously crafted polcies.

---
 libsepol/src/services.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/src/services.c +6 -0
index e8f0e622..3e8bd38b 100644
@@ -1799,6 +1799,12 @@ int str_read(char **strp, struct policy_file *fp, size_t len)
 	if (rc)
 		return rc;
 
+	/* Check for an embedded NUL character */
+	if (memchr(str, '\0', len)) {
+		errno = EINVAL;
+		return -1;
+	}
+
 	str[len] = '\0';
 	return 0;
 }
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · James Carter

Check that data read from a policy file does not have an embedded NUL to protect against maliciously crafted polcies.

policies

Quoted 2 lines

Otherwise,

Quoted 24 lines
---
 libsepol/src/services.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/src/services.c +6 -1
index e8f0e622..3e8bd38b 100644
@@ -1799,6 +1799,12 @@ int str_read(char **strp, struct policy_file *fp, size_t len)
        if (rc)
                return rc;
 
+       /* Check for an embedded NUL character */
+       if (memchr(str, '\0', len)) {
+               errno = EINVAL;
+               return -1;
+       }
+
        str[len] = '\0';
        return 0;
 }
--

2.55.0

maintainer
#2 lore raw
Quoted 6 lines · Stephen Smalley
Quoted 3 lines · James Carter

Check that data read from a policy file does not have an embedded NUL to protect against maliciously crafted polcies.

Quoted 7 lines

policies

Quoted 2 lines

Otherwise,

Merged.

Quoted 25 lines
Quoted 25 lines
---
 libsepol/src/services.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/src/services.c +6 -1
index e8f0e622..3e8bd38b 100644
@@ -1799,6 +1799,12 @@ int str_read(char **strp, struct policy_file *fp, size_t len)
        if (rc)
                return rc;
 
+       /* Check for an embedded NUL character */
+       if (memchr(str, '\0', len)) {
+               errno = EINVAL;
+               return -1;
+       }
+
        str[len] = '\0';
        return 0;
 }
--

2.55.0