From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87CDEC47094 for ; Mon, 7 Jun 2021 16:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37C1561452 for ; Mon, 7 Jun 2021 16:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233349AbhFGQ1N (ORCPT ); Mon, 7 Jun 2021 12:27:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:32772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232192AbhFGQXG (ORCPT ); Mon, 7 Jun 2021 12:23:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6005761933; Mon, 7 Jun 2021 16:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623082529; bh=yj8ftTlOiTAwjfjuv4XnTbRRyDBDAiG+Pt5Uz2JaO/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uiepu2vV7fbfIpTU7EQS95H15mLbeXphWjV3R6qRxZgmOlqslsPTtLEhGYxH2JQQA LFeE11jXZzQbN86HS4wiRPx4HWmMCOuektBF8tXfNvEfepY6TmGDo6Qg6T4D4Tg8Db LzKioKZQMxBHlZj4Fw5bDg04AkmCvgR7VU9BrAUb+84he+Uwic+U/VmmVjiUXSqbSl zb/xwyLPr19rC4jNi8Q7CkSbbyCHWSfQAbt80b/Bcz82oPGif5VAt/JqxBEEkW8fCR kg4AN0o2NfAaJbLCxiY/JjV/eTa+Va/HBDM6oztk2h3tmA/DZsQBHhVOmPBDMdaaqW TOQo2fd21Ou/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lin Ma , Marcel Holtmann , Sasha Levin , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 08/18] Bluetooth: use correct lock to prevent UAF of hdev object Date: Mon, 7 Jun 2021 12:15:06 -0400 Message-Id: <20210607161517.3584577-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210607161517.3584577-1-sashal@kernel.org> References: <20210607161517.3584577-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lin Ma [ Upstream commit e305509e678b3a4af2b3cfd410f409f7cdaabb52 ] The hci_sock_dev_event() function will cleanup the hdev object for sockets even if this object may still be in used within the hci_sock_bound_ioctl() function, result in UAF vulnerability. This patch replace the BH context lock to serialize these affairs and prevent the race condition. Signed-off-by: Lin Ma Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 93093d7c3824..120064e9cb2b 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -750,7 +750,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) /* Detach sockets from device */ read_lock(&hci_sk_list.lock); sk_for_each(sk, &hci_sk_list.head) { - bh_lock_sock_nested(sk); + lock_sock(sk); if (hci_pi(sk)->hdev == hdev) { hci_pi(sk)->hdev = NULL; sk->sk_err = EPIPE; @@ -759,7 +759,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) hci_dev_put(hdev); } - bh_unlock_sock(sk); + release_sock(sk); } read_unlock(&hci_sk_list.lock); } -- 2.30.2