Skip to content

Commit 0142c56

Browse files
cgzonespcmoore
authored andcommitted
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")). Signed-off-by: Christian Göttsche <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 4cece76 commit 0142c56

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

security/selinux/ss/ebitmap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,24 @@ int ebitmap_read(struct ebitmap *e, void *fp)
448448
goto bad;
449449
}
450450
map = le64_to_cpu(mapbits);
451+
if (!map) {
452+
pr_err("SELinux: ebitmap: empty map\n");
453+
goto bad;
454+
}
451455

452456
index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE;
453457
while (map) {
454458
n->maps[index++] = map & (-1UL);
455459
map = EBITMAP_SHIFT_UNIT_SIZE(map);
456460
}
457461
}
462+
463+
if (n && n->startbit + EBITMAP_SIZE != e->highbit) {
464+
pr_err("SELinux: ebitmap: high bit %d is not equal to the expected value %ld\n",
465+
e->highbit, n->startbit + EBITMAP_SIZE);
466+
goto bad;
467+
}
468+
458469
ok:
459470
rc = 0;
460471
out:

0 commit comments

Comments
 (0)