Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2266843iof; Wed, 8 Jun 2022 00:55:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm2j0ra1tjY7/S7bWSaJ5cSQlNd/amCOi4qeXi6BHfpWTN/O9j8hhL27GzM4MlBvk2M+l4 X-Received: by 2002:a63:ea06:0:b0:3fd:a385:a856 with SMTP id c6-20020a63ea06000000b003fda385a856mr14121561pgi.393.1654674933501; Wed, 08 Jun 2022 00:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654674933; cv=none; d=google.com; s=arc-20160816; b=FyLgiK2vxNxG1Y5Gm/bmFTB05pFilEBM1XotUmOvnHs3tKfbAdeuj8Bde/rEW2EBCB orO+xnZ/aF3mbyFraJ92L6U/SkJEmfV8c5co3M9xzeEed+W9NEOAm/ldorEG4XMdC8G6 kGj0b397/XFgJ4hUJ25D6eEU+O3f+bNcbqvqtXtbhaKyUKiEqfEdAiYGMJj60+drousp s94gNMxN+3xPGCKAol/n5EfGrv4d67tK/60ItCQNOstu2D5X0syon+DOwRQ7VQKtoLry cgAjd80qsUWkm3YV6hvNt7nc5yPKJF0FbFMpQRBgm2RokllM4gA45Ot1jbVE6y1btZic fCoA== 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=NYHU8Y9D8xtMQmPTX62I+0yMRn9fzcY9UuEPTh5o5bs=; b=nrUs5TkRmQwuoLh03oMDmSoRRV8Jf/+kUCDVHLj7vLMegUyrLYZa52nHxHdmqRDWXe TVNHETXMTI/6Ov5ITu+NPzwJk5+Y57BYBvaBX44SO17U7SqhPpd9HmHZfPSHgsXap8yI ldJvmtFverwbDPF2Ori+11+BUGgbD84SNiIlqe53V8z33+0GPTlsbfoIxPP5FB06OseN 2s9Bx92L4mUR0mObLC24Pd9kkpB1+3LWY+XcKnzEpMbG/0Tz8gaZmD+DiF1Xhp/C4vaS whKiOossthFFENxSpRHCIXHPf83M3Q9wJxIiYEQ0JvhkmxcHnmXtUepNgPt8Ef6oYJ++ q1vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pbD0MHil; 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 y73-20020a638a4c000000b003fa4f55c763si26451460pgd.776.2022.06.08.00.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 00:55:33 -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=pbD0MHil; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67AAF1DD4C3; Wed, 8 Jun 2022 00:24:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386801AbiFGWt2 (ORCPT + 99 others); Tue, 7 Jun 2022 18:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381302AbiFGVk0 (ORCPT ); Tue, 7 Jun 2022 17:40:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07B272218B7; Tue, 7 Jun 2022 12:06:31 -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 A5360B822C0; Tue, 7 Jun 2022 19:06:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01947C385A2; Tue, 7 Jun 2022 19:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628788; bh=ij/4hImqJWkFdktGF0byICBrtQSl52EtTpSPV326/W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pbD0MHilah+LAGYx7JEivV/ObuZZUWUDrGOclS35aeiXjDddj6vQHEdtxxb1JtpT5 OD47yjfyxWVZTwGnX/PuTonTP8BIk0biuFtqFXOaq4MKeXqs82X6u5JFlo+ghBEEQf 6h0acvOj8de4+jdk4EB3v9ua9OexPCsvnGLG8vAg= 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.18 454/879] Bluetooth: use hdev lock for accept_list and reject_list in conn req Date: Tue, 7 Jun 2022 18:59:32 +0200 Message-Id: <20220607165016.048605042@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 66451661283c..a835ce6f8430 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3225,10 +3225,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data, 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 @@ -3240,13 +3242,11 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data, !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); @@ -3258,8 +3258,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data, HCI_ROLE_SLAVE); if (!conn) { bt_dev_err(hdev, "no memory for new connection"); - hci_dev_unlock(hdev); - return; + goto unlock; } } @@ -3299,6 +3298,10 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data, 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