fix count(), compat_count() bounds checking
Subsystems (2)
PATCH 1/1 fix count(), compat_count() bounds checking
hi,
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 '>='.
thanks,
-Jason
---
fs/compat.c | 2 +- fs/exec.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/compat.c +1 -1
@@ -1233,7 +1233,7 @@ static int compat_count(compat_uptr_t __user *argv, int max)if (!p)break ; argv++; -if (++i > max) +if (i++ >= max)return -E2BIG ; } }
fs/exec.c +1 -1
@@ -389,7 +389,7 @@ static int count(char __user * __user * argv, int max)if (!p)break ; argv++; -if (++i > max) +if (i++ >= max)return -E2BIG ;cond_resched (); }
Quoted 9 lines · Jason Baron
hi,
With
MAX_ARG_STRINGSset to0x7FFFFFFF, and being passed to 'count()' andcompat_count(), it would appear that the current max bounds check offs/exec.c:394:if(++i > max) return -E2BIG;
Quoted 8 lines
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 '>='.
thanks,
-Jason
Right - looks sane enough, although in practise I'm not sure we'll ever care since I suspect we'll hit the target stack limit before this.
Ollie?
Quoted 1 line
Signed-off-by Jason Baron <[email protected]>
Quoted 34 lines
---
fs/compat.c | 2 +- fs/exec.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/compat.c +1
-1@@ -1233,7 +1233,7 @@ static int compat_count(compat_uptr_t __user *argv, int max)if (!p)break ; argv++; -if (++i > max) +if (i++ >= max)return -E2BIG ; } }fs/exec.c +1
-1@@ -389,7 +389,7 @@ static int count(char __user * __user * argv, int max)if (!p)break ; argv++; -if (++i > max) +if (i++ >= max)return -E2BIG ;cond_resched (); }
Quoted 9 lines · Peter Zijlstra
Quoted 2 lines · Jason Baron
Simple fix seems to be chaning ++i to i++ and checking for '>='.
Right - looks sane enough, although in practise I'm not sure we'll ever care since I suspect we'll hit the target stack limit before this.
Ollie?
Sounds reasonable to me. I'd also be ok with changing MAX_ARG_STRINGS to 0x7FFFFFFE to help prevent people from making this mistake in the future.
Ollie