From patchwork Fri Jun 30 22:09:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 114905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10690959vqr; Fri, 30 Jun 2023 15:16:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlG33Jz+oAR7Ccbg6G6tqKdE/k1DGySXoS7WUK6sSgoX0hYLuB8EoXiZz1o6ZGKNCJdpIPqO X-Received: by 2002:a17:90a:ac01:b0:263:70d5:6d60 with SMTP id o1-20020a17090aac0100b0026370d56d60mr2726552pjq.30.1688163414216; Fri, 30 Jun 2023 15:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688163414; cv=none; d=google.com; s=arc-20160816; b=nRqs//ehlDmku73WTGr60B/ry3Ab269z2DkA0PrjTp6xMB7J8uLdIEgiZ8P7vwzOYp bHnhMLH3G6IEsqUa2EcFlZqszi8ZzH4Lw9skTXBTOdqpnOa/EXQJ84e5gYL8nWY6lRW4 QwGhPtLYsmyTEdv/OZPgztEp6N2ufQWOProe4knZqIzmIZCEZ5xVJ/T4cFHZ3mrCgLGn pNxopoPW9CAYq4HGk7So7x2+fwGHqS/5chX+lZmTYknBvr8Rctj5lzsET4vOnNSDFqjt 8G4VpttkjgRkHf5bP8ilJ+tEwdGl9ZEZcjJ5FS5/jTbIFytJP9SCVN/g9F9Q2PQ6EAph WGjA== 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=wJ7kxnAKg6Cu8Pu7Voq9nKWydDnN6Tk0Ch2JNhThoso=; fh=60tGFC72lEsfjbN6e3AcXrRl0Hn4cz3CZzXi4n3bLI0=; b=aSTJGxQ4yGAsuEV4mLSJ24MhF4BeGXVKgBZsUH1+ub4+UlGEgfIIWlGIZ13ce9uk/9 XLhpsM36VSNU3iF74pR9gIqF+9SFuQBbH+ia3m1yha2pgu7Ax89qai2l6KlquspG3o4s F9YMr/QLREiOyAnX3V1Cf4FGuPXPFx5xOi1sQEF2swoejxg0g4WIerqI0m66pkdarJPJ MZGwyGIBkENwsNNrMWgVhG82Szu0C+nNK/9KMD64MpPmJa6im3xQh4rJxqxTA8d1iJkH Sk9MYBO2zEcf8Hj9uytbIkoGFcp8h4U9Kbum/NQXk+rfOZiSZX+4usNm3dZbVRQjdWEq Gz4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aGkPwnLn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a64-20020a639043000000b005538aedccecsi13990970pge.565.2023.06.30.15.16.38; Fri, 30 Jun 2023 15:16:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=aGkPwnLn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S230054AbjF3WKW (ORCPT + 99 others); Fri, 30 Jun 2023 18:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjF3WKV (ORCPT ); Fri, 30 Jun 2023 18:10:21 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 651383C22 for ; Fri, 30 Jun 2023 15:10:19 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-55adfa72d3fso1310486a12.3 for ; Fri, 30 Jun 2023 15:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688163019; x=1690755019; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wJ7kxnAKg6Cu8Pu7Voq9nKWydDnN6Tk0Ch2JNhThoso=; b=aGkPwnLnHayzjcvlPC0S/w8My+uR91LuCAWSxVO4ashAxJ1pmhX/Ebg1wreE5baRh9 ipTQHJK80q1LmoGv4y1dxVHl+x0VkLHjPDlqiD2UnPcXgDWjMXGVQB0KbU1+rBZEHA66 NtBF7MwzFRdjHIb4vortgyayAbaOd2zEvjC9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688163019; x=1690755019; 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=wJ7kxnAKg6Cu8Pu7Voq9nKWydDnN6Tk0Ch2JNhThoso=; b=PzEYe3039sDfXNFqGHyElU/wJCzDNcqPRyCja1BI7OnQC0BR/LJOhqGSaEMr91uNgy PF9fkwg/TlexgvgfeGyz945QTAkQtMadW3CcvTFqjTbLuGo9M7qVOe8S8/9n07b6Kxwc K7REaBVB8mXCFk/7iLo0yWT20WjOKojpK+Tzr553ufEg6/G+DDjJrIqIpcrtu3iM3AWa +yjyKgrMS/S2ymQjO7W6rdBoWN28gcBTKLbmWSPXms0KCIXUCFeYkm82EW1XBR0SSELf vgU1+MUBfLA0x3B9mJbhWlYnlTYgns1h+9O/8yRu4BMIl3n+CIvcYzPEbQ7+r2/hC6Ny colg== X-Gm-Message-State: AC+VfDxmXgO5ey+jUNi/gHzGR+ba3eimLOyy+Egiz/8npG7/jQdkVVgU 97cR8nl6qnU2VTqmj5GZVH2QHg== X-Received: by 2002:a05:6a20:b711:b0:12c:7528:d981 with SMTP id fg17-20020a056a20b71100b0012c7528d981mr2972407pzb.18.1688163018835; Fri, 30 Jun 2023 15:10:18 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:e9c4:8375:7234:e6c2]) by smtp.gmail.com with ESMTPSA id q3-20020a17090311c300b001ac897026cesm11238797plh.102.2023.06.30.15.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 15:10:18 -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 v2 1/2] Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor() Date: Fri, 30 Jun 2023 15:09:06 -0700 Message-ID: <20230630150906.v2.1.I3b7c8905728f3124576361ca35ed28e37f12f5d1@changeid> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 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=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770167640398772644?= X-GMAIL-MSGID: =?utf-8?q?1770167640398772644?= 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() Moving the printout to before the memory is freed. Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") Signed-off-by: Douglas Anderson --- Changes in v2: - Move the print, don't stash handle in a local. net/bluetooth/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 48917c68358d..7e2ecf8a55d8 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1980,9 +1980,9 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, goto free_monitor; case HCI_ADV_MONITOR_EXT_MSFT: - status = msft_remove_monitor(hdev, monitor); bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", hdev->name, monitor->handle, status); + status = msft_remove_monitor(hdev, monitor); break; } From patchwork Fri Jun 30 22:09:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 114906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10691281vqr; Fri, 30 Jun 2023 15:17:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFBhyOS/5TH0hML6MKV8GRB/kwI9F6WWMwEPRAe+VocPxFSTynILSiI26Xeh4kvag3Ho4w+ X-Received: by 2002:a17:90b:20e:b0:263:730b:f562 with SMTP id fy14-20020a17090b020e00b00263730bf562mr3584572pjb.11.1688163455042; Fri, 30 Jun 2023 15:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688163455; cv=none; d=google.com; s=arc-20160816; b=isAtjOJi06ZNbLfraWqaWpnUguDvDRDgrka0SEgTotZR5ZNHGuOV6MeXu2DMKnU8UC txaE3D7RWPEmK8h9Cs4aJ87zRG26YKwzXchfuAxBImx7fPFe3vfz74ZF/MFdZodsYIIc UTOjxuTWgStkH7oiktYoBYBGBBh4xTG9pE+sNf4fwcBNu4W4vptPfdjrFB3xG+WF3DzT gy5idawXVsOJQOfNDa4Wi31cyKd+jygX6H+JDNcdpTTW7h4UPNX/cftqCltmLiHT2tCD C0Och2Tnqqi4Jra+pSDydDRYr6/65PDuoKlmjNG/+QZIK3EA7QPlC2GDtrNAZm5eLHUH qBng== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HaAN0G7fwCuNl5CzPxOPdbGCqVfxseZDjS8aC/Jsx3Y=; fh=SQljAXgUV5jhA9EE8xL7/thT6xIi1kqlJVG0bNl7NtQ=; b=nM+MOuP7xDPr85MNm2BOkDJSjqbEZXJFN25N6rL13JzQvagKuusXlwVSKqbhH8SZcZ yTtbwLab6LkgDLJgVWIDeD6KO/chan5/9yuyJ5uje882okBRngke1Nh+AEJ/F9eQevob SjL6da4E4A/cRe2CzYsVpt27FLm9vl8721+ZVEobDbzpvqZwrM5jn/ggbq6WyXK063SR Kut8oNne1SqpmixjV9lWG+VFmZ88K+KOPv5YasneFZO8GagsEVMLKHo5RskvJhGpVxvM QN2RqSc+vnzNjedkPTmLDuFzSQqC4sCVfAFLulVTuoqIBb+MCj4pcUDvJAiGocnq1TTD hUfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=e3P4cQ8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 15-20020a17090a198f00b00250331e6044si7075452pji.25.2023.06.30.15.17.20; Fri, 30 Jun 2023 15:17:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=e3P4cQ8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S231844AbjF3WK0 (ORCPT + 99 others); Fri, 30 Jun 2023 18:10:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbjF3WKW (ORCPT ); Fri, 30 Jun 2023 18:10:22 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5FB420E for ; Fri, 30 Jun 2023 15:10:20 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b8054180acso17906615ad.1 for ; Fri, 30 Jun 2023 15:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688163020; x=1690755020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HaAN0G7fwCuNl5CzPxOPdbGCqVfxseZDjS8aC/Jsx3Y=; b=e3P4cQ8hu7ahgxfyUOoSkEIYQdlx2lHHDXZTEEP32jHHZTvBd6yXMb3tZ1VNAewpvb e+LkTlfonZstm3DdWuKP4h2Pjtv7qPH3Ha539VoU8zZSfg6sF9yE62h76pewy3hEpQfq 9IvjY5xDP+Cdjy/gkQeFL7D7so60UlGTKUe8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688163020; x=1690755020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HaAN0G7fwCuNl5CzPxOPdbGCqVfxseZDjS8aC/Jsx3Y=; b=h944wOjjG5IDplqm8n7rU5Ql9YOMZ/fSiO4dTPqwCg38jqVI0UNf1tVjX2u4WozjPI yDlcy+WQHDZQhE69tyLo+XB5Vewy59IuCDPGrq4pl6MWYx3FZPBhE7XiaQwrFkaf5phr 4nNeT93TuKpAaIf0EZ4xKwu++8gnw0XtGdf/m3DquRjo6Y9JgM+LFZHzxAO2RWXM9zO0 9VBdxJiGyUzq6+tB+96cQu2TFhAojyw1Fii2kJhvjeWNBJZXWple0qLRHz6XZUXOAvdJ vdo9dj/1l4S905HOS2olADcZs78Po5p9vrSwMZmyki1QL803bWsdRY8nDmkB8KmO4tZv HXSA== X-Gm-Message-State: ABy/qLbXNX7pt2ckvi4QnDC0VYus3Y4Z3+1igRpTxAVLdqwN00mljr2o lXDv66E41gIDecWILb3OW7g5gg== X-Received: by 2002:a17:903:24e:b0:1b7:f73d:524 with SMTP id j14-20020a170903024e00b001b7f73d0524mr4015022plh.43.1688163020445; Fri, 30 Jun 2023 15:10:20 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:e9c4:8375:7234:e6c2]) by smtp.gmail.com with ESMTPSA id q3-20020a17090311c300b001ac897026cesm11238797plh.102.2023.06.30.15.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 15:10:19 -0700 (PDT) From: Douglas Anderson To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Stephen Boyd , Douglas Anderson , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] Bluetooth: hci_sync: Don't double print name in add/remove adv_monitor Date: Fri, 30 Jun 2023 15:09:07 -0700 Message-ID: <20230630150906.v2.2.I8b6365c6a13afc74d7a91324dad73601a42038c9@changeid> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230630150906.v2.1.I3b7c8905728f3124576361ca35ed28e37f12f5d1@changeid> References: <20230630150906.v2.1.I3b7c8905728f3124576361ca35ed28e37f12f5d1@changeid> MIME-Version: 1.0 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=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770167683041317487?= X-GMAIL-MSGID: =?utf-8?q?1770167683041317487?= The hci_add_adv_monitor() hci_remove_adv_monitor() functions call bt_dev_dbg() to print some debug statements. The bt_dev_dbg() macro automatically adds in the device's name. That means that we shouldn't include the name in the bt_dev_dbg() calls. Suggested-by: Luiz Augusto von Dentz Signed-off-by: Douglas Anderson --- Changes in v2: - ("Don't double print name...") new for v2. net/bluetooth/hci_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 7e2ecf8a55d8..a8e54383e551 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1949,14 +1949,14 @@ int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) switch (hci_get_adv_monitor_offload_ext(hdev)) { case HCI_ADV_MONITOR_EXT_NONE: - bt_dev_dbg(hdev, "%s add monitor %d status %d", hdev->name, + bt_dev_dbg(hdev, "add monitor %d status %d", monitor->handle, status); /* Message was not forwarded to controller - not an error */ break; case HCI_ADV_MONITOR_EXT_MSFT: status = msft_add_monitor_pattern(hdev, monitor); - bt_dev_dbg(hdev, "%s add monitor %d msft status %d", hdev->name, + bt_dev_dbg(hdev, "add monitor %d msft status %d", monitor->handle, status); break; } @@ -1975,13 +1975,13 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, switch (hci_get_adv_monitor_offload_ext(hdev)) { case HCI_ADV_MONITOR_EXT_NONE: /* also goes here when powered off */ - bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, + bt_dev_dbg(hdev, "remove monitor %d status %d", monitor->handle, status); goto free_monitor; case HCI_ADV_MONITOR_EXT_MSFT: - bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", - hdev->name, monitor->handle, status); + bt_dev_dbg(hdev, "remove monitor %d msft status %d", + monitor->handle, status); status = msft_remove_monitor(hdev, monitor); break; }