Skip to content

Commit 8c652cb

Browse files
author
Xin Long
committed
tipc: fix an use-after-free issue in tipc_recvmsg
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160540 Tested: compile only commit cc19862 Author: Xin Long <lucien.xin@gmail.com> Date: Fri Jul 23 13:25:36 2021 -0400 tipc: fix an use-after-free issue in tipc_recvmsg syzbot reported an use-after-free crash: BUG: KASAN: use-after-free in tipc_recvmsg+0xf77/0xf90 net/tipc/socket.c:1979 Call Trace: tipc_recvmsg+0xf77/0xf90 net/tipc/socket.c:1979 sock_recvmsg_nosec net/socket.c:943 [inline] sock_recvmsg net/socket.c:961 [inline] sock_recvmsg+0xca/0x110 net/socket.c:957 tipc_conn_rcv_from_sock+0x162/0x2f0 net/tipc/topsrv.c:398 tipc_conn_recv_work+0xeb/0x190 net/tipc/topsrv.c:421 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422 As Hoang pointed out, it was caused by skb_cb->bytes_read still accessed after calling tsk_advance_rx_queue() to free the skb in tipc_recvmsg(). This patch is to fix it by accessing skb_cb->bytes_read earlier than calling tsk_advance_rx_queue(). Fixes: f4919ff ("tipc: keep the skb in rcv queue until the whole data is read") Reported-by: syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent 8333545 commit 8c652cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

net/tipc/socket.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,10 +1982,12 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
19821982
tipc_node_distr_xmit(sock_net(sk), &xmitq);
19831983
}
19841984

1985-
if (!skb_cb->bytes_read)
1986-
tsk_advance_rx_queue(sk);
1985+
if (skb_cb->bytes_read)
1986+
goto exit;
1987+
1988+
tsk_advance_rx_queue(sk);
19871989

1988-
if (likely(!connected) || skb_cb->bytes_read)
1990+
if (likely(!connected))
19891991
goto exit;
19901992

19911993
/* Send connection flow control advertisement when applicable */

0 commit comments

Comments
 (0)