From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 604E52FF164 for ; Tue, 7 Jul 2026 19:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783450976; cv=none; b=idDdVndsWdRP4d3sR9FFMsA9XduJZdhdEPNfFdAKZ2mOZZIbFq9U3JDZo+oP2WwdBBdPJCmrNn0ABK4d/qZmVSl5kHn6zxA5SHC+fVcxwygk0liPMXlCanO5heC3t8KFlHedBSn7JNoih5RwbkHVUJOhlD9F+PSsuBA07Xh3nnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783450976; c=relaxed/simple; bh=ifTmuhdYEfA8S+Ti9vBnBv8jVJkTFG9fKTW/c6hx1FQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g98ffb2Jwdmi9jiwDb5nbSfTndactgIp9mgMNsXgmPXly/r+yWCCY+x/alFhpBAGGUpuxmq3yqbRNUa3xYXFbgJeLrl+PR5UkILGc7JdhMKj9dV2FVyxMxzEAJuBK2oS+q/Cwz3W6tQUVlFqlYZSR8vFyBpmeLSYQGYtyh42nAo= 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=AP7rpcqE; arc=none smtp.client-ip=209.85.214.173 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="AP7rpcqE" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2cace7da66eso44031825ad.0 for ; Tue, 07 Jul 2026 12:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783450975; x=1784055775; darn=vger.kernel.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=ibl0MHrnxFzM837MpKxLVego5yHxJdHEFJ+77R4ZX9E=; b=AP7rpcqEK5S9B7W2eR7+tA+od7iBgBaWyY5p1QvuTTpydqmQLNqZvd514leH3pOZX5 o2q4TZga2HHb7foAe+BB9WFBrQemb7aaw3BMXD1FznHinztufSrO9aKzlkpCK2oDksT0 4/7YHE9yuP9h9Kxs0vPT4FeUb3ISWvFduJ6R+LruaCJkn45T0RYoHCDB3ksXuJA9VLcl qWXm7GBvGBw6wgD6By1TXlsHk41g+KFhSBlHgyQQPevfG10RxM+ELxB3e3YghJdTtCTr r6xfrhi2JH8CRQjE9iyXbOWGfY70jSLAqjmkYkuFRlwXTAyvWQYgbfyT/241c15n5l9H bL2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783450975; x=1784055775; 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=ibl0MHrnxFzM837MpKxLVego5yHxJdHEFJ+77R4ZX9E=; b=LGnS7ETMa17K6anWAeeHBxNRyNluaZzhSkVfuupU8k3cGpn0jB0VfKv1peP28/fHm7 vqxVxyv5bdley4ezGb83nRPSre4D9/N6KD4YLmT9srS0NVQnNcLd+13b/iU+pEzw/kz3 hVANE51VqKFzxclELDOGlU3uCacrYIDsbys4xK5g4kdZnFTtGt/BPa1vhLZCW9bgJFzK REcJIFdjHLru9V/vL9aM5Y556CONYTHSl4WVkiQ2Qac4tva6GFgQSRQT72o1kn/xD0WQ 13ISvrSgktYRzauFVAt6cDHatuJTApSIySZ6VPoU7gFZq/FUdwyd4yn64aKoRnVi/4m/ DEdg== X-Forwarded-Encrypted: i=1; AHgh+RpwdGmovkHWBAdA+bLHipbC2oJCRIr+Tc28QThLsbnWCFqz+dNXJTYN5XbQgLtg7h/Yu2z3+0um3JYGccU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2Yc0PJh3jKUEuiNvm0cSdNYBBelaA9lUeFFd4uHN3InJ2Q23B UCVxlC0HjsbEp1SVtGtMyFd6uQ9okSSs0OXrziBw4InXCv8xrzSqP3fU X-Gm-Gg: AfdE7cnrWdokxJsvUORjIpKpJ31J1x8eLsMCgBRl2xECFt+MKGJL2/t6VDlbY4Lx4FW XzudGGu+/TUAqGUJWOGDXJEQJKl46OKDnP9rJjQaA7SY5pZL9LU60TE2RYaOAgPld2eCKZN42ZY zAgLAz5jI2Ynd+387EGWkWPnNXKQeaAGWn8ZDdA3OcJQSNvKdAz0HUxsqXAlZ9nreHKYJkZtA5p //YNypNOBAkczOM+k33uY5ixRtyBOIry3AkQqpQLMgUJUaRSBsLtPIVqDqgr9eacYHzQ6hT2I+T AFNmKlLxg04pyShp9EOFsqGlkteVFZ4bdwl08XWR+c5+twQgJ+45f21lDhRphuGTimDYDfzJbjM qY3SaOa+1xhkcBTt5G5aeWvQFSEnxb5CH82FPHgvjat5qNI4X1z/5r3tuY+ExFFhOTk6C7UM9sK ljTN8C X-Received: by 2002:a05:6300:2203:b0:3bf:6237:4d3f with SMTP id adf61e73a8af0-3c08ed081d3mr7453396637.18.1783450974527; Tue, 07 Jul 2026 12:02:54 -0700 (PDT) Received: from beelink.. ([186.22.57.86]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b6593c76dsm10704585c88.3.2026.07.07.12.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 12:02:54 -0700 (PDT) From: Aldo Ariel Panzardo To: linux-xfs@vger.kernel.org, Carlos Maiolino Cc: "Darrick J . Wong" , Dave Chinner , linux-kernel@vger.kernel.org, Aldo Ariel Panzardo , stable@vger.kernel.org Subject: [PATCH v2] xfs: bound da-node entry count against the correct geometry Date: Tue, 7 Jul 2026 16:02:45 -0300 Message-ID: <20260707190245.3813498-1-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260707135930.3214701-1-qwe.aldo@gmail.com> References: <20260707135930.3214701-1-qwe.aldo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit xfs_da3_node_verify() bounds the node entry count against the larger of the directory and attribute geometries because, as a buffer verifier, it cannot tell whether the block belongs to the directory or the attribute tree. When the directory block size exceeds the fs block size (e.g. mkfs.xfs -n size=64k -b size=4k), an attribute node buffer is a single fs block that holds only m_attr_geo->node_ents entries, yet a crafted attr node may claim a count up to m_dir_geo->node_ents and still pass the verifier. xfs_da3_node_lookup_int() then indexes btree[] up to that count during its binary search -- an out-of-bounds read via getxattr/listxattr on a mounted crafted image. The buffer verifier is the wrong place to tighten this: it has no fork context, and the transaction-less read path used by getxattr does not run xfs_da3_node_set_type() either. xfs_da3_node_lookup_int(), on the other hand, always runs on that path and holds args->geo, the geometry of the fork actually being searched. Bound the entry count against args->geo->node_ents there, before walking the entries. Fixes: 7ab610f9e0f1 ("xfs: move node entry counts to xfs_da_geometry") Cc: Signed-off-by: Aldo Ariel Panzardo --- v2: reworked per Darrick's review. Do not infer dir-vs-attr from the buffer size in the verifier; instead bound the entry count in xfs_da3_node_lookup_int() against args->geo->node_ents, the geometry of the fork being searched. cc stable. fs/xfs/libxfs/xfs_da_btree.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index 9debb95d86fa..95ea3737eb33 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -1787,6 +1787,20 @@ xfs_da3_node_lookup_int( } else expected_level--; + /* + * The node verifier cannot tell whether this block belongs to + * the directory or the attribute tree, so it only bounds the + * entry count against the larger of the two geometries. Here + * args->geo is the geometry of the fork we are actually + * searching, so reject a count that would walk btree[] off the + * end of this node buffer. + */ + if (nodehdr.count > args->geo->node_ents) { + xfs_buf_mark_corrupt(blk->bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } + max = nodehdr.count; blk->hashval = be32_to_cpu(btree[max - 1].hashval); -- 2.53.0