Commit c25b7a7a authored by Florian Westphal's avatar Florian Westphal Committed by Paolo Abeni
Browse files

inet: ping: use hlist_nulls rcu iterator during lookup



ping_lookup() does not acquire the table spinlock, so iteration should
use hlist_nulls_for_each_entry_rcu().

Spotted during code review.

Fixes: dbca1596 ("ping: convert to RCU lookups, get rid of rwlock")
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20221129140644.28525-1-fw@strlen.de


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 9aff0ec5
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -535,6 +535,7 @@ ForEachMacros:
  - 'perf_hpp_list__for_each_sort_list_safe'
  - 'perf_hpp_list__for_each_sort_list_safe'
  - 'perf_pmu__for_each_hybrid_pmu'
  - 'perf_pmu__for_each_hybrid_pmu'
  - 'ping_portaddr_for_each_entry'
  - 'ping_portaddr_for_each_entry'
  - 'ping_portaddr_for_each_entry_rcu'
  - 'plist_for_each'
  - 'plist_for_each'
  - 'plist_for_each_continue'
  - 'plist_for_each_continue'
  - 'plist_for_each_entry'
  - 'plist_for_each_entry'
+0 −3
Original line number Original line Diff line number Diff line
@@ -16,9 +16,6 @@
#define PING_HTABLE_SIZE 	64
#define PING_HTABLE_SIZE 	64
#define PING_HTABLE_MASK 	(PING_HTABLE_SIZE-1)
#define PING_HTABLE_MASK 	(PING_HTABLE_SIZE-1)


#define ping_portaddr_for_each_entry(__sk, node, list) \
	hlist_nulls_for_each_entry(__sk, node, list, sk_nulls_node)

/*
/*
 * gid_t is either uint or ushort.  We want to pass it to
 * gid_t is either uint or ushort.  We want to pass it to
 * proc_dointvec_minmax(), so it must not be larger than MAX_INT
 * proc_dointvec_minmax(), so it must not be larger than MAX_INT
+6 −1
Original line number Original line Diff line number Diff line
@@ -49,6 +49,11 @@
#include <net/transp_v6.h>
#include <net/transp_v6.h>
#endif
#endif


#define ping_portaddr_for_each_entry(__sk, node, list) \
	hlist_nulls_for_each_entry(__sk, node, list, sk_nulls_node)
#define ping_portaddr_for_each_entry_rcu(__sk, node, list) \
	hlist_nulls_for_each_entry_rcu(__sk, node, list, sk_nulls_node)

struct ping_table {
struct ping_table {
	struct hlist_nulls_head	hash[PING_HTABLE_SIZE];
	struct hlist_nulls_head	hash[PING_HTABLE_SIZE];
	spinlock_t		lock;
	spinlock_t		lock;
@@ -192,7 +197,7 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
		return NULL;
		return NULL;
	}
	}


	ping_portaddr_for_each_entry(sk, hnode, hslot) {
	ping_portaddr_for_each_entry_rcu(sk, hnode, hslot) {
		isk = inet_sk(sk);
		isk = inet_sk(sk);


		pr_debug("iterate\n");
		pr_debug("iterate\n");