From: Khalid Aziz <khalid@kernel.org>
To: Kshitij Paranjape <kshitijvparanjape@gmail.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Doug Gilbert <dgilbert@interlog.com>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev, stable@vger.kernel.org,
syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com
Subject: Re: [PATCH] scsi: fix shift out-of-bounds in sg_build_indirect The num variable is set to 0. The variable num gets its value from scatter_elem_sz. However the minimum value of scatter_elem_sz is PAGE_SHIFT. So setting num to PAGE_SIZE when num < PAGE_SIZE.
Date: Mon, 6 Oct 2025 13:41:30 -0600 [thread overview]
Message-ID: <a6709051-bd95-4f7f-8a85-d4d670f7a316@kernel.org> (raw)
In-Reply-To: <20251006174658.217497-1-kshitijvparanjape@gmail.com>
On 10/6/25 11:46 AM, Kshitij Paranjape wrote:
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=270f1c719ee7baab9941
> Signed-off-by: Kshitij Paranjape <kshitijvparanjape@gmail.com>
> ---
> drivers/scsi/sg.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index effb7e768165..9ae41bb256d7 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1888,6 +1888,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
> if (num < PAGE_SIZE) {
> scatter_elem_sz = PAGE_SIZE;
> scatter_elem_sz_prev = PAGE_SIZE;
> + num = scatter_elem_sz;
> } else
> scatter_elem_sz_prev = num;
> }
Have you seen any issues caused by not setting num to PAGE_SIZE when num
< PAGE_SIZE?
From what I can see, num is used to calculate the page order for
allocation which will be 0 whether num=PAGE_SIZE or < PAGE_SIZE. After
that num gets assigned a new value any way before its next use.
--
Khalid
next prev parent reply other threads:[~2025-10-06 19:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 17:46 [PATCH] scsi: fix shift out-of-bounds in sg_build_indirect The num variable is set to 0. The variable num gets its value from scatter_elem_sz. However the minimum value of scatter_elem_sz is PAGE_SHIFT. So setting num to PAGE_SIZE when num < PAGE_SIZE Kshitij Paranjape
2025-10-06 18:00 ` vivek yadav
2025-10-06 19:23 ` Khalid Aziz
2025-10-06 19:41 ` Khalid Aziz [this message]
2025-10-07 1:42 ` David Hunter
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=a6709051-bd95-4f7f-8a85-d4d670f7a316@kernel.org \
--to=khalid@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=david.hunter.linux@gmail.com \
--cc=dgilbert@interlog.com \
--cc=kshitijvparanjape@gmail.com \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=skhan@linuxfoundation.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+270f1c719ee7baab9941@syzkaller.appspotmail.com \
/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