public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Nithurshen <nithurshen.dev@gmail.com>, linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org
Subject: Re: [PATCH 1/2] erofs-utils: fix undefined behavior shift in erofs_init_devices
Date: Mon, 20 Apr 2026 09:52:24 +0800	[thread overview]
Message-ID: <00f14a87-6914-4e4a-96f1-6d0f911edc4d@linux.alibaba.com> (raw)
In-Reply-To: <20260419131604.95875-1-nithurshen.dev@gmail.com>



On 2026/4/19 21:16, Nithurshen wrote:
> In erofs_init_devices(), roundup_pow_of_two() can potentially trigger
> an undefined behavior shift if the incremented 'ondisk_extradevs'
> value results in an overflow or an input that leads to an
> out-of-bounds shift.

I wonder why there is "out-of-bounds shift"? why you all
think it's an issue? Can you please explain in details?

ondisk_extradevs is 65535 at most.

Thanks,
Gao Xiang


> 
> Promote the argument to u64 before the increment to ensure the
> rounding logic operates on a safe bit-width.
> 
> Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
> ---
>   lib/super.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/super.c b/lib/super.c
> index 088c9a0..10831a7 100644
> --- a/lib/super.c
> +++ b/lib/super.c
> @@ -49,7 +49,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
>   		return 0;
>   
>   	sbi->extra_devices = ondisk_extradevs;
> -	sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
> +	sbi->device_id_mask = roundup_pow_of_two((u64)ondisk_extradevs + 1) - 1;
>   	sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs));
>   	if (!sbi->devs)
>   		return -ENOMEM;



  parent reply	other threads:[~2026-04-20  1:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 13:16 [PATCH 1/2] erofs-utils: fix undefined behavior shift in erofs_init_devices Nithurshen
2026-04-19 13:16 ` [PATCH 2/2] erofs-utils: libzstd: fix undefined behavior shift in setdictsize Nithurshen
2026-04-20  1:54   ` Gao Xiang
2026-04-20  1:52 ` Gao Xiang [this message]
2026-04-20  2:50   ` Nithurshen
2026-04-20  2:57     ` Gao Xiang

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=00f14a87-6914-4e4a-96f1-6d0f911edc4d@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=nithurshen.dev@gmail.com \
    --cc=xiang@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