Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4822889pxj; Wed, 9 Jun 2021 02:44:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylNz8LrxtkfDzuwsvznwEX1Qy+6Zg47VmOYY5MbLvUQTDI0btdna+r5VNhqjhtiYO0rU5m X-Received: by 2002:a6b:630c:: with SMTP id p12mr22287748iog.124.1623231840820; Wed, 09 Jun 2021 02:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623231840; cv=none; d=google.com; s=arc-20160816; b=Bh6MEs/5mWS9o2qjjNOXuAOA9n9PnDev7xt8IHHRXc+Vovm6VkX6EOEnx+gx/HCy92 R/Yv5Un3Xy1n5WSuQCFpcOns82fNy/zu9egvR1iGxWFE8+L1jaxqk3bnSA7SXm25akL6 3S5bQDaO/vFte1mROZW7LLxr2UWUn8X2n37KC3vBAqR6b4qExvhWcxyP8pl44CPmn23q q70AW6hG1oZi+efVXktipL7SFOqqY5pQvgkL0panUinaVT/r+NEjgx4oWbE/5c0yTccl k2WPch3QQKJGKlU0ZbyZGa6AFkZRj3EdP9RoGSScozrYI4FywLcPSdfLA3EEx44cdu4j XI3Q== 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=OjHOWd4lZtdUlJqFWR917zaad3GeCawHtkefGIOL6OJ2W0Mh123IONoImxZWfml0HR a+9N9r2ZUblWqgvIGdnfC1a8nOh5/tYfDw3tvJj3+4wAb/pM6+h7wpaML0XqXmLJAvXq nQ8HMSAiecf1mjS2DAHYFEhOQjtD+PkTn1WSV03Ij9wdf4LgL3/5W1dIcCQnrLnwwmmE UJU6fcRrg5/v9wNE/9iuy2zOS2UPzsnt31tpp+KpSzj0tAZwGApi1ndGHfS18xCLy2TX ZEEXkUw2JbGJYunG6mXlQVhBb4pUsV542ARQqvtUJN6OTeayObe5/aU0bkYGjs0ycndc pfXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z72rvcuo; 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 a7si2689321ilr.20.2021.06.09.02.43.49; Wed, 09 Jun 2021 02:44:00 -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=Z72rvcuo; 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 S235181AbhFHSlx (ORCPT + 99 others); Tue, 8 Jun 2021 14:41:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:36164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234950AbhFHSh1 (ORCPT ); Tue, 8 Jun 2021 14:37:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8AC5F6140C; Tue, 8 Jun 2021 18:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177191; bh=9b4TT9IQSDNwMwIJyDMC05NcS5dkRU56xlqceDCnJVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z72rvcuoyR1PkhMnybwntlsEZqx/l5JCdTHDv+zwAthid1TRNjVdGXR8YCwsBTN5Q Lamy8PlzJRxUxD/+dXxINCAKpRMn/1jwg3BwTIHYnkNsker5LXdRtGSwWfoZOjeGvg kV7Wej24iN3tIg9hq1M6jyLB3zbNrZX7QMfDoOQA= 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.19 20/58] Bluetooth: use correct lock to prevent UAF of hdev object Date: Tue, 8 Jun 2021 20:27:01 +0200 Message-Id: <20210608175932.948149634@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175932.263480586@linuxfoundation.org> References: <20210608175932.263480586@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); }