summaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorXin Long <lucien.xin@gmail.com>2021-07-23 13:25:36 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-09-22 12:27:56 +0200
commitee3ffd56b40ea6e5128502d03b49ffb53a09c7f6 (patch)
tree4ba4997f81fed6ec8be7ee9c1ed1fed2ed04a65a /net/tipc
parent12551b75b00b8d1de3a944ab44c997bee7c9bce0 (diff)
downloadlinux-stable-ee3ffd56b40ea6e5128502d03b49ffb53a09c7f6.tar.gz
linux-stable-ee3ffd56b40ea6e5128502d03b49ffb53a09c7f6.tar.bz2
linux-stable-ee3ffd56b40ea6e5128502d03b49ffb53a09c7f6.zip
tipc: fix an use-after-free issue in tipc_recvmsg
commit cc19862ffe454a5b632ca202e5a51bfec9f89fd2 upstream. 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: f4919ff59c28 ("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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/socket.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 963047c57c27..91230eecb7a8 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1980,10 +1980,12 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
tipc_node_distr_xmit(sock_net(sk), &xmitq);
}
- if (!skb_cb->bytes_read)
- tsk_advance_rx_queue(sk);
+ if (skb_cb->bytes_read)
+ goto exit;
+
+ tsk_advance_rx_queue(sk);
- if (likely(!connected) || skb_cb->bytes_read)
+ if (likely(!connected))
goto exit;
/* Send connection flow control advertisement when applicable */