Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1901659rdb; Tue, 20 Feb 2024 10:13:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVWUdJbPGYq1beefnKxuPOgvzw5h0etIh6/ywXe0k5Yx5c0rWCpaQIQc6TJRtf0cmX79W1WY37McdOQX/rjxt7JmScQ5P1Wzas+pvqnsw== X-Google-Smtp-Source: AGHT+IHktzZdsDO7qIeV0+EWCAasfPLPXQfqLnWa+N2w2Rn3P/G+vQwBhbdFueXwpZHG1gYM5b+2 X-Received: by 2002:a17:902:e5c3:b0:1dc:87:855f with SMTP id u3-20020a170902e5c300b001dc0087855fmr6468757plf.28.1708452809076; Tue, 20 Feb 2024 10:13:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452809; cv=pass; d=google.com; s=arc-20160816; b=alPhF9i5PmDTEnrJ8TGRiq6IInHIXo1JQOabDGS4lF/bO0Jn9+pV7YP0EB31KwVnI8 81hik77EOlJJhGlt1LTunOk1HUt5tfWHHVH3MXU6GocB8JkfILi1dMJXL9p2doZAc0nL KCnpwKMTnrk0tBJ8l5LqiKkjfscehYRjzK6+tcdVHswUn2HyArCLmgXiwzCZhmrrykgP AcSKmH1xZsYiRne5UH84sGcqjyqiqe1CXGa5NLke79KdcYl43qmPz8//wULe6MM68IHw 1JO3ThTQ6BklHPh0sft9WPA42U8U2GTLhjXE2O2dTItooMErhAoS8qQL1Fs4Mqkjo+lb iq4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=7rtatphqznERiVJ4enLULaeElYlS5CJ4pOukIE0BXno=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=Voz22rAmu7O92Duma5NC5kmsynpygJ1YgRKyO5hxFx5lmFFKj6gRBkqEZrIfmxJRHc KrQx35JkCEWsUknVBqZQobqXcM/yhxZ5w72c0i+nsb2031g2zsS/8THHbzL8vKRhWTjG fB/c+vtDLX1voLioT+Mq4FKdDvJetGc6K+X7v/nkBX9u10HwtTiz9SmPfNFR2ibIA/hM VGwg44Hm3BJrYPc5L9ey2fWG3e/3fwdQ0c/SQd/SI9mMfp8HM1B7LSZEoa9I7D3q+N0O FlMgRnC3VQv9y5ap1OzPudtUHCRn9ezOBbq/K/vhkUjYHtu5wjrtgjDMz+DHJf7edtYb tgWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DdSjWJ8p; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2035-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2035-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n18-20020a170902d2d200b001db2ad550d7si6554913plc.144.2024.02.20.10.13.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:13:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2035-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DdSjWJ8p; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2035-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2035-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C501B2859E7 for ; Tue, 20 Feb 2024 18:13:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D026577F05; Tue, 20 Feb 2024 18:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DdSjWJ8p" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B078E762EC for ; Tue, 20 Feb 2024 18:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708452805; cv=none; b=d7leDhEoVVTXPX02QU3ctBz2A/7MG2gEsBMoJPURiMukMQBa2GtAPPyneRzCIt4UzvRLYxhk/x6z8nA8BMigAln9eSpLaTCtIjD3LnW9/+5j3dizt7BSI/Aq6XQrfIB7a95xaL7+tMK2OaJB0EwTvT+5VSskPCUcFv9c76+7EyM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708452805; c=relaxed/simple; bh=ozfdrdAtQIOlLEIIYeYShm+7LwPmM8HtxLnz7Maoc3M=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=krShB8/KiC1U6MQWQdVV6Ne5HZBRJtTSGfiwtq6/Lg6SxO2qScyA1S44ftCgJHdxgHmYsNqRA1wx8F7Zhlxq4hWAQQMw1lQw+luOG8K0x/dR466yLGBkVNSrMplyJquft2ySuo1fNLN75YjbCWAyQcc0DDPzE4xjAzXJcKpLqLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DdSjWJ8p; arc=none smtp.client-ip=209.85.160.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-21e6be74db4so2594192fac.2 for ; Tue, 20 Feb 2024 10:13:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708452802; x=1709057602; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=7rtatphqznERiVJ4enLULaeElYlS5CJ4pOukIE0BXno=; b=DdSjWJ8pQTFygq/41Xo2QG72HtSpTxP3weqZV6bTkxLoyes7HkjPxpzj4KvBNxkY3C ALa4gsKc3AgWBCvm+o18YEXTvnsjJ0ZqjLPGNAjuYYpDNn0ODcbgqQ7jRIh/qecpVJQs uGkDxcYFaH3zwWEzXH3x2bt7ruxTWMxHDKN3yX7GIVxqHwyy8rr17mOwaIdkZUXjKBqL xBvdMPBbVVMYwIclUueJBFVSs17x/TmLp4DEZLyh2JPrvWV5jQcU3MFzqmY+/Quawhke dPGLwm+274SRO8I2JQe3dpDsIF88gvuLZOFCuWv9yYkF6gk/o6fnhTrNsrpRU81DXleA 3X5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708452802; x=1709057602; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7rtatphqznERiVJ4enLULaeElYlS5CJ4pOukIE0BXno=; b=YeIZAqVG//hJV1x2IEeE7d8fQ5IJu/Z5d6SP9FpWcl+PP3uUAJfrgxgDMOtT1yquas hx9ETJzkC5TsG65ttHTPsBk8BQeVdEJzUE72bNEW+4UoKjn0UAW+RCmLYmgGPembnXrb npKbDq1RLpOmWthqEZo5LigIGf8imQ5KImTq3hHxV6SvMF/iPLUEMtpB80FoB2guw1zz kZ6/LRn/yiuyWy3SOmfEwWhL0h5QZbUl8ig8Ethfd7iTZFkeaQ+MaBuL2bej52ZL1/ae JT0VaEWaCA/PbCT16rZbeEC9tdr7w106vbVEmAShkVGnBOfFJCYn5ScOtMq+7ESvIyqW B4kw== X-Gm-Message-State: AOJu0YwHG5eih+cYwYHjojd3ZNdqr4L59GVM9vOml81pPUJoeooQerH+ 3m4bjqGoGkNU27s5k102I/P6VtZ1XkF1xTkesZj78tZIAIytRL2wEETWYk6r X-Received: by 2002:a05:6871:653:b0:21f:2b1:cdea with SMTP id x19-20020a056871065300b0021f02b1cdeamr4629371oan.57.1708452801744; Tue, 20 Feb 2024 10:13:21 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id 2-20020a9f2382000000b007ce34bd1de9sm1788248uao.16.2024.02.20.10.13.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:13:21 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1] Bluetooth: hci_sync: Fix UAF on create_le_conn_complete Date: Tue, 20 Feb 2024 13:13:19 -0500 Message-ID: <20240220181319.368485-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz While waiting for hci_dev_lock the hci_conn object may be cleanup causing the following trace: BUG: KASAN: slab-use-after-free in hci_connect_le_scan_cleanup+0x29/0x350 Read of size 8 at addr ffff888001a50a30 by task kworker/u3:1/111 CPU: 0 PID: 111 Comm: kworker/u3:1 Not tainted 6.8.0-rc2-00701-g8179b15ab3fd-dirty #6418 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014 Workqueue: hci0 hci_cmd_sync_work Call Trace: dump_stack_lvl+0x21/0x70 print_report+0xce/0x620 ? preempt_count_sub+0x13/0xc0 ? __virt_addr_valid+0x15f/0x310 ? hci_connect_le_scan_cleanup+0x29/0x350 kasan_report+0xdf/0x110 ? hci_connect_le_scan_cleanup+0x29/0x350 hci_connect_le_scan_cleanup+0x29/0x350 create_le_conn_complete+0x25c/0x2c0 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 7306020ccda3..669099cf9b1a 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -6708,6 +6708,9 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) hci_dev_lock(hdev); + if (!hci_conn_valid(hdev, conn)) + goto done; + if (!err) { hci_connect_le_scan_cleanup(conn, 0x00); goto done; -- 2.43.0