Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353032pxb; Mon, 20 Sep 2021 19:50:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdjR73l+mHHSlh13NE63w7L5sDgIFiTVJO5SzmTFU01h9E73AWV8hFwqYWlIHQsorjjLrF X-Received: by 2002:a50:da0a:: with SMTP id z10mr4775617edj.298.1632192648754; Mon, 20 Sep 2021 19:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192648; cv=none; d=google.com; s=arc-20160816; b=qsR6U7Dr//N1qrhw/qrc4suW9Wt02VT3rRPd91lz0bWcGkfOIFBan/WwSerpAzhl6U pdR4L5XRUHKhy/iGfNQDx5qPLxMhmiD/VRXhOfVxBxegsz+S5W4SxoT2m94D4LtmqvyM 4fnRtBVT3DPGpy7jyCXU+kBdWGgWSdcC6hzGMS0vskBpZagnlSUmRBvsJSlT8CsGG876 mS4ISq12YDxhs0yv2Qg1kJPXHbA5ji7Tyo6JGXF2g0j6NTZToXmbJDbGkTnHteYWXPPT kWyBNQaTqPDPbtPEKsUsGOQxkDitrjGPQBAi6p3RNI4VWd58xZCv8tvOJrInyfXuMCC0 wWOA== 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=sWn96ylfp5vaady3N/3VPdV0jeoM5I+kuY0KcQd+JU4=; b=vKSASIBovqMV1J3M4ac8P1MJXBHcBj6OFnVQgL+mqsOjLDHjWK6xSQfpc9TWHH35mm xe9rn7iWZtgGf0TioBRuOU9GRt5c6wHWCUYYoNvPMhebhVe6zx+dX4O94RAorWD/SLZY B/cJxoNam34PqjM4HEZN54uYnHTHLzKbkUXmY10EFJb8M6gcR6+8Z9Ck7nqyF7ETkKP5 3XiGMycnksILvA+585xiTRjYW1j4oEJgY4naUy7AyETp3b1K3R+ANDP9awW4jnHsCQJJ XH9SE87UcWYErKap4giLPZ1x4IOvXWT5JGgvB2HlyVwZRuckVwSy1AsDa3D8eb8/Cj30 yCyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kl7T49Yj; 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 bi20si17999974ejb.575.2021.09.20.19.50.25; Mon, 20 Sep 2021 19:50:48 -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=kl7T49Yj; 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 S1348105AbhITSnw (ORCPT + 99 others); Mon, 20 Sep 2021 14:43:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:53082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381505AbhITSia (ORCPT ); Mon, 20 Sep 2021 14:38:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 923BA63325; Mon, 20 Sep 2021 17:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159014; bh=uaLzsrKXU0y7gZmS6t7XQBLvcTt8U9l50H81dd7GlIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kl7T49Yj/bf61HGrRG24BYsb+bypHfeDXKddfto7Tw397w11MoR/MJaWsM2azUBaI YJCV3Y3O4Xj+l0sr+3U+/68cUhMSlHLP704JJ/OzjgopI1aMCL8MYBwCvRpNegqJUw R93OfFhNPEks6d89eZzDNT8BUkYMTYtExs9aGm5I= 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.14 037/168] tipc: fix an use-after-free issue in tipc_recvmsg Date: Mon, 20 Sep 2021 18:42:55 +0200 Message-Id: <20210920163922.865479003@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 @@ -1979,10 +1979,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 */