linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namjae Jeon <linkinjeon@kernel.org>
To: Randy Dunlap <rdunlap@infradead.org>
Cc: linux-fsdevel@vger.kernel.org,
	syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	ntfs3@lists.linux.dev, Alexander Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kari Argillander <kari.argillander@stargateuniverse.net>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH v3] fs/ntfs3: validate BOOT sectors_per_clusters
Date: Tue, 3 May 2022 14:52:56 +0900	[thread overview]
Message-ID: <CAKYAXd8wWbe+xtd5jWSxmb9NF1YFYDo-2DQAJVLhZCHQaEnRSg@mail.gmail.com> (raw)
In-Reply-To: <20220502175342.20296-1-rdunlap@infradead.org>

2022-05-03 2:53 GMT+09:00, Randy Dunlap <rdunlap@infradead.org>:
> When the NTFS BOOT sectors_per_clusters field is > 0x80,
> it represents a shift value. Make sure that the shift value is
> not too large before using it (NTFS max cluster size is 2MB).
> Return -EVINVAL if it too large.
>
> This prevents negative shift values and shift values that are
> larger than the field size.
>
> Prevents this UBSAN error:
>
>  UBSAN: shift-out-of-bounds in ../fs/ntfs3/super.c:673:16
>  shift exponent -192 is negative
>
> Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Reported-by: syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com
> Cc: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
> Cc: ntfs3@lists.linux.dev
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kari Argillander <kari.argillander@stargateuniverse.net>
> Cc: Namjae Jeon <linkinjeon@kernel.org>
> Cc: Matthew Wilcox <willy@infradead.org>
Looks good to me:)

Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>

Thanks.
> ---
> v2: use Willy's suggestions
> v3: use Namjae's suggestions -- but now Konstantin can decide.
>     drop Willy's Rev-by: tag due to changes
>
>  fs/ntfs3/super.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> --- linux-next-20220428.orig/fs/ntfs3/super.c
> +++ linux-next-20220428/fs/ntfs3/super.c
> @@ -668,9 +668,11 @@ static u32 format_size_gb(const u64 byte
>
>  static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
>  {
> -	return boot->sectors_per_clusters <= 0x80
> -		       ? boot->sectors_per_clusters
> -		       : (1u << (0 - boot->sectors_per_clusters));
> +	if (boot->sectors_per_clusters <= 0x80)
> +		return boot->sectors_per_clusters;
> +	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
> +		return 1U << (0 - boot->sectors_per_clusters);
> +	return -EINVAL;
>  }
>
>  /*
> @@ -713,6 +715,8 @@ static int ntfs_init_from_boot(struct su
>
>  	/* cluster size: 512, 1K, 2K, 4K, ... 2M */
>  	sct_per_clst = true_sectors_per_clst(boot);
> +	if ((int)sct_per_clst < 0)
> +		goto out;
>  	if (!is_power_of_2(sct_per_clst))
>  		goto out;
>
>
>

      reply	other threads:[~2022-05-03  5:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 17:53 [PATCH v3] fs/ntfs3: validate BOOT sectors_per_clusters Randy Dunlap
2022-05-03  5:52 ` Namjae Jeon [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=CAKYAXd8wWbe+xtd5jWSxmb9NF1YFYDo-2DQAJVLhZCHQaEnRSg@mail.gmail.com \
    --to=linkinjeon@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=kari.argillander@stargateuniverse.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=rdunlap@infradead.org \
    --cc=syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).