Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2382071lqp; Sun, 24 Mar 2024 16:57:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUUBVVB/YZptovKI2aAwIaCrrd34cLWfGE5RhQq3vbqB4yyRub4y95k02tkWhyf+nDBN8FmXe6GVokS9OqVjObel6ikQHmEjnBzH9A0zg== X-Google-Smtp-Source: AGHT+IG9GIhi6zUpTQVAUbbVgTmYF+itOJaSmd5DZ6lOH2Ze9IYoYs0e66CCvGgNxsqTXcjUmIq2 X-Received: by 2002:a05:6359:4c87:b0:17e:bb98:4879 with SMTP id kk7-20020a0563594c8700b0017ebb984879mr7012122rwc.3.1711324671971; Sun, 24 Mar 2024 16:57:51 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c23-20020a6566d7000000b005dcbbacc92esi6132818pgw.872.2024.03.24.16.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:57:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113207-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=OSpdP+0F; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-113207-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113207-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D624AB22BBE for ; Sun, 24 Mar 2024 23:44:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8EFE131BD3; Sun, 24 Mar 2024 22:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OSpdP+0F" 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 0567B131BA5; Sun, 24 Mar 2024 22:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320009; cv=none; b=qxqr6ZnHJL9NbdiUiP88AozMcSpwvCuxdnMfy7YwyJaF/heKQ08t8ooyXT87ZZFOoQ4AlIWhzX6Ykb0Kv6gPYmPDnPPRMccABGmv283ThgaL8KZ/JNe4OXv6jOJhn+PDBmycdaA/PxXijSNFSC6w6cl1oJKw+Ih/k+f8kwyIutQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320009; c=relaxed/simple; bh=CgppWVbYSdfdH7pUfBvvux86ej8YyJiAHOmFHrzmnXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GHIheQECA/OzV1hxTqFJ81QT51zXXXuDhVPEYbWXJC7jnWz7jrEOkKkV01nXSVw3A+0anMaIc6J5NMiBiTjxNJMurHWC3+WSwR3xOD9gaijpI/GCncXVZD8/qRfZlxFzROmY0ME+k9JUmgcwa7GLH7orClWhy7Us6wSq7IlC08o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OSpdP+0F; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E611C43399; Sun, 24 Mar 2024 22:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320008; bh=CgppWVbYSdfdH7pUfBvvux86ej8YyJiAHOmFHrzmnXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSpdP+0FgNnBsb84NNj+RV+ZAv5gway4REsNXF+EcXn7JVFEBNRavNMcZBIFsx4kE DQhuVPutO+3KdpwKKg5DohE48UlPWNn56uO3RksBbUcmqkcCbUUUr2WITz1ln/wrR0 frg+nI5PkYRpNxyfL2LeX7lyJdSpF6PEAaVek2P58gKkuuGBUteir99o7zOw9JPwzh GTsBGul+8qJ5T8DUuYduBhmDHzQ7F0yD9/ViQQmNJ+DQclRsP9lQNDHhGrseLnHFB+ wwan61Cwdf6gCSTOpQpNGqfcEzWx9wIlF1jVWo28ASqkPlZfQWG0iYLta5U/i0eZZT yEGGH7qk+Gcyw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pauli Virtanen , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.8 316/715] Bluetooth: fix use-after-free in accessing skb after sending it Date: Sun, 24 Mar 2024 18:28:15 -0400 Message-ID: <20240324223455.1342824-317-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Pauli Virtanen [ Upstream commit 947ec0d002dce8577b655793dcc6fc78d67b7cb6 ] hci_send_cmd_sync first sends skb and then tries to clone it. However, the driver may have already freed the skb at that point. Fix by cloning the sent_cmd cloned just above, instead of the original. Log: ================================================================ BUG: KASAN: slab-use-after-free in __copy_skb_header+0x1a/0x240 .. Call Trace: .. __skb_clone+0x59/0x2c0 hci_cmd_work+0x3b3/0x3d0 [bluetooth] process_one_work+0x459/0x900 .. Allocated by task 129: ... __alloc_skb+0x1ae/0x220 __hci_cmd_sync_sk+0x44c/0x7a0 [bluetooth] __hci_cmd_sync_status+0x24/0xb0 [bluetooth] set_cig_params_sync+0x778/0x7d0 [bluetooth] .. Freed by task 0: ... kmem_cache_free+0x157/0x3c0 __usb_hcd_giveback_urb+0x11e/0x1e0 usb_giveback_urb_bh+0x1ad/0x2a0 tasklet_action_common.isra.0+0x259/0x4a0 __do_softirq+0x15b/0x5a7 ================================================================ Fixes: 2615fd9a7c25 ("Bluetooth: hci_sync: Fix overwriting request callback") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 85a91c438d721..7d5334b529834 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -4185,7 +4185,7 @@ static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) if (hci_req_status_pend(hdev) && !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) { kfree_skb(hdev->req_skb); - hdev->req_skb = skb_clone(skb, GFP_KERNEL); + hdev->req_skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); } atomic_dec(&hdev->cmd_cnt); -- 2.43.0