linux-kernel-test/include
Paul E. McKenney f65846a180 list: Fix double fetch of pointer in hlist_entry_safe()
The current version of hlist_entry_safe() fetches the pointer twice,
once to test for NULL and the other to compute the offset back to the
enclosing structure.  This is OK for normal lock-based use because in
that case, the pointer cannot change.  However, when the pointer is
protected by RCU (as in "rcu_dereference(p)"), then the pointer can
change at any time.  This use case can result in the following sequence
of events:

1.	CPU 0 invokes hlist_entry_safe(), fetches the RCU-protected
	pointer as sees that it is non-NULL.

2.	CPU 1 invokes hlist_del_rcu(), deleting the entry that CPU 0
	just fetched a pointer to.  Because this is the last entry
	in the list, the pointer fetched by CPU 0 is now NULL.

3.	CPU 0 refetches the pointer, obtains NULL, and then gets a
	NULL-pointer crash.

This commit therefore applies gcc's "({ })" statement expression to
create a temporary variable so that the specified pointer is fetched
only once, avoiding the above sequence of events.  Please note that
it is the caller's responsibility to use rcu_dereference() as needed.
This allows RCU-protected uses to work correctly without imposing
any additional overhead on the non-RCU case.

Many thanks to Eric Dumazet for spotting root cause!

Reported-by: CAI Qian <caiqian@redhat.com>
Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Li Zefan <lizefan@huawei.com>
2013-03-14 13:18:30 -07:00
..
acpi ACPI / glue: Drop .find_bridge() callback from struct acpi_bus_type 2013-03-04 14:23:40 +01:00
asm-generic ImgTec Meta architecture changes for v3.9-rc1 2013-03-03 12:06:09 -08:00
clocksource ImgTec Meta architecture changes for v3.9-rc1 2013-03-03 12:06:09 -08:00
crypto
drm drm: Documentation typo fixes 2013-03-08 08:32:23 +10:00
keys
linux list: Fix double fetch of pointer in hlist_entry_safe() 2013-03-14 13:18:30 -07:00
math-emu
media
memory
misc
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2013-03-05 18:42:29 -08:00
pcmcia
ras
rdma
rxrpc
scsi SCSI for-linus on 20130301 2013-03-02 11:42:16 -08:00
sound arm-soc: late OMAP changes 2013-02-28 20:00:40 -08:00
target target: Rename spc_get_write_same_sectors -> sbc_get_write_same_sectors 2013-02-23 12:46:14 -08:00
trace Various bug fixes for ext4. The most important is a fix for the new 2013-03-02 19:33:21 -08:00
uapi UAPI disintegration 2012-12-20 2013-03-03 14:24:59 -08:00
video UAPI disintegration 2012-12-20 2013-03-03 14:24:59 -08:00
xen
Kbuild