Skip to content

Commit

Permalink
exec.c, compat.c: fix count(), compat_count() bounds checking
Browse files Browse the repository at this point in the history
With MAX_ARG_STRINGS set to 0x7FFFFFFF, and being passed to 'count()' and
compat_count(), it would appear that the current max bounds check of
fs/exec.c:394:

	if(++i > max)
		return -E2BIG;

would never trigger. Since 'i' is of type int, so values would wrap and the
function would continue looping.

Simple fix seems to be chaning ++i to i++ and checking for '>='.

Signed-off-by: Jason Baron <jbaron@redhat.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: "Ollie Wild" <aaw@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Jason Baron authored and Linus Torvalds committed Oct 16, 2008
1 parent 9679e4d commit 362e666
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ static int compat_count(compat_uptr_t __user *argv, int max)
if (!p)
break;
argv++;
if(++i > max)
if (i++ >= max)
return -E2BIG;
}
}
Expand Down
2 changes: 1 addition & 1 deletion fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static int count(char __user * __user * argv, int max)
if (!p)
break;
argv++;
if(++i > max)
if (i++ >= max)
return -E2BIG;
cond_resched();
}
Expand Down

0 comments on commit 362e666

Please sign in to comment.