53 lines
1.9 KiB
Diff
53 lines
1.9 KiB
Diff
From 974da80e08d24e92e5409bb040f95d06a47776a2 Mon Sep 17 00:00:00 2001
|
|
From: James Carter <jwcart2@gmail.com>
|
|
Date: Fri, 8 Oct 2021 10:27:49 -0400
|
|
Subject: [PATCH] libsepol/cil: Fix potential undefined shifts
|
|
|
|
An expression of the form "1 << x" is undefined if x == 31 because
|
|
the "1" is an int and cannot be left shifted by 31.
|
|
|
|
Instead, use "UINT32_C(1) << x" which will be an unsigned int of
|
|
at least 32 bits.
|
|
|
|
This bug was found by the secilc-fuzzer.
|
|
|
|
Signed-off-by: James Carter <jwcart2@gmail.com>
|
|
---
|
|
libsepol/cil/src/cil_binary.c | 6 +++---
|
|
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c
|
|
index ec5f01e..d8aa495 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 |= UINT32_C(1) << (sepol_perm->s.value - 1);
|
|
|
|
return SEPOL_OK;
|
|
|
|
@@ -1523,7 +1523,7 @@ int cil_avrule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_
|
|
/* index of the u32 containing the permission */
|
|
#define XPERM_IDX(x) (x >> 5)
|
|
/* set bits 0 through x-1 within the u32 */
|
|
-#define XPERM_SETBITS(x) ((1U << (x & 0x1f)) - 1)
|
|
+#define XPERM_SETBITS(x) ((UINT32_C(1) << (x & 0x1f)) - 1)
|
|
/* low value for this u32 */
|
|
#define XPERM_LOW(x) (x << 5)
|
|
/* high value for this u32 */
|
|
@@ -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 & (UINT32_C(1) << i)) == 0) continue;
|
|
perm = perm_value_to_cil[class][i+1];
|
|
if (!perm) goto exit;
|
|
cil_list_append(cp->perms, CIL_PERM, perm);
|
|
--
|
|
1.8.3.1
|
|
|