Skip to content

Commit aa4b605

Browse files
cgzonespcmoore
authored andcommitted
selinux: make left shifts well defined
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 <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 002903e commit aa4b605

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

security/selinux/ss/services.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,30 @@ static void map_decision(struct selinux_map *map,
207207

208208
for (i = 0, result = 0; i < n; i++) {
209209
if (avd->allowed & mapping->perms[i])
210-
result |= 1<<i;
210+
result |= (u32)1<<i;
211211
if (allow_unknown && !mapping->perms[i])
212-
result |= 1<<i;
212+
result |= (u32)1<<i;
213213
}
214214
avd->allowed = result;
215215

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

221221
for (i = 0, result = 0; i < n; i++) {
222222
if (avd->auditdeny & mapping->perms[i])
223-
result |= 1<<i;
223+
result |= (u32)1<<i;
224224
if (!allow_unknown && !mapping->perms[i])
225-
result |= 1<<i;
225+
result |= (u32)1<<i;
226226
}
227227
/*
228228
* In case the kernel has a bug and requests a permission
229229
* between num_perms and the maximum permission number, we
230230
* should audit that denial
231231
*/
232232
for (; i < (sizeof(u32)*8); i++)
233-
result |= 1<<i;
233+
result |= (u32)1<<i;
234234
avd->auditdeny = result;
235235
}
236236
}

0 commit comments

Comments
 (0)