From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05D76129EC8; Mon, 18 Dec 2023 14:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zs+YuTwD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FEDFC433C8; Mon, 18 Dec 2023 14:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1702908699; bh=JTFnUlb+qZo57so8ow7I4wA4HKs90EW1EkyVoe8JCJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zs+YuTwD1Eluo3usrXWCAM79WJ+IpRBsZkEmDmgmGjEbN/oHJOQLmbczWq0WAMxp0 sg4UoMT7Q8W9fkyvo7J+AnMg15mS1NtjcCwjXRvKny+lH7p/x/geZ0XuU/2gNIJdwx kqICti/6e8bhXNiO5BzI3K6ACV1y+Y4BFbFwU8Hw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hyunwoo Kim , Paolo Abeni , Sasha Levin Subject: [PATCH 5.4 16/40] appletalk: Fix Use-After-Free in atalk_ioctl Date: Mon, 18 Dec 2023 14:52:11 +0100 Message-ID: <20231218135043.295854801@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218135042.748715259@linuxfoundation.org> References: <20231218135042.748715259@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hyunwoo Kim [ Upstream commit 189ff16722ee36ced4d2a2469d4ab65a8fee4198 ] 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: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim Link: https://lore.kernel.org/r/20231213041056.GA519680@v4bel-B760M-AORUS-ELITE-AX Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/appletalk/ddp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index 4610c352849bc..70cd5f55628d3 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -1803,15 +1803,14 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) break; } case TIOCINQ: { - /* - * These two are safe on a single CPU system as only - * user tasks fiddle here - */ - struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); + struct sk_buff *skb; long amount = 0; + spin_lock_irq(&sk->sk_receive_queue.lock); + skb = skb_peek(&sk->sk_receive_queue); if (skb) amount = skb->len - sizeof(struct ddpehdr); + spin_unlock_irq(&sk->sk_receive_queue.lock); rc = put_user(amount, (int __user *)argp); break; } -- 2.43.0