Skip to content

Commit 1ade48d

Browse files
f0rm2l1ndavem330
authored andcommitted
ax25: NPD bug when detaching AX25 device
The existing cleanup routine implementation is not well synchronized with the syscall routine. When a device is detaching, below race could occur. static int ax25_sendmsg(...) { ... lock_sock() ax25 = sk_to_ax25(sk); if (ax25->ax25_dev == NULL) // CHECK ... ax25_queue_xmit(skb, ax25->ax25_dev->dev); // USE ... } static void ax25_kill_by_device(...) { ... if (s->ax25_dev == ax25_dev) { s->ax25_dev = NULL; ... } Other syscall functions like ax25_getsockopt, ax25_getname, ax25_info_show also suffer from similar races. To fix them, this patch introduce lock_sock() into ax25_kill_by_device in order to guarantee that the nullify action in cleanup routine cannot proceed when another socket request is pending. Signed-off-by: Hanjie Wu <[email protected]> Signed-off-by: Lin Ma <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b2f37ae commit 1ade48d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/ax25/af_ax25.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ static void ax25_kill_by_device(struct net_device *dev)
8585
again:
8686
ax25_for_each(s, &ax25_list) {
8787
if (s->ax25_dev == ax25_dev) {
88-
s->ax25_dev = NULL;
8988
spin_unlock_bh(&ax25_list_lock);
89+
lock_sock(s->sk);
90+
s->ax25_dev = NULL;
91+
release_sock(s->sk);
9092
ax25_disconnect(s, ENETUNREACH);
9193
spin_lock_bh(&ax25_list_lock);
9294

0 commit comments

Comments
 (0)