[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5406BF88.8040102@ladisch.de>
Date: Wed, 03 Sep 2014 09:13:12 +0200
From: Clemens Ladisch <clemens@...isch.de>
To: Scotty Bauer <sbauer@....utah.edu>, linux-kernel@...r.kernel.org
Subject: Re: Compat sysinfo syscall (kernel/sys.c) relying on undefined behavior?
Scotty Bauer wrote:
> In the compat version of sysinfo, kernel/sys.c we see the following:
>
> /* Check to see if any memory value is too large for 32-bit and scale
> * down if needed
> */
> if ((s.totalram >> 32) || (s.totalswap >> 32)) {
This code is supposed to check if any of the bits in the upper half of
these 64-bit values are set.
> s.totalram is a u32
Oops.
> the behavior is undefined.
For a constant shift amount, gcc happens to generate correct code, i.e.,
the result is zero. (If the shift amount were not a constant, x86
processors would use only its lowest five bits, and the result would be
wrong.)
Anyway, it's not a good idea to rely on gcc's implementation of this
undefined behaviour; the code should have used upper_32_bits() instead.
Please write a patch.
Regards,
Clemens
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists