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]
Date:	Mon, 03 Mar 2014 19:55:08 +0100
From:	Torvald Riegel <triegel@...hat.com>
To:	paulmck@...ux.vnet.ibm.com
Cc:	Linus Torvalds <torvalds@...ux-foundation.org>,
	Will Deacon <will.deacon@....com>,
	Peter Zijlstra <peterz@...radead.org>,
	Ramana Radhakrishnan <Ramana.Radhakrishnan@....com>,
	David Howells <dhowells@...hat.com>,
	"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
	"mingo@...nel.org" <mingo@...nel.org>,
	"gcc@....gnu.org" <gcc@....gnu.org>
Subject: Re: [RFC][PATCH 0/5] arch: atomic rework

On Fri, 2014-02-28 at 16:50 -0800, Paul E. McKenney wrote:
> +o	Do not use the results from the boolean "&&" and "||" when
> +	dereferencing.	For example, the following (rather improbable)
> +	code is buggy:
> +
> +		int a[2];
> +		int index;
> +		int force_zero_index = 1;
> +
> +		...
> +
> +		r1 = rcu_dereference(i1)
> +		r2 = a[r1 && force_zero_index];  /* BUGGY!!! */
> +
> +	The reason this is buggy is that "&&" and "||" are often compiled
> +	using branches.  While weak-memory machines such as ARM or PowerPC
> +	do order stores after such branches, they can speculate loads,
> +	which can result in misordering bugs.
> +
> +o	Do not use the results from relational operators ("==", "!=",
> +	">", ">=", "<", or "<=") when dereferencing.  For example,
> +	the following (quite strange) code is buggy:
> +
> +		int a[2];
> +		int index;
> +		int flip_index = 0;
> +
> +		...
> +
> +		r1 = rcu_dereference(i1)
> +		r2 = a[r1 != flip_index];  /* BUGGY!!! */
> +
> +	As before, the reason this is buggy is that relational operators
> +	are often compiled using branches.  And as before, although
> +	weak-memory machines such as ARM or PowerPC do order stores
> +	after such branches, but can speculate loads, which can again
> +	result in misordering bugs.

Those two would be allowed by the wording I have recently proposed,
AFAICS.  r1 != flip_index would result in two possible values (unless
there are further constraints due to the type of r1 and the values that
flip_index can have).

I don't think the wording is flawed.  We could raise the requirement of
having more than one value left for r1 to having more than N with N > 1
values left, but the fundamental problem remains in that a compiler
could try to generate a (big) switch statement.

Instead, I think that this indicates that the value_dep_preserving type
modifier would be useful: It would tell the compiler that it shouldn't
transform this into a branch in this case, yet allow that optimization
for all other code.

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