Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4340295pxj; Tue, 8 Jun 2021 11:55:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRKbYGvgvVmkYm5A7bl24SkovbgYHkqv83TA3XoOhRGUtOXdgh3VQWhkKx2eaz+JdpzzZH X-Received: by 2002:a05:6402:177a:: with SMTP id da26mr27185349edb.40.1623178543803; Tue, 08 Jun 2021 11:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623178543; cv=none; d=google.com; s=arc-20160816; b=wnLF4RpFKGc92jixLGElXNFNejZC+aDgv7KXTUttnw6rz657f2lUzRaXfitM8buEiz HC1AWxOD7GcDx+pOkJF1ob48D/EZNMN+mUlcYu9jMURlFuIFzsHWmFWc9M0Aczvkcp38 ifJQ5D5xBUkeoK9jTJZPZYjK61RXyqjxzt2WHPq817CwDb02/ZHRH42ifyvbCmyGyHGl gf2cPo7V7kYww0FGxbaXgPQDluWNEZgrNVaUbl3qWK5FF6KsE14xln7hLuvehUQtjbC3 HxGVstOrMxLPLHSEwHmiLVptstoNBVCFjJznrW5K+MyQ0We47R8dVA1wh/C0TTXl2QLL 3dkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7A8K+wF3I09LDVZ1IdSngY2FNu/ZUvAD/i5XJ2V9duI=; b=bEXZig4ecqPrxTQPY4UYGbhjKXZW7OO7AyrNH5seg+Nu72uInLdA5XtB4Dy7Ux7sdF +/R1HfVAS+GobfK1N1ix2FZQYRJcfpFw2L1D9aj71JXqhY/Y4NWwXVk9E6LQnYZ7yHlz dLK9ZAbF89Tpkx5ThifYKOvIauWy5MFfP+aiVEl6qunYmvz2X3rA75zQy0dSHekq5AGW yQ+Edm1qQv6FZyg8eOHZZkpbSX8EISLqYYF80/NtcZ3rljHgRLdNFO/ktLL9MDtpBWPe sxxL0/psVqcjkr7ixEKpxz3DijzB4qT24ydpfGdxJU8Hh4RuFzLce7ZmaLDw24pAJite e9+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zwGpHr4r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f7si439346edd.502.2021.06.08.11.55.20; Tue, 08 Jun 2021 11:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zwGpHr4r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236255AbhFHSyB (ORCPT + 99 others); Tue, 8 Jun 2021 14:54:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:44790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235186AbhFHSsA (ORCPT ); Tue, 8 Jun 2021 14:48:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5FC161416; Tue, 8 Jun 2021 18:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177498; bh=9b4TT9IQSDNwMwIJyDMC05NcS5dkRU56xlqceDCnJVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zwGpHr4rLb2K7IXu1FVZ0EFmkI9VlNbZmUi3T2ISdyMrCHTVSce4FExe9s880eiGK 5dEhDvFbr4k3h9EytM1L760Y0X9LRv70zRlkqtWNUgRw0QTbDp4hNCbDN/lTeVwU9d K3ETEXPbSfQCZ2edIZL3fFFyVo9G3YKNSjDtEao8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Ma , Marcel Holtmann Subject: [PATCH 5.4 39/78] Bluetooth: use correct lock to prevent UAF of hdev object Date: Tue, 8 Jun 2021 20:27:08 +0200 Message-Id: <20210608175936.584233292@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lin Ma commit e305509e678b3a4af2b3cfd410f409f7cdaabb52 upstream. 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: Greg Kroah-Hartman --- net/bluetooth/hci_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -755,7 +755,7 @@ void hci_sock_dev_event(struct hci_dev * /* 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 * hci_dev_put(hdev); } - bh_unlock_sock(sk); + release_sock(sk); } read_unlock(&hci_sk_list.lock); }