From nobody Mon Nov 23 04:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794498724; cv=none; d=zohomail.com; s=zohoarc; b=G9LO3Z+rFrNpE0MkfgGTaeGOUA09Lkx6eIOHe9pC0X21YmjrokDVgeAXsRumQokReIWQ1YSHMW+l32LyKvJJFnLIF6Bkf+FR99x2Wif7s65jI59W93dJh2NQGrmojIhIOcc58jneVqwI4EdVlQBOkihDU5hZgbUKPMsXF4cTv8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794498724; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YX0uzXaxGzHtcUKWfAH0tVvgPKthjDaKe+Cz0H0QFLg=; b=Bn3s6XbAT/4ekNQPCH1zBdIf6fxYsBWE0aKCkpfVBw3QrcYezPXwySuX80+7FghoYRB6pWm/xp6y1lvM6Oi0xYUXmYoDT/ffFtclfwuo/LmlsRjMM6KeiDyMLUsCkocr2cp61IuXADrkCw1KsQgW7nO3u+ZDhiL5Ay7mPSg9t/U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794498724717100.45731909554172; Thu, 12 Nov 2026 07:52:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRX4y-00078n-7i; Thu, 12 Nov 2026 10:51:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRWow-0007aC-7S for qemu-devel@nongnu.org; Thu, 12 Nov 2026 10:34:44 -0500 Received: from mail-yx1-xb136.google.com ([2607:f8b0:4864:20::b136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRWou-0004ZN-GN for qemu-devel@nongnu.org; Thu, 12 Nov 2026 10:34:37 -0500 Received: by mail-yx1-xb136.google.com with SMTP id 956f58d0204a3-677af43eed4so4991537d50.0 for ; Thu, 12 Nov 2026 07:34:36 -0800 (PST) Received: from [192.168.0.195] ([2804:14c:3b83:954b::221c]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67c58a09074sm7656618d50.18.2026.11.12.07.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 07:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794497675; x=1795102475; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YX0uzXaxGzHtcUKWfAH0tVvgPKthjDaKe+Cz0H0QFLg=; b=nt69Zk5waaD4+CiEqTuKo5maniY9NB1sKc+tNM8XL4AA+gm7PWJrIk2qq3or+/3IfN 4TYJtlc870C/8N+YjVQpyHD8jMGeINIqYrxMD21TOds1Dd43b7j+gRUGvuslFgtN75dy YnVneE+ImaQNiHpTnqRqHAIdmcl5Z0mfFnJRP2KVQknDOQDFiei+vqm3y5u4KsSGReIk uUYL7gH0YKSBOK4RevHSogJghfZ3+e7o7lxuiLE63FneeYxWjatES/QA/VoJfS4vPqV8 FGKb9CV8HiRXMnnY6wqduMDafXSTJsnc7srLM+iTU93idkLxizDdsKEaJP9xR/FGnNQO 9VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794497675; x=1795102475; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YX0uzXaxGzHtcUKWfAH0tVvgPKthjDaKe+Cz0H0QFLg=; b=ssUcBlYkPPwCJyglEx1K7XPXgJxKnKN0iOgB7uqhuYgZIxq28fHpAyG5VnYaFiR1Pg 1ZpV5FJbxu6pm+r9X9hViBakRZthBOUXl/3ar8jGWBIexQocTRy1f/Rg3klZ0tsUSiru M2KGeHTXgY5HpQcV/kQJ6pC11BP7Ka7XaxlgMJ9Ypu3kp4VOeiLdVvBaCav/3W7vPxlB rXKYd/cQ7XqR+LtBUQRFokEqcbRVDzgbAhuFTJyqaeDC8dpKkuMyEwXjCFWRzEdVPKZI FgCyCaCCDSxkpQ7JS+/mTFR/46OOoeHFW23kZ68C3RYWJE7aTZzyFzaaOvpz9kx2dZVJ OVPQ== X-Gm-Message-State: APuU4Z+RRuEhlyFNYU5YY7TH5iyclg2QFJ3qaZWn6wWbJ5pY2QKNMqFx EU/Y0k49kQfbv1A/pDMEOOR0CQxA+4xfVA2GZclIKxZVJVdE3L2ksP5irMBHxA== X-Gm-Gg: AYBFou2YrIEu/VX4cSlNiMdyp9svBBneOQwtHknmfcqr/HXN/HNmsWAYvD9kzUh1I4t tITNf4GQBa92gTt0pN9snUPK0FZK8S9GqdAYiixeolP9i5lrs8y4Xb3vs+VW74xi+CTCczbsCvm niuFNejB6w+umPKMw1lg560h/18lOixRprVV/obwugw6D2bEYpYvper1gvFQl87PTtxTYVP/dNC jA6oQS3LYDEFdmgnMiMxnEb77GPzqk2K68fkJiFhVE/TyyeUlGADGGOi6BvHD4M+u/Z7h6lucp4 UTjjh3YAYSrVIW8CELkrNx84N1vhiwbU4eVEQEYHEq0GiHJ9ICVQwvM1SU2aHToB/FgQpGFNUgt GtQfeXaVZTye3QgkHakREaYZGHAM5zlJvRN3KEDCQv8e5GsYjnmynA9LcJd0XRKc/8Tj/QsbQdt K7oJ/C4v0nyIZntOqAD+yr6VfTo3zxdRi54WCydrLwJCzSSn+NAb1kQYloTLDAAH6JnsNTgrpE5 pgauWEVoUVUq+uzJhdPK0kLD5sAONqRP/SfshwSfJjb2GsP7hHN1B71n9e2eNudOIscUhJ+0qJJ 38aXh9gOsZMn/2JHmQ== X-Received: by 2002:a05:690e:43c5:b0:67c:1dca:80d with SMTP id 956f58d0204a3-67c67fabc89mr2926391d50.69.1794497675264; Thu, 12 Nov 2026 07:34:35 -0800 (PST) From: Julio Faracco Date: Thu, 12 Nov 2026 12:33:56 -0300 Subject: [PATCH 1/2] block/dmg-lzfse: reject short LZFSE decodes MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-dmg-short-decode-v1-1-f7f342097b60@gmail.com> References: <20261112-dmg-short-decode-v1-0-f7f342097b60@gmail.com> In-Reply-To: <20261112-dmg-short-decode-v1-0-f7f342097b60@gmail.com> To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , qemu-block@nongnu.org, Julio Faracco , oxsignal X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794497667; l=3737; i=jcfaracco@gmail.com; s=20261112; h=from:subject:message-id; bh=XZ5vwBF3GlRwZHRdlVeL5lr2xHF+6hHh4EotpXGq8i8=; b=7D10GTMc81miZmeIegAg6J3HQrh6b1L0lMzpQy5IKGqa6bZ6o04UwjQc5raTIGWGUBCdWJPWV tLWaYPWabeMBtCcVtz5fllQ7cJKwDuHgMukEn7GAv3LgEClT1xPgEWh X-Developer-Key: i=jcfaracco@gmail.com; a=ed25519; pk=hAqVCeSg6RtgTRedcz7HIqiICyRcEDanumwIF9bNBHg= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b136; envelope-from=jcfaracco@gmail.com; helo=mail-yx1-xb136.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 12 Nov 2026 10:51:10 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794498726719158501 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 =3D=3D 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 Signed-off-by: Julio Faracco --- 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 =3D lzfse_decode_buffer((uint8_t *) next_out, avail_ou= t, - (uint8_t *) next_in, avail_in, - NULL); + size_t out_size; =20 - /* We need to decode the single chunk only. */ - /* So, out_size =3D=3D 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 =3D=3D avail_out) be distinguished from a short or oversi= zed + * stream, without a per-chunk scratch allocation or memcpy. + * + * next_out MUST have room for avail_out + 1 bytes. + */ + out_size =3D lzfse_decode_buffer((uint8_t *) next_out, avail_out + 1, + (uint8_t *) next_in, avail_in, + NULL); + + if (out_size !=3D avail_out) { + return -1; } - return -1; + return out_size; } =20 __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 *optio= ns, int flags, /* initialize zlib engine */ s->compressed_chunk =3D 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 =3D qemu_try_blockalign(bs->file->bs, - 512 * ds.max_sectors_per_c= hunk); + 512 * ds.max_sectors_per_c= hunk + + 1); if (s->compressed_chunk =3D=3D NULL || s->uncompressed_chunk =3D=3D NU= LL) { ret =3D -ENOMEM; goto fail; --=20 2.56.0 From nobody Mon Nov 23 04:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794498709; cv=none; d=zohomail.com; s=zohoarc; b=YcpXc5Z4qSUuQlyEhYlX2tEQ1MOceMwAudo21p7JAglys9keRHKgc/ZL8HsDc3UH9PS3OeApR9kUI1YitpkeKugIx3/QX9ZqtdnbPP/dC/LnnYQAZiCrPHzSMkUg/KIYIUeSPLOj34+BzMMo5kM8NW17SrR3EkbQBstQ0eD2ic4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794498709; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zANwaYKdGSgNJt295Sr9bJFo22t9rxZ3P/MbCD+xx1w=; b=HPeQ/B7D+vSy7kjmXWKODl8Qxp4NjEL6dRjOcKFK2vvaT8UcBZLa6WkUBcUKogloFOPZugDXIguoqbeMZkuToadhmHaTi+hgvZnvRMBbndg2s7lAKCf2l26AQsjebL/eiEYMnNUPx7QwUgALMRYJoizhup+XHfA3iB/qiOE4GSA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794498709852261.57248543342007; Thu, 12 Nov 2026 07:51:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRX50-0007K5-UX; Thu, 12 Nov 2026 10:51:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRWp1-0007bJ-UC for qemu-devel@nongnu.org; Thu, 12 Nov 2026 10:34:44 -0500 Received: from mail-yx1-xb135.google.com ([2607:f8b0:4864:20::b135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRWoy-0004Zr-8m for qemu-devel@nongnu.org; Thu, 12 Nov 2026 10:34:43 -0500 Received: by mail-yx1-xb135.google.com with SMTP id 956f58d0204a3-67be1e468a8so3651045d50.0 for ; Thu, 12 Nov 2026 07:34:39 -0800 (PST) Received: from [192.168.0.195] ([2804:14c:3b83:954b::221c]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67c58a09074sm7656618d50.18.2026.11.12.07.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 07:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794497679; x=1795102479; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zANwaYKdGSgNJt295Sr9bJFo22t9rxZ3P/MbCD+xx1w=; b=a/7mTHojffLkSlkgtCDkVZMyWNR1AB24SsedVoEht6Lwn1d3uMgEQdnU1BMuFvg5vu Olv5ZMy/aXKBNFwH4TjFWvgV71i6BlBOjndvrX6Z+L40E4lDtKVVu79KfOUS7Su36m6l kBiIb54mUZlTtTPom+ytqjjrZQPlUp3dRWdcJ37m1sqmxlH+8ZD3eO1BEznrV31C/ZGJ 36wHEl5RDGK9o8e2n6xsr/6AsEu///z8HozEmuSPNO/7Z3B8MN3g/YI0Y91rYv6d8wpv EspQdVjWTMzErk7/3F2OI9awt546HlwfkBKgCfQmYY+OExvGV9hI2QfK/lNGZgNHr5g4 mCDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794497679; x=1795102479; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zANwaYKdGSgNJt295Sr9bJFo22t9rxZ3P/MbCD+xx1w=; b=N4Kvn5SFeQaAhQpmTackU08LoGLdk8wMzjTM6Gpi3aW+6BRxx0yVM/tLC0A4xUQpx+ daw6t/R3e/67Ga19UzmVmY4rkwdVDvt2DMJFXDqIsQ/Yq4MYrim/zQAWMfBbHBtPszpl /DdMbEuRW84o+3yuTr/pKPzGv1B6/Lqa8roS873gzuy0aRb8+136Mlly5ILXcXEAKz1J dScnUz/168ba3JEs84QZRJTZ5vooti2qoVVgag/WkuAk70CrnTTtnSs0roTXy2TBCmHS 5gX6TJ6OiXROXa5qYqCK0KVpOk6evnQeIsCuBMvKaqZA2ndBcEP+c5275xDn0YLx5KjY vTsQ== X-Gm-Message-State: APuU4Z9sXpGt23mddutB3yXxAwy/pg659M8VCgesdrSoWjPrwYySkG50 4XCEfvf01kRNEvZmjhHqcPgHbLZBsFhuU9y9XIEw1JwFx+7Ripbdevju X-Gm-Gg: AYBFou0RX+FPCxjcArJMnUW9Z/ZQel8cDCvYwHxr+JDjSdlcGI0LzefHAhi6x6y/9x9 uYfIJdTwscUty+ZPD53sngV8bwywqlGoBUwazZ5fW9WKgwy2y30xDTXLcjkEFBkkTmV7/bmKYTp DU4x6BUSX4qlUfq10BkM2yBPrzstkYaHM/YANoLW2lQqr7alkHUY7niTG5IUEXS6H4/KEgGvVzf 5Z2z6UbOcWJVCFeKEWBXxSgBPeUXwo+I44D8HI5tdqyXJ6NWuc3lcWkpoCOuolx6nbl3z3FtfRd tM9MT+YhyeXw4bE4QGsl7QrpsUtJ8TQhhXzO5+Z3XqtHEGNBLQc3+RoWX63q1fi5IWzwxC0ytqD 5F3WqN/wH+UbBRKMY1QGd6cQTHXo1D174CEA3B5ceogQydfwQzNCSSkVynEmtKOr4aPFLuR6yCw 9irCCNdn0zOocJ/iVY88RdVOqyCL3cfXFZErPEWP9ydAlY1YT62rhpu+Fr64TY26pI59xcy9AC1 vUy3f9XdotUcJyY8EmN9dcd2UK3/LXK0jKbZS51Qtl8MXNXFjswMDzien/8fj+FbAJ6WRtxu3Ib pi23+c6uwIVH+X7NLg== X-Received: by 2002:a05:690e:4509:10b0:67c:2752:e53c with SMTP id 956f58d0204a3-67c67f6e4dcmr2990787d50.39.1794497678723; Thu, 12 Nov 2026 07:34:38 -0800 (PST) From: Julio Faracco Date: Thu, 12 Nov 2026 12:33:57 -0300 Subject: [PATCH 2/2] tests/qemu-iotests: cover the dmg LZFSE short-decode fix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261112-dmg-short-decode-v1-2-f7f342097b60@gmail.com> References: <20261112-dmg-short-decode-v1-0-f7f342097b60@gmail.com> In-Reply-To: <20261112-dmg-short-decode-v1-0-f7f342097b60@gmail.com> To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , qemu-block@nongnu.org, Julio Faracco X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794497667; l=7218; i=jcfaracco@gmail.com; s=20261112; h=from:subject:message-id; bh=k/K8U+Tz7gp/lpKwrEoUljN2D+g0N1+lMDxrD+/1uL8=; b=Tc7MuC0TcvHXSSqqMw1O/C+u4Kwb61KKSiFXarm41Be1bvPzRJ7WNLNAOpMLeevrIyM2QeRE8 3ovqfuStJ8/AynDtCXkHj2GkqaWl7PPFa3KamPWfgPilSvvwp1BaOuw X-Developer-Key: i=jcfaracco@gmail.com; a=ed25519; pk=hAqVCeSg6RtgTRedcz7HIqiICyRcEDanumwIF9bNBHg= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b135; envelope-from=jcfaracco@gmail.com; helo=mail-yx1-xb135.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 12 Nov 2026 10:51:10 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794498712795158500 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 --- 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 . +# +# 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 =3D 0x80000007 # LZFSE compressed block type +SECTOR =3D 512 + + +def lzfse_uncompressed_stream(payload: bytes) -> bytes: + """A valid LZFSE stream: one uncompressed block + end-of-stream marker= .""" + return (b'bvx-' + struct.pack(' byt= es: + """ + 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 =3D stream + + # BLKX ("mish") block: 204-byte header followed by one 40-byte entry. + mish =3D 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 n= umber + struct.pack_into('>Q', mish, 0x10, total_sectors) # sector count + struct.pack_into('>Q', mish, 0x18, 0) # data fork offs= et + + entry =3D 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 offs= et + struct.pack_into('>Q', entry, 0x20, len(data_fork)) # compressed leng= th + mish +=3D entry + + xml =3D (b'' + + base64.b64encode(bytes(mish)) + + b'') + + buf =3D bytearray() + buf +=3D data_fork + xml_off =3D len(buf) + buf +=3D xml + koly_off =3D len(buf) + + # UDIF trailer ("koly" block), 512 bytes, big-endian. + koly =3D 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 +=3D koly + + assert koly_off =3D=3D len(buf) - 512 + return bytes(buf) + + +def convert_to_raw(dmg: bytes, name: str): + dmg_path =3D os.path.join(iotests.test_dir, name) + raw_path =3D dmg_path + '.raw' + with open(dmg_path, 'wb') as f: + f.write(dmg) + res =3D iotests.qemu_img('convert', '-f', 'dmg', '-O', 'raw', + dmg_path, raw_path, check=3DFalse) + return res, dmg_path, raw_path + + +def main() -> None: + payload =3D 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 =3D build_dmg(lzfse_uncompressed_stream(payload), + decl_sectors=3D1, total_sectors=3D1) + res, _, raw_path =3D convert_to_raw(good, 'good.dmg') + if res.returncode !=3D 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() !=3D 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 =3D build_dmg(lzfse_uncompressed_stream(payload), + decl_sectors=3D2, total_sectors=3D2) + res, _, _ =3D convert_to_raw(evil, 'evil.dmg') + if res.returncode =3D=3D 0: + iotests.log('FAIL: short LZFSE decode was accepted') + return + iotests.log('short LZFSE decode rejected: ok') + + +iotests.script_main(main, supported_fmts=3D['dmg'], + supported_protocols=3D['file'], + supported_platforms=3D['linux']) diff --git a/tests/qemu-iotests/tests/dmg-lzfse-short.out b/tests/qemu-iote= sts/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 --=20 2.56.0