Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1006176pxb; Fri, 22 Apr 2022 16:34:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFlewFXWJDbA+8PKgrxMeQHC4spzfstsrzjZrcyozG2vIg+17XgGZot71m/lcihrkuzAz2 X-Received: by 2002:a17:903:32c6:b0:159:118:e12c with SMTP id i6-20020a17090332c600b001590118e12cmr7078647plr.81.1650670462951; Fri, 22 Apr 2022 16:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650670462; cv=none; d=google.com; s=arc-20160816; b=K/sEi3x6DhDUV1xhgkZqCeaKZBhXDJ3JHX0kKXdAtqCOTPvMVFUkVHVAKS/ncRwtBA c0SThb0p+Ebc/H3x741DIZnQJH0nEBkdTv13Mg94U0NUp8Uctw28pDqEE3+Bg8qDPCu1 XGF1mmjehuc6ZYkEOyz1FMcdN+UCO7V4qyA/kOyL5qFO3Lotkhy0YqpW/Q6di7pIy2Ei moqG72LDz8m3L9CECNbDua2ckNAYtuKJeGfB+ma5dyQPKK8fFi58NAoNNFrb+0UnDp4g Dze38Zse/plZsblK8tPSJPK5aD6dVK60wCxbFB4heKLpSD5MFMhGW4jvYQLFyrlpnPSR ORRw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=eHfIxAFqQN61lGS5l7pwUUOsrYG7F+//1ileyJBeizo=; b=NL+faXG5ilc3CwdUdGjRfzGIpY84kfWMs9hDfiC6hZuKAHy/A68NojQMX9oOcUhKOm 5jcj0Qd3DjtxgiMQS3Ryhj2MewwnHywGIbPCKK7hG4WmStVODPmK+8CjjzC4f571wSHL eGnfePlrCLF4MyQBftcaeHKjgsGVC6aYxWrthGADOiwkuAj24LxB1pB9HEpFEXZnN2re CZ2IS+AJKKzZ5FU4qAeE/5C7YCioz0Crr+I1YUzjtmDzpwj0auo+pIUfNBvWi2GG0GAD xhZci5usylTpb5Kmg1gJ9OPbxMu8wmO3/eoRCzi6C8Kb1Yc011eWPzPemEQk4C0FGrcd XP+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZdjJr/jx"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c10-20020a056a00248a00b0050a4154760fsi10462533pfv.99.2022.04.22.16.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20210112 header.b="ZdjJr/jx"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B088B20185; Fri, 22 Apr 2022 16:02:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234126AbiDVXF1 (ORCPT + 99 others); Fri, 22 Apr 2022 19:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234205AbiDVXFJ (ORCPT ); Fri, 22 Apr 2022 19:05:09 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 805EFD95E5 for ; Fri, 22 Apr 2022 15:34:09 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id ks6so18998699ejb.1 for ; Fri, 22 Apr 2022 15:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eHfIxAFqQN61lGS5l7pwUUOsrYG7F+//1ileyJBeizo=; b=ZdjJr/jxili3+imimW4/sFImfb58urLOAQ0p1mf0BseJDxFqSLPBVLIknx8B9+dWeT fcevYTW55XjczS/hVesMxyGNm4lWFoib4Pl8XaCsvk54Brrr1I4+DkvUPcVnGsO1IgX8 MmcQq20Xx7MuITaBp0y011PXB2Heajg94riVzUYCnLYDhmD2ElVGmkGJbBcQJBnA2C5w TrG4MLirDJsXzuNqCpJ8ymMA2DwV1Jn+l7xy02bTT19PnORyFZitU6xbg466QVVdMyBM lPg+BqqWcLKSTJGLD/xUkaB6K+tvoeKKuvkGwkr6rt8tIl8QhRoHxnlpFEan1uXeyZiJ AnIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eHfIxAFqQN61lGS5l7pwUUOsrYG7F+//1ileyJBeizo=; b=ef3fgpc4CkSaCkxCai8108RJCsGlg4bN5lmrHsZ6n/HfZlVqP5V414NnqafY/0Bx1i nVPudL8FHxHuDvnzIJvlen2YPy0DWfFqlefZ73uZalyIcoLiHtTrva3CjtE1rg4TPLDs 3JRrIQKhPKdnURauEAAbLX6KdQkzjUJf5DHY4D88YG1UOZjU41XGYY/8KheikaXPMyRM 4QJc4mxiLUYO2tSUS7vjRg4ILyqgJuPQqPs0/wc5kaRBPaK/2gjuZ+eoLwHTooKw3V3F kgDmYZb0cJKQtJcc5y6oS8t0ZJz99eS88qPTlWgVnJj/J90iR6pM1l5nkl5GJ8U6MpvD OnDA== X-Gm-Message-State: AOAM533dORJA3jzSYy7psbaKp7LNDWFxl1AMlFzBoxTWEx2p4fD7y/i5 elbtNh0BLhjE58AwCYTQGS7LPM9DkPM= X-Received: by 2002:a17:906:4fc3:b0:6e0:66a5:d59c with SMTP id i3-20020a1709064fc300b006e066a5d59cmr5959048ejw.131.1650666847981; Fri, 22 Apr 2022 15:34:07 -0700 (PDT) Received: from nlaptop.localdomain (178-117-137-225.access.telenet.be. [178.117.137.225]) by smtp.gmail.com with ESMTPSA id zk19-20020a17090733d300b006f00e918483sm1137073ejb.84.2022.04.22.15.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:34:07 -0700 (PDT) From: Niels Dossche To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Ankit Navik , Niels Dossche Subject: [PATCH] Bluetooth: protect le accept and resolv lists with hdev->lock Date: Sat, 23 Apr 2022 00:31:17 +0200 Message-Id: <20220422223116.70026-1-dossche.niels@gmail.com> X-Mailer: git-send-email 2.35.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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-bluetooth@vger.kernel.org Concurrent operations from events on le_{accept,resolv}_list are currently unprotected by hdev->lock. Most existing code do already protect the lists with that lock. This can be observed in hci_debugfs and hci_sync. Add the protection for these events too. Fixes: b950aa88638c ("Bluetooth: Add definitions and track LE resolve list modification") Fixes: 0f36b589e4ee ("Bluetooth: Track LE white list modification via HCI commands") Signed-off-by: Niels Dossche --- Note: I am currently working on a static analyser to detect missing locks using type-based static analysis as my master's thesis in order to obtain my master's degree. If you would like to have more details, please let me know. This was a reported case. I manually verified the report by looking at the code, so that I do not send wrong information or patches. After concluding that this seems to be a true positive, I created this patch. This was compile-tested and runtime-tested on x86_64. This issue was found on Linux v5.17.4. net/bluetooth/hci_event.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index abaabfae19cc..f314eb0bf284 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1835,7 +1835,9 @@ static u8 hci_cc_le_clear_accept_list(struct hci_dev *hdev, void *data, if (rp->status) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_clear(&hdev->le_accept_list); + hci_dev_unlock(hdev); return rp->status; } @@ -1855,8 +1857,10 @@ static u8 hci_cc_le_add_to_accept_list(struct hci_dev *hdev, void *data, if (!sent) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr, sent->bdaddr_type); + hci_dev_unlock(hdev); return rp->status; } @@ -1876,8 +1880,10 @@ static u8 hci_cc_le_del_from_accept_list(struct hci_dev *hdev, void *data, if (!sent) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr, sent->bdaddr_type); + hci_dev_unlock(hdev); return rp->status; } @@ -1949,9 +1955,11 @@ static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data, if (!sent) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr, sent->bdaddr_type, sent->peer_irk, sent->local_irk); + hci_dev_unlock(hdev); return rp->status; } @@ -1971,8 +1979,10 @@ static u8 hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, void *data, if (!sent) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr, sent->bdaddr_type); + hci_dev_unlock(hdev); return rp->status; } @@ -1987,7 +1997,9 @@ static u8 hci_cc_le_clear_resolv_list(struct hci_dev *hdev, void *data, if (rp->status) return rp->status; + hci_dev_lock(hdev); hci_bdaddr_list_clear(&hdev->le_resolv_list); + hci_dev_unlock(hdev); return rp->status; } -- 2.35.2