rhashtable: Fix unprotected RCU dereference in __rht_ptr
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 24 Jul 2020 10:12:53 +0000 (20:12 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Aug 2020 07:58:43 +0000 (09:58 +0200)
commitd1ccc048372956621f1250098ff2f85ae5411317
treeafe0bab0a5c1b86026711af88313315033484cbb
parent2531a9b130179b3ee478576a194af30de81270b4
rhashtable: Fix unprotected RCU dereference in __rht_ptr

[ Upstream commit 1748f6a2cbc4694523f16da1c892b59861045b9d ]

The rcu_dereference call in rht_ptr_rcu is completely bogus because
we've already dereferenced the value in __rht_ptr and operated on it.
This causes potential double readings which could be fatal.  The RCU
dereference must occur prior to the comparison in __rht_ptr.

This patch changes the order of RCU dereference so that it is done
first and the result is then fed to __rht_ptr.  The RCU marking
changes have been minimised using casts which will be removed in
a follow-up patch.

Fixes: ba6306e3f648 ("rhashtable: Remove RCU marking from...")
Reported-by: "Gong, Sishuai" <sishuai@purdue.edu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/rhashtable.h