Skip to content
/ linux Public

Commit 9bd9e66

Browse files
q2venSasha Levin
authored andcommitted
ping: Convert hlist_nulls to plain hlist.
[ Upstream commit f1b5dfe ] Since introduced in commit c319b4d ("net: ipv4: add IPPROTO_ICMP socket kind"), ping socket does not use SLAB_TYPESAFE_BY_RCU nor check nulls marker in loops. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: ad5dfde ("ping: annotate data-races in ping_lookup()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cc0402a commit 9bd9e66

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

net/ipv4/ping.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@
4949
#include <net/transp_v6.h>
5050
#endif
5151

52-
#define ping_portaddr_for_each_entry(__sk, node, list) \
53-
hlist_nulls_for_each_entry(__sk, node, list, sk_nulls_node)
54-
#define ping_portaddr_for_each_entry_rcu(__sk, node, list) \
55-
hlist_nulls_for_each_entry_rcu(__sk, node, list, sk_nulls_node)
56-
5752
struct ping_table {
58-
struct hlist_nulls_head hash[PING_HTABLE_SIZE];
53+
struct hlist_head hash[PING_HTABLE_SIZE];
5954
spinlock_t lock;
6055
};
6156

@@ -74,17 +69,16 @@ static inline u32 ping_hashfn(const struct net *net, u32 num, u32 mask)
7469
}
7570
EXPORT_SYMBOL_GPL(ping_hash);
7671

77-
static inline struct hlist_nulls_head *ping_hashslot(struct ping_table *table,
78-
struct net *net, unsigned int num)
72+
static inline struct hlist_head *ping_hashslot(struct ping_table *table,
73+
struct net *net, unsigned int num)
7974
{
8075
return &table->hash[ping_hashfn(net, num, PING_HTABLE_MASK)];
8176
}
8277

8378
int ping_get_port(struct sock *sk, unsigned short ident)
8479
{
85-
struct hlist_nulls_node *node;
86-
struct hlist_nulls_head *hlist;
8780
struct inet_sock *isk, *isk2;
81+
struct hlist_head *hlist;
8882
struct sock *sk2 = NULL;
8983

9084
isk = inet_sk(sk);
@@ -98,7 +92,7 @@ int ping_get_port(struct sock *sk, unsigned short ident)
9892
result++; /* avoid zero */
9993
hlist = ping_hashslot(&ping_table, sock_net(sk),
10094
result);
101-
ping_portaddr_for_each_entry(sk2, node, hlist) {
95+
sk_for_each(sk2, hlist) {
10296
isk2 = inet_sk(sk2);
10397

10498
if (isk2->inet_num == result)
@@ -115,7 +109,7 @@ int ping_get_port(struct sock *sk, unsigned short ident)
115109
goto fail;
116110
} else {
117111
hlist = ping_hashslot(&ping_table, sock_net(sk), ident);
118-
ping_portaddr_for_each_entry(sk2, node, hlist) {
112+
sk_for_each(sk2, hlist) {
119113
isk2 = inet_sk(sk2);
120114

121115
/* BUG? Why is this reuse and not reuseaddr? ping.c
@@ -133,9 +127,8 @@ int ping_get_port(struct sock *sk, unsigned short ident)
133127
isk->inet_num = ident;
134128
if (sk_unhashed(sk)) {
135129
pr_debug("was not hashed\n");
136-
sock_hold(sk);
130+
sk_add_node_rcu(sk, hlist);
137131
sock_set_flag(sk, SOCK_RCU_FREE);
138-
hlist_nulls_add_head_rcu(&sk->sk_nulls_node, hlist);
139132
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
140133
}
141134
spin_unlock(&ping_table.lock);
@@ -161,9 +154,7 @@ void ping_unhash(struct sock *sk)
161154

162155
pr_debug("ping_unhash(isk=%p,isk->num=%u)\n", isk, isk->inet_num);
163156
spin_lock(&ping_table.lock);
164-
if (sk_hashed(sk)) {
165-
hlist_nulls_del_init_rcu(&sk->sk_nulls_node);
166-
sock_put(sk);
157+
if (sk_del_node_init_rcu(sk)) {
167158
isk->inet_num = 0;
168159
isk->inet_sport = 0;
169160
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
@@ -175,10 +166,9 @@ EXPORT_SYMBOL_GPL(ping_unhash);
175166
/* Called under rcu_read_lock() */
176167
static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
177168
{
178-
struct hlist_nulls_head *hslot = ping_hashslot(&ping_table, net, ident);
169+
struct hlist_head *hslot = ping_hashslot(&ping_table, net, ident);
179170
struct sock *sk = NULL;
180171
struct inet_sock *isk;
181-
struct hlist_nulls_node *hnode;
182172
int dif, sdif;
183173

184174
if (skb->protocol == htons(ETH_P_IP)) {
@@ -197,7 +187,7 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
197187
return NULL;
198188
}
199189

200-
ping_portaddr_for_each_entry_rcu(sk, hnode, hslot) {
190+
sk_for_each_rcu(sk, hslot) {
201191
isk = inet_sk(sk);
202192

203193
pr_debug("iterate\n");
@@ -1043,15 +1033,14 @@ static struct sock *ping_get_first(struct seq_file *seq, int start)
10431033

10441034
for (state->bucket = start; state->bucket < PING_HTABLE_SIZE;
10451035
++state->bucket) {
1046-
struct hlist_nulls_node *node;
1047-
struct hlist_nulls_head *hslot;
1036+
struct hlist_head *hslot;
10481037

10491038
hslot = &ping_table.hash[state->bucket];
10501039

1051-
if (hlist_nulls_empty(hslot))
1040+
if (hlist_empty(hslot))
10521041
continue;
10531042

1054-
sk_nulls_for_each(sk, node, hslot) {
1043+
sk_for_each(sk, hslot) {
10551044
if (net_eq(sock_net(sk), net) &&
10561045
sk->sk_family == state->family)
10571046
goto found;
@@ -1068,7 +1057,7 @@ static struct sock *ping_get_next(struct seq_file *seq, struct sock *sk)
10681057
struct net *net = seq_file_net(seq);
10691058

10701059
do {
1071-
sk = sk_nulls_next(sk);
1060+
sk = sk_next(sk);
10721061
} while (sk && (!net_eq(sock_net(sk), net)));
10731062

10741063
if (!sk)
@@ -1204,6 +1193,6 @@ void __init ping_init(void)
12041193
int i;
12051194

12061195
for (i = 0; i < PING_HTABLE_SIZE; i++)
1207-
INIT_HLIST_NULLS_HEAD(&ping_table.hash[i], i);
1196+
INIT_HLIST_HEAD(&ping_table.hash[i]);
12081197
spin_lock_init(&ping_table.lock);
12091198
}

0 commit comments

Comments
 (0)