Skip to content

Commit e62885c

Browse files
pvts-matPlaidCat
authored andcommitted
rcu: Upgrade rcu_swap_protected() to rcu_replace_pointer()
jira VULN-7633 cve-pre CVE-2023-1281 commit-author Paul E. McKenney <[email protected]> commit a63fc6b Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace_pointer() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace_pointer(), rcu_swap_protected() will be removed. Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/ Reported-by: Linus Torvalds <[email protected]> [ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ] Signed-off-by: Paul E. McKenney <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Johannes Thumshirn <[email protected]> Cc: Shane M Seymour <[email protected]> Cc: Martin K. Petersen <[email protected]> (cherry picked from commit a63fc6b) Signed-off-by: Marcin Wcisło <[email protected]>
1 parent ba92bd2 commit e62885c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/linux/rcupdate.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,24 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
969969
#define rcu_assign_pointer(p, v) \
970970
__rcu_assign_pointer((p), (v), __rcu)
971971

972+
/**
973+
* rcu_replace_pointer() - replace an RCU pointer, returning its old value
974+
* @rcu_ptr: RCU pointer, whose old value is returned
975+
* @ptr: regular pointer
976+
* @c: the lockdep conditions under which the dereference will take place
977+
*
978+
* Perform a replacement, where @rcu_ptr is an RCU-annotated
979+
* pointer and @c is the lockdep argument that is passed to the
980+
* rcu_dereference_protected() call used to read that pointer. The old
981+
* value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
982+
*/
983+
#define rcu_replace_pointer(rcu_ptr, ptr, c) \
984+
({ \
985+
typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \
986+
rcu_assign_pointer((rcu_ptr), (ptr)); \
987+
__tmp; \
988+
})
989+
972990
/**
973991
* RCU_INIT_POINTER() - initialize an RCU protected pointer
974992
*

0 commit comments

Comments
 (0)