Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2615536lqp; Mon, 25 Mar 2024 04:39:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUPJJdxdMq+l0NLwtkcfREsh9uCfS4lti+ahB2+VjhjnymmYj4P+m3NsIILzDCrUoPDkAlaiFuvEOovuuaTPUdwgNTvIk/BND5Kl8se0g== X-Google-Smtp-Source: AGHT+IFS9j08VGVUKs8/SyQNSmF49Y/J9hmaoysgapl8YBiUF4cb9/7sHbpR/ptxAXBdu5cDoU/N X-Received: by 2002:a50:d49e:0:b0:567:1221:d486 with SMTP id s30-20020a50d49e000000b005671221d486mr5017854edi.33.1711366741400; Mon, 25 Mar 2024 04:39:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711366741; cv=pass; d=google.com; s=arc-20160816; b=lKdWIvGqfATZvtjlCiwtXtMqd6ADmjDvW90dHb6guNOzODKETrlw3WRsTblinUTRBV YXlcWs9xWdlZeVNlYQsZj2KZdCxFVj4SRgR9OaAgVrT6m4MCjZKzYoml4262lIKGwwOo ZtQbu72H/ubUSMJhhUID897M9X5bZWv+I2a3BqTPastWtSpKFxtBkBFFAgDEATt7Y+GZ Zv7nO0/Bwmf/JtiuUbCuP1A1iGkiAHHdxmrn0pqOmSlv8otST8NghM77gEpg6Oq5mdv4 r2Bzoe5GEVnm5E6feuJWNx+TYhyNzGfTYifWwq5Y2fI8VRYZCq6zFqDIcZ1HJHMSi3r2 4Unw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tOxAcArBqmMCc1N8UsIe8IUXY/KO54rvT1RPPHyowDg=; fh=m5blFiIWqx+vNsWXJJ4dkUhOL1Qvg4gBXI/KNuwcMEQ=; b=Nsfouxh30GIU0Hd6/hBnuztanRO/MsKJqPp0gg047rqIQrZLFs70pdWsD5iXf3fGoX wiBevxcZXZUFF/hQWTzvTZmoVEBjfpu4Cfmomk17KM8DH/rjDyL2X9M7ir9yVh7S+rUp ggyLL783+V5iOQYnycKe0NTKGFElDLMUtzX34Cjhiy6L4KvxYMgUuj5AS8r4T1t+VIsZ naY49MvM8ZKcgq6xcpGFQmUMY6RpJ20Wy1u2Uz9CuMSJquGdAKWYEiVshenEqyq0JchS IfUsfA4PvRsGdqsrET65a+lU6yuB/Koqb7NrrZDrbNHLdwRYvTLQ4DDAY3rMzyC5R+uS CCgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ksfqt3Ht; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cq15-20020a056402220f00b0056529e7d47esi2438971edb.494.2024.03.25.04.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 04:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115671-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=@kernel.org header.s=k20201202 header.b=Ksfqt3Ht; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 267AA1F3573C for ; Mon, 25 Mar 2024 11:39:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA404355A1C; Mon, 25 Mar 2024 02:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ksfqt3Ht" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B214A209E14; Sun, 24 Mar 2024 23:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321578; cv=none; b=oGoTx3XzmbjT9UzW7sbBu/ae8FV/ycv4lzdxLfFLUOFpdI1guSALum8/CNi4MGiD6vNBndf56r+GA+HEoGQlUCCzjdaOFzYYMHJCuf9GUs5xF09QyV7Zyxi24M8PoKUXIerbi/DB+pNjF2Yr3BZyxnfBjeyrFJak83/I5WvJ+wE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321578; c=relaxed/simple; bh=ZcHPGh/+6JRCBw+dWU/yC1PN20jUS9Kcv6f7ag8lQs8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jwr6gc1vldWpGfuni7/2GbwnMJo4FawCQ+2ax7g6+Zmvmw/HknAxKclysKAvz86w2jMQ8PPyBQb76GTpQbfirmONpQYeWffZqA0xcHzXSucNF/7CFfldyIa6vkTUCGBYo//Mrk9WEkDW/qlpu31AXn14V187B2LoJaesDxs7AFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ksfqt3Ht; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEB29C43330; Sun, 24 Mar 2024 23:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321578; bh=ZcHPGh/+6JRCBw+dWU/yC1PN20jUS9Kcv6f7ag8lQs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ksfqt3Ht1ggajX0yr1oEkkAkhcUZ1RgL+rZkpYKfGlGvyS7TwjIEvsXiuj/UA5wcP AWcXmUn3P1c0B7ZuTCoxo/Rnonw+7iWTgYQcrnxTxu3Z2iJ2kfk0oZNvCco0Jw4dC8 tXu8pPYHjzeABxEy+zEp7O6nvBfw+vgAS+DzbwZQbTWc0wc561eI7sDk1goFG3Ev5I MDyHk+fwihBh4jMYxx7NfOV2gWBMjXTadGdEt+ORDrZUsIGUDOoDkHfNrwIv4+lDiC YnbhaKd7kgvNDUnW65ETo3ehVIFatIunLF/KuARkoGOJLsSLaKxnkyIUaMg8paaW2l C+FUhAtVJ3Ewg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrey Skvortsov , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.6 307/638] Bluetooth: btrtl: fix out of bounds memory access Date: Sun, 24 Mar 2024 18:55:44 -0400 Message-ID: <20240324230116.1348576-308-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Andrey Skvortsov [ Upstream commit de4e88ec58c4202efd1f02eebb4939bbf6945358 ] The problem is detected by KASAN. btrtl driver uses private hci data to store 'struct btrealtek_data'. If btrtl driver is used with btusb, then memory for private hci data is allocated in btusb. But no private data is allocated after hci_dev, when btrtl is used with hci_h5. This commit adds memory allocation for hci_h5 case. ================================================================== BUG: KASAN: slab-out-of-bounds in btrtl_initialize+0x6cc/0x958 [btrtl] Write of size 8 at addr ffff00000f5a5748 by task kworker/u9:0/76 Hardware name: Pine64 PinePhone (1.2) (DT) Workqueue: hci0 hci_power_on [bluetooth] Call trace: dump_backtrace+0x9c/0x128 show_stack+0x20/0x38 dump_stack_lvl+0x48/0x60 print_report+0xf8/0x5d8 kasan_report+0x90/0xd0 __asan_store8+0x9c/0xc0 [btrtl] h5_btrtl_setup+0xd0/0x2f8 [hci_uart] h5_setup+0x50/0x80 [hci_uart] hci_uart_setup+0xd4/0x260 [hci_uart] hci_dev_open_sync+0x1cc/0xf68 [bluetooth] hci_dev_do_open+0x34/0x90 [bluetooth] hci_power_on+0xc4/0x3c8 [bluetooth] process_one_work+0x328/0x6f0 worker_thread+0x410/0x778 kthread+0x168/0x178 ret_from_fork+0x10/0x20 Allocated by task 53: kasan_save_stack+0x3c/0x68 kasan_save_track+0x20/0x40 kasan_save_alloc_info+0x68/0x78 __kasan_kmalloc+0xd4/0xd8 __kmalloc+0x1b4/0x3b0 hci_alloc_dev_priv+0x28/0xa58 [bluetooth] hci_uart_register_device+0x118/0x4f8 [hci_uart] h5_serdev_probe+0xf4/0x178 [hci_uart] serdev_drv_probe+0x54/0xa0 really_probe+0x254/0x588 __driver_probe_device+0xc4/0x210 driver_probe_device+0x64/0x160 __driver_attach_async_helper+0x88/0x158 async_run_entry_fn+0xd0/0x388 process_one_work+0x328/0x6f0 worker_thread+0x410/0x778 kthread+0x168/0x178 ret_from_fork+0x10/0x20 Last potentially related work creation: kasan_save_stack+0x3c/0x68 __kasan_record_aux_stack+0xb0/0x150 kasan_record_aux_stack_noalloc+0x14/0x20 __queue_work+0x33c/0x960 queue_work_on+0x98/0xc0 hci_recv_frame+0xc8/0x1e8 [bluetooth] h5_complete_rx_pkt+0x2c8/0x800 [hci_uart] h5_rx_payload+0x98/0xb8 [hci_uart] h5_recv+0x158/0x3d8 [hci_uart] hci_uart_receive_buf+0xa0/0xe8 [hci_uart] ttyport_receive_buf+0xac/0x178 flush_to_ldisc+0x130/0x2c8 process_one_work+0x328/0x6f0 worker_thread+0x410/0x778 kthread+0x168/0x178 ret_from_fork+0x10/0x20 Second to last potentially related work creation: kasan_save_stack+0x3c/0x68 __kasan_record_aux_stack+0xb0/0x150 kasan_record_aux_stack_noalloc+0x14/0x20 __queue_work+0x788/0x960 queue_work_on+0x98/0xc0 __hci_cmd_sync_sk+0x23c/0x7a0 [bluetooth] __hci_cmd_sync+0x24/0x38 [bluetooth] btrtl_initialize+0x760/0x958 [btrtl] h5_btrtl_setup+0xd0/0x2f8 [hci_uart] h5_setup+0x50/0x80 [hci_uart] hci_uart_setup+0xd4/0x260 [hci_uart] hci_dev_open_sync+0x1cc/0xf68 [bluetooth] hci_dev_do_open+0x34/0x90 [bluetooth] hci_power_on+0xc4/0x3c8 [bluetooth] process_one_work+0x328/0x6f0 worker_thread+0x410/0x778 kthread+0x168/0x178 ret_from_fork+0x10/0x20 ================================================================== Fixes: 5b355944b190 ("Bluetooth: btrtl: Add btrealtek data struct") Fixes: 044014ce85a1 ("Bluetooth: btrtl: Add Realtek devcoredump support") Signed-off-by: Andrey Skvortsov Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- drivers/bluetooth/hci_h5.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index b66136348bd64..c0436881a533c 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -1072,6 +1072,7 @@ static struct h5_vnd rtl_vnd = { .suspend = h5_btrtl_suspend, .resume = h5_btrtl_resume, .acpi_gpio_map = acpi_btrtl_gpios, + .sizeof_priv = sizeof(struct btrealtek_data), }; static const struct h5_device_data h5_data_rtl8822cs = { -- 2.43.0