Skip to content

Commit

Permalink
fs/exec.c: work around icc miscompilation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
xiw authored and torvalds committed Jan 11, 2013
1 parent 7964c06 commit 6d92d4f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ static int count(struct user_arg_ptr argv, int max)
if (IS_ERR(p))
return -EFAULT;

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

if (fatal_signal_pending(current))
return -ERESTARTNOHAND;
Expand Down

0 comments on commit 6d92d4f

Please sign in to comment.