Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1279340

[RFC] arch/ia64/kernel/palinfo.c: bitvector_process reading out of bounds

From Geyslan Gregório Bem <geyslan@gmail.com>
Newsgroups linux.kernel
Subject [RFC] arch/ia64/kernel/palinfo.c: bitvector_process reading out of bounds
Date 2015-11-29 15:10 +0100
Message-ID <qAaPU-7a0-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Hello,

I'm doing some static analysis and stumbled in this function

static void bitvector_process(struct seq_file *m, u64 vector)
{
    int i,j;
    static const char *units[]={ "", "K", "M", "G", "T" };

    for (i=0, j=0; i < 64; i++ , j=i/10) {
        if (vector & 0x1)
            seq_printf(m, "%d%s ", 1 << (i-j*10), units[j]);
        vector >>= 1;
    }
}

It appears that units[] (5 elements) can be accessed out of bounds in
seq_printf call

            seq_printf(m, "%d%s ", 1 << (i-j*10), units[j]);

once j is being set to i/10.

i goes from 0 to 63 (u64 bits length), and when vector & 1 (odd),
units[j] will calculate outside the boundaries when vector get close
to Petabyte magnitude.

Well, as bitvector_process doesn't control the max size of vector and
the future is knocking on door, I would suggest this change

-static const char *units[]={ "", "K", "M", "G", "T" };
+static const char *units[]={ "", "K", "M", "G", "T", "P", "E" };

then if the u64 max value (18446744073709551615) is used the array
will provide the correct (E) suffix.

If that change is not pertinent I would like to know why.

-- 
Regards,

Geyslan G. Bem
hackingbits.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[RFC] arch/ia64/kernel/palinfo.c: bitvector_process reading out of bounds Geyslan Gregório Bem <geyslan@gmail.com> - 2015-11-29 15:10 +0100

csiph-web