mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: Poil Zero <poilandgginchi@gmail.com>, Jens Axboe <axboe@kernel.dk>
Cc: Boqun Feng <boqun@kernel.org>,
	Yingjie Wang <x-professor@outlook.com>,
	linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rnull: reject device size overflow
Date: Thu, 03 Dec 2026 14:56:50 +0100	[thread overview]
Message-ID: <87ecbyzcv1.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <20261203115742.384873-1-poilandgginchi@gmail.com>

"Poil Zero" <poilandgginchi@gmail.com> writes:

> The configfs size attribute accepts any u64 value in MiB.
> NullBlkDevice::new() converts it to a count of 512-byte sectors with
> capacity_mib << (20 - SECTOR_SHIFT). Bits shifted out of the u64 are
> silently discarded, so 2^53 MiB becomes zero sectors and 2^53 + 1 MiB
> becomes 2048 sectors. Smaller values can also exceed
> BLK_DEV_MAX_SECTORS and are clamped by set_capacity().
>
> Reject sizes above BLK_DEV_MAX_SECTORS / SECTORS_PER_MIB in the
> configfs store before updating the saved size. Also use checked_mul()
> and check the resulting sector count in NullBlkDevice::new(),
> returning -EINVAL if either limit is exceeded. Validate capacity before
> allocating the tag set or queue data. This prevents a device from being
> created with a wrapped or clamped capacity.
>
> Apply the same overflow and capacity bounds proposed for C null_blk
> in the linked patch by Yingjie Wang.
>
> Fixes: d969d504bc13 ("rnull: enable configuration via `configfs`")
> Link: https://lore.kernel.org/all/20261201140214.346038-1-x-professor@outlook.com/
> Signed-off-by: Poil Zero <poilandgginchi@gmail.com>

Thanks for fixing! Looks good to me, but I think we should move some of
the constants.

Please define `MAX_SECTORS` in rust/kernel/block.rs based on the
C define.

I don't think `SECTORS_PER_MIB` exist in the C code, but please add that
to block.rs as well. It seems generally useful.


Best regards,
Andreas Hindborg



      reply	other threads:[~2026-12-03 13:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mefIjhqK67vjOlDMxBPBLxVsVn8lVZXLDwt5hMhTYPk_P1UNJ2l1ho-9PsROe0Tx3RAYp6Ye6p1yWz4CtDSQ8Q==@protonmail.internalid>
2026-12-03 11:57 ` Poil Zero
2026-12-03 13:56   ` Andreas Hindborg [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=87ecbyzcv1.fsf@t14s.mail-host-address-is-not-set \
    --to=a.hindborg@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=boqun@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=poilandgginchi@gmail.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=x-professor@outlook.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

all inboxes | Powered by JetHome®