selinux: require a class's permission values to cover its permission count
authorBryam Vargas <hexlabsecurity@proton.me>
Fri, 31 Jul 2026 17:44:10 +0000 (12:44 -0500)
committerPaul Moore <paul@paul-moore.com>
Mon, 3 Aug 2026 20:03:56 +0000 (16:03 -0400)
commitb98a8ac50775540f3804397ed08f61ef9910bcab
tree392ede3bbcf1d8c675b13fc41b15cf2e2772050f
parente5c0235a3c4e9eb047a16cd02323fe4ecf2f570e
selinux: require a class's permission values to cover its permission count

security_get_permissions() sizes an array by the class's permissions.nprim
and fills it at value - 1, from the inherited common's permission table and
then the class's own. A value no permission defines leaves a NULL that
sel_make_perm_files() passes to d_alloc_name(), an oops inside
sel_write_load() that strands selinux_state.policy_mutex and leaves every
later load in uninterruptible sleep; two permissions sharing a value
overwrite the first kstrdup(). Bounding each value by nprim catches
neither, and neither would a count: the symbol table is keyed on the
permission name, so duplicates pass.

Track the values each permission table claims and require them to cover
exactly what its count declares, rejecting a count no value can reach.
Conforming policies are unaffected.

Cc: stable@vger.kernel.org
Fixes: 55fcf09b3fe4 ("selinux: add support for querying object classes and permissions from the running policy")
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/policydb.c