Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2159771iof; Tue, 7 Jun 2022 21:44:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG7tUrf1+5GFXRgbLKRIHPL6cK+2hyKbBnZX9289eb2EZutYiIlhRwAKxSrc2BrkvXHdBJ X-Received: by 2002:a17:902:a418:b0:161:f216:4f49 with SMTP id p24-20020a170902a41800b00161f2164f49mr32324104plq.129.1654663498140; Tue, 07 Jun 2022 21:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663498; cv=none; d=google.com; s=arc-20160816; b=FT1n4u4IzVKQlCEZPV7z+hy74eforORonEf18LlPBIJpBZOy9ZDGLqhK4nC6lgjVpE BaO0/QrI4hxS/jO4SAf/w5w6agEppHy/NELxBcWEEA/7K5236S3GFvuTfsNDeSbOsKaQ FxDpzFSmhmHz2GivFK1mZtFRP8IdP7W5BtykeKe9Flf6qeP4zqXPUwquhbbcf39FUwkt B03qad33G3xpdkay1dWFEpAyF454TdwjnVSbHeYd4dViZysvo8OX96g8Z1jtWCnQznyI ocWX1baNeDz7XUp3YkstTPUIXWcnaTxLhNQpltDU5Q1kG2+YR/fAln/ZYqzyjrczQhhW b2rA== 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=FysbmOo0xkFM3JaeJMRFLW/nRKb4V+KyA5Pd+FdpZBw=; b=hG9OXEXHVFkZSEWLCHWY4Jb0ROiBXKsyMPYKyBmR3irxqYG5abanZFmUGlemMe5pIb gyItx79ofZFG8UE05q/OneNbL6vdbnpJVF1cqQOCtwVYP5azBYGsJyO8CWc+IjnOie3l RW6iHAss7T2z9dBQ3sDkgWZHjVfaM536W4QcSy/Mvqzlrtukh+1QToOLYz/nWPTEGr9Y Dxed1ZBi81SM+KrH8GDI6hCzvlWGGRpfqCD1e9dto1nP0cXTTTJA7NTcS4q8fCR72rqa vfEzKBjQcppFH6Z59C/JfZUkpxj4X/k05vq8KO4W4yRn1BIbGR24vYGy/+hEFguFAno0 SS4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g4TCu+7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n20-20020a17090aab9400b001cb6940edb6si24957096pjq.13.2022.06.07.21.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:44:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g4TCu+7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31B3745619C; Tue, 7 Jun 2022 21:22:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343493AbiFGRmY (ORCPT + 99 others); Tue, 7 Jun 2022 13:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347750AbiFGRbC (ORCPT ); Tue, 7 Jun 2022 13:31:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A2D11B696; Tue, 7 Jun 2022 10:28:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7282FB82285; Tue, 7 Jun 2022 17:28:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC875C385A5; Tue, 7 Jun 2022 17:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622894; bh=oO4LYSgGxXdMf4Wf1lkUNBzkU4g7sGH0x1F5PBK5a5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g4TCu+7uki6VKRtfZCLgVtc54lAuqkPnrKPkpC7NUaL/feb9497PfWkKG6LRnpbUu osWmBFGsPaP+UmmNfBJMDzC2eL9ZXsPCZkrFE6mL06OVIfItPsUD9et8+Twik4yfjr 7wCbQEQ3RpOmgJuKaXip4cRr8nirCbF0LRSQD3tU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niels Dossche , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.10 221/452] Bluetooth: use hdev lock for accept_list and reject_list in conn req Date: Tue, 7 Jun 2022 19:01:18 +0200 Message-Id: <20220607164915.147931627@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niels Dossche [ Upstream commit fb048cae51bacdfbbda2954af3c213fdb1d484f4 ] All accesses (both reads and modifications) to hdev->{accept,reject}_list are protected by hdev lock, except the ones in hci_conn_request_evt. This can cause a race condition in the form of a list corruption. The solution is to protect these lists in hci_conn_request_evt as well. I was unable to find the exact commit that introduced the issue for the reject list, I was only able to find it for the accept list. Fixes: a55bd29d5227 ("Bluetooth: Add white list lookup for incoming connection requests") Signed-off-by: Niels Dossche Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_event.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index f75869835e3e..954b29605c94 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2709,10 +2709,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) return; } + hci_dev_lock(hdev); + if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr, BDADDR_BREDR)) { hci_reject_conn(hdev, &ev->bdaddr); - return; + goto unlock; } /* Require HCI_CONNECTABLE or an accept list entry to accept the @@ -2724,13 +2726,11 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) !hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr, BDADDR_BREDR)) { hci_reject_conn(hdev, &ev->bdaddr); - return; + goto unlock; } /* Connection accepted */ - hci_dev_lock(hdev); - ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); if (ie) memcpy(ie->data.dev_class, ev->dev_class, 3); @@ -2742,8 +2742,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) HCI_ROLE_SLAVE); if (!conn) { bt_dev_err(hdev, "no memory for new connection"); - hci_dev_unlock(hdev); - return; + goto unlock; } } @@ -2783,6 +2782,10 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) conn->state = BT_CONNECT2; hci_connect_cfm(conn, 0); } + + return; +unlock: + hci_dev_unlock(hdev); } static u8 hci_to_mgmt_reason(u8 err) -- 2.35.1