Skip to content

Commit 6d92d4f

Browse files
xiwtorvalds
authored andcommitted
fs/exec.c: work around icc miscompilation
The tricky problem is this check: if (i++ >= max) icc (mis)optimizes this check as: if (++i > max) The check now becomes a no-op since max is MAX_ARG_STRINGS (0x7FFFFFFF). This is "allowed" by the C standard, assuming i++ never overflows, because signed integer overflow is undefined behavior. This optimization effectively reverts the previous commit 362e666 ("exec.c, compat.c: fix count(), compat_count() bounds checking") that tries to fix the check. This patch simply moves ++ after the check. Signed-off-by: Xi Wang <xi.wang@gmail.com> Cc: Jason Baron <jbaron@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7964c06 commit 6d92d4f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/exec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ static int count(struct user_arg_ptr argv, int max)
434434
if (IS_ERR(p))
435435
return -EFAULT;
436436

437-
if (i++ >= max)
437+
if (i >= max)
438438
return -E2BIG;
439+
++i;
439440

440441
if (fatal_signal_pending(current))
441442
return -ERESTARTNOHAND;

0 commit comments

Comments
 (0)