From: Ming Lei <ming.lei@redhat.com>
To: Mehul Rao <mehulrao@gmail.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] ublk: fix NULL pointer dereference in ublk_ctrl_set_size()
Date: Fri, 6 Mar 2026 11:17:17 +0800 [thread overview]
Message-ID: <aapHPc07uU_dBwKG@fedora> (raw)
In-Reply-To: <20260305193146.304526-1-mehulrao@gmail.com>
On Thu, Mar 05, 2026 at 02:31:46PM -0500, Mehul Rao wrote:
> ublk_ctrl_set_size() unconditionally dereferences ub->ub_disk via
> set_capacity_and_notify() without checking if it is NULL.
>
> ub->ub_disk is NULL before UBLK_CMD_START_DEV completes (it is only
> assigned in ublk_ctrl_start_dev()) and after UBLK_CMD_STOP_DEV runs
> (ublk_detach_disk() sets it to NULL). Since the UBLK_CMD_UPDATE_SIZE
> handler performs no state validation, a user can trigger a NULL pointer
> dereference by sending UPDATE_SIZE to a device that has been added but
> not yet started, or one that has been stopped.
>
> Fix this by checking ub->ub_disk under ub->mutex before dereferencing
> it, and returning -ENODEV if the disk is not available.
>
> Fixes: 98b995660bff ("ublk: Add UBLK_U_CMD_UPDATE_SIZE")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mehul Rao <mehulrao@gmail.com>
Looks fine given ublk_detach_disk() is called with ub->mutex grabbed:
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
next prev parent reply other threads:[~2026-03-06 3:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 19:31 [PATCH] ublk: fix NULL pointer dereference in ublk_ctrl_set_size() Mehul Rao
2026-03-06 3:17 ` Ming Lei [this message]
2026-03-06 11:26 ` Jens Axboe
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=aapHPc07uU_dBwKG@fedora \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mehulrao@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