From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039237; b=I8+PZNXejP8WP3l4UfAO/jODMf3/k6rJzxzreHQ5vKoGHHVFXMoDm5GXWyzobWvaTkr9 5PNTuMa+H19v3DE5QuJ21c6Mj/L8D2CK3CAa78bgO7OSoDeC2NNMVZLiT54yIizRy55eu hEkYEC/I3G6lwDN5hh0YgJvq+ghuZ593BLStDP824CVVM0ggfNf5fRM974w6yFKKBKbkF /8KTKQE5yNko/RnqspUQa7uLc3kg4Tsa5WeWPTCbIhQaUaCcLNdoMNRLBSpqsWZinJzp5 q7dfU55fJZqGbYe8zihQLKhHEdyTN5aglAJ12F8+7RR4/87ALBORN+nYJL9Y29Mr2tA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796039237; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=Bp4nIm3AF6eSNOaUX28bguF1AM4JfSf9i+htq85hIRI=; b=gk5EYA9EXFy6vPHYxIbVQnlHWXTM7vXY2VNnuWpYZy4/c3KHRXT2mfG4PePPHzXovoPP Td3LacIV+IlNrVhJpjqS5UI4PfDfOg++Pmj4IqJP74ZlQ1YyuVgpv9vs4dYflosGZhZL1 5I2ua3fjf/EgBD4LLuu/6WMGvge7VCpYAPQCBZNiJK/AVjgHSBTpqB/NIMAh66mQSfqLi l3tVcB3cL0rOxlUHEm4Ylb4pisimP/5/4R+xJHUvMmglousmTsv8eEB8GueuMVKTVDjlY juF4p2RnTxgtPfnK5RE4tt+RhxPn/adIRzdnADMR5oaXrAVCFY+6g37HiXaEN/VVBXQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lxMLESZi; arc=none smtp.remote-ip=209.85.210.181 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 535AB606A31C for ; Mon, 30 Nov 2026 11:47:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 535AB606A31C 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lxMLESZi Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8b58d6f67a5so4989539b3a.2 for ; Mon, 30 Nov 2026 03:47:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796039237; x=1796644037; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Bp4nIm3AF6eSNOaUX28bguF1AM4JfSf9i+htq85hIRI=; b=lxMLESZimfGroil7kRo2PeKMAc5r0C+vNw51IfnjnEnNw6wSoVilG1pZT8FD/7M9n+ NJ7aAe3PyBEaVW6Q5jnYGc/sAZFdj3cQrfprP8mWWf8pk+efS2g1n5JXLaVE6QgsU9RU Hp/GEaBS2MiX0+xf7AzQ/iYxJikUcZ50jYefl4NVagde2zdOMaC04NfmaFKpovZZooui JPuByCYfx9Fs8ftHuzsWFl/HT1jZWPNBFGEAtAJtPuzGzSPv1VWKBbSK/yjQK+DyfC4t zqvxRt9qvXCD4e9Ot2ofgbd8YIVnNLrQzRPoUUrVV1Sq9qAx/sbyXByQmH9XGbAxYipX bt2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796039237; x=1796644037; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Bp4nIm3AF6eSNOaUX28bguF1AM4JfSf9i+htq85hIRI=; b=nCuzprA7ppl+tslCO//OLHC4fT/NcclrgpuIejfiJNPr/RtOyNqyBAZiJoVgJVL8Ai q25+w9EIUeiGDyzH0X4XTVujtLi0p2sK8qZdBH1iAQ3DVDf6JO8jvLiyfqXyNpdjWWoZ JBIpds6zacDtu3OoiuwKsqIg2BNaPm4QDNg7U8NM3KFnbBXUDcBZf4J4haWABu25Awnn wDSEYSa9MNRWHpYldw5dHCgN5QDRY5p7Vhm+NYTII7YgBi86h7zFRrhcJ5Nx28CaSEnu HobaR1vIg0qeOBtfZ3OxJbOf+FQPxkqlY+yC5b6x1X9r+c8YnuVmKR7UaUjNA+uOHpix CUgQ== X-Forwarded-Encrypted: i=1; AL+hErF2gmYA5ZHPRMyK6xxub3W7PtOrbDBELzUe3f3LPaceXMmp79q2Ofzkhlwr9PAttD7iTAOvxWpkMlLA6q8=@vger.kernel.org X-Gm-Message-State: APuU4Z+s8gC/01rWRz/uS8xAyLdhWdXGtdx6Nb2XBzLcKrFsxuc02VOC SW6v7l1LpPwqKExTK1eUdFx96QFouJuxeqgGM/xEzAsHP7HiPWbtNgGX X-Gm-Gg: AZFdTZfgY6yRzEv2/+q7Sn2bcm6dBSJLRImUzuPV35qUM26RTCFPhSU0g1iopRIO6Jw jwjL5B/d2igeNC8mekrVGlSCCnksOaAtiiWQ0HUX91uPCrSV9tXqrO1UGfEZYLzeZxodW8TOUNJ L0C7SOrHT1lN4mLfMVePSNEVrAY0Y8Q5BcUnV60Rzv8hM03fMTAnUNclpEp7A33aaYwOxaGdgOL 9AM4UqeNJIrq8mf4udqVNlQSGBLYFtCK38hrbR22/8JXrQBrCZk02EKp36vvwmkI0wTsL4L3uyw EA+5jZk+d6Zya3Uv2lfEQ91em9kNiwxNNM7rIvWlI1sKkRazmBm+R+oU2jremtRjDKHVUuMtmMA UlKImtXs5ysK/+rc/R9jNHwfZjPvujUDZgf/1dmCXFkWINHSuva1Vsv39JM/EYNBG5oH5lRazhy QNGTtmG5cm9Q8YcUo5dYvIpJR2cPsXb3dZ12onxofOeeg1/R/S7+u1qLgvF8KXhduX0lOHGYYgM +udUfUgv1hs0wSR02hPZCZKGvx35BrUtH9Y5PawmG9cTPpfdNsFukJIOpaUfLwpGk78OtBAqPPI 7xiscouHnDgsCVeNlNW4/kuz8R22ddTSxv8RrYkAoLBybbYvFEeJuNS1daK3UDktoPQX3dw90oZ bbWueGqU= X-Received: by 2002:a05:6a00:2d06:b0:8a9:95d6:31f4 with SMTP id d2e1a72fcca58-8c87c8605d3mr30421801b3a.32.1796039236302; Mon, 30 Nov 2026 03:47:16 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c8706844a0sm17782030b3a.1.2026.11.30.03.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 03:47:15 -0800 (PST) From: Lin Tzu Yang To: Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: Keith Busch , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks Date: Mon, 30 Nov 2026 19:47:11 +0800 Message-ID: <20261130114711.842577-1-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 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-Transfer-Encoding: 8bit The show callbacks for the namespace attribute device_path and the host attributes dhchap_key and dhchap_ctrl_key print the stored string with sprintf(page, "%s\n", ...). configfs accepts up to 4095 bytes in a store, and the store side keeps them all, so with a 4095-byte value the show writes the string, the newline and the terminating NUL, one byte past the PAGE_SIZE buffer. KASAN in a QEMU arm64 guest, after writing 4095 bytes to namespaces/1/device_path and reading it back: BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc Write of size 1 at addr ffff0000127cf000 by task cat/4329 vsnprintf+0xdd8/0xdfc sprintf+0xb0/0xec nvmet_ns_device_path_show+0x44/0x68 configfs_read_iter+0x284/0x46c The buggy address is located 0 bytes to the right of allocated 4096-byte region dhchap_key and dhchap_ctrl_key with "DHHC-1:00:" followed by 4085 bytes give the same report. Use scnprintf() with PAGE_SIZE, as the passthru device_path show already does. A value that does not fit loses its trailing newline instead of overflowing the buffer. Fixes: a07b4970f464 ("nvmet: add a generic NVMe target") Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication") Cc: stable@vger.kernel.org Signed-off-by: Lin Tzu Yang --- Tested on configfs-next 2e0fad9d2eae in a QEMU/KVM arm64 guest with KASAN and kasan_multi_shot. Writing 4095 bytes to each of the three attributes and reading it back gave one KASAN report per attribute before the patch, and none after; reads return 4095 bytes. Normal values such as /dev/nullb0 and DHHC-1:00:abcd: still read back with their newline, and enabling the namespace still works. Build-tested with W=1 on nvme-7.4. Found by writing boundary values to every nvmet configfs attribute. This patch was written with the help of an AI coding assistant (Claude). I ran the tests above and reviewed the change. drivers/nvme/target/configfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 27c50fa533..f88a295bc1 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -531,7 +531,8 @@ CONFIGFS_ATTR(nvmet_, addr_tsas); */ static ssize_t nvmet_ns_device_path_show(struct config_item *item, char *page) { - return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path); + return scnprintf(page, PAGE_SIZE, "%s\n", + to_nvmet_ns(item)->device_path); } static ssize_t nvmet_ns_device_path_store(struct config_item *item, @@ -2242,7 +2243,7 @@ static ssize_t nvmet_host_dhchap_key_show(struct config_item *item, if (!dhchap_secret) ret = sprintf(page, "\n"); else - ret = sprintf(page, "%s\n", dhchap_secret); + ret = scnprintf(page, PAGE_SIZE, "%s\n", dhchap_secret); up_read(&nvmet_config_sem); return ret; } @@ -2275,7 +2276,7 @@ static ssize_t nvmet_host_dhchap_ctrl_key_show(struct config_item *item, if (!dhchap_secret) ret = sprintf(page, "\n"); else - ret = sprintf(page, "%s\n", dhchap_secret); + ret = scnprintf(page, PAGE_SIZE, "%s\n", dhchap_secret); up_read(&nvmet_config_sem); return ret; } -- 2.47.3