Am 12.11.2026 um 16:33 hat Julio Faracco geschrieben: > dmg_uncompress_lzfse_do() treated any non-zero lzfse_decode_buffer() > return as success. A crafted DMG can declare a larger chunk output size > than its LZFSE stream decodes to, leaking the unzeroed tail of > uncompressed_chunk to the guest as sector data -- a heap disclosure.
This paragraph talks about a too large destination, so it's a bit confusing to read about "exact-size and a too-small destination" as if this were related to solving the problem described here. My understanding is that the next paragraph is talking about a case that doesn't leak any information, but for which we still add validation while we're touching the code so that invalid images that contain "hidden" compressed data that would never be read are detected, too. Maybe this can be made a bit clearer in the commit message. > lzfse_decode_buffer() returns the destination capacity both for an > exact-size and a too-small destination, so decode with one extra byte of > capacity (allocated in dmg_open()): an exact stream returns avail_out, a > short or oversized one does not. Require out_size == avail_out. Decoding > in place also avoids a per-chunk g_malloc()/memcpy() of up to 64 MiB in > the read path. > > zlib and bzip2 chunk paths already enforce this; LZFSE did not. > > Fixes: CVE-2026-116483 > Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4662 > Reported-by: oxsignal <[email protected]> > Signed-off-by: Julio Faracco <[email protected]> > --- > block/dmg-lzfse.c | 27 +++++++++++++++++++-------- > block/dmg.c | 8 +++++++- > 2 files changed, 26 insertions(+), 9 deletions(-) > > diff --git a/block/dmg-lzfse.c b/block/dmg-lzfse.c > index 4ea0b9b20d..b1acd87135 100644 > --- a/block/dmg-lzfse.c > +++ b/block/dmg-lzfse.c > @@ -33,16 +33,27 @@ > static int dmg_uncompress_lzfse_do(char *next_in, unsigned int avail_in, > char *next_out, unsigned int avail_out) > { > - size_t out_size = lzfse_decode_buffer((uint8_t *) next_out, avail_out, > - (uint8_t *) next_in, avail_in, > - NULL); > + size_t out_size; > > - /* We need to decode the single chunk only. */ > - /* So, out_size == avail_out is not an error here. */ > - if (out_size > 0) { > - return out_size; > + /* > + * lzfse_decode_buffer() returns the destination capacity both on an > + * exact decode and when the destination is too small, so on its own it > + * cannot tell a full chunk from a short one. The caller allocates ...from a too long one, no? Well, depending if you're talking about the compressed or uncompressed chunk. Maybe say "a truncated one" instead? "short" sounds like the input side, i.e. the compressed stream, to me. > + * next_out one byte larger than avail_out (see dmg_open() in dmg.c); > + * decoding with that extra byte of capacity lets an exact decode > + * (out_size == avail_out) be distinguished from a short or oversized > + * stream, without a per-chunk scratch allocation or memcpy. > + * > + * next_out MUST have room for avail_out + 1 bytes. > + */ > + out_size = lzfse_decode_buffer((uint8_t *) next_out, avail_out + 1, > + (uint8_t *) next_in, avail_in, > + NULL); > + > + if (out_size != avail_out) { > + return -1; > } > - return -1; > + return out_size; > } Kevin
