Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp657441lqc; Fri, 8 Mar 2024 08:07:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqC78Ze1FKwX5lv2Wrxj0uVVIO0vdj1FR+V6Mgo9UFw3aryKEofgiC5l+OK5zgPmLDIcj+y5dYppjNK/FLddrq1p2sW0DQRNYklfTNRQ== X-Google-Smtp-Source: AGHT+IH+OHazaJP4paN+5s9yB0M1EdH19vwFACOQcNH8GhKRL0lv0VGgm6M93bcIzlkVEuw/K3dm X-Received: by 2002:a17:907:20b9:b0:a43:6cd2:7a27 with SMTP id pw25-20020a17090720b900b00a436cd27a27mr13591826ejb.19.1709914064127; Fri, 08 Mar 2024 08:07:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709914064; cv=pass; d=google.com; s=arc-20160816; b=kwj4h+ADrZqDlhW8NlqpyNILT4+uyxD7823rfllsjb+5Z0KUQCbNWYqMJMah4XjL4G 0JC4wEnps96yoPTI/oRUdTM7+IhGqZ8kxz+J9pkrqlwZD+/nvXiDAVunld/GrtT9+QhL E8viU3ucwXu4NbnQbN8QiyN0YXqJ55NQtTrnZHwkS97vZWMpKkJpVMYoL4SGutkLJGsN LTBLKAqLl5lsI0RWdBK8L2Rr3Fjxa5G3S9NCE1Y39o+JGQgRbPFD7Cxp21a16bXY7sUZ DfK1kw80CIN3rKGvZBTVayPaXBWJxWxl5tAX1uJN0EgYp2X24gK0y4MoQzBtAJ0ecWUH ADMg== 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=8ExXaF/MToz4KdRSrAZxQmHnGbA7c6seQEWIwrQs7DE=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=NL4FSZeDcJi2705Fn9CbiGyGeTrkaneCiLhgh9JP2nCbA9XTdQ+inj6bLBqrSEF46O lbCTAagmT22PdvIqgbEuQt2HEFVH7MK7JLEA1UMpjjpEIoBI3JBM9Q6FeDTqyd5I79IM UcXDu2tlCxfukuFM/G0USdUcxPSaeOu2oLVNv2C8LYlInD48SzkaLdpJJk2gzIY1Xxl9 oVlCK3HFFoKOE76HKJnLZpg/NAct8wPANu3jm/C6AliraxstWWwUzw7qtujxM5v7sHHU QpJP0jMKJYrUt6ZkdWj9PqjK+XXZpn81HMXhE83EzlxL2SN3lcJIPZN6WWznhMcyT6m2 Mh4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dBQ+Mf3R; 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-2373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v6-20020a1709064e8600b00a45cfcef158si1604565eju.431.2024.03.08.08.07.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 08:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dBQ+Mf3R; 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-2373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2373-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A989D1F22EFF for ; Fri, 8 Mar 2024 16:07:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A72738DF9; Fri, 8 Mar 2024 16:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBQ+Mf3R" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (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 191FD2E3F2 for ; Fri, 8 Mar 2024 16:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709914041; cv=none; b=CEFl99AWpnhO2NfKMsodm5V7z7Q6o2z/3KmIIZQvI5gdxeaER6DcfigLbF1ZDqX6HcT5CgFwbqbyrw515YDoWRdkR9uetVERB7RFAabXjwpf5FPvpdQPKFmMMSpnAncrMqKvC3RnZ98aPouTLkNIcQy9/0eUHxIGOaVKhmenEX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709914041; c=relaxed/simple; bh=K1R/q/N/kaI19m81pJG0nPwp0L+SeYWs3lWlthlj0Dc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kJLHpFqtexadqkkVcN5DvGKLxxmnKhkN+Ps2CO9wzUW6zYqWgIZIongRr53aTjt26rP2vC/ew2VkLY66EzYMjCWE+Ewla5uOw6r7SiYluEIDmjK3v/+u1vILgo0MoJ1UbXITsxSNzbOnfrrJ18xsEEHSV6BBMjwEW1Q+ItILSTA= 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=dBQ+Mf3R; arc=none smtp.client-ip=209.85.222.41 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-ua1-f41.google.com with SMTP id a1e0cc1a2514c-7dba7098dd8so669163241.3 for ; Fri, 08 Mar 2024 08:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709914038; x=1710518838; 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=8ExXaF/MToz4KdRSrAZxQmHnGbA7c6seQEWIwrQs7DE=; b=dBQ+Mf3Rb7cdN9EVlvirF+fAxXem5ST2JYtSmKpt4ToCaqR+lnEX16tb0nSi3EZ5sb rbPye3/11vNHmWOEgFG6Vosx4U2GTcx5JsCKNvqu5wPvRlKM5+gHVEr0bK4WDdhHL+8o KAlaT/eO43FCEZ879Tdk/VNWeST2WcDXUvjpbYNT4CTGrmbMNqChm+uchArzsAbFCCv+ pmB2ka6D6yVF1V6/5C8vqoqYeKQLam3NIN8ivCsU8FDOXEJixIye8K1kYEERO9ZHlVla LUvRlrlJZtiPOWM4QXY/Pd97cyFT7yyMlQwxBDSTpgI4lq/sTA5XuExLs8vqZqDHBN9Z k+1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709914038; x=1710518838; 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=8ExXaF/MToz4KdRSrAZxQmHnGbA7c6seQEWIwrQs7DE=; b=H0T7BdrglSvAkjhLsWLOXP4ot2UaU3KYUa2DkBu0Lc6X5yaARb6yPDmJQ6I0YKDgga rCR6GgmvcQT0gGQLdg1MuuZdm9Z1y8i5uhctK8WXPZsoJa5GPQSAJfT3LpuwvrwbFitR l7lUR2RVSyr4pvH3pVEhgRBFG8wxZKdZsbiQuKO5LVZgfbqEzRS23O+NYvmODjs759yd uUpM8HXpIDzd1mSDeida5XZkYwxzqdnoploIg/WQsvu4JsPwyIXYTaVUGGB/DfOPW8W1 0hcVqLF9AKoFBy+XZyrSDvHfYwkQuZTwjeb0AEw0Iq/HFvHx0Rx8lTRCULNt7jjAvTdI uidw== X-Gm-Message-State: AOJu0YxJUQLfx7WuCGYE5E4gTEJm+4uz28kX/nepJ7zHgm207jRanZgT 01QzIETtkpZaMvNoQDzsmAlnqrnDYq2XdELM2Z2At9ySWd3je5XJC4/u3Iei X-Received: by 2002:a05:6122:319f:b0:4d3:3236:e91 with SMTP id ch31-20020a056122319f00b004d332360e91mr11456566vkb.11.1709914037465; Fri, 08 Mar 2024 08:07:17 -0800 (PST) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id n21-20020ac5cd55000000b004c0460eeea3sm2079505vkm.43.2024.03.08.08.07.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 08:07:16 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v1] Bluetooth: hci_sync: Fix UAF in hci_acl_create_conn_sync Date: Fri, 8 Mar 2024 11:07:15 -0500 Message-ID: <20240308160715.88478-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 This fixes the following error caused by hci_conn being freed while hcy_acl_create_conn_sync is pending: ================================================================== BUG: KASAN: slab-use-after-free in hci_acl_create_conn_sync+0xa7/0x2e0 Write of size 2 at addr ffff888002ae0036 by task kworker/u3:0/848 CPU: 0 PID: 848 Comm: kworker/u3:0 Not tainted 6.8.0-rc6-g2ab3e8d67fc1 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_acl_create_conn_sync+0xa7/0x2e0 kasan_report+0xdf/0x110 ? hci_acl_create_conn_sync+0xa7/0x2e0 hci_acl_create_conn_sync+0xa7/0x2e0 ? __pfx_hci_acl_create_conn_sync+0x10/0x10 ? __pfx_lock_release+0x10/0x10 ? __pfx_hci_acl_create_conn_sync+0x10/0x10 hci_cmd_sync_work+0x138/0x1c0 process_one_work+0x405/0x800 ? __pfx_lock_acquire+0x10/0x10 ? __pfx_process_one_work+0x10/0x10 worker_thread+0x37b/0x670 ? __pfx_worker_thread+0x10/0x10 kthread+0x19b/0x1e0 ? kthread+0xfe/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2f/0x50 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 847: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0x8f/0xa0 hci_conn_add+0xc6/0x970 hci_connect_acl+0x309/0x410 pair_device+0x4fb/0x710 hci_sock_sendmsg+0x933/0xef0 sock_write_iter+0x2c3/0x2d0 do_iter_readv_writev+0x21a/0x2e0 vfs_writev+0x21c/0x7b0 do_writev+0x14a/0x180 do_syscall_64+0x77/0x150 entry_SYSCALL_64_after_hwframe+0x6c/0x74 Freed by task 847: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0xfa/0x150 kfree+0xcb/0x250 device_release+0x58/0xf0 kobject_put+0xbb/0x160 hci_conn_del+0x281/0x570 hci_conn_hash_flush+0xfc/0x130 hci_dev_close_sync+0x336/0x960 hci_dev_close+0x10e/0x140 hci_sock_ioctl+0x14a/0x5c0 sock_ioctl+0x58a/0x5d0 __x64_sys_ioctl+0x480/0xf60 do_syscall_64+0x77/0x150 entry_SYSCALL_64_after_hwframe+0x6c/0x74 Fixes: 45340097ce6e ("Bluetooth: hci_conn: Only do ACL connections sequentially") 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 8a3d0d1f7871..f6b662369322 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -6709,6 +6709,9 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data) struct hci_cp_create_conn cp; int err; + if (!hci_conn_valid(hdev, conn)) + return -ECANCELED; + /* Many controllers disallow HCI Create Connection while it is doing * HCI Inquiry. So we cancel the Inquiry first before issuing HCI Create * Connection. This may cause the MGMT discovering state to become false -- 2.43.0