Re: [PATCH] mmc: block: reject invalid perdev_minors before division

Ulf Hansson <[email protected]> Fri, 10 Jul 2026 15:21:03 +0200
Newsgroups org.kernel.vger.linux-mmc,org.kernel.vger.linux-kernel
Message-ID <CAPx+jO_b5daCjCXBSB_j4BqWwaJ8tKiLoD5VutHF_F1Dmsb3DQ@mail.gmail.com>
On Mon, Jul 6, 2026 at 11:25 AM raoxu <[email protected]> wrote:
>
> From: Xu Rao <[email protected]>
>
> The mmcblk.perdev_minors module parameter is parsed as a signed int and
> is used during mmc_blk_init() to compute the number of supported block
> devices.
>
> Passing perdev_minors=0 makes the init path divide by zero when it
> computes max_devices. Negative values are invalid as well and would make
> max_devices negative before it is later used as an IDA limit.
>
> Reject non-positive perdev_minors values before registering any mmcblk
> resources.
>
> Signed-off-by: Xu Rao <[email protected]>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/core/block.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 0274e8d07660..9cfd27c90215 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -3338,6 +3338,11 @@ static int __init mmc_blk_init(void)
>  {
>         int res;
>
> +       if (perdev_minors <= 0) {
> +               pr_err("mmcblk: invalid minors per device: %d\n", perdev_minors);
> +               return -EINVAL;
> +       }
> +
>         res  = bus_register(&mmc_rpmb_bus_type);
>         if (res < 0) {
>                 pr_err("mmcblk: could not register RPMB bus type\n");
> --
> 2.50.1
>