The maximum number of permissions in a class is 32. This is so that each permission can be represented by a bit in a uint32_t. In two places while building the binary policy from CIL an expression of the form "1 << x" is used to set the permission bit. Unfortunately, this expression is undefined if x == 31 because the 1 is an int and cannot be left shifted by 31. Instead, use 1U << x, because an unsigned can be shifted 31. This bug was found by the secilc-fuzzer. Signed-off-by: James Carter <jwcart2@xxxxxxxxx> --- libsepol/cil/src/cil_binary.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c index ec5f01e5..90af430d 100644 --- a/libsepol/cil/src/cil_binary.c +++ b/libsepol/cil/src/cil_binary.c @@ -1225,7 +1225,7 @@ int __perm_str_to_datum(char *perm_str, class_datum_t *sepol_class, uint32_t *da goto exit; } } - *datum |= 1 << (sepol_perm->s.value - 1); + *datum |= 1U << (sepol_perm->s.value - 1); return SEPOL_OK; @@ -4760,7 +4760,7 @@ static struct cil_list *cil_classperms_from_sepol(policydb_t *pdb, uint16_t clas cil_list_init(&cp->perms, CIL_PERM); for (i = 0; i < sepol_class->permissions.nprim; i++) { struct cil_perm *perm; - if ((data & (1 << i)) == 0) continue; + if ((data & (1U << i)) == 0) continue; perm = perm_value_to_cil[class][i+1]; if (!perm) goto exit; cil_list_append(cp->perms, CIL_PERM, perm); -- 2.31.1