Skip to content

Commit 189ff16

Browse files
ImV4belPaolo Abeni
authored andcommitted
appletalk: Fix Use-After-Free in atalk_ioctl
Because atalk_ioctl() accesses sk->sk_receive_queue without holding a sk->sk_receive_queue.lock, it can cause a race with atalk_recvmsg(). A use-after-free for skb occurs with the following flow. ``` atalk_ioctl() -> skb_peek() atalk_recvmsg() -> skb_recv_datagram() -> skb_free_datagram() ``` Add sk->sk_receive_queue.lock to atalk_ioctl() to fix this issue. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim <[email protected]> Link: https://lore.kernel.org/r/20231213041056.GA519680@v4bel-B760M-AORUS-ELITE-AX Signed-off-by: Paolo Abeni <[email protected]>
1 parent e23c0d2 commit 189ff16

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

net/appletalk/ddp.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,15 +1775,14 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
17751775
break;
17761776
}
17771777
case TIOCINQ: {
1778-
/*
1779-
* These two are safe on a single CPU system as only
1780-
* user tasks fiddle here
1781-
*/
1782-
struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
1778+
struct sk_buff *skb;
17831779
long amount = 0;
17841780

1781+
spin_lock_irq(&sk->sk_receive_queue.lock);
1782+
skb = skb_peek(&sk->sk_receive_queue);
17851783
if (skb)
17861784
amount = skb->len - sizeof(struct ddpehdr);
1785+
spin_unlock_irq(&sk->sk_receive_queue.lock);
17871786
rc = put_user(amount, (int __user *)argp);
17881787
break;
17891788
}

0 commit comments

Comments
 (0)