Stefan Hajnoczi 509a41bab5 block/cloop: prevent offsets_size integer overflow (CVE-2014-0143)
The following integer overflow in offsets_size can lead to out-of-bounds
memory stores when n_blocks has a huge value:

    uint32_t n_blocks, offsets_size;
    [...]
    ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4);
    [...]
    s->n_blocks = be32_to_cpu(s->n_blocks);

    /* read offsets */
    offsets_size = s->n_blocks * sizeof(uint64_t);
    s->offsets = g_malloc(offsets_size);

    [...]

    for(i=0;i<s->n_blocks;i++) {
        s->offsets[i] = be64_to_cpu(s->offsets[i]);

offsets_size can be smaller than n_blocks due to integer overflow.
Therefore s->offsets[] is too small when the for loop byteswaps offsets.

This patch refuses to open files if offsets_size would overflow.

Note that changing the type of offsets_size is not a fix since 32-bit
hosts still only have 32-bit size_t.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-01 13:59:47 +02:00
..
2014-02-21 21:02:24 +01:00
2013-12-20 16:26:16 +01:00
2014-02-21 21:02:24 +01:00
2014-02-21 21:02:23 +01:00
2013-09-12 10:12:47 +02:00
2014-03-25 14:09:50 +01:00
2013-08-19 15:52:19 +02:00
2014-02-25 10:50:11 +00:00
2014-02-21 21:02:22 +01:00
2014-03-19 09:39:41 +01:00
2014-02-21 21:02:24 +01:00
2014-02-17 11:57:23 -05:00
2014-03-25 14:09:50 +01:00
2014-02-17 11:57:23 -05:00
2014-03-25 14:09:50 +01:00
2013-09-12 10:12:48 +02:00
2014-03-25 14:09:50 +01:00
2014-03-25 14:09:50 +01:00
2014-02-21 21:02:23 +01:00
2014-02-21 21:02:24 +01:00