Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2352381pxb; Mon, 20 Sep 2021 19:49:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6/gj9TFvtMSggueSDeUvdLCnIxbFzZUXOMyIqXbAej3oHcvlnsnWUSLXSBSle8MmVUbYW X-Received: by 2002:a05:6402:21d6:: with SMTP id bi22mr2361663edb.40.1632192570438; Mon, 20 Sep 2021 19:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192570; cv=none; d=google.com; s=arc-20160816; b=OUREYl7sC5bjalFNYZ1yPfAs6me/IHRkPMGSlXY8EjahV7ld8EYrcXDr+cQqfpk9ib 7en2ZngpzREiSN+J1VdU62Yzb5SJrre0opVS9OKeF5ZSjJ4FgMIrRluSifBqXf40/GQ4 TzTCFA1ueTVC6JuDhxfSnEBQAm3QkPoVgDo1OQwiNVOuKrQwjReH0UXKwF0JvQzWGCk4 AKqw803OKabJ5NhNzp4YW9amRNqGFSuJBmtFJDozE9Gz7TrgJfVaVGv4v2nxyWIRDZBX ndH8t8lNuFpA8by+TrUK+Ph96w15bFTbcDDGPmgjNH1d8jvfrYJ5VM8BpZ4MCyefoxD4 gF3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nU4EeOrsnIowwmtA4i4fhKjOxj9SEi8MKgCtNyZ6f6I=; b=wfwZ4INS3FRzxkKJMJ3YoYnS8F8Qb3agqokm+kcCp6Q9gHLkqzooVLJZBUlVi/wVq1 xZC9fu44jJPWfPAvGZcTwXNJRENF3CKV2s7+eB79RDn5X0hyuZf22jiskLuDvXLiLkwB wwJpAfKb5UxE6IuwLDoAQKodgKkP0TOYdFMPulfcq2YIBGbDAcNTdKmrc1lVc/G2Dj9s yMbBie68B5VQu5KKZpHzgdBEGDzdj67xgeeqBWdL5SQ1mXvCRS9gFAEoM7TYJJj3Y2ys zTJqWNkOWcwFPfKUlkVzxa5qGJbd+R5CKgyS8EFiUA1B0Fua0Bo85dkYz5HPNOfnphwF zM/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZBorFSnm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c33si2168296edf.373.2021.09.20.19.49.07; Mon, 20 Sep 2021 19:49:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZBorFSnm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348149AbhITSbU (ORCPT + 99 others); Mon, 20 Sep 2021 14:31:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378560AbhITSYy (ORCPT ); Mon, 20 Sep 2021 14:24:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C0DE632CF; Mon, 20 Sep 2021 17:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158712; bh=sgaDquabHhXipN7bYiM9tlfCbyGN7BiCnwsUd6JWe1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBorFSnm3oSYQ6+DfE6AdjZbrDB03r73kbAz7V9+B4wrK8nR7UljAjMcz7uLEao1Y BySOuYaE03T5JDd3u0akuqLPVOVpioH24l5yS6VHvcGx2YMgTuswb6jWyWe6xF24fQ NrznOTaUS57ojffFRqhvvYucnhfdQG74Kdfp88gw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com, Xin Long , Jon Maloy , "David S. Miller" Subject: [PATCH 5.10 021/122] tipc: fix an use-after-free issue in tipc_recvmsg Date: Mon, 20 Sep 2021 18:43:13 +0200 Message-Id: <20210920163916.472003750@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163915.757887582@linuxfoundation.org> References: <20210920163915.757887582@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long 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 Acked-by: Jon Maloy Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1980,10 +1980,12 @@ static int tipc_recvmsg(struct socket *s 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 */