Skip to content

Commit

Permalink
kernel/groups.c: fix integer overflow in groups_search
Browse files Browse the repository at this point in the history
gid_t is a unsigned int.  If group_info contains a gid greater than
MAX_INT, groups_search() function may look on the wrong side of the search
tree.

This solves some unfair "permission denied" problems.

Signed-off-by: Jerome Marchand <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jeromemarchand authored and torvalds committed Sep 10, 2010
1 parent 94131e1 commit 1c24de6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions kernel/groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ int groups_search(const struct group_info *group_info, gid_t grp)
right = group_info->ngroups;
while (left < right) {
unsigned int mid = (left+right)/2;
int cmp = grp - GROUP_AT(group_info, mid);
if (cmp > 0)
if (grp > GROUP_AT(group_info, mid))
left = mid + 1;
else if (cmp < 0)
else if (grp < GROUP_AT(group_info, mid))
right = mid;
else
return 1;
Expand Down

0 comments on commit 1c24de6

Please sign in to comment.