mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Lin Tzu Yang <rongh7426@gmail.com>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>
Cc: Keith Busch <kbusch@kernel.org>,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
Date: Wed, 2 Dec 2026 11:42:20 +0100	[thread overview]
Message-ID: <1b16c1fc-1030-4a8c-a499-d0ef65880168@suse.de> (raw)
In-Reply-To: <20261130114711.842577-1-rongh7426@gmail.com>

On 11/30/26 12:47 PM, Lin Tzu Yang wrote:
> 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 <rongh7426@gmail.com>
> ---
> 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(-)
> 
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

      parent reply	other threads:[~2026-12-02 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:47 Lin Tzu Yang
2026-12-01  8:01 ` Christoph Hellwig
2026-12-02 10:42 ` Hannes Reinecke [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b16c1fc-1030-4a8c-a499-d0ef65880168@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=rongh7426@gmail.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®