Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 2/4] scsi: proc: use kmalloc() in proc writers
Date: Tue, 30 Jun 2026 11:19:07 +0000	[thread overview]
Message-ID: <20260630111907.EC94B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630-b4-scsi-v1-2-494fb37ebe7b@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The buffer allocated for the SCSI host write_info callback is not zero-initialized or explicitly null-terminated before being passed to drivers. This causes drivers that use string-parsing functions like simple_strtoul() to read past the user-provided length into uninitialized memory.
--

commit 781e3d263bb9419478bfe3f51bf7dd6d8c93c647
Author: Mike Rapoport (Microsoft) <rppt@kernel.org>

scsi: proc: use kmalloc() in proc writers

proc_scsi_host_write(), proc_scsi_write() and proc_scsi_devinfo_write()
allocate temporary buffers for /proc writes using __get_free_page().
This commit replaces the __get_free_page() calls with kmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com

> diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
> index 1799dcae775c0..fdc355d783da3 100644
> --- a/drivers/scsi/scsi_proc.c
> +++ b/drivers/scsi/scsi_proc.c
[ ... ]
> @@ -74,7 +75,7 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
>  	if (!shost->hostt->write_info)
>  		return -EINVAL;
>  
> -	page = (char *)__get_free_page(GFP_KERNEL);
> +	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
>  	if (page) {
>  		ret = -EFAULT;
>  		if (copy_from_user(page, buf, count))
>  			goto out;
>  		ret = shost->hostt->write_info(shost, page, count);

[Severity: High]
This is a pre-existing issue, but the buffer allocated for the SCSI host
write_info callback is not zero-initialized or explicitly null-terminated
before being passed to drivers.

If a user writes data to a SCSI host /proc file without appending a non-digit
character (like a newline or null terminator), driver callbacks that use
string parsing functions like simple_strtoul() will continue reading past
the user input into uninitialized memory.

For example, this can happen in drivers/scsi/imm.c:imm_write_info():

	dev->mode = simple_strtoul(buffer + 5, NULL, 0);

Could we explicitly null-terminate the buffer or use kzalloc() here, so that
these string parsing functions don't read garbage data from uninitialized
memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630-b4-scsi-v1-0-494fb37ebe7b@kernel.org?part=2

  reply	other threads:[~2026-06-30 11:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 10:54 [PATCH 0/4] scsi: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-06-30 10:54 ` [PATCH 1/4] scsi: target: file: use kmalloc() to allocate temporary protection buffer Mike Rapoport (Microsoft)
2026-07-01  6:58   ` Hannes Reinecke
2026-06-30 10:54 ` [PATCH 2/4] scsi: proc: use kmalloc() in proc writers Mike Rapoport (Microsoft)
2026-06-30 11:19   ` sashiko-bot [this message]
2026-07-01  6:58   ` Hannes Reinecke
2026-07-01 10:52   ` John Garry
2026-07-01 13:50     ` Mike Rapoport
2026-06-30 10:54 ` [PATCH 3/4] scsi: ipr: use kmalloc() to allocate IPR dump buffer memory Mike Rapoport (Microsoft)
2026-06-30 11:28   ` sashiko-bot
2026-07-01  7:03   ` Hannes Reinecke
2026-07-01  9:52     ` Mike Rapoport
2026-07-01 21:03       ` Brian King
2026-06-30 10:54 ` [PATCH 4/4] scsi: sym53c8xx_2: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-06-30 11:37   ` sashiko-bot
2026-07-01  7:04   ` Hannes Reinecke

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=20260630111907.EC94B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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