From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123093; b=p8rrl8pMu3+KpjluS3kMGvEZzY9mnL/nZ5XSZjUHkSHkyJZD1mKnbBmaCmR7+avy/T70 TM52b9pj44oEAAU42cQdGZoGd+UyaMlsR/V9F2uB7tZOFYNYfgZ8bajME5k/kTi//3J1u CJdleYvr357WK1Cb7S86J/jRns1F6BiLi8/SfbJK6FaMDQYsoPMlHGiYoNTRN3tQe+mVp eq3ALK8EKsqv88qIMaCcADtd5BGH3kZU72vBCs0kLMuEwfDnB9RCNyjgXGlWZiWFCgBF4 86ETGDFEM5F1O3PjFCDCinD9mYXMu65eoGkLQ1sucBZ65YpYXUtPgI+RwrpSKcQfrrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123093; 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=05wO8ZgcdumS1rlxEMHJPxNNNaM+kLdjMrlxhnOKvI8=; b=2yz+9jGlb6VoTGmWvppu4WS7UvVvHj/wkPp4ohFRyperloGAW5xQD6EoJrdL5HHMDaZy aB/K9QYPXTC9KgYehLGwXPan6HXHsu22TcWQ99jP+dADDnuEJ1xVydceAz5KJqOiEbJPI 5RDnf9m4c+uCO1REbbE+kAKzAJ+Fsg2wLU/JfhFSaj/oSEffr0oHisRy12qoaoySWMCaG YySVd1fULK3edjYgIuh4ahVQaMI/gFz5FmGXjl9livm+O1jF66I9YdHFr+XpT3TBTx4i1 9AYlrHoyCQOBS5OaOwywTiWBSp9R2/agIUKaYT5KbZxBU4TLTmvBTseupvPYL6z6p0g== 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=vz5tiEid; arc=none smtp.remote-ip=209.85.216.54 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 3438C606A32C for ; Tue, 1 Dec 2026 11:04:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3438C606A32C 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=vz5tiEid Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3ae1da332bcso5667808a91.2 for ; Tue, 01 Dec 2026 03:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796123092; x=1796727892; 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=05wO8ZgcdumS1rlxEMHJPxNNNaM+kLdjMrlxhnOKvI8=; b=vz5tiEidtcyb1hjSCB2pAeCXNwiPv4g5HxbXzzEly4VDISMm/Df42bd8b9H9AsqhhQ uF5I/lMGcCBqqgUv53fcKq4nxGriOZ92NHMpNiij6+jqvgMdkcpct2iG9kJrd7vNAsg5 v+VRur5WFrImbiNdfzJCH/DjYwykcDAlhFnSUxeQ118jLnCo0pD0OPejgULhf3LcSLNF yTwFniVOO6Ytww/miQGWV3PyFNMeMzFEJTTSVcgeBt4jE5wIgiM+WNSIiNFZS16PtRcp LgQ9RAqSCMKwhMtyDpnhxIzTjU+UirA56bNmmk9eXElDEENfMPHq7iMatZ75Lza4mC92 uyOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796123092; x=1796727892; 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=05wO8ZgcdumS1rlxEMHJPxNNNaM+kLdjMrlxhnOKvI8=; b=RoIFEgmEn3dwYekNLgajAbf6cu9q0GMiv4ISft2e0EokO/SO9uftSPw3i0C5vee8VD YXJkv3efWYPkkuUNWpKvr3yqrsT0FGJedVVwS2tHhhzKpO3WBjxvfa5w1wgYRW8W2HUG mOB8a8UE48TErtfVKaweifWWlJjRJyPHPN9P+U4c5vjLxiTuaNSsbpiZe0zwjohWJ5Ed phVvxlfu3APdh+QV+CyyHda/LEiMRqJdfjS/xKOXu62ZXVmUViGQhmCw7tFlyVUN5gco rQ/BuEMJUc6XGl6gxvyUnZhDPxffTb1IjgDmSTd+fbC9oa/kQtu4JMOpkr0OeP43d54L 7syQ== X-Forwarded-Encrypted: i=1; AL+hErGEyU6t+uT6rnL7GCGihXoXu0hxEY2+I/1OQtHa6zdhCytNOSI0PjANmtEjDorHXUgx7B9/N9vSWFi3Kp0=@vger.kernel.org X-Gm-Message-State: APuU4Z/JyRIsh7LHN6yoTFh3UWj3lqMHqgfItn4a5XiAJeCdlxmRv4cC /njfppKN3q0ew8z6Donk3y57HOnUOvW/APbaB8VX6TtwXi17fsmdI1bU X-Gm-Gg: AZFdTZcijEyrDqf2switcNLeFIsfOIvdmwb0NqzSJ4z4KPSKDSY1NvMVzPWXSMnWm0h +aV3d8Pj0tb9qYJo16XHPJcRvZO0qrTH60esIS5K/l87aRioN9Nk850F2Uz2sb1Qtw1xI50VGxT QhIBc4eGhfIqNBYDSq4kg2CreOPAjSULd1kSmPGmgivcyIeSy4+iLg4508ubxe9ANnUAG7MO3fV TOaEAor9z+UAL+hKCPBZimSSioRoPjlX1DiJBD6Qiap2Xek3ts5mMSNhewgawUoyVY3PfjLWDq0 BFrHoAd+wmi8Xo0UYpz5v6HKqLZyeT7oHzaErHGJjRTiHfpt1IRX6aPpJKrI66lgdKnEUgcwKLa sXdpSB6yzFayhuSrMc5XgjT7cwcWfg2jMr5PlK2f8QSQjEH8BFSODYtmZkld0EHrjbC/ZzzISCA NNdoeaPCvQjMnnuUw0BZCSBHsT6NtjbAE5GLtWSuxmEGhEsP3vINVok0a5MfudA6ig/88mA6MZQ FpNTZjWdnAAA31UnMzvXqY62VDpnorP8RpsraiRCvzE2GYRXLpszQhFpQ6zqZuLuelNHtlxY2Py UQtuhhyhqeK6UNKy/umY3QuEJggS6tpe2I2XTd/S9S9WbcSVw6qJW/JjrcIL2P2Jwv9XdIxKQGf ++IvcjUghLw+pvMpIamCjvsdaJ809 X-Received: by 2002:a17:90b:5109:b0:3ac:97bc:4c98 with SMTP id 98e67ed59e1d1-3b41c9bc501mr34937305a91.64.1796123092128; Tue, 01 Dec 2026 03:04:52 -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 98e67ed59e1d1-3b41ad46ef5sm57779256a91.8.2026.12.01.03.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 03:04:51 -0800 (PST) From: Lin Tzu Yang To: Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvmet: use scnprintf() in the passthru device_path show Date: Tue, 1 Dec 2026 19:04:48 +0800 Message-ID: <20261201110448.893469-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 nvmet_passthru_device_path_show() returns the value of snprintf(), which is the length the output would have had. device_path keeps up to 4095 bytes, and for such a path the string plus newline does not fit: snprintf() stores 4095 characters and the NUL, and returns 4096. configfs then hands all 4096 bytes to userspace, so the read ends with a NUL byte instead of the last character of the path. Use scnprintf(), which returns the number of characters actually stored. A path that does not fit now loses only its trailing newline. Fixes: cae5b01a2afc ("nvmet: introduce the passthru configfs interface") Signed-off-by: Lin Tzu Yang --- Follow-up to "nvmet: fix one-byte overflow in configfs string show callbacks" (20261130114711.842577-1-rongh7426@gmail.com), for the attribute Sashiko pointed out there. The two patches touch different functions and apply in either order. I checked the other "%s" show callbacks in this file: the remaining ones print fixed-size or length-checked strings. Tested on configfs-next 2e0fad9d2eae in a QEMU/KVM arm64 guest. Writing 4095 bytes to subsystems//passthru/device_path and reading it back returned 4096 bytes ending in a NUL before the patch, and the 4095 bytes that were written after it. A normal path such as /dev/nvme0 reads back the same as before. Build-tested with W=1 on nvme-7.4. 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 27c50fa533..ad36bcd90a 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -915,9 +915,9 @@ static ssize_t nvmet_passthru_device_path_show(struct config_item *item, ssize_t ret; mutex_lock(&subsys->lock); - ret = snprintf(page, PAGE_SIZE, "%s\n", - subsys->passthru && subsys->passthru->ctrl_path ? - subsys->passthru->ctrl_path : ""); + ret = scnprintf(page, PAGE_SIZE, "%s\n", + subsys->passthru && subsys->passthru->ctrl_path ? + subsys->passthru->ctrl_path : ""); mutex_unlock(&subsys->lock); return ret; } -- 2.47.3