* [PATCH 0/2] block/dmg-lzfse: fix short-decode heap disclosure and add regression test
@ 2026-11-12 15:33 Julio Faracco
2026-11-12 15:33 ` [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes Julio Faracco
2026-11-12 15:33 ` [PATCH 2/2] tests/qemu-iotests: cover the dmg LZFSE short-decode fix Julio Faracco
0 siblings, 2 replies; 6+ messages in thread
From: Julio Faracco @ 2026-11-12 15:33 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Hanna Reitz, Stefan Hajnoczi, qemu-block,
Julio Faracco, oxsignal
This series fixes a heap disclosure vulnerability in the DMG block driver's
LZFSE decompression path (CVE-2026-116483) and adds a regression test.
Specifically, this series (1) updates `dmg_uncompress_lzfse_do()` to decode
with one extra byte of capacity (pre-allocated in `dmg_open()`) so that
exact decodes can be reliably distinguished from short or oversized LZFSE
streams, preventing unzeroed chunk tail leakage.
It also (2) introduces a new qemu-iotest (`dmg-lzfse-short`) that
constructs a crafted DMG with a short LZFSE stream and verifies that
reading the chunk correctly fails with an I/O error.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
Julio Faracco (2):
block/dmg-lzfse: reject short LZFSE decodes
tests/qemu-iotests: cover the dmg LZFSE short-decode fix
block/dmg-lzfse.c | 27 +++--
block/dmg.c | 8 +-
tests/qemu-iotests/tests/dmg-lzfse-short | 142 +++++++++++++++++++++++++++
tests/qemu-iotests/tests/dmg-lzfse-short.out | 2 +
4 files changed, 170 insertions(+), 9 deletions(-)
---
base-commit: 29760efaf96bbe5928f8111881eddbf5ac06439e
change-id: 20261112-dmg-short-decode-69099ac44700
Best regards,
--
Julio Faracco <jcfaracco@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes
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 ` Julio Faracco
2026-11-16 17:03 ` Kevin Wolf
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
1 sibling, 2 replies; 6+ messages in thread
From: Julio Faracco @ 2026-11-12 15:33 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Hanna Reitz, Stefan Hajnoczi, qemu-block,
Julio Faracco, oxsignal
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.
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
+ * 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;
}
__attribute__((constructor))
diff --git a/block/dmg.c b/block/dmg.c
index 412d4bfc35..aa0a0a2fe5 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -587,8 +587,14 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
/* initialize zlib engine */
s->compressed_chunk = qemu_try_blockalign(bs->file->bs,
ds.max_compressed_size + 1);
+ /*
+ * One extra byte so dmg-lzfse.c can decode a chunk in place with a
+ * capacity of avail_out + 1 and still tell an exact decode from a
+ * short or oversized LZFSE stream. See dmg_uncompress_lzfse_do().
+ */
s->uncompressed_chunk = qemu_try_blockalign(bs->file->bs,
- 512 * ds.max_sectors_per_chunk);
+ 512 * ds.max_sectors_per_chunk
+ + 1);
if (s->compressed_chunk == NULL || s->uncompressed_chunk == NULL) {
ret = -ENOMEM;
goto fail;
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] tests/qemu-iotests: cover the dmg LZFSE short-decode fix
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-12 15:33 ` Julio Faracco
2026-11-16 16:49 ` Kevin Wolf
1 sibling, 1 reply; 6+ messages in thread
From: Julio Faracco @ 2026-11-12 15:33 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Hanna Reitz, Stefan Hajnoczi, qemu-block,
Julio Faracco
Add a regression test for the LZFSE short-decode heap disclosure. It
builds a minimal DMG (koly trailer, plist, BLKX block, LZFSE data fork)
whose chunk declares two sectors of output while its LZFSE stream only
decodes to one, and checks that reading the chunk now fails with an I/O
error instead of leaking stale heap bytes.
A valid single-sector DMG is converted first; if that fails, the test
is skipped as LZFSE support is not built in.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
tests/qemu-iotests/tests/dmg-lzfse-short | 142 +++++++++++++++++++++++++++
tests/qemu-iotests/tests/dmg-lzfse-short.out | 2 +
2 files changed, 144 insertions(+)
diff --git a/tests/qemu-iotests/tests/dmg-lzfse-short b/tests/qemu-iotests/tests/dmg-lzfse-short
new file mode 100755
index 0000000000..fc0b69cee3
--- /dev/null
+++ b/tests/qemu-iotests/tests/dmg-lzfse-short
@@ -0,0 +1,142 @@
+#!/usr/bin/env python3
+# group: rw quick
+#
+# Regression test for the dmg LZFSE short-decode heap disclosure.
+#
+# Copyright (C) 2026 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# A crafted DMG can declare a chunk output size larger than its LZFSE
+# stream actually produces. dmg_uncompress_lzfse_do() used to accept
+# such a short decode and hand the untouched tail of the (unzeroed)
+# uncompressed chunk buffer to the guest -- a heap disclosure. Reading
+# such a chunk must now fail with an I/O error instead.
+
+import base64
+import os
+import struct
+import sys
+
+import iotests
+
+ULFO = 0x80000007 # LZFSE compressed block type
+SECTOR = 512
+
+
+def lzfse_uncompressed_stream(payload: bytes) -> bytes:
+ """A valid LZFSE stream: one uncompressed block + end-of-stream marker."""
+ return (b'bvx-' + struct.pack('<I', len(payload)) # uncompressed block
+ + payload
+ + b'bvx$') # end of stream
+
+
+def build_dmg(stream: bytes, decl_sectors: int, total_sectors: int) -> bytes:
+ """
+ Build a minimal DMG with a single LZFSE chunk. The chunk declares
+ decl_sectors sectors of output; when that exceeds what 'stream'
+ decodes to, the decode is short.
+ """
+ data_fork = stream
+
+ # BLKX ("mish") block: 204-byte header followed by one 40-byte entry.
+ mish = bytearray(204)
+ struct.pack_into('>I', mish, 0x00, 0x6d697368) # 'mish' magic
+ struct.pack_into('>I', mish, 0x04, 1) # version
+ struct.pack_into('>Q', mish, 0x08, 0) # first sector number
+ struct.pack_into('>Q', mish, 0x10, total_sectors) # sector count
+ struct.pack_into('>Q', mish, 0x18, 0) # data fork offset
+
+ entry = bytearray(40)
+ struct.pack_into('>I', entry, 0x00, ULFO) # entry type
+ struct.pack_into('>Q', entry, 0x08, 0) # sector number
+ struct.pack_into('>Q', entry, 0x10, decl_sectors) # sector count
+ struct.pack_into('>Q', entry, 0x18, 0) # compressed offset
+ struct.pack_into('>Q', entry, 0x20, len(data_fork)) # compressed length
+ mish += entry
+
+ xml = (b'<plist><dict><data>'
+ + base64.b64encode(bytes(mish))
+ + b'</data></dict></plist>')
+
+ buf = bytearray()
+ buf += data_fork
+ xml_off = len(buf)
+ buf += xml
+ koly_off = len(buf)
+
+ # UDIF trailer ("koly" block), 512 bytes, big-endian.
+ koly = bytearray(512)
+ struct.pack_into('>4s', koly, 0x000, b'koly') # signature
+ struct.pack_into('>I', koly, 0x004, 4) # version
+ struct.pack_into('>I', koly, 0x008, 512) # header size
+ struct.pack_into('>Q', koly, 0x018, 0) # DataForkOffset
+ struct.pack_into('>Q', koly, 0x020, len(data_fork)) # DataForkLength
+ struct.pack_into('>Q', koly, 0x028, 0) # RsrcForkOffset
+ struct.pack_into('>Q', koly, 0x030, 0) # RsrcForkLength
+ struct.pack_into('>Q', koly, 0x0d8, xml_off) # XMLOffset
+ struct.pack_into('>Q', koly, 0x0e0, len(xml)) # XMLLength
+ struct.pack_into('>q', koly, 0x1ec, total_sectors) # SectorCount
+ buf += koly
+
+ assert koly_off == len(buf) - 512
+ return bytes(buf)
+
+
+def convert_to_raw(dmg: bytes, name: str):
+ dmg_path = os.path.join(iotests.test_dir, name)
+ raw_path = dmg_path + '.raw'
+ with open(dmg_path, 'wb') as f:
+ f.write(dmg)
+ res = iotests.qemu_img('convert', '-f', 'dmg', '-O', 'raw',
+ dmg_path, raw_path, check=False)
+ return res, dmg_path, raw_path
+
+
+def main() -> None:
+ payload = b'\xab' * SECTOR
+
+ # A well-formed single-sector chunk must convert cleanly. Skip only
+ # when QEMU was built without the LZFSE module (so this would never
+ # work); treat any other failure as a real regression.
+ good = build_dmg(lzfse_uncompressed_stream(payload),
+ decl_sectors=1, total_sectors=1)
+ res, _, raw_path = convert_to_raw(good, 'good.dmg')
+ if res.returncode != 0:
+ if 'dmg-lzfse module is missing' in res.stdout:
+ iotests.notrun('LZFSE decompression not available')
+ iotests.log('FAIL: valid LZFSE chunk failed to convert')
+ iotests.log(res.stdout)
+ sys.exit(1)
+
+ with open(raw_path, 'rb') as f:
+ if f.read() != payload:
+ iotests.log('FAIL: valid LZFSE chunk decoded incorrectly')
+ return
+ iotests.log('valid LZFSE chunk converts: ok')
+
+ # Same 512-byte stream, but the chunk claims two sectors (1024 bytes).
+ # The decode is short and must be rejected with an I/O error.
+ evil = build_dmg(lzfse_uncompressed_stream(payload),
+ decl_sectors=2, total_sectors=2)
+ res, _, _ = convert_to_raw(evil, 'evil.dmg')
+ if res.returncode == 0:
+ iotests.log('FAIL: short LZFSE decode was accepted')
+ return
+ iotests.log('short LZFSE decode rejected: ok')
+
+
+iotests.script_main(main, supported_fmts=['dmg'],
+ supported_protocols=['file'],
+ supported_platforms=['linux'])
diff --git a/tests/qemu-iotests/tests/dmg-lzfse-short.out b/tests/qemu-iotests/tests/dmg-lzfse-short.out
new file mode 100644
index 0000000000..6802cf1a76
--- /dev/null
+++ b/tests/qemu-iotests/tests/dmg-lzfse-short.out
@@ -0,0 +1,2 @@
+valid LZFSE chunk converts: ok
+short LZFSE decode rejected: ok
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] tests/qemu-iotests: cover the dmg LZFSE short-decode fix
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
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2026-11-16 16:49 UTC (permalink / raw)
To: Julio Faracco; +Cc: qemu-devel, Hanna Reitz, Stefan Hajnoczi, qemu-block
Am 12.11.2026 um 16:33 hat Julio Faracco geschrieben:
> Add a regression test for the LZFSE short-decode heap disclosure. It
> builds a minimal DMG (koly trailer, plist, BLKX block, LZFSE data fork)
> whose chunk declares two sectors of output while its LZFSE stream only
> decodes to one, and checks that reading the chunk now fails with an I/O
> error instead of leaking stale heap bytes.
>
> A valid single-sector DMG is converted first; if that fails, the test
> is skipped as LZFSE support is not built in.
>
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
The last paragraph isn't completely accurate any more, the test checks
the specific error message now.
> tests/qemu-iotests/tests/dmg-lzfse-short | 142 +++++++++++++++++++++++++++
> tests/qemu-iotests/tests/dmg-lzfse-short.out | 2 +
> 2 files changed, 144 insertions(+)
>
> diff --git a/tests/qemu-iotests/tests/dmg-lzfse-short b/tests/qemu-iotests/tests/dmg-lzfse-short
> new file mode 100755
> index 0000000000..fc0b69cee3
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/dmg-lzfse-short
> @@ -0,0 +1,142 @@
> +#!/usr/bin/env python3
> +# group: rw quick
> +#
> +# Regression test for the dmg LZFSE short-decode heap disclosure.
> +#
> +# Copyright (C) 2026 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# A crafted DMG can declare a chunk output size larger than its LZFSE
> +# stream actually produces. dmg_uncompress_lzfse_do() used to accept
> +# such a short decode and hand the untouched tail of the (unzeroed)
> +# uncompressed chunk buffer to the guest -- a heap disclosure. Reading
> +# such a chunk must now fail with an I/O error instead.
> +
> +import base64
> +import os
> +import struct
> +import sys
> +
> +import iotests
> +
> +ULFO = 0x80000007 # LZFSE compressed block type
> +SECTOR = 512
> +
> +
> +def lzfse_uncompressed_stream(payload: bytes) -> bytes:
> + """A valid LZFSE stream: one uncompressed block + end-of-stream marker."""
> + return (b'bvx-' + struct.pack('<I', len(payload)) # uncompressed block
> + + payload
> + + b'bvx$') # end of stream
> +
> +
> +def build_dmg(stream: bytes, decl_sectors: int, total_sectors: int) -> bytes:
> + """
> + Build a minimal DMG with a single LZFSE chunk. The chunk declares
> + decl_sectors sectors of output; when that exceeds what 'stream'
> + decodes to, the decode is short.
> + """
> + data_fork = stream
> +
> + # BLKX ("mish") block: 204-byte header followed by one 40-byte entry.
> + mish = bytearray(204)
> + struct.pack_into('>I', mish, 0x00, 0x6d697368) # 'mish' magic
> + struct.pack_into('>I', mish, 0x04, 1) # version
> + struct.pack_into('>Q', mish, 0x08, 0) # first sector number
> + struct.pack_into('>Q', mish, 0x10, total_sectors) # sector count
> + struct.pack_into('>Q', mish, 0x18, 0) # data fork offset
> +
> + entry = bytearray(40)
> + struct.pack_into('>I', entry, 0x00, ULFO) # entry type
> + struct.pack_into('>Q', entry, 0x08, 0) # sector number
> + struct.pack_into('>Q', entry, 0x10, decl_sectors) # sector count
> + struct.pack_into('>Q', entry, 0x18, 0) # compressed offset
> + struct.pack_into('>Q', entry, 0x20, len(data_fork)) # compressed length
> + mish += entry
> +
> + xml = (b'<plist><dict><data>'
> + + base64.b64encode(bytes(mish))
> + + b'</data></dict></plist>')
> +
> + buf = bytearray()
> + buf += data_fork
> + xml_off = len(buf)
> + buf += xml
> + koly_off = len(buf)
> +
> + # UDIF trailer ("koly" block), 512 bytes, big-endian.
> + koly = bytearray(512)
> + struct.pack_into('>4s', koly, 0x000, b'koly') # signature
> + struct.pack_into('>I', koly, 0x004, 4) # version
> + struct.pack_into('>I', koly, 0x008, 512) # header size
> + struct.pack_into('>Q', koly, 0x018, 0) # DataForkOffset
> + struct.pack_into('>Q', koly, 0x020, len(data_fork)) # DataForkLength
> + struct.pack_into('>Q', koly, 0x028, 0) # RsrcForkOffset
> + struct.pack_into('>Q', koly, 0x030, 0) # RsrcForkLength
> + struct.pack_into('>Q', koly, 0x0d8, xml_off) # XMLOffset
> + struct.pack_into('>Q', koly, 0x0e0, len(xml)) # XMLLength
> + struct.pack_into('>q', koly, 0x1ec, total_sectors) # SectorCount
> + buf += koly
> +
> + assert koly_off == len(buf) - 512
> + return bytes(buf)
> +
> +
> +def convert_to_raw(dmg: bytes, name: str):
> + dmg_path = os.path.join(iotests.test_dir, name)
> + raw_path = dmg_path + '.raw'
> + with open(dmg_path, 'wb') as f:
> + f.write(dmg)
> + res = iotests.qemu_img('convert', '-f', 'dmg', '-O', 'raw',
> + dmg_path, raw_path, check=False)
> + return res, dmg_path, raw_path
The test forgets to clean up after itself, i.e. remove the image files
it created. iotests.py has the FilePath context manager, or if that is
hard to integrate, the file_path() function to support this.
It's a common pattern to wrap a test in something like this:
with iotests.FilePath('disk.img') as path:
...
> +
> +
> +def main() -> None:
> + payload = b'\xab' * SECTOR
> +
> + # A well-formed single-sector chunk must convert cleanly. Skip only
> + # when QEMU was built without the LZFSE module (so this would never
> + # work); treat any other failure as a real regression.
> + good = build_dmg(lzfse_uncompressed_stream(payload),
> + decl_sectors=1, total_sectors=1)
> + res, _, raw_path = convert_to_raw(good, 'good.dmg')
> + if res.returncode != 0:
> + if 'dmg-lzfse module is missing' in res.stdout:
> + iotests.notrun('LZFSE decompression not available')
> + iotests.log('FAIL: valid LZFSE chunk failed to convert')
> + iotests.log(res.stdout)
> + sys.exit(1)
> +
> + with open(raw_path, 'rb') as f:
> + if f.read() != payload:
> + iotests.log('FAIL: valid LZFSE chunk decoded incorrectly')
> + return
> + iotests.log('valid LZFSE chunk converts: ok')
> +
> + # Same 512-byte stream, but the chunk claims two sectors (1024 bytes).
> + # The decode is short and must be rejected with an I/O error.
> + evil = build_dmg(lzfse_uncompressed_stream(payload),
> + decl_sectors=2, total_sectors=2)
> + res, _, _ = convert_to_raw(evil, 'evil.dmg')
> + if res.returncode == 0:
> + iotests.log('FAIL: short LZFSE decode was accepted')
> + return
> + iotests.log('short LZFSE decode rejected: ok')
I wonder if we should check a more specific error message here, too. If
anything else goes wrong (can't open the image or whatever), we don't
necessarily want to count that as a success.
I'm also wondering why you chose to 'qemu-img convert' and then open the
raw image in Python. Is there a problem with the simpler way of just
verifying with qemu-io that 'read -P 0xab 0 512' directly on the dmg
image returns the expected result?
> +
> +
> +iotests.script_main(main, supported_fmts=['dmg'],
> + supported_protocols=['file'],
> + supported_platforms=['linux'])
> diff --git a/tests/qemu-iotests/tests/dmg-lzfse-short.out b/tests/qemu-iotests/tests/dmg-lzfse-short.out
> new file mode 100644
> index 0000000000..6802cf1a76
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/dmg-lzfse-short.out
> @@ -0,0 +1,2 @@
> +valid LZFSE chunk converts: ok
> +short LZFSE decode rejected: ok
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes
2026-11-12 15:33 ` [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes Julio Faracco
@ 2026-11-16 17:03 ` Kevin Wolf
2026-11-16 22:09 ` Stefan Hajnoczi
1 sibling, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2026-11-16 17:03 UTC (permalink / raw)
To: Julio Faracco
Cc: qemu-devel, Hanna Reitz, Stefan Hajnoczi, qemu-block, oxsignal
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes
2026-11-12 15:33 ` [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes Julio Faracco
2026-11-16 17:03 ` Kevin Wolf
@ 2026-11-16 22:09 ` Stefan Hajnoczi
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2026-11-16 22:09 UTC (permalink / raw)
To: Julio Faracco; +Cc: qemu-devel, Kevin Wolf, Hanna Reitz, qemu-block, oxsignal
On Thu, Nov 12, 2026 at 12:33:56PM -0300, Julio Faracco wrote:
> 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.
>
> 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)
> {
The +1 approach could cause bugs in the future. block/dmg.h does not
document that avail_out + 1 bytes may be written to next_out:
typedef int BdrvDmgUncompressFunc(char *next_in, unsigned int avail_in,
char *next_out, unsigned int avail_out);
I would rather avoid the dangerous +1 even if it means oversized
compressed inputs are not detected. So how about only checking that the
return value from lzfse_decode_buffer() is out_size and returning -1 if
it is smaller?
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-16 22:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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.