All of lore.kernel.org
 help / color / mirror / Atom feed
From: bugzilla-daemon@bugzilla.kernel.org
To: linux-ext4@vger.kernel.org
Subject: [Bug 114701] ubsan: "shift exponent -1 is negative" in fs/ext4/mballoc.c:2612:15
Date: Wed, 30 Mar 2016 09:12:29 +0000	[thread overview]
Message-ID: <bug-114701-13602-vrpyELHlhR@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-114701-13602@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=114701

Navin Parakkal <navinp1912@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |navinp1912@gmail.com

--- Comment #1 from Navin Parakkal <navinp1912@gmail.com> ---
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 50e05df..8ccfcf7 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1278,6 +1278,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;
                }
+               if (order > e4b->bd_blkbits)
+                       break;
                bb += 1 << (e4b->bd_blkbits - order);
                order++;
        }
@@ -2616,6 +2618,8 @@ int ext4_mb_init(struct super_block *sb)
        do {
                sbi->s_mb_offsets[i] = offset;
                sbi->s_mb_maxs[i] = max;
+               if (i > sb->s_blocksize_bits)
+                       break;
                offset += 1 << (sb->s_blocksize_bits - i);
                max = max >> 1;
                i++;


The only case if when i>b you compute off and max but those are not assigned .
So those values can be ignored. It keeps the old behaviour intact and fixes the
undefined behaviour.


offset += 1 << (sb->s_blocksize_bits - i);


/* Remove the if to see trap error at runtime */
/* gcc -fsanitize=undefined x.c */
int main()
{
    int i=1;
    int b=12;
    unsigned ub=12;
    unsigned off=0,uoff=0;
    do{
        if(i> b) break;
        off+=1<<(b-i);
        uoff+=1<<(ub-i);
        i++;
    } while(i<=b+1);
}

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

  reply	other threads:[~2016-03-30  9:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 19:53 [Bug 114701] New: ubsan: "shift exponent -1 is negative" in fs/ext4/mballoc.c:2612:15 bugzilla-daemon
2016-03-30  9:12 ` bugzilla-daemon [this message]
2016-05-06  1:19 ` [Bug 114701] " bugzilla-daemon

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=bug-114701-13602-vrpyELHlhR@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@bugzilla.kernel.org \
    --cc=linux-ext4@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.