linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: dhowells@redhat.com, willy@infradead.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v3] fs: fix undefined behavior in bit shift for SB_NOUSER
Date: Sat, 19 Nov 2022 05:14:35 +0000	[thread overview]
Message-ID: <Y3hmOzZwqpyHv8Ab@ZenIV> (raw)
In-Reply-To: <20221031142621.194389-1-cuigaosheng1@huawei.com>

On Mon, Oct 31, 2022 at 10:26:21PM +0800, Gaosheng Cui wrote:
> Shifting signed 32-bit value by 31 bits is undefined, so changing most
> significant bit to unsigned, and mark all of the flags as unsigned so
> that we don't mix types. The UBSAN warning calltrace like below:

... is completely irrelevant.  If you want to credit UBSAN for finding
that - sure, no problem, but who cares about the call chain leading to
use of SB_NOUSER?  If nothing else, report would be just as valid if
the only use had been in initializer for static variable...

I've no problem with the change itself, but I'd go with something along
the lines of

----
SB_... flags are masks for struct super_block ->s_flags, which is an
unsigned long.  In particular, SB_NOUSER lives in bit 31.  1 << 31
is not the right way to spell that - it's not just that it is an
undefined behaviour; it's not the right value when used to initialize
an unsigned long variable.  Nasal demons aside, on 64bit architecture
	unsigned long v = 1 << 31;
is *not* going to have v equal to 0x80000000 - it'll be 0xffffffff80000000.

Make the entire bunch explicitly unsigned - 1U << constant.  Note that
it doesn't make sense to go for 1UL - the flags are arch-independent
and that limits us to 32 bits anyway.

Spotted by UBSAN.
----

for commit message.  Not sure about "Fixes:", to be honest...

  parent reply	other threads:[~2022-11-19  5:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 14:26 [PATCH v3] fs: fix undefined behavior in bit shift for SB_NOUSER Gaosheng Cui
2022-10-31 14:28 ` Matthew Wilcox
2022-11-19  5:14 ` Al Viro [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-04-24  5:01 [PATCH V2] " Al Viro
2023-04-24  5:18 ` [PATCH V3] " Hao Ge

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=Y3hmOzZwqpyHv8Ab@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=cuigaosheng1@huawei.com \
    --cc=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --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).