All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Julio Faracco <jcfaracco@gmail.com>
Cc: qemu-devel@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-block@nongnu.org, oxsignal <awo@kakao.com>
Subject: Re: [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes
Date: Mon, 16 Nov 2026 18:03:53 +0100	[thread overview]
Message-ID: <avs3eZhTRm-ItTZU@redhat.com> (raw)
In-Reply-To: <20261112-dmg-short-decode-v1-1-f7f342097b60@gmail.com>

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 <awo@kakao.com>
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  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



  reply	other threads:[~2026-11-16 17:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 15:33 [PATCH 0/2] block/dmg-lzfse: fix short-decode heap disclosure and add regression test Julio Faracco
2026-11-12 15:33 ` [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes Julio Faracco
2026-11-16 17:03   ` Kevin Wolf [this message]
2026-11-16 22:09   ` Stefan Hajnoczi
2026-11-12 15:33 ` [PATCH 2/2] tests/qemu-iotests: cover the dmg LZFSE short-decode fix Julio Faracco
2026-11-16 16:49   ` Kevin Wolf

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=avs3eZhTRm-ItTZU@redhat.com \
    --to=kwolf@redhat.com \
    --cc=awo@kakao.com \
    --cc=hreitz@redhat.com \
    --cc=jcfaracco@gmail.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.