Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4820131pxj; Wed, 9 Jun 2021 02:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1AQKvYfhqm8VrSwxrzqEWDH8g5jLA8NH3IAwvjmNCp7o2E9ZxNO9vyrG8WvpPjBNvbFIw X-Received: by 2002:a17:90a:5a4c:: with SMTP id m12mr7241723pji.229.1623231547496; Wed, 09 Jun 2021 02:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623231547; cv=none; d=google.com; s=arc-20160816; b=MrUZP2fNseP6285FaVIHJ+UwtqhWMKab6nQVwov0ykSVEXeyjw3x7LJP+a7JGlOE3y cGRzctlzFFoxpoPAKCHh9UYMk7kND0WkDHqyo5XRi0gpO+tfoVxY0oNTWoV2la0QXISI KtrIuPF06v9c1rZZdykgJzabJu3dEgQbdTeETZE7NWpclJ6zwOhezj7jPJzizfZK9sPd Y3mBLCpNGMPcWR+Dcm0QOKjj4JyONu3F1S5kZRpFC1ABOUy+ksYKg3JLtXQlwzFP0L4M JybTL70lIXNOS/7nlqukPKf+pwah+TeNGaynbnCEurpywVudia7Fk10T+yx1/IP/k5Y+ vYWw== 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=Iv+T7/1UccR0fnv4vX4w0MgrrhcgF/IupgqKg/OftSM=; b=RlHA1Al0e7/+03oYV1TcZxuJyJU9ZywB0iO6FQ2RP4HW+cU7gvvLA21bpgD99zi8PI fv/IgidlHUSmwQXyWG2I03kewfXzzk0/ZnJlTdtSAodK4K1/JE1KsMTSBPe8nkw+E+XZ egpXHfCH5dEHqB5u0SnndYWoGA3qnUt0ISsEqRTcQmQV0QT3rSE8IHIitAEGTL33orCQ Sngr9eQgq1whBih936YX0WDpOiJ5vo4I/sqCV3kh3TBfEjPGduYsHsUZ0IVB7q4MGxhF FZW3/h6WCax93TT2/62hr/jUr9N9Ya8TKhUUkqVOE9yFDOapzv3QMY+w2npu5xVwHk2z wLsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SpXH2Dyy; 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 oj12si6006282pjb.25.2021.06.09.02.38.54; Wed, 09 Jun 2021 02:39:07 -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=SpXH2Dyy; 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 S234537AbhFHSgt (ORCPT + 99 others); Tue, 8 Jun 2021 14:36:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:57916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234573AbhFHSex (ORCPT ); Tue, 8 Jun 2021 14:34:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8EBA613D2; Tue, 8 Jun 2021 18:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177123; bh=EHZJLvG/aunoeWaZiHpji8erF1KoKgD/dmIWqn/lG2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SpXH2DyyAs5vPPo2aro3gtTyCx0+8PKqZKnr6DjWWjou2GtaA5Al5SnGo+B8hPusx 14BjwB+aLfiFH6GwBUgJ02rnKNXw+XKwssWzIfFNQtwG90Dl81UQ4Mum94U2a4OLSE bbZ69uDYIC1YADNHM9HY0tpfmKwB+wohCce63bpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Ma , Marcel Holtmann Subject: [PATCH 4.14 14/47] Bluetooth: use correct lock to prevent UAF of hdev object Date: Tue, 8 Jun 2021 20:26:57 +0200 Message-Id: <20210608175930.951544948@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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 @@ -750,7 +750,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; @@ -759,7 +759,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); }