lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87vbmt52dm.fsf@rasmusvillemoes.dk>
Date:	Wed, 05 Nov 2014 12:10:45 +0100
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Maxime COQUELIN <maxime.coquelin@...com>
Cc:	gong.chen@...ux.intel.com, Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>,
	" Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>, tytso@....edu,
	linux-kernel@...r.kernel.org, stable@...r.kernel.org,
	kernel@...inux.com, eric.paire@...com
Subject: Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

On Tue, Nov 04 2014, Maxime COQUELIN <maxime.coquelin@...com> wrote:

> -#define GENMASK(h, l)		(((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
> -#define GENMASK_ULL(h, l)	(((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
> +#define GENMASK(h, l) \
> +	((~0UL >> (BITS_PER_LONG - ((h) - (l) + 1))) << (l))
> +
> +#define GENMASK_ULL(h, l) \
> +	((~0ULL >> (BITS_PER_LONG_LONG - ((h) - (l) + 1))) << (l))

Slightly bikeshedding here, but may I suggest spelling it

  (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))

? This will ensure the arguments are expanded once each, and will, IMHO,
DTRT if/when l > h (namely, yield 0).

Rasmus
--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ