From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796352853; b=cL2yykxYb0UymiMJyQC3PuTbmPIgz+yh0VVbrMcR3ShIm3UHi+zMxldSjYV0At4TP3Tv 0jCS/+0SOytbdSBJfkz7U9tsJ6jRtlmT177OhmsnujIUpSw/rnsG6gOf0uB3Su1ujwkUI lzLbgXGEUWH3r1HLX+Rwvmq7fk2zGDcLv5E8PTjflCFfwLaZuPTkGEfrXBCk2dkYcEyZh kI8aqVkQ2FZDCwZtv6Wc2IpbUro50w7UDsNzn1xNY2VYgouvHkqOGbeB9EqGUnkitKDRp pSPzrq8Zt45WO2QdAspOXDHWn5OkkbcbU/wiuYdYvJSDoKTOKcjwjy9HeNZKN50dFYg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352853; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=FcUPCh2zeC07k5siAXZSIuREyKPnCHylTH950n9Xpi0=; b=isLVKaWXxbeZktwJfrj3Dynfcb5ixTodXfAKPEZ6e2Ax5I4hSK2UuvAGpqzPN1HjLM+d fWAqLV5Q3+RWAYMWVC3CH2iom6rHQm6ac6gpDnfyCf6Iy8datUjdQai4oy0QadJvPKO/M GYajjGUMKmOs2j62rs6g0a21sO3LQD921MOPZJVOygx0Yh9Ah1LOFx0TDvGjVYdhpikcd K3iRkAQJFIC+kVgjS4tIjnCPEM5lYwRacQlILuNrrFBBMc4efAfSglKXz/vG3U4lHv00/ 10u75fflF+LAUUSXWjKvSNYW9cfcr122GBdMOcV7651/e43S1VxBJRONc0Z40Nc1EXA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="jDrKmZP/"; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23C78606A322; Fri, 4 Dec 2026 02:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jDrKmZP/ Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796352852; b=Uw2beq4NOGQBTVocA1W5gnSuwoBgW8nscGACSqqZHEyr/cKeVux0JToSRJU4OWH5nKRO uj6jzNsae2AONGZIBQrJpzc5j+0iLyWpsxKi+TS9GSNGQ1hkmtctBT27TFixKhhjlnkLY Dd/ozjQGgpGwvrN0FtIAkwNx7yTY608vJ13l2HWS5hmT5OVACFMNn5A/raumUMYpDWzsG TgXa9093W3Ac7VLkfEmgnMiCu0imZ1uY2/XyTxUuBo4dLWA7Lvf/ubZLL/1e8RDNwNIou 0hvwQvpHbCD3fH4fIa02JTZfzjRho7anOo7LDE+FAI2kfq777DJBhtme+zaDImN7piw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796352852; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=FcUPCh2zeC07k5siAXZSIuREyKPnCHylTH950n9Xpi0=; b=idpuBAX195jW7HltVLh/IikvIay3TVCKM0ZNLtv0I4z5EYUShfecDUIrDJHvhYW8n7ed O2UcgEhN8D+iEr/zuL4gGTMLdnTGHzC4XN1B8cuy2PCWziQFQ1nxvMysyJWcl2fkUUa3L cWYvvse84vhKUXxaLoPqHMmK6RlPXyzi5DvqXLkqvE+spaHPoLr0LoKmYqc8WzO9a2mqx hlFVkqHS3jwgjJMnzCkI4N1iFQJnoul/f3xxLvUkmh1z48X0wbgbwNAmOJc4d/dqepsg0 4JE/pTc9FUzSADzTiCALtqz7Iw7XwwzIMmqH6LH4VkIBuuVwinw74O8NwAD5E6gZAOQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 2AA451F000C2; Fri, 4 Dec 2026 02:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796352852; bh=FcUPCh2zeC07k5siAXZSIuREyKPnCHylTH950n9Xpi0=; h=From:Date:Subject:To:Cc:Reply-To; b=jDrKmZP/GYKypKqZhRke6OPCR0MHWNZdUb8D5MI7CFRhSk55iFbrukUPETKww7dnF 10R7qz6BVyi2sVtarnKhgPHySVXrTPyJtrmiXnwAXKg3uPxbwSbeM4eIsfiikyvQxg 2VFq8CJriQf5/GgDeNwD1S3t8Q4zIzlIo46RUDet7WKF1s6LNrHFkzWb8VAqGNxpS7 Iv1IPkQ5li5VILuWplsN4GT+Aw9v541GvRk6J9LWUjXDOCQ0XBNoZyLQhkY2UHO5Ns Ya3ElT5cF0uWDvh2V808b1+rx8d7O5wbxFUf8utkZ7RtoIPyHHx1ioNdegKecOM0BG B+p2mjQH2zU/A== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B15FC4221B; Fri, 4 Dec 2026 02:54:11 +0000 (UTC) From: Anh Nguyen Hoang via B4 Relay Date: Thu, 03 Dec 2026 20:54:12 -0600 Subject: [PATCH] scsi: target: configfs: Bound the output of target_dev_lba_map_show() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261203-kbug-l986-v1-1-00584b0bc42a@gmail.com> X-B4-Tracking: v=1; b=H4sIAFMrEmsC/yXMTQ5AMBBA4as0s9akrX9XEYtiMEhJi0jE3RXLL 3l5Fzi0hA4KdoHFgxwtxkMGDJpBmx45td6ghEqkEiGf6r3nc54lHKM8jVuhsZMafL9a7Oj8XmX 12+31iM32DuC+H5Js+5ZtAAAA X-Change-ID: 20261203-kbug-l986-e4975d0aef1a To: "Martin K. Petersen" Cc: Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Anh Nguyen Hoang X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796352851; l=3726; i=anhnh.4work@gmail.com; s=20261127; h=from:subject:message-id; bh=yFBnJxEBq5efBmKhzaSnWCO1xvR9GWTgjPP8hdvTUPc=; b=W39lbQpi3iGUzIvEkqLNwKxjxaOjA0vUgC9d5TLgzSpcumxTwN/o4PRUCvYr/9SaP5/SbOmOk mF+QbMBXxZ5DNI80eIrJuYuSIXogntBLGHrcIUE8X6MZ4gcBVrvttr5 X-Developer-Key: i=anhnh.4work@gmail.com; a=ed25519; pk=9NJ/0SKqaFZmt1/I5XY11TZSNY2ys6RWB3gvqzrLHmI= X-Endpoint-Received: by B4 Relay for anhnh.4work@gmail.com/20261127 with auth_id=1662 X-Original-From: Anh Nguyen Hoang Reply-To: anhnh.4work@gmail.com Content-Transfer-Encoding: 7bit From: Anh Nguyen Hoang target_dev_lba_map_show() appends every map and member with sprintf() and never checks the room left in the configfs page. The stored map can print longer than the 4095 bytes it was written with. A pg_id above INT_MAX is stored as a negative number, which prints one character longer. Every map line also gets a newline even if the input had none. Reading lba_map back then writes past the end of the page: BUG: KASAN: slab-out-of-bounds in number+0x85d/0x8b0 Write of size 1 at addr ff11000002f69000 by task init/1 ... sprintf+0xb1/0xe0 target_dev_lba_map_show+0x20a/0x330 configfs_read_iter+0x2ec/0x5d0 Use scnprintf() with the remaining space instead. Found by a static analysis tool. Fixes: 229d4f112fd6 ("target_core_alua: Referrals configfs integration") Signed-off-by: Anh Nguyen Hoang --- Tested in QEMU (x86_64, defconfig + TARGET_CORE, with and without KASAN) on v7.4-rc4+ (9437ee8b6cf6), where this function is the same as on scsi for-next. As root, a map was written to the lba_map attribute of an rd_mcp device and read back. Before: with 314 members whose pg_id is 2147483648 and up (4089 bytes in, 4404 out), KASAN reports the write above. Without KASAN, the read hits the WARN_ON_ONCE() in fill_read_buffer() and returns -EIO. With valid pg_ids and a 4095-byte map that has no final newline, one NUL byte lands past the buffer (seen with slub_debug=FZ). After: no report in either case, and the output stops at 4095 bytes. A small map reads back unchanged. No Cc: stable: only root can write this attribute. This patch was drafted with AI assistance (Claude, claude-fable-5-2). Testing: - Compile-tested on x86_64 (allmodconfig, W=1): drivers/target/target_core_configfs.o; no new warnings. - checkpatch.pl --strict: no errors or warnings. --- drivers/target/target_core_configfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 2b19a956007b..bb35d2dc48ad 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -2601,12 +2601,12 @@ static ssize_t target_dev_lba_map_show(struct config_item *item, char *page) spin_lock(&dev->t10_alua.lba_map_lock); if (!list_empty(&dev->t10_alua.lba_map_list)) - bl += sprintf(b + bl, "%u %u\n", - dev->t10_alua.lba_map_segment_size, - dev->t10_alua.lba_map_segment_multiplier); + bl += scnprintf(b + bl, PAGE_SIZE - bl, "%u %u\n", + dev->t10_alua.lba_map_segment_size, + dev->t10_alua.lba_map_segment_multiplier); list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { - bl += sprintf(b + bl, "%llu %llu", - map->lba_map_first_lba, map->lba_map_last_lba); + bl += scnprintf(b + bl, PAGE_SIZE - bl, "%llu %llu", + map->lba_map_first_lba, map->lba_map_last_lba); list_for_each_entry(mem, &map->lba_map_mem_list, lba_map_mem_list) { switch (mem->lba_map_mem_alua_state) { @@ -2626,10 +2626,10 @@ static ssize_t target_dev_lba_map_show(struct config_item *item, char *page) state = '.'; break; } - bl += sprintf(b + bl, " %d:%c", - mem->lba_map_mem_alua_pg_id, state); + bl += scnprintf(b + bl, PAGE_SIZE - bl, " %d:%c", + mem->lba_map_mem_alua_pg_id, state); } - bl += sprintf(b + bl, "\n"); + bl += scnprintf(b + bl, PAGE_SIZE - bl, "\n"); } spin_unlock(&dev->t10_alua.lba_map_lock); return bl; --- base-commit: 4ff20abe28d65a0c52f0b280008fcfb93c3ee2b2 change-id: 20261203-kbug-l986-e4975d0aef1a Best regards, -- Anh Nguyen Hoang