From patchwork Fri Jan 26 20:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1891612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TM8vs3X3kz23gK for ; Sat, 27 Jan 2024 07:50:00 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rTT96-0005hk-O5; Fri, 26 Jan 2024 20:49:52 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rTT8w-0005gz-9H for kernel-team@lists.ubuntu.com; Fri, 26 Jan 2024 20:49:42 +0000 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0E76541DE0 for ; Fri, 26 Jan 2024 20:49:42 +0000 (UTC) Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7bec4b24a34so44045839f.3 for ; Fri, 26 Jan 2024 12:49:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706302179; x=1706906979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MGp4cQ4JVuzTx6unAYe1twKTachfIwhdHr/qhBrplng=; b=vNTilU4mJnpV/lO+KdbyiWioQElUXsqEzzwQT9KlvB0gEZYyy+19HZPy3yBe7SFgUX BJZ1R7OKIWuYHRFXHie717JB3Y2yY+Nk0323SesOKxwthFqInye225+dRd85UaUA5OUD drBQ+W4ZFoZcFRad+KuhRWL2/dnjdForps1amYBwQymTQxc7LDRluiJ5UWBg1aKhF7m4 ZwG+68/07Mw9SYblRHAwXgyZtpiH0258W7eSyfu2+xmup/WBiC17C/Wy9hqgkfRfNfXa aRNjkxojLLVBZ3E9ztc1BQS6Ep2XMDu02eXLX/ibuJC2MzwmmFGKG5N7bPXUT+1+wu8V nh8Q== X-Gm-Message-State: AOJu0YzX6+z3HQTBORmgGsMV0tihqYUsb3C3dwPOjjLycxcZCxEO9h6o G1rzFeZ3yjXfVFoX9nfQdSmRazRA24QXzHtxLyui4LDEQ0DYIl7Udh+yzd8zQjshZSrGvFcChzK Bbmd1MHJKdmdQE8ycJQeCIXbOoSxPQ96CSVGWUz7vEUKquSkk8h+ZoQT7xPIPSjyQeJnQP/UpSE dhiK5jCgwq3g== X-Received: by 2002:a6b:d801:0:b0:7bf:4c7b:2da1 with SMTP id y1-20020a6bd801000000b007bf4c7b2da1mr464393iob.11.1706302179636; Fri, 26 Jan 2024 12:49:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHd8h9wckRZknGMdDgNYvJT6nx5ZqlOQqBmg8QWdVssq7sTyUPJsk9dLDNafJjxbWOk/0Icqg== X-Received: by 2002:a6b:d801:0:b0:7bf:4c7b:2da1 with SMTP id y1-20020a6bd801000000b007bf4c7b2da1mr464389iob.11.1706302179340; Fri, 26 Jan 2024 12:49:39 -0800 (PST) Received: from smtp.gmail.com (104-218-69-19.dynamic.lnk.ne.allofiber.net. [104.218.69.19]) by smtp.gmail.com with ESMTPSA id t15-20020a6bdb0f000000b007bfd52828b0sm94541ioc.17.2024.01.26.12.49.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 12:49:38 -0800 (PST) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][Mantic][Lunar][Jammy][Focal][PATCH 1/1] appletalk: Fix Use-After-Free in atalk_ioctl Date: Fri, 26 Jan 2024 14:49:37 -0600 Message-Id: <20240126204937.36079-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240126204937.36079-1-bethany.jamison@canonical.com> References: <20240126204937.36079-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Hyunwoo Kim 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 (cherry picked from commit 189ff16722ee36ced4d2a2469d4ab65a8fee4198) CVE-2023-51781 Signed-off-by: Bethany Jamison --- 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 8978fb6212ffb..b070a89912000 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -1811,15 +1811,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; }