From: Theodore Ts'o <tytso@mit.edu>
To: Nicolai Stange <nicstange@gmail.com>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] fs/ext4: mb_find_order_for_block(): silence UBSAN
Date: Thu, 5 May 2016 17:58:19 -0400 [thread overview]
Message-ID: <20160505215819.GA30122@thunk.org> (raw)
In-Reply-To: <1458421925-5481-2-git-send-email-nicstange@gmail.com>
On Sat, Mar 19, 2016 at 10:12:04PM +0100, Nicolai Stange wrote:
> Currently, in mb_find_order_for_block(), there's a loop like the following:
>
> while (order <= e4b->bd_blkbits + 1) {
> ...
> bb += 1 << (e4b->bd_blkbits - order);
> }
>
> Note that the updated bb is used in the loop's next iteration only.
>
> However, at the last iteration, that is at order == e4b->bd_blkbits + 1,
> the shift count becomes negative (c.f. C99 6.5.7(3)) and UBSAN reports
>
> UBSAN: Undefined behaviour in fs/ext4/mballoc.c:1281:11
> shift exponent -1 is negative
> [...]
> Call Trace:
> [<ffffffff818c4d35>] dump_stack+0xbc/0x117
> [<ffffffff818c4c79>] ? _atomic_dec_and_lock+0x169/0x169
> [<ffffffff819411bb>] ubsan_epilogue+0xd/0x4e
> [<ffffffff81941cbc>] __ubsan_handle_shift_out_of_bounds+0x1fb/0x254
> [<ffffffff81941ac1>] ? __ubsan_handle_load_invalid_value+0x158/0x158
> [<ffffffff816e93a0>] ? ext4_mb_generate_from_pa+0x590/0x590
> [<ffffffff816502c8>] ? ext4_read_block_bitmap_nowait+0x598/0xe80
> [<ffffffff816e7b7e>] mb_find_order_for_block+0x1ce/0x240
> [...]
>
> Unless compilers start to do some fancy transformations (which at least
> GCC 6.0.0 doesn't currently do), the issue is of cosmetic nature only: the
> such calculated value of bb is never used again.
>
> Silence UBSAN by introducing another variable, bb_incr, holding the next
> increment to apply to bb and adjust that one by right shifting it by one
> position per loop iteration.
>
> Signed-off-by: Nicolai Stange <nicstange@gmail.com>
Thanks, applied.
- Ted
next prev parent reply other threads:[~2016-05-05 21:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-19 21:12 [PATCH v2 0/2] fs/ext4: mballoc.c: silence two UBSAN reports Nicolai Stange
2016-03-19 21:12 ` [PATCH v2 1/2] fs/ext4: mb_find_order_for_block(): silence UBSAN Nicolai Stange
2016-05-05 21:58 ` Theodore Ts'o [this message]
2016-03-19 21:12 ` [PATCH v2 2/2] fs/ext4: ext4_mb_init(): " Nicolai Stange
2016-05-05 23:47 ` Theodore Ts'o
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=20160505215819.GA30122@thunk.org \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicstange@gmail.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;
as well as URLs for NNTP newsgroup(s).