Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1361153
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Nicolai Stange <nicstange@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH] fs/ext4: mb_find_order_for_block(): silence UBSAN |
| Date | Sat, 19 Mar 2016 21:00:01 +0100 |
| Message-ID | <revct-4om-3@gated-at.bofh.it> (permalink) |
| X-Original-To | "Theodore Ts'o" <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=qyl+0jpWodP3ed4C+n82kYtmcybrLl+VVQmCKqo1wHQ=; b=0vt8vTf4Rpq69FB1ooV9e15nUwpLnbnopDHb6jNuDvxfWWKQKGTW9BsWD/JsjIShQ1 p1Ix/rXOKPNkpVSL385p9YMuHde4lXRlMEd6SYm5tW3lC5D4yxcrGsf5SSe0IsT8omIa JN7M4mO80gP50il2PrxbEW7caZmNks5XxEMRQQlKfEXFW3QeonKJrJuTXoWHDi47IiPj 00OtZ04P2/rFeDjB9h6rkzniz4Z6KDfUw0CfPf40yec1BCKFXXv0XEcqJf7pkFXO8HU3 1a1/6Djho/htpL7pD103jjFXnueDFfTzvQOhHsScGfBtx80cwZzcVSEpyyZGY5TPWdpr Yi8A== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qyl+0jpWodP3ed4C+n82kYtmcybrLl+VVQmCKqo1wHQ=; b=SmObvrvdQWKd/iqT6XQrVE6f5zupcWBXIzC+6jSqjmW8qcKFD+Il/Bqr4kSaylhayD H3w4QxTNuP+oPHWG6v0XT02YGscDFKHj+LL2jE/7Om3Pa5edKueYCOHfQGpMfxHT7o+8 n7g0eZvO0tRWswAlNMjaBUJRu1imfEI/AR2wc9vIR6cLbtyldQH96yS/4EDB3uR2buSv kaptwRfcQxRDZhlEK1wubxTPwAKpVu/D+ABZCG1rI+icDIcs872Hr0rZuxX7Siwbrklf U+b2NirlmG0fb6FwJ0E+mcVyV1vokuGmIcoEUp/5pKpga7vVdE/8ZI7jJhhSACe55p/l gA6Q== |
| X-Gm-Message-State | AD7BkJJyN5oQqyH70/xM+Xj4Iess5/3lvGdOXgfiMVZJBSklxCrMmGfDZD6qKF1LSqzM5A== |
| X-Received | by 10.28.48.216 with SMTP id w207mr5228307wmw.69.1458417257568; Sat, 19 Mar 2016 12:54:17 -0700 (PDT) |
| X-Mailer | git-send-email 2.7.3 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 64 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange <nicstange@gmail.com> |
| X-Original-Date | Sat, 19 Mar 2016 20:54:07 +0100 |
| X-Original-Message-ID | <1458417247-3164-1-git-send-email-nicstange@gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1361153 |
Show key headers only | View raw
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 4.6.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>
---
Applicable to linux-next-20160318
fs/ext4/mballoc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 50e05df..4bc89fe 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1266,6 +1266,7 @@ static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)
static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
{
int order = 1;
+ int bb_incr = 1 << (e4b->bd_blkbits - 1);
void *bb;
BUG_ON(e4b->bd_bitmap == e4b->bd_buddy);
@@ -1278,7 +1279,8 @@ static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
/* this block is part of buddy of order 'order' */
return order;
}
- bb += 1 << (e4b->bd_blkbits - order);
+ bb += bb_incr;
+ bb_incr >>= 1;
order++;
}
return 0;
--
2.7.3
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] fs/ext4: mb_find_order_for_block(): silence UBSAN Nicolai Stange <nicstange@gmail.com> - 2016-03-19 21:00 +0100 Re: [PATCH] fs/ext4: mb_find_order_for_block(): silence UBSAN Nicolai Stange <nicstange@gmail.com> - 2016-03-19 22:20 +0100
csiph-web