Skip to content

Commit

Permalink
ping: Fix potentail NULL deref for /proc/net/icmp.
Browse files Browse the repository at this point in the history
After commit dbca159 ("ping: convert to RCU lookups, get rid
of rwlock"), we use RCU for ping sockets, but we should use spinlock
for /proc/net/icmp to avoid a potential NULL deref mentioned in
the previous patch.

Let's go back to using spinlock there.

Note we can convert ping sockets to use hlist instead of hlist_nulls
because we do not use SLAB_TYPESAFE_BY_RCU for ping sockets.

Fixes: dbca159 ("ping: convert to RCU lookups, get rid of rwlock")
Signed-off-by: Kuniyuki Iwashima <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
q2ven authored and kuba-moo committed Apr 5, 2023
1 parent 0a78cf7 commit ab5fb73
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,13 +1089,13 @@ static struct sock *ping_get_idx(struct seq_file *seq, loff_t pos)
}

void *ping_seq_start(struct seq_file *seq, loff_t *pos, sa_family_t family)
__acquires(RCU)
__acquires(ping_table.lock)
{
struct ping_iter_state *state = seq->private;
state->bucket = 0;
state->family = family;

rcu_read_lock();
spin_lock(&ping_table.lock);

return *pos ? ping_get_idx(seq, *pos-1) : SEQ_START_TOKEN;
}
Expand All @@ -1121,9 +1121,9 @@ void *ping_seq_next(struct seq_file *seq, void *v, loff_t *pos)
EXPORT_SYMBOL_GPL(ping_seq_next);

void ping_seq_stop(struct seq_file *seq, void *v)
__releases(RCU)
__releases(ping_table.lock)
{
rcu_read_unlock();
spin_unlock(&ping_table.lock);
}
EXPORT_SYMBOL_GPL(ping_seq_stop);

Expand Down

0 comments on commit ab5fb73

Please sign in to comment.