Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22922050rwd; Fri, 30 Jun 2023 14:55:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6DkW0RydXn9ZzRRygEmQtA26UYxYgZX0Q62A46HyLzeRK+t2ox3iP051NnmKYFo2gJM9A X-Received: by 2002:a05:6a00:182a:b0:666:ae6b:c476 with SMTP id y42-20020a056a00182a00b00666ae6bc476mr4691107pfa.25.1688162133087; Fri, 30 Jun 2023 14:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688162133; cv=none; d=google.com; s=arc-20160816; b=uX1d8oEPGlRdqiB7brYF81OYZ70iEs6NbX5mnq7PHPWZ8qvWz3nvrdPTgjdNdjgORK 4Lw3xm1wU28bQndgNDCheGJKDBzUi7r/FJCs+UpU/b7q9rMny0Od3axg9K2XtjSu+r+0 ooDhqgilaKMsa7UV7xpm19aXfl6JCkRm/dleiOWaAv9I9IgxP/F1jdqDKvrgGL/2DeGT iVmh3gj1/2RmgEju+BG/R3Er/GQbWogoapwexwuLddKV7YTcHnzlJI4S34lfjS9bO2WR mBCFyxBoID4ujZZ14D4w/QzRMUGZv+Aslz8tnDmt58p9chya3o+Nc4BpO5v4CLI5gMvM i3zA== 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=7Cg9zB1fXkpk+7GpB/Svxkl6enKDK8Dwoq2y9kTCjIA=; fh=60tGFC72lEsfjbN6e3AcXrRl0Hn4cz3CZzXi4n3bLI0=; b=Mu9iIMUaTUayWkK9YCqbuk+OYINJkVZFr2Hs5JMXY9kSqtcE+lomMkhRund5PbvxPD cQlGNwe3H/PdqLMlTCyvlTT0uDeAcwOI3Q9znSyD5Sr/o4nQoZgoHcPgWBsWjNF2GJ9R z8cuhlwFGHhEp3rokykYFHGCxorQHrSI91v8v8tn0HjeGXwPGYcA9+/5ohfqsbjannvH fFd1pmUzzs6LOFHjhWEDgmBVpbXFNHbdtJ2EVCXSIn9hEkadjfx8NqySPTa8pGC6fTFX 53AyzZfvaMMbGZV5ero3ygbU8+41URuJ30NqST6HsguNwNGG+VAzOv7KLzQv6U3ZQg+W QkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oFavwefy; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a056a00148800b0067b51fca490si9014515pfu.248.2023.06.30.14.55.06; Fri, 30 Jun 2023 14:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oFavwefy; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232435AbjF3Vk6 (ORCPT + 99 others); Fri, 30 Jun 2023 17:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232599AbjF3Vkv (ORCPT ); Fri, 30 Jun 2023 17:40:51 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334DF3A87 for ; Fri, 30 Jun 2023 14:40:50 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1b078b34df5so2187091fac.2 for ; Fri, 30 Jun 2023 14:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688161249; x=1690753249; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7Cg9zB1fXkpk+7GpB/Svxkl6enKDK8Dwoq2y9kTCjIA=; b=oFavwefyLR9wVs3hmLyB5TX6tYYx6yw96aWF5BCuMXqpto5h1lLwIe1nty1LMcFyYW 2R0z9JLTeXyR6sb0i3kCQ77dHdcvLctI14pOhwvH5vKxwf0yEeay55z5MfhdIMf36/8I B1mhF+5WUXgVZebJTYgGdGTWGS8+sxqtHgCOo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688161249; x=1690753249; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7Cg9zB1fXkpk+7GpB/Svxkl6enKDK8Dwoq2y9kTCjIA=; b=THrwiz8wHMhEG6X8w3lcg+DnYJHTuFbvtjarcqdPzULywIIhdUcljXqyFEEN10w4s0 VZ8HcuVFHDyfdKAHC4HgWc8iEAO0amgAlVNcnfbY0iX3vMzuOFq+yPVNhtLrDriPqNuw YW1f42hMEPGO5Q4jmh3TJmQgimfQpnNbYL2DAKDj9vmyN2bWgBxZR12dsOftANGXNFkF P05a8coqEPud4Q1hntLz33z8+hLbj3WrdUHHSdM8WMm1TgfYR4p3JQ20zR4pxh3HXSUU WBLbfS+RAMgFbMWeW1QshfZWk/kU7ZV05ZJvsQKkM5P7hAjcxhDx/UxpDmJ2ryKBvOll ro0A== X-Gm-Message-State: ABy/qLZlGx4djZBBaHMRimwKWEnplSgoRfBzxGhoklkFr0/D9cr8sNZE b60zkwHT/NPeAVkKRnf5WzPBOxAhnnevBFrixyTYvw== X-Received: by 2002:a05:6871:822:b0:1a3:1cb3:37e9 with SMTP id q34-20020a056871082200b001a31cb337e9mr5354026oap.4.1688161249516; Fri, 30 Jun 2023 14:40:49 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:e9c4:8375:7234:e6c2]) by smtp.gmail.com with ESMTPSA id v8-20020a17090ad58800b00256a4d59bfasm12916841pju.23.2023.06.30.14.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 14:40:48 -0700 (PDT) From: Douglas Anderson To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Stephen Boyd , Douglas Anderson , Manish Mandlik , Miao-chen Chou , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor() Date: Fri, 30 Jun 2023 14:31:27 -0700 Message-ID: <20230630143125.1.I3b7c8905728f3124576361ca35ed28e37f12f5d1@changeid> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-bluetooth@vger.kernel.org KASAN reports that there's a use-after-free in hci_remove_adv_monitor(). Trawling through the disassembly, you can see that the complaint is from the access in bt_dev_dbg() under the HCI_ADV_MONITOR_EXT_MSFT case. The problem case happens because msft_remove_monitor() can end up freeing the monitor structure. Specifically: hci_remove_adv_monitor() -> msft_remove_monitor() -> msft_remove_monitor_sync() -> msft_le_cancel_monitor_advertisement_cb() -> hci_free_adv_monitor() Let's fix the problem by just stashing the relevant data when it's still valid. Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") Signed-off-by: Douglas Anderson --- net/bluetooth/hci_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 48917c68358d..dbb2043a9112 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1972,6 +1972,7 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) { int status = 0; + int handle; switch (hci_get_adv_monitor_offload_ext(hdev)) { case HCI_ADV_MONITOR_EXT_NONE: /* also goes here when powered off */ @@ -1980,9 +1981,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, goto free_monitor; case HCI_ADV_MONITOR_EXT_MSFT: + handle = monitor->handle; status = msft_remove_monitor(hdev, monitor); bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", - hdev->name, monitor->handle, status); + hdev->name, handle, status); break; } -- 2.41.0.255.g8b1d071c50-goog