From: Greg KH <gregkh@linuxfoundation.org>
To: Khemissi Mohammed el Amine <aminekhemissi61@gmail.com>
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] scsi: Fix NULL pointer dereference in scsi_setup_scsi_cmnd()
Date: Tue, 24 Feb 2026 01:29:58 +0100 [thread overview]
Message-ID: <2026022446-grape-harpist-90c5@gregkh> (raw)
In-Reply-To: <20260223231403.14069-1-aminekhemissi61@gmail.com>
On Mon, Feb 23, 2026 at 03:14:03PM -0800, Khemissi Mohammed el Amine wrote:
> A NULL pointer dereference can occur in scsi_setup_scsi_cmnd() when handling
> BSG ioctls with zero-length requests. The function calls scsi_command_size()
> before cmd->cmnd is initialized, leading to a kernel oops when the pointer
> is dereferenced.
>
> The crash occurs in the following sequence:
> 1. BSG ioctl issued with sg_io_v4.request = NULL, request_len = 0
> 2. scsi_setup_scsi_cmnd() invoked via scsi_queue_rq()
> 3. If scsi_req(req)->cmd_len == 0, code calls scsi_command_size(cmd->cmnd)
> 4. cmd->cmnd has not been set yet (still NULL or uninitialized)
> 5. scsi_command_size() dereferences the NULL pointer without checking
> 6. Kernel NULL pointer dereference oops
>
> This issue affects Linux 5.10 LTS . Local users with access to
> /dev/bsg/* device nodes can trigger this crash.
>
> Fix this by:
> 1. Adding a NULL check in scsi_command_size() to handle NULL input gracefully
> 2. Adding a NULL check in scsi_setup_scsi_cmnd() before calling
> scsi_command_size()
>
> Signed-off-by: Khemissi Mohammed el Amine <aminekhemissi61@gmail.com>
> ---
> drivers/scsi/scsi_lib.c | 6 ++++++
> include/scsi/scsi_common.h | 2 ++
> 2 files changed, 8 insertions(+)
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
prev parent reply other threads:[~2026-02-24 0:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 23:14 [PATCH] scsi: Fix NULL pointer dereference in scsi_setup_scsi_cmnd() Khemissi Mohammed el Amine
2026-02-24 0:29 ` Greg KH [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=2026022446-grape-harpist-90c5@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=aminekhemissi61@gmail.com \
--cc=stable@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