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 C4696C47094 for ; Mon, 7 Jun 2021 16:22:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB5E060FE5 for ; Mon, 7 Jun 2021 16:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233507AbhFGQXu (ORCPT ); Mon, 7 Jun 2021 12:23:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:60486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233180AbhFGQUs (ORCPT ); Mon, 7 Jun 2021 12:20:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08A8961442; Mon, 7 Jun 2021 16:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623082501; bh=OyTJLTSEgoLMdac8dhGMhwVLIYqzC3ei+mTLxQ6eDD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mcno7Ntvk9jOtuxQw8KLgsfKt9xxug89iNNU2V/OBDErOit2IPgJ71RyEO7TxuUGW N4+N74FOl5B8lxUluSy/K+U1EV7PWJGGf9IMuwGLiU4WsnIdmsweiUfsKtSzrNqydU ZlQXNrOKn7TAMawrwm5UvU3e/0brPbDEufOS7JZaxt8cu2cUez3+aXq4w8lj3bLLzl XMzA+1k8z3cBwfoob5OzrztI/3PL7+8ihzA8EvOYwDqy+5/c4B5HULe8Hy6NC7l2gm +9OeO5kQltxtEZSpoqLzNkbJat9o+sT9Ndn7lQXCmDvztrhtvWUez+UsQbPx3DqImp 97l6IeZ5S/pyg== 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.19 10/21] Bluetooth: use correct lock to prevent UAF of hdev object Date: Mon, 7 Jun 2021 12:14:37 -0400 Message-Id: <20210607161448.3584332-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210607161448.3584332-1-sashal@kernel.org> References: <20210607161448.3584332-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 e506c51ff765..06156de24c50 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -755,7 +755,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; @@ -764,7 +764,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