From nobody Mon Apr 6 22:03:57 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 586503E92B1 for ; Tue, 17 Mar 2026 15:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773761088; cv=none; b=j1tDEVh/HDn1Y0JMNWRbIGAdhKR/gkX3kz3t3WAHfU9bjYK1el6jbon80Na7W8xO1eJemUPsKjC2g+0LAq7u7hCD36PI8tpmt5dEc40MFU7FVUGk7Nvpd1GtR6vNXt2uaIBiY3YToMIU1bnss81MX7BLtC5VQf1LxhONRn3R/+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773761088; c=relaxed/simple; bh=XASGvewUCN3OybZd2mz7V579OWP/qxPuhXw1INT5D0M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=E/Mo2wrWKWt0ERhhu6KXcL2S6yApL6Ea9Tjs+xixq9DMew8g1UKQnyK4DyMdXTzosYTD9RqA67DHCsNt7t1evjOXcLUjXE6cv1o9xBB7XdaQCNGXKgYsoktT+HzNLgWtsakJBK6LqrLNPLWiSyv1bhU9Da14GVZoyNi+YtuwUFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OcYM9EBE; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OcYM9EBE" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3597822d6d8so382835a91.3 for ; Tue, 17 Mar 2026 08:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773761086; x=1774365886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zK973YcGAPsQClcyZbHw6YemyR2f7H0nUyi0FbVd4iI=; b=OcYM9EBEmMhJRVH4snWTxUCpMJHlRWaZDUXU+uk/Ij27SY6ygB7Z+1lnqPUnVW5Shg lvrERco+WphH9Cxj6saVGUUhzuRBBTPou5X+0lo7Fvz6z148UNeWaQi6lT8YqW5S/y8w ccviduuv7o14Z70mnpAhPG5oClBJSpBnDtyfgBiv3BVxGRDkBTXP0rcTPw6dz+mRZgP+ mBHstb6cR79lSUfVQ6/Yupifl4lUql1JAArEpMwCyTGGcIHH8B1lsVLPIfHKug8kALSU Rc8L66ZvogUFifNyS+OLoHSCYJB9WL4En0hwyXtReHA4bpNwbarYwQwhVllZRSP629o5 +eIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773761086; x=1774365886; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zK973YcGAPsQClcyZbHw6YemyR2f7H0nUyi0FbVd4iI=; b=mx4Rq5BWWa4sipEP3msAed0HJ+J9ZhXxh1KaD4SJDLHP1/5zToYSY8Cib7v1eOKGPh /MrbzcX2VRigruRaDbM4oGSAJeprbBW311ni3jh5RAGoETr56SDWxFMklAjS8QRBu5Ce 9AVdMpvKq4Ynptq0QvANLetEUAQ1yHP6JZA75L2QPxBsPU4G8NU0RroQa9BLxtp+oyIE Iw5R7wqo3zoH2dfrY5VWgmkaf0HvthZ0Ly3AhDFuIprZNjvXZFY/RmfwV145RgUnFqiy 9hRAIRS4+avVSTNR0L94yAuMXP7mZhNoPTrewxos1Tof5WDwg7MekrlTB+wTgW5MVvwT zJvw== X-Forwarded-Encrypted: i=1; AJvYcCWqDY/KaCzRwjYBJR2Yb3QUkrfoExVFe09jEg8cxHT/grwMeXKpL/HTVmguPBQNOGcV6NwRaynpz6ZKjNY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvod5Kvn8GQZ0i14FsvoCt/LDnBMvOzA4oKSP0Og9mC686368S HggpMBJu0tPAVqFCz1p093ZzRHwK9YAiK/BswA6KW6uTVdpM/sVkSDni7jrS+VRu X-Gm-Gg: ATEYQzyI/t1936dQUwWPszmtDUypsEEk+B+gw9vXlFRfhu6YnU02TKm4XU/Cxi/me90 FrtL8u75JRD2KLheuflAOlmAkicSrjniCU06N3Ewn56MoJXeN8RWpZqiGCZvLahn8QVeHPMgBDe DV//redP2JZ7d/+GNfOxlI0uXT5K2Z8mdbXnLYCLMAABcvj6LS88WeApVW5OWIWCrP8XlXgqkrG WDEE9wXXewPzNcGswyLxQtAmOMJzu/e7KmgU5s0c8vni+qHZ0icj3yhGmbMLzr4UJ4oF0Zm5VRf W60wPnpm+pXMWpnYjRdUZEyzypBvyI4IlvS3kLhVMOYK0LkjIAVbZ3TSCzXqJTE2be8K6qHT0co nr65Fceq6ClShNzSIKl4UClV12kw2zxK1ijuMFbt8ACxmnovgbEIcpg5EXotN77toI8h+h6JWO2 wn3q7E/UXsa6oEC5BBhT4eMS9S1KNpeMRYpXjNgMD9pBIUkVIPT3+XALHAF44LycOeQ96NMNELi iK+mMTlAySU8PqZfcj7FGwwXtZibZgzyO+gIA== X-Received: by 2002:a17:903:90f:b0:2ae:63fd:6d6a with SMTP id d9443c01a7336-2aecaaf805dmr112552775ad.7.1773761086165; Tue, 17 Mar 2026 08:24:46 -0700 (PDT) Received: from DESKTOP-PU4IGQQ.localdomain ([117.203.246.41]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b06b74c672sm17614815ad.66.2026.03.17.08.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 08:24:45 -0700 (PDT) From: Utkal Singh To: linux-erofs@lists.ozlabs.org Cc: xiang@kernel.org, yifan.yfzhao@linux.dev, linux-kernel@vger.kernel.org, Utkal Singh Subject: [PATCH v2] erofs: harden h_shared_count in erofs_init_inode_xattrs() Date: Tue, 17 Mar 2026 15:24:39 +0000 Message-ID: <20260317152439.5738-1-singhutkal015@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" `u8 h_shared_count` indicates the shared xattr count of an inode. It is read from the on-disk xattr ibody header, which should be corrupted if the size of the shared xattr array exceeds the space available in `xattr_isize`. It does not cause harmful consequence (e.g. crashes), since the image is already considered corrupted, it indeed results in the silent processing of garbage metadata. Let's harden it to report -EFSCORRUPTED earlier. Signed-off-by: Utkal Singh Reviewed-by: Chao Yu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index c411df5d9dfc..aaac37c6bb78 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -85,6 +85,14 @@ static int erofs_init_inode_xattrs(struct inode *inode) } vi->xattr_name_filter =3D le32_to_cpu(ih->h_name_filter); vi->xattr_shared_count =3D ih->h_shared_count; + if ((u32)vi->xattr_shared_count * sizeof(__le32) > + vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) { + erofs_err(sb, "invalid h_shared_count %u in nid %llu", + vi->xattr_shared_count, vi->nid); + erofs_put_metabuf(&buf); + ret =3D -EFSCORRUPTED; + goto out_unlock; + } vi->xattr_shared_xattrs =3D kmalloc_objs(uint, vi->xattr_shared_count); if (!vi->xattr_shared_xattrs) { erofs_put_metabuf(&buf); --=20 2.43.0