From: Jason Baron Date: Thu, 16 Oct 2008 05:01:52 +0000 (-0700) Subject: exec.c, compat.c: fix count(), compat_count() bounds checking X-Git-Tag: v2.6.28-rc1~522 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=362e6663ef2369d77251496d865ad02a2376f962;p=linux-2.6-omap-h63xx.git exec.c, compat.c: fix count(), compat_count() bounds checking 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 Acked-by: Peter Zijlstra Cc: "Ollie Wild" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/fs/compat.c b/fs/compat.c index 075d0509970..aae13d31612 100644 --- a/fs/compat.c +++ b/fs/compat.c @@ -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; } } diff --git a/fs/exec.c b/fs/exec.c index cecee501ce7..7b5ed50eade 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -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(); }