Skip to contentSkip to conversation

selinux: reject invalid ebitmaps

PATCH Superseded Christian Göttsche 3 participants 3 messages Aug 18, 2023 – Sep 12, 2023 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: reject invalid ebitmaps

Reject ebitmaps with a node containing an empty map or with an incorrect highbit. Both checks are already performed by userspace, the former since 2008 (patch 13cd4c896068 ("initial import from svn trunk revision 2950")), the latter since v2.7 in 2017 (patch 75b14a5de10a ("libsepol:
ebitmap: reject loading bitmaps with incorrect high bit")).

---
 security/selinux/ss/ebitmap.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
security/selinux/ss/ebitmap.c +11 -0
index 77875ad355f7..ac9da819531d 100644
@@ -450,6 +450,10 @@ int ebitmap_read(struct ebitmap *e, void *fp)
 			goto bad;
 		}
 		map = le64_to_cpu(mapbits);
+		if (!map) {
+			pr_err("SELinux: ebitmap: empty map\n");
+			goto bad;
+		}
 
 		index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE;
 		while (map) {
@@ -457,6 +461,13 @@ int ebitmap_read(struct ebitmap *e, void *fp)
 			map = EBITMAP_SHIFT_UNIT_SIZE(map);
 		}
 	}
+
+	if (n && n->startbit + EBITMAP_SIZE != e->highbit) {
+		pr_err("SELinux: ebitmap: high bit %d has not the expected value %ld\n",
+		       e->highbit, n->startbit + EBITMAP_SIZE);
+		goto bad;
+	}
+
 ok:
 	rc = 0;
 out:
Signature · 1 line
2.40.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Christian Göttsche

Reject ebitmaps with a node containing an empty map or with an incorrect highbit. Both checks are already performed by userspace, the former since 2008 (patch 13cd4c896068 ("initial import from svn trunk revision 2950")), the latter since v2.7 in 2017 (patch 75b14a5de10a ("libsepol:
ebitmap: reject loading bitmaps with incorrect high bit")).

maintainer
#2 lore raw
In reply to Christian Göttsche
Quoted 17 lines · On Aug 18, 2023 Stephen Smalley <[email protected]> wrote:

Reject ebitmaps with a node containing an empty map or with an incorrect highbit. Both checks are already performed by userspace, the former since 2008 (patch 13cd4c896068 ("initial import from svn trunk revision 2950")), the latter since v2.7 in 2017 (patch 75b14a5de10a ("libsepol:
ebitmap: reject loading bitmaps with incorrect high bit")).

---
 security/selinux/ss/ebitmap.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
security/selinux/ss/ebitmap.c +0 -0
index 77875ad355f7..ac9da819531d 100644

...

security/selinux/ss/ebitmap.c int ebitmap_read(struct ebitmap *e, void *fp) · line 466

Quoted 7 lines
security/selinux/ss/ebitmap.c +3 -0
@@ -457,6 +461,13 @@ int ebitmap_read(struct ebitmap *e, void *fp)
 			map = EBITMAP_SHIFT_UNIT_SIZE(map);
 		}
 	}
+
+	if (n && n->startbit + EBITMAP_SIZE != e->highbit) {
+		pr_err("SELinux: ebitmap: high bit %d has not the expected value %ld\n",

That reads a little awkward in English, how about "high bit %d is not equal to the expected value %ld\n"?

Quoted 9 lines
security/selinux/ss/ebitmap.c +4 -0
+		       e->highbit, n->startbit + EBITMAP_SIZE);
+		goto bad;
+	}
+
 ok:
 	rc = 0;
 out:
Signature · 1 line
2.40.1

--
paul-moore.com