From nobody Mon Nov 23 22:31:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794484648; cv=none; d=zohomail.com; s=zohoarc; b=P6dfL3zIfAEhW2F0Whxj/mkiSzZcHnbx2L6TdHVg44NCjLoKdsVEqygVhxCRAkUz3wRa6qClxryMKmLtWmyDlhp0BjwCTADUhNLRpzR97dciK18HKKXi2cFdwJOpiUd2RvySGo0BbvjoNHgbBYis+HM46Rf/Pt/CO8Ji2HfwIrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484648; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9oz6JE0EN9c7kdjLdJQwsC7btxzag2OqhGihNme+k3I=; b=k50IMe6WaCQaSIUf7AYS8rhcQa/ixAz23TS2DV3e/BUb87l391vicFtIOg81l5Uvv25fHn6cTyT5ZDxRREOHQoylB2xJOgbsRXcxZ0hg2euqm+2nWgQN47btyZ0J1HD27bKhlXjziGkyEX1+p30KKRph4GXpjpF1VWvjx8d1a38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794484648168552.1638190158852; Thu, 12 Nov 2026 03:57:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1485656.1688807 (Exim 4.92) (envelope-from ) id 1xRTQG-0005jG-Lh; Thu, 12 Nov 2026 11:56:56 +0000 Received: by outflank-mailman (output) from mailman id 1485656.1688807; Thu, 12 Nov 2026 11:56:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTQG-0005iw-EA; Thu, 12 Nov 2026 11:56:56 +0000 Received: by outflank-mailman (input) for mailman id 1485656; Thu, 12 Nov 2026 11:51:18 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTKo-0005Zv-5h for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 11:51:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xRTKn-003gWe-7F for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 12:51:17 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af5a823-bab6-0a2a0a5309dd-0a2a4508dff0-26 for ; Thu, 12 Nov 2026 12:51:17 +0100 Received: from [209.85.215.175] (helo=mail-pg1-f175.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af5a833-f659-0a2a45080019-d155d7afc0a7-3 for ; Thu, 12 Nov 2026 12:51:17 +0100 Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-cdab9e9761cso2161455a12.2 for ; Thu, 12 Nov 2026 03:51:16 -0800 (PST) Received: from Soun ([211.176.214.155]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b197c42a4csm4538630a91.4.2026.11.12.03.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 03:51:14 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794484275; x=1795089075; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9oz6JE0EN9c7kdjLdJQwsC7btxzag2OqhGihNme+k3I=; b=TXjECf6jvZTKGDZ0sgn8cKp19P7tBZfFhtTm/mhnz/rfM97/lU89PBkW+1xtgIrgPR vXnw9k0w68OE4SmmfIZFel7dHftn88cNgSC7W3S2ir/6HoS2S2ksF6crYssaqvtC/rSP NmMnzFw5SOwQMpP4Z0GtMcTrfNKBnNiZ9xgVGVqfx34Fgw8fnSEHBeyF1cjQ6i8rkqsX byfaXi8zLuXNYnh4N9UtAw+JVVEkJWr1+dDaozAbGwRHik3zPzb2ZpAvo8h3x+oUFwde +2dd7gSEmdY0/PbuE5S1RGA2hcoyY6370vNLp1s47nLijNPEqLyPNgE1Vcd3DMijBgbI GV9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794484275; x=1795089075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9oz6JE0EN9c7kdjLdJQwsC7btxzag2OqhGihNme+k3I=; b=XzdaP8DsScf1NLYyNdaU4NF0kc/o7phXvXx8sWPwq9BtAfYAzyoW93OgXZgakGlGZu gEm9cq9rV3DSiTSoVlKGo/jHhg3ZVRTQjwFmeYvL9DJLEti5w67Si9/suKzoKRGcajxr rj2B+JFKI63QpltFo12NsMW20TFrS6lh806Vq4tBTUVx5DaxIk2cp3Z3TMe7HYmEl4EF cDJC/KrNuJChVM3HXXJN/CQqMFTUy2lS3+ia50SsMvLJZ+sWCZ0VaAIUcA1yLeVREBOb yRBim8ISCM5LLG1EVX9dGoWznpYn13b1B0f7EVXg2fuu1//oJf2FLetHnyVWhtSKnYsM 9kWA== X-Gm-Message-State: APuU4Z93ziVtm09OXo0OY2RSJSovvRZkQYWP7VkDaF7UAUHpfFcSzG2H cYehHt9rIkXCECeM+rOCQslacpIXQeK4m9/o5IFk9r1GhiB/cO/L1JWu X-Gm-Gg: AYBFou0Eti+5UIVtojYaVIjxGA0GU3Nhbvct2adnSlIfPfF7edginBPV1swo90snvtu BkhsoM30RRTY4I+t0AZ/vPr2hOOLvjP1idwbVxTrbjgFAKKiTwXiso8NwEtP1Kf0QK4tcjhGW+S B8nLfuzgkQvMS/rPMkk/m+VIJS/iZNxN+iqkjUJIX99k8e1nO4OUxTMMZUD5Wnm3MEVuOCNLsI9 xtINV2Q9Zye9j7wApGoEhbmiBXhfUEOC/giz9662mlyuEMGApUzRqbJd0AwfNJm0t/PDtQ0lsOW tz+X3qUJw1PyrFwNXGcpzoIZOXxVFW9wXU19j1tjBjv2mOuB2u0wT1+EUEO2fZtX9bCeDcLuAoW iR39Z1SOXhSDL13vMU1N6ygBH8zhQrf5+G62cxwFWP4DJ0XQvarPsYTs0v5/mCZrpNdZ5bipLd+ 9jzv0PpB/kR6l5ByHlma9p/gRcUpOgb5LCI6KM3mwMDbx/qekrkvMJD8il6NFz630aVVGy2fI1N u0zq7oxwGCrY1+qZ15YWF81uQ50v2y/0GYqG8gPRc7GH+5hV+z3qgZD7qW5Wa9P/+j/xVTqlz5F 1U6z7sO8xf7qtcKjGUA43R6/bvHlyL7TcoFF0pSzYsQ/fD5/WrRKIn6VKb7nCBOSLU4FT1APEmu jFO1f5dS6dkIqiTiy X-Received: by 2002:a17:90b:17c8:b0:3ac:3e42:60a2 with SMTP id 98e67ed59e1d1-3b182edc9d1mr4950349a91.33.1794484274935; Thu, 12 Nov 2026 03:51:14 -0800 (PST) From: SounLabs To: Anthony PERARD Cc: xen-devel@lists.xenproject.org, SounLabs Subject: [PATCH 1/4] libfsimage/ext2: validate attacker-controlled superblock and extent fields Date: Thu, 12 Nov 2026 20:49:46 +0900 Message-ID: <20261112114949.9936-2-holyting07@gmail.com> X-Mailer: git-send-email 2.52.0.windows.1 In-Reply-To: <20261112114949.9936-1-holyting07@gmail.com> References: <20261112114949.9936-1-holyting07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1794484277-CC57487B-BC8F1461/0/0 X-purgate-type: clean X-purgate-size: 5800 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794484648404158500 Content-Type: text/plain; charset="utf-8" libfsimage is used by pygrub to parse the filesystem of an untrusted guest disk image from dom0. Several ext2/ext4 metadata fields are used without validation: - s_log_block_size sizes the INODE/DATABLOCK1/DATABLOCK2 buffers inside the fixed FSYS_BUFLEN region; a large value makes ext2_rdfsb() write a block past the buffer (heap out-of-bounds write). - s_inode_size and s_inodes_per_group are used as divisors and can be zero (SIGFPE). - an ext4 extent header's eh_entries is iterated without bounding it to the region that holds the entries (heap out-of-bounds read). - ext4_recurse_extent_index() has no depth limit, so a self-referencing index block recurses until the stack overflows. Reject the out-of-range superblock values at mount time, and bound both the extent-entry count (against the inode inline area or block that holds the header) and the extent-tree recursion depth. This is the same class of issue addressed for the iso9660 plugin by XSA-497. pygrub is only security supported when run de-privileged (XSA-508), so this is hardening rather than a security fix. Signed-off-by: SounLabs --- tools/libfsimage/ext2fs/fsys_ext2fs.c | 48 ++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/tools/libfsimage/ext2fs/fsys_ext2fs.c b/tools/libfsimage/ext2f= s/fsys_ext2fs.c index 5ed8fce90e..db635b9f4a 100644 --- a/tools/libfsimage/ext2fs/fsys_ext2fs.c +++ b/tools/libfsimage/ext2fs/fsys_ext2fs.c @@ -337,6 +337,22 @@ ext2fs_mount (fsi_file_t *ffi, const char *options) || SUPERBLOCK->s_magic !=3D EXT2_SUPER_MAGIC) retval =3D 0; =20 + /* s_log_block_size, s_inode_size and s_inodes_per_group come straight + * from the untrusted on-disk superblock. The buffer-layout macros + * (INODE, DATABLOCK1, DATABLOCK2) place three block-sized buffers in + * the fixed FSYS_BUFLEN region, and later code divides by the inode + * size and by the inodes-per-group count. Reject values that would + * overflow the buffer or divide by zero. s_log_block_size is tested + * first (short-circuit) so EXT2_BLOCK_SIZE() never shifts out of range.= */ + if (retval + && (SUPERBLOCK->s_log_block_size > 6 + || sizeof (struct ext2_super_block) + sizeof (struct ext2_inode) + + 3UL * (unsigned long) EXT2_BLOCK_SIZE (SUPERBLOCK) > FSYS_BUFLEN + || SUPERBLOCK->s_inode_size =3D=3D 0 + || SUPERBLOCK->s_inode_size > EXT2_BLOCK_SIZE (SUPERBLOCK) + || SUPERBLOCK->s_inodes_per_group =3D=3D 0)) + retval =3D 0; + return retval; } =20 @@ -351,14 +367,29 @@ ext2_rdfsb (fsi_file_t *ffi, int fsblock, char *buffe= r) EXT2_BLOCK_SIZE (SUPERBLOCK), (char *) buffer); } =20 -/* Walk through extents index tree to find the good leaf */ +/* ext4 extent trees are at most 5 levels deep in the on-disk format. */ +#define EXT4_MAX_EXTENT_DEPTH 5 + +/* Walk through extents index tree to find the good leaf. + * max_bytes bounds the region the header and its entries occupy: the + * inode's 60-byte inline area for the first call, a full block for an + * index block read from disk. This stops a corrupted eh_entries from + * being iterated past that region (both ext4_extent and ext4_extent_idx + * are the same size). depth bounds the recursion so a self-referencing + * index block cannot spin or overflow the stack. */ static struct ext4_extent_header * -ext4_recurse_extent_index(fsi_file_t *ffi, struct ext4_extent_header *exte= nt_block, int logical_block) +ext4_recurse_extent_index(fsi_file_t *ffi, struct ext4_extent_header *exte= nt_block, int logical_block, unsigned int max_bytes, int depth) { int i; struct ext4_extent_idx *index =3D (struct ext4_extent_idx *) (extent_blo= ck + 1); + if (depth > EXT4_MAX_EXTENT_DEPTH) + return NULL; if (extent_block->eh_magic !=3D EXT4_EXT_MAGIC) return NULL; + if (sizeof (struct ext4_extent_header) + + (unsigned int) extent_block->eh_entries * sizeof (struct ext4_exte= nt) + > max_bytes) + return NULL; if (extent_block->eh_depth =3D=3D 0) return extent_block; for (i =3D 0; i < extent_block->eh_entries; i++) @@ -368,7 +399,7 @@ ext4_recurse_extent_index(fsi_file_t *ffi, struct ext4_= extent_header *extent_blo } if (i =3D=3D 0 || !ext2_rdfsb(ffi, index[i-1].ei_leaf, DATABLOCK1)) return NULL; - return (ext4_recurse_extent_index(ffi, (struct ext4_extent_header *) DAT= ABLOCK1, logical_block)); + return (ext4_recurse_extent_index(ffi, (struct ext4_extent_header *) DAT= ABLOCK1, logical_block, EXT2_BLOCK_SIZE (SUPERBLOCK), depth + 1)); } =20 =20 @@ -483,7 +514,7 @@ ext2fs_block_map (fsi_file_t *ffi, int logical_block) { int i; struct ext4_extent_header *extent_hdr =3D - ext4_recurse_extent_index(ffi, (struct ext4_extent_header *) INOD= E->i_block, logical_block); + ext4_recurse_extent_index(ffi, (struct ext4_extent_header *) INOD= E->i_block, logical_block, sizeof (INODE->i_block), 0); struct ext4_extent *extent =3D (struct ext4_extent *) (extent_hdr + = 1); if ( extent_hdr =3D=3D NULL || extent_hdr->eh_magic !=3D EXT4_EXT_MA= GIC) { @@ -863,6 +894,15 @@ ext2fs_dir (fsi_file_t *ffi, char *dirname) } off =3D loc & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1); dp =3D (struct ext2_dir_entry *) (DATABLOCK2 + off); + /* rec_len is attacker-controlled. It must be at least the fixed + * 8-byte directory-entry header; a smaller value (in particular 0) + * would never advance loc and would spin forever. */ + if (dp->rec_len < 8) + { + errnum =3D ERR_FSYS_CORRUPT; + *rest =3D ch; + return 0; + } /* advance loc prematurely to next on-disk directory entry */ loc +=3D dp->rec_len; =20 --=20 2.52.0.windows.1 From nobody Mon Nov 23 22:31:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794484631; cv=none; d=zohomail.com; s=zohoarc; b=LFUDKrfRaGo5jYJaIdACQJk4n4L6WfrcC/MJgBB8VNIK5FUT3j6Kmte8z1ZXu65oZX421kK0E49znaD+27zZrN//ExJ+0Iy5EhXS6oIku9gmSX4tVynUj3A43UmVJtvX9hvwsnC60m0fCL7XVP6mfmmM1ryy9z8T9uKgZJpmnng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9E20EbwIjTi+wfLtCh2CvjL1HiP4RRaKiCZgKQ0LTcU=; b=CY+GDIvL9CRqpSDT9mdpMVYaDXgwG+W/hB0pBReUxNwySS3arWvS2iciw4gzPAjkP2OAFNP173RcRrI7JLa2pA71FlLeMbzqUGba8F6EvykNQJ1Rf6jd7feJGDn4AoYwZvxPJMifK7pkS3XVZplEfD+dVk7DT77/tNQQdOc+Y/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794484631140298.2839810111665; Thu, 12 Nov 2026 03:57:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1485657.1688813 (Exim 4.92) (envelope-from ) id 1xRTQG-0005oA-U8; Thu, 12 Nov 2026 11:56:56 +0000 Received: by outflank-mailman (output) from mailman id 1485657.1688813; Thu, 12 Nov 2026 11:56:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTQG-0005nW-Nx; Thu, 12 Nov 2026 11:56:56 +0000 Received: by outflank-mailman (input) for mailman id 1485657; Thu, 12 Nov 2026 11:51:19 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTKp-0005a1-DS for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 11:51:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xRTKo-003gWe-QS for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 12:51:18 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af5a823-bab6-0a2a0a5309dd-0a2a4508dff0-32 for ; Thu, 12 Nov 2026 12:51:18 +0100 Received: from [209.85.216.45] (helo=mail-pj1-f45.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af5a835-f659-0a2a45080019-d155d82db4f4-3 for ; Thu, 12 Nov 2026 12:51:18 +0100 Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3b10ca4e3f9so2375741a91.0 for ; Thu, 12 Nov 2026 03:51:18 -0800 (PST) Received: from Soun ([211.176.214.155]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b197c42a4csm4538630a91.4.2026.11.12.03.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 03:51:16 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794484277; x=1795089077; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9E20EbwIjTi+wfLtCh2CvjL1HiP4RRaKiCZgKQ0LTcU=; b=ijwXl9aQPrRevEsSOOGfKENsh1y3fPGUOqxfPbX5zulEMLmss6Xyml1WJxnZLnJkzv evnniYmHPbXNklaeJcC1qOCzCFFf25ET2RbPu78wS2dCNAzGC0bcgXhOZJU9V+zRKXmw qR/9QrS462qg6IwIN4fw0qtpfVRyh2V12+vkcBmISBg0NOpYzMQazDqRgt5YdJSnXlYK M0XrELlhq0JVHPrEImylznR75sYx2b01iUEb0lbf5ioTBK2fsiD2qLLinzNvHlqMTTFq 5yBSBS/FMEP4fAbcEwE5ZaNbPdK+l8UKVYSh/OvXzVKBWTvYXXVeHtzihjgwR0mRGsUk p+WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794484277; x=1795089077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9E20EbwIjTi+wfLtCh2CvjL1HiP4RRaKiCZgKQ0LTcU=; b=G23J5yldYmSNuV+si54OYXPffMxCs46xyB5LBYgvK4aikdolAh2F9cHaoSjdZwNvot pzr6SUrrGShs+qGGWG+JjIvww+OqhayKm0ZEtKILQFG5QMar3cmigclht7VPDKt+KHFQ ZL0yRzv6rC5f11b79/KB/LA3a4KMXeSdlWKAT0JPRyjr4rbMPweovaqX7Hk32AU+4gjt 5z22kwqVFF71lMf/o7/YH/tvtpTdsCV2dED1V1efKvDRWyxr+mETspzl7XzX8t1MIy9K ycTtHwwAMeF35//JuvpahF8/gUdPPmEaFM+VULpp9OyysUq/47YcXWCXZaXtNdt5npUB GnZA== X-Gm-Message-State: APuU4Z8XCRWkbVl6xTdRlRJRUxMyM/BMY+xu3ej6Qt51Qbhnxy8z4Otf E4JiTgzG6gyfvKbspnLt++vmxRMSXfQkC8SvIgx1DqxTWkjTc1rC1lo7 X-Gm-Gg: AYBFou1GeO7sYVh17YZvbabMnyLxwIeiKMcRhugckXhoQqXQDApdvsbu0jL9jhFIhDS 27uYVJ5Y6AlUE7oJIEcMF0fVgeb0WTyjToFn6FpQ1lQKd1zNTjY4AxszDvKMilqA1u98BBehm2c SSdYo8UdS8s6DKf4JU2lJN3fqsQulWkz5fyXvf1UHBt64DnXWbwNLLJOwG+MoIRbrdAzBSe5aV7 KPWSqscoUlBJwV4UWngpE9/LtFI/7FP+qRZxFCXPFNViZYOeZfnjt/oxxhoRSWTgVane8o1xBd7 9Al4RdGl5favFZvVG3oCBxnT03aN4pAnw/7HMX37BVeUL2R1FoLSOkuoa49Ykq4RMShNxjw9ioj ZR7w1c94Ub81AJLSOl9lB8sXsSpK3CGsrGA50BoKkPRlDV6pviZ16K6JyrND3TpUVyUNMwGhuBS QKMhell0UKZW+801hTRqzGcigJIpStIGfkw1u+npQRrozKRMpYNP7Nx7cncjiz+gT7orCqJcSO5 qGcAmbUbLwNZ7ddZBgUdkUw/sm1GAqMFNNec9j83W8hk2Q2IOj8AvdSMBTk+jUzdtRn35My1vuj 6cXgUJeEYmrjsihegt+I+Lg/dIeRqnWGq6JY2g//hUUjNhpH9x2Wnc/mNeWfwts6XdHPizpZgN1 Wbftm7WwDA8xHByMX X-Received: by 2002:a17:90b:1c01:b0:3ac:6fcf:81a2 with SMTP id 98e67ed59e1d1-3b182fa3b9emr4999530a91.57.1794484276563; Thu, 12 Nov 2026 03:51:16 -0800 (PST) From: SounLabs To: Anthony PERARD Cc: xen-devel@lists.xenproject.org, SounLabs Subject: [PATCH 2/4] libfsimage/reiserfs: validate item counts and journal length Date: Thu, 12 Nov 2026 20:49:47 +0900 Message-ID: <20261112114949.9936-3-holyting07@gmail.com> X-Mailer: git-send-email 2.52.0.windows.1 In-Reply-To: <20261112114949.9936-1-holyting07@gmail.com> References: <20261112114949.9936-1-holyting07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1794484278-CCF4F87B-FE6DF68C/0/0 X-purgate-type: clean X-purgate-size: 5199 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794484634293158500 Content-Type: text/plain; charset="utf-8" libfsimage is used by pygrub to parse the filesystem of an untrusted guest disk image from dom0. Three reiserfs on-disk counts are used without validation: - block_head.blk_nr_item is iterated as item headers / keys in search_stat= () and next_key() without checking they fit in the block (heap OOB read). - item_head.ih_entry_count is iterated as directory headers in reiserfs_di= r() without bounding it to the item body (heap OOB read). - the journal descriptor/commit j_len indexes commit.j_realblock[], which holds JOURNAL_TRANS_HALF entries, in journal_init() and block_read() without a bound (stack OOB read). Check each count against the structure that holds it: blk_nr_item against t= he block size when a node is read (including the root), ih_entry_count against ih_item_len, and j_len against 2 * JOURNAL_TRANS_HALF. Same class of issue as XSA-497 (iso9660). pygrub is only security supported when run de-privileged (XSA-508), so this is hardening rather than a securi= ty fix. Signed-off-by: SounLabs --- tools/libfsimage/reiserfs/fsys_reiserfs.c | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/libfsimage/reiserfs/fsys_reiserfs.c b/tools/libfsimage/r= eiserfs/fsys_reiserfs.c index 10ca657476..395488245b 100644 --- a/tools/libfsimage/reiserfs/fsys_reiserfs.c +++ b/tools/libfsimage/reiserfs/fsys_reiserfs.c @@ -420,6 +420,13 @@ block_read (fsi_file_t *ffi, int blockNr, int start, i= nt len, char *buffer) return 0; =20 j_len =3D desc.j_len; + /* See journal_init(): j_len must not index commit.j_realblock[] + * (JOURNAL_TRANS_HALF entries) out of bounds. */ + if (j_len > JOURNAL_TRANS_HALF * 2) + { + errnum =3D ERR_FSYS_CORRUPT; + return 0; + } while (i < j_len && i < JOURNAL_TRANS_HALF) if (desc.j_realblock[i++] =3D=3D blockNr) goto found; @@ -497,7 +504,11 @@ journal_init (fsi_file_t *ffi) commit_block =3D (desc_block + desc.j_len + 1) & (block_count - 1); journal_read (ffi, commit_block, sizeof (commit), (char *) &commit); if (desc.j_trans_id !=3D commit.j_trans_id - || desc.j_len !=3D commit.j_len) + || desc.j_len !=3D commit.j_len + /* j_len indexes desc.j_realblock[] and commit.j_realblock[], + * which together hold at most 2 * JOURNAL_TRANS_HALF entries; + * a larger (attacker-controlled) value reads past 'commit'. */ + || desc.j_len > JOURNAL_TRANS_HALF * 2) /* no more valid transactions */ break; =20 @@ -555,6 +566,8 @@ journal_init (fsi_file_t *ffi) return errnum =3D=3D 0; } =20 +static int blkh_nr_item_ok (char *cache, unsigned int blocksize); + /* check filesystem types and read superblock into memory buffer */ static int reiserfs_mount (fsi_file_t *ffi, const char *options) @@ -646,6 +659,8 @@ reiserfs_mount (fsi_file_t *ffi, const char *options) =20 if (INFO->tree_depth >=3D MAX_HEIGHT) return 0; + if (! blkh_nr_item_ok (ROOT, INFO->blocksize)) + return 0; if (INFO->tree_depth =3D=3D DISK_LEAF_NODE_LEVEL) { /* There is only one node in the whole filesystem,=20 @@ -676,6 +691,22 @@ reiserfs_mount (fsi_file_t *ffi, const char *options) * efficient, but this really doesn't hurt for grub. =20 */ =20 +/* A block_head's blk_nr_item is attacker-controlled. Confirm the keys or + * item headers it claims actually fit inside the on-disk block, so the + * item/key scans in search_stat() and next_key() cannot run past the + * cached block. */ +static int +blkh_nr_item_ok (char *cache, unsigned int blocksize) +{ + unsigned int nr =3D BLOCKHEAD (cache)->blk_nr_item; + if (BLOCKHEAD (cache)->blk_level =3D=3D DISK_LEAF_NODE_LEVEL) + /* leaf: block_head followed by nr_item item headers */ + return (unsigned long) nr * IH_SIZE + BLKH_SIZE <=3D blocksize; + /* internal: block_head, nr_item keys, nr_item + 1 disk-child pointers */ + return (unsigned long) nr * (KEY_SIZE + DC_SIZE) + DC_SIZE + BLKH_SIZE + <=3D blocksize; +} + /* Read in the node at the current path and depth into the node cache. * You must set INFO->blocks[depth] before. */ @@ -707,6 +738,11 @@ read_tree_node (fsi_file_t *ffi, unsigned int blockNr,= int depth) errnum =3D ERR_FSYS_CORRUPT; return 0; } + if (! blkh_nr_item_ok (cache, INFO->blocksize)) + { + errnum =3D ERR_FSYS_CORRUPT; + return 0; + } =20 INFO->blocks[depth] =3D blockNr; return cache; @@ -1140,6 +1176,14 @@ reiserfs_dir (fsi_file_t *ffi, char *dirname) name_end =3D INFO->current_item + INFO->current_ih->ih_item_len; de_head =3D (struct reiserfs_de_head *) INFO->current_item; num_entries =3D INFO->current_ih->u.ih_entry_count; + /* ih_entry_count is attacker-controlled; the directory headers it + * counts (DEH_SIZE each) must fit within this item's body. */ + if ((unsigned long) num_entries * DEH_SIZE + > INFO->current_ih->ih_item_len) + { + errnum =3D ERR_FSYS_CORRUPT; + return 0; + } while (num_entries > 0) { char *filename =3D INFO->current_item + de_head->deh_location; --=20 2.52.0.windows.1 From nobody Mon Nov 23 22:31:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794484638; cv=none; d=zohomail.com; s=zohoarc; b=msG+eN0R2/R4xqaxRuyokAg98dBsfq0ZK6oRbrTEJwp2qnEyopfzL0nKuBUQuS/0u5PyG8E3iRBDQ9gTRRGtBI15DKB8b/l2KrWuFSpr5JN2PsYW349zYgjJROEd78XYvuFd6XDUXPemQJeFVJfOcVVacnnr9GzAHjDJGENAWGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484638; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WVjATkhG9ZCGiH/NrYplUUMcfvyC1YgRbLZoC0yxMF4=; b=YCMoq/391UOsnlh0mgSyh/8pnx312mXNs8FLa/WxFupqtqGoAhvBe9D/INaqW9HFlZSXwSnf2dc6R2cjFaPk0z545NNvrlBQCiLd76jo+A1FQ/kJb5uPyGVAQHmcxlWUMr6mEDzSqr4jgj7KfBiwhCSaG0UfgMKrHeTk3ytVSd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794484638909861.8967571073003; Thu, 12 Nov 2026 03:57:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1485659.1688820 (Exim 4.92) (envelope-from ) id 1xRTQH-0005w6-6v; Thu, 12 Nov 2026 11:56:57 +0000 Received: by outflank-mailman (output) from mailman id 1485659.1688820; Thu, 12 Nov 2026 11:56:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTQH-0005uY-0s; Thu, 12 Nov 2026 11:56:57 +0000 Received: by outflank-mailman (input) for mailman id 1485659; Thu, 12 Nov 2026 11:51:20 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTKq-0005aT-Qm for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 11:51:20 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xRTKq-00H85w-7Q for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 12:51:20 +0100 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af5a825-8faa-0a2a0a5109dd-0a2a4502a0e6-40 for ; Thu, 12 Nov 2026 12:51:20 +0100 Received: from [209.85.215.176] (helo=mail-pg1-f176.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af5a836-6ca4-0a2a45020019-d155d7b0b98a-3 for ; Thu, 12 Nov 2026 12:51:20 +0100 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cc4aa0246b7so1721190a12.3 for ; Thu, 12 Nov 2026 03:51:19 -0800 (PST) Received: from Soun ([211.176.214.155]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b197c42a4csm4538630a91.4.2026.11.12.03.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 03:51:17 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794484278; x=1795089078; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WVjATkhG9ZCGiH/NrYplUUMcfvyC1YgRbLZoC0yxMF4=; b=AlqGT9EYExh/4hneF1YWQMNGgvPlBCQVT5cEjFPzkEHcqqcrpH7wq1zjpSYlfk6wfO pD5qUva9xnEGFOjbXPHMghGVJuxTG16ZIMV8YuD2nuOg8QtwHEOSAr0geOX5yMcLdKVy yK8zrSwIVxjYNYvK6mvTcs3ZJ8W3W5PXgIUMGEUzcw41m0i2QRboyGgs0kx6B2Re/uPu T733YOQXNDX6qTYaBT/TAMa5E/E+VpXYkfoH0K0eFIKXVFrPIQ+Cr8FhIxPHLW8iSTgZ 4InE0/S+6sDkJ3kwA33tTE/4X97wpTomEDFX8QmAQqVPkmabnQT/P/sJNc16bIi/b05y /upw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794484278; x=1795089078; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WVjATkhG9ZCGiH/NrYplUUMcfvyC1YgRbLZoC0yxMF4=; b=dMLEcZBGumwoxCWaSSMqgDbaC6yV8GpUH5BXFi7O5p1LZip/PwDQ++HHPBavF+JRkO 6LAK1NO7nJ9Jk43kbIgEbF24KTTZTpfh2hNnF3lK9m2lDSktlwMvG2h7C3AQ54adqPjz NWvLhXbRgGFWxfKQi41tqnjW/H0guKXZ8MxIcclgd5IzQ7CJrYd6XiC6e13krBZOoxCQ 0ToJmpnDED1AE0tgAccgbHHFyeXoMsICw3C8WhHJdUKqwtUat+/YLU9IcOHv83GvZlEe W7XMqwl4uZ1SR/Gacn1PMrA6oYqzBlY8EbgLAorgs5eyReaLEFnKYE4z6FBLKHB3O94B ioXA== X-Gm-Message-State: APuU4Z9sRw+Su/MDU40zfz6pYIy4+3Dj4Ic58Xavh7Wf44BQ6yVEQ83t eBFF8RFAK7OJ45PldsAeEp2RtXEQPGjAHiBC9VU78XkBAW3NVMDX2YbM X-Gm-Gg: AYBFou1AAujryYPQgHXROtU/fRHQ/RHIFye7CMx5OngnO5W3YB4GfF37lGPzbdqXEPz FTbcFK9U8UazDjX3et7vJttlFZhv1AdBexNN6okC1ibDPfItGBxbTzCYXzTcBjPkogeqV0K7WUh ysRp5deI1QOMxOLAjsN2roF+LZDrzHsP1dx8mV5hyL+Nidzqk4lfEmUyTy2JWHHEGfA6XUDyotF dsDgohZ/z6TZdfTmcU8vCAakgsJM635/Etgj23vrHFJeQdMDZ+AI2Iizt8QXvaEO9e7ZlfuuVlJ nAYb+ebDfV/RSXuV4lzfSz5yyNC+vfg/TljywIr6rauEWEiIpg+ZiTro2ibM2YHgb+7cvNWcCQ9 9mdgNO7UqnVQpfFVlgiR9piV9eBFoHJKGbiOG30EblMDvOoUWzqZlcN5B+7IxS/dx/WNGN9GZFG cBFI2Oo4vUTiRNSNjaubu5hlE7YrL0PYahATF//maFtxbe4hwDRE9HPeROuhpVHuiqH+5UNiMbb Z9zgQ99wnx3oEBzfB5WvP6dhKKcEsG7nIOAn4b1JDO3FYCvbS7vYAg/GBTydsSujTH4LYOCIh02 kFFZijJQ9Z7L5A4Vu0kZIEvn3TwCwAWJY0xhAab28Q2LNBQW9oSU8UaBYYdocQ9MDbKxJKyqnrh 4nErx6hoCi+Ro3AwAg/wc5Dzo8bnb5P9UqGyJj3w= X-Received: by 2002:a17:90b:224b:b0:3ac:403d:6239 with SMTP id 98e67ed59e1d1-3b182f45135mr4637556a91.43.1794484278055; Thu, 12 Nov 2026 03:51:18 -0800 (PST) From: SounLabs To: Anthony PERARD Cc: xen-devel@lists.xenproject.org, SounLabs Subject: [PATCH 3/4] libfsimage/ufs: validate superblock divisors and directory record length Date: Thu, 12 Nov 2026 20:49:48 +0900 Message-ID: <20261112114949.9936-4-holyting07@gmail.com> X-Mailer: git-send-email 2.52.0.windows.1 In-Reply-To: <20261112114949.9936-1-holyting07@gmail.com> References: <20261112114949.9936-1-holyting07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1794484280-F2AB52AC-E9DA121E/0/0 X-purgate-type: clean X-purgate-size: 2077 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794484640275158500 Content-Type: text/plain; charset="utf-8" libfsimage is used by pygrub to parse the filesystem of an untrusted guest disk image from dom0. Three ufs on-disk fields are used without validation: - fs_inopb and fs_ipg are used as divisors by the itoo()/itog()/itod() macros in openi(); a zero value divides by zero (SIGFPE). - a directory entry's d_reclen advances the scan in dlook(); a zero value never advances and spins forever. Reject a non-positive fs_inopb or fs_ipg at mount time, and stop the directory scan on a zero d_reclen. Same class of issue as XSA-497 (iso9660). pygrub is only security supported when run de-privileged (XSA-508), so this is hardening rather than a securi= ty fix. Signed-off-by: SounLabs --- tools/libfsimage/ufs/fsys_ufs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/libfsimage/ufs/fsys_ufs.c b/tools/libfsimage/ufs/fsys_uf= s.c index a545bc9f65..12cc2f700d 100644 --- a/tools/libfsimage/ufs/fsys_ufs.c +++ b/tools/libfsimage/ufs/fsys_ufs.c @@ -49,7 +49,12 @@ ufs_mount(fsi_file_t *ffi, const char *options) if (/*! IS_PC_SLICE_TYPE_SOLARIS(current_slice) || */ !devread(ffi, UFS_SBLOCK, 0, UFS_SBSIZE, (char *)SUPERBLOCK) || SUPERBLOCK->fs_magic !=3D UFS_MAGIC || - MAXBSIZE < SUPERBLOCK->fs_bsize) + MAXBSIZE < SUPERBLOCK->fs_bsize || + /* fs_inopb and fs_ipg are attacker-controlled and are used as + * divisors by the itoo()/itog()/itod() macros in openi(); a + * zero (or negative) value divides by zero (SIGFPE). */ + SUPERBLOCK->fs_inopb <=3D 0 || + SUPERBLOCK->fs_ipg <=3D 0) return 0; =20 return 1; @@ -257,6 +262,10 @@ dlook(fsi_file_t *ffi, grub_ino_t dir_ino, char *name) dp =3D (struct direct *)(DIRENT + off); if (dp->d_ino && substring(name, dp->d_name) =3D=3D 0) return (dp->d_ino); + /* d_reclen is attacker-controlled; a zero value would never + * advance loc and would spin forever. */ + if (dp->d_reclen =3D=3D 0) + return (0); loc +=3D dp->d_reclen; } return (0); --=20 2.52.0.windows.1 From nobody Mon Nov 23 22:31:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794484636; cv=none; d=zohomail.com; s=zohoarc; b=dcLIFWo34cdg0m8f/sr+zq0iWYJDBVUqk4xDpWGWNMMJvGzt0lXGMVPPGYRrAaJ/627PjdQb4pWjD527CfMrDcRjOWatqO/ipWhqWa+51praX3c4UZDDNJw0muHYHE8qujwxdTOmXmVs5GgqKQo+9mIXzP5weansoY7ob0I6aI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794484636; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WQ8QG17P3Y8DiLIc7VFs/FvC5yBJsW5SXVDTD633UI4=; b=B+7V1KitYC02rxG5Vhepvzx908lbO3iHkj1J6ItkaH1klc3Yy9ux9OqtkRyrdbVPCc7QDYKOQ4FzNQdjhJt7iZOqhNfBJ1o5cM3OdjJkbUuymJ1PDbMPYrk+dxnWPVCpK3IOqaIUPn13dXql+QSjzDlpqVspXjuKu8ZXi073zBI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 179448463648311.062367035739157; Thu, 12 Nov 2026 03:57:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1485662.1688826 (Exim 4.92) (envelope-from ) id 1xRTQH-00064r-HF; Thu, 12 Nov 2026 11:56:57 +0000 Received: by outflank-mailman (output) from mailman id 1485662.1688826; Thu, 12 Nov 2026 11:56:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTQH-00062D-Bu; Thu, 12 Nov 2026 11:56:57 +0000 Received: by outflank-mailman (input) for mailman id 1485662; Thu, 12 Nov 2026 11:51:23 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xRTKt-0005bN-Jx for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 11:51:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xRTKt-00H88Z-0q for xen-devel@lists.xenproject.org; Thu, 12 Nov 2026 12:51:23 +0100 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af5a838-e002-0a2a0a5209dd-0a2a450ab1ee-14 for ; Thu, 12 Nov 2026 12:51:22 +0100 Received: from [209.85.215.182] (helo=mail-pg1-f182.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af5a838-f2d2-0a2a450a0019-d155d7b6b4a5-3 for ; Thu, 12 Nov 2026 12:51:22 +0100 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cd61cef87f1so2016623a12.0 for ; Thu, 12 Nov 2026 03:51:21 -0800 (PST) Received: from Soun ([211.176.214.155]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b197c42a4csm4538630a91.4.2026.11.12.03.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 03:51:19 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794484280; x=1795089080; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WQ8QG17P3Y8DiLIc7VFs/FvC5yBJsW5SXVDTD633UI4=; b=QmELgtuvv0BcKpGaG0RUfK/hM+17d9db7+vmiwDkeyU32zMFgptPLyUNiRkf64iHJb m9SR9uUiWBdo14Do0jcfVNF99qhCodfzvYNAjCMH8g/zQlowcfxq4QSCWy5iqZbp63bc a+xG4Ufr6SK6TkQDvZn88qN1bSU2K03bkfltTw+FuqdG3vhUy/PpAGqhyuF3JmEwMm3j s8II+jyQnoifzDzqFIBafmP5r7r3dYaMqntmkq9Z69VSkCyEJRuSU4bOdUq4GNkEh0Xo 6jNg43XjZU2NqkbUD/WMasjFE9BY9ljv64kgRSJeZb17s8FFVU7WvE+tf0ZzCGjqhHlz 3wEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794484280; x=1795089080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WQ8QG17P3Y8DiLIc7VFs/FvC5yBJsW5SXVDTD633UI4=; b=HJw5EoNCJFf3EIfta9yOL9IboYY1dq6bnzyNqk6BXOYWll/miDmEwVdiPgoE3/SjfJ qNBHnt3B/VmdJllvZTBi0u/mY0/l1I3xe6wGOG2cc/7LJ+c6v2D4o5E4G3i4MuR56jyf m6g0h+ShqsOS2DmIbK6kMDq4lKLvxPof0pBLRQMPVV6Shg7rO7laIm0V3a1/Cq0X78DE CZHwhvXGuN/QLtPjxj3/cSsU3Xv7QdC5/eaHcK0vUT5tbjoO+dSLwwSK11AY7Z6JDkDt 5X8K57eAOwLMz6Nss+uXrQQxKp3ZO9mkjY8+DOWZGlg2xlfuNnEXZX1FH/p8QN9O77vw uxNg== X-Gm-Message-State: APuU4Z/y6muRI+p1nmrnlxodf0zGbSDWaJStreZKjNgl+r7fEvZ4bKdN XPgxPh3zPZIuXfIoNrgvvV0jj3SY4DS40NowPvmkwB9zT4gSzz+x8im3 X-Gm-Gg: AYBFou21vV4oZ+yd5m7wFqb6Wb4DMuqD5IYBeu5I1fz/Owhmxaq9nEH5BZRjct+MBM+ JS1BYSg6PaJTbeJWVIiXYwvZxysHyJ62OFOPcLH62QtIYIZmkdENLRLOTcziWeryq1IoufJOzai 4fzQC/IWGvN6Sv50ID32rh7WvTMDSk24286ZUZ2NXEOXYK0oQblIVr3+Yp6s4zPfnBsofkPdPdA ifoYwYxlqKWRARJ1xcJbeCoLIpRo1uxx/EnXCsLlHgmwazfwy3a39UwjYUQwmv99eTIH/MkmJxL rVo+n9BGCejPI9zGoSO8vXd4GskOJ9JSQJeqxjxrXH45OfAYW2Xk6o13N3vpe2ON+Ww3h3MSvWB nZ/hXh9ZhTI/V5VjWuKXvOfVOqN1n3QDevg2zOaRELPs9Dk06L0yZdhB1rLPp1/2R0X7cUt5wk8 ykQJHaYKAqk8/E2chb7J4w9azpEtmAbORQ1QE7x6u/MGTVN14JnMrLpWXqZDNVWm/bhMEoWW5s+ 1upg4l3q8rQYOHQR9BDgzPFDDyt0GGk9bfRVZPhh1yvnidYVbISUKmpUT4uai8cb6XbFAQJNlcY CDCJR+7EtP/s3hPxjGj2Zr+c/ZxBlcSYhSnCH4P5whkMfUGzDmzFB35vAuMvQexvegDxLB+jzAM jIRGX38jERC0E97Y/ X-Received: by 2002:a17:90b:3e8e:b0:3ab:7031:d962 with SMTP id 98e67ed59e1d1-3b182f407cdmr5266435a91.41.1794484280033; Thu, 12 Nov 2026 03:51:20 -0800 (PST) From: SounLabs To: Anthony PERARD Cc: xen-devel@lists.xenproject.org, SounLabs Subject: [PATCH 4/4] libfsimage/xfs: bound inline extent count and directory btree traversals Date: Thu, 12 Nov 2026 20:49:49 +0900 Message-ID: <20261112114949.9936-5-holyting07@gmail.com> X-Mailer: git-send-email 2.52.0.windows.1 In-Reply-To: <20261112114949.9936-1-holyting07@gmail.com> References: <20261112114949.9936-1-holyting07@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1794484282-589C9CFC-B7DFF5FC/0/0 X-purgate-type: clean X-purgate-size: 5877 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794484638335158500 Content-Type: text/plain; charset="utf-8" libfsimage is used by pygrub to parse the filesystem of an untrusted guest disk image from dom0. Several xfs on-disk fields are used without validati= on, leading to an out-of-bounds read and to unbounded tree descents that loop forever: - init_extents(), XFS_DINODE_FMT_EXTENTS: di_nextents is taken as the numb= er of inline extent records; next_extent() then iterates that many records = from the inode data fork without checking they fit (heap OOB read). - init_extents(), XFS_DINODE_FMT_BTREE: the root-to-leaf descent follows bb_level/ptr0 with no depth limit, so a node whose bb_level does not decrease (e.g. one pointing to itself) loops forever. - first_dentry(), directory da-btree: the root-to-leaf descent assigns xfs.dablk =3D btree[0].before with no depth limit or cycle detection, so= a self-referential or cyclic directory node loops forever. This is the lo= op reached by the di_nextents reproducer as well, which therefore triggers both the OOB read above and this unbounded da-descent hang. When the descent is bounded and the directory yields no entries, first_dentry() returns NULL and the caller in xfs_dir() dereferenced that NULL name via substring(dirname, NULL) (NULL read). Cap di_nextents to the number of records that fit in the inode data fork, bound both the bmap btree and the directory da-btree descents to a fixed maximum depth, and have xfs_dir() fail the lookup gracefully when a directo= ry yields no first entry. Same class of issue as XSA-497 (iso9660); the superblock sanity check added by XSA-443 does not cover these inode-level and btree-level fields. pygrub= is only security supported when run de-privileged (XSA-508), so this is harden= ing rather than a security fix. Signed-off-by: SounLabs --- tools/libfsimage/xfs/fsys_xfs.c | 57 +++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/tools/libfsimage/xfs/fsys_xfs.c b/tools/libfsimage/xfs/fsys_xf= s.c index e98b367901..7fbd78a122 100644 --- a/tools/libfsimage/xfs/fsys_xfs.c +++ b/tools/libfsimage/xfs/fsys_xfs.c @@ -201,20 +201,42 @@ di_read (fsi_file_t *ffi, xfs_ino_t ino) return 1; } =20 +/* An XFS bmap btree is only a handful of levels deep; use a generous cap + * to bound a traversal that would otherwise loop forever on a node whose + * bb_level does not decrease (e.g. one that points to itself). */ +#define XFS_BM_MAXLEVELS 32 + +/* A directory da-btree is likewise only a few levels deep; bound the + * root-to-leaf descent in first_dentry() so a node whose btree[0].before + * never reaches a leaf (e.g. one that points to itself) cannot loop forev= er. */ +#define XFS_DA_MAXLEVELS 32 + static void init_extents (fsi_file_t *ffi) { xfs_bmbt_ptr_t ptr0; xfs_btree_lblock_t h; + int levels; =20 switch (icore.di_format) { - case XFS_DINODE_FMT_EXTENTS: + case XFS_DINODE_FMT_EXTENTS: { + /* di_nextents is attacker-controlled; the inline extent + * records (xfs_bmbt_rec_32_t each) must fit in the inode's + * data fork, or next_extent() reads past the inode buffer. */ + int fork_bytes =3D + (icore.di_forkoff ? (icore.di_forkoff << 3) : xfs.isize) + - (int) offsetof(xfs_dinode_t, di_u); + unsigned int maxext =3D fork_bytes > 0 + ? (unsigned int) fork_bytes / sizeof(xfs_bmbt_rec_32_t) : 0; xfs.xt =3D inode->di_u.di_bmx; xfs.nextents =3D le32 (icore.di_nextents); + if (xfs.nextents > maxext) + xfs.nextents =3D maxext; break; + } case XFS_DINODE_FMT_BTREE: ptr0 =3D xfs.ptr0; - for (;;) { + for (levels =3D 0; ; levels++) { xfs.daddr =3D fsb2daddr (le64(ptr0)); devread (ffi, xfs.daddr, 0, sizeof(xfs_btree_lblock_t), (char *)&h); @@ -224,6 +246,12 @@ init_extents (fsi_file_t *ffi) xfs.fpos =3D sizeof(xfs_btree_block_t); return; } + if (levels >=3D XFS_BM_MAXLEVELS) { + /* malformed btree: refuse to iterate */ + xfs.nextents =3D 0; + xfs.next =3D 0; + return; + } devread (ffi, xfs.daddr, xfs.btnode_ptr0_off, sizeof(xfs_bmbt_ptr_t), (char *)&ptr0); } @@ -392,6 +420,8 @@ next_dentry (fsi_file_t *ffi, xfs_ino_t *ino) static char * first_dentry (fsi_file_t *ffi, xfs_ino_t *ino) { + int da_levels; + xfs.forw =3D 0; switch (icore.di_format) { case XFS_DINODE_FMT_LOCAL: @@ -413,7 +443,7 @@ first_dentry (fsi_file_t *ffi, xfs_ino_t *ino) xfs.dablk =3D (1ULL << 35) >> xfs.blklog; #define h ((xfs_dir2_leaf_hdr_t *)dirbuf) #define n ((xfs_da_intnode_t *)dirbuf) - for (;;) { + for (da_levels =3D 0; ; da_levels++) { xfs_dabread (ffi); if ((n->hdr.info.magic =3D=3D le16(XFS_DIR2_LEAFN_MAGIC)) || (n->hdr.info.magic =3D=3D le16(XFS_DIR2_LEAF1_MAGIC))) { @@ -421,6 +451,16 @@ first_dentry (fsi_file_t *ffi, xfs_ino_t *ino) xfs.forw =3D le32 (h->info.forw); break; } + if (da_levels >=3D XFS_DA_MAXLEVELS) { + /* malformed directory da-btree: a node + * that never descends to a leaf (e.g. a + * btree[0].before that points to itself) + * would otherwise loop forever. Treat + * the directory as empty. */ + xfs.dirmax =3D 0; + xfs.forw =3D 0; + break; + } xfs.dablk =3D le32 (n->btree[0].before); } #undef n @@ -602,6 +642,17 @@ xfs_dir (fsi_file_t *ffi, char *dirname) *rest =3D 0; =20 name =3D first_dentry (ffi, &new_ino); + if (name =3D=3D NULL) { + /* A malformed directory (e.g. one whose da-btree + * descent was bounded above) yields no entries; + * fail the lookup instead of dereferencing NULL. */ + if (print_possibilities < 0) + return 1; + + errnum =3D ERR_FILE_NOT_FOUND; + *rest =3D ch; + return 0; + } for (;;) { cmp =3D (!*dirname) ? -1 : substring (dirname, name); #ifndef STAGE1_5 --=20 2.52.0.windows.1