Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anh Nguyen Hoang" <anhnh.4work@gmail.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH] scsi: target: configfs: Bound the output of target_dev_lba_map_show()
Date: Fri, 04 Dec 2026 03:02:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-249015@kernel.org> (raw)
In-Reply-To: <20261203-kbug-l986-v1-1-00584b0bc42a@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: target: target_dev_lba_map_show() exceeds 4KB configfs
  limit
--

commit 3c3acef60382791667727ab0d330848e93b99d18
Author: Anh Nguyen Hoang <anhnh.4work@gmail.com>

scsi: target: configfs: Bound the output of target_dev_lba_map_show()

This commit replaces sprintf() with scnprintf() bounded by PAGE_SIZE - bl
in target_dev_lba_map_show() so formatting the LBA map cannot write past
the configfs page buffer.

> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index 2b19a956007b7..bb35d2dc48add 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;

[Severity: Medium]
Can these scnprintf() calls still exceed configfs's 4096-byte attribute
limit on kernels where PAGE_SIZE > 4096?

In fs/configfs/file.c, fill_read_buffer() caps simple attributes at
SIMPLE_ATTR_SIZE (4096) regardless of PAGE_SIZE.  On architectures with
larger pages such as 16KB or 64KB, an expanding LBA map can still format
past 4096 bytes, triggering WARN_ON_ONCE() and returning -EIO.

Bounding the output to min_t(size_t, PAGE_SIZE, 4096) (or exposing
SIMPLE_ATTR_SIZE) would avoid that on non-4KB-page kernels.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-kbug-l986-v1-1-00584b0bc42a@gmail.com?part=1

  reply	other threads:[~2026-12-04  3:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:54 [PATCH] scsi: target: configfs: Bound the output of target_dev_lba_map_show() Anh Nguyen Hoang via B4 Relay
2026-12-04  3:02 ` sashiko-bot [this message]
     [not found]   ` <CABjBT5U5DUoT2UyZVT6SSxT4VAdSDna-RmnrAwf2kZZnQE86xg@mail.gmail.com>
2026-12-04  3:43     ` Anh Nguyen Hoang

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=sashiko-outbox-249015@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anhnh.4work@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=target-devel@vger.kernel.org \
    /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