Skip to content

Commit

Permalink
selinux: make left shifts well defined
Browse files Browse the repository at this point in the history
The loops upper bound represent the number of permissions used (for the
current class or in general).  The limit for this is 32, thus we might
left shift of one less, 31.  Shifting a base of 1 results in undefined
behavior; use (u32)1 as base.

Signed-off-by: Christian Göttsche <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
cgzones authored and pcmoore committed Aug 9, 2023
1 parent 002903e commit aa4b605
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,30 @@ static void map_decision(struct selinux_map *map,

for (i = 0, result = 0; i < n; i++) {
if (avd->allowed & mapping->perms[i])
result |= 1<<i;
result |= (u32)1<<i;
if (allow_unknown && !mapping->perms[i])
result |= 1<<i;
result |= (u32)1<<i;
}
avd->allowed = result;

for (i = 0, result = 0; i < n; i++)
if (avd->auditallow & mapping->perms[i])
result |= 1<<i;
result |= (u32)1<<i;
avd->auditallow = result;

for (i = 0, result = 0; i < n; i++) {
if (avd->auditdeny & mapping->perms[i])
result |= 1<<i;
result |= (u32)1<<i;
if (!allow_unknown && !mapping->perms[i])
result |= 1<<i;
result |= (u32)1<<i;
}
/*
* In case the kernel has a bug and requests a permission
* between num_perms and the maximum permission number, we
* should audit that denial
*/
for (; i < (sizeof(u32)*8); i++)
result |= 1<<i;
result |= (u32)1<<i;
avd->auditdeny = result;
}
}
Expand Down

0 comments on commit aa4b605

Please sign in to comment.