From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 2E1833624CF for ; Thu, 6 Aug 2026 02:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785982856; cv=none; b=cDYqn4r7xBWrkaPCZG/brCmdzUJxWJCGB9ywx8Io1Zd/GlVJagt7Ssu3PjsHYl/xJo8Lu19nFEHGgFhDxKhroKM7+bdC7ZFNray/3r2ENQKlBkkFNj499+72EuGVumuWpX1sxEfMQH88v3NhzCfLwKucE4SOdzCJXvSVuGdKCoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785982856; c=relaxed/simple; bh=w19NtSrhDkavmkUlqXA4R+/hToYaKJSwinog3Ti6Hjo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CDlDHTQ32RJhOCKc4IPF93wIJn80WjXMvnqRnC1GzoyU07Z7v/WQA8flElr5oJZisiD9rjVFp5avZjql7g3xrxA1nPs1yPley+mNqLLF6lNFONmcVuIMugqxVR3+V3Jk/54YEkvUms3hVeDImw7LF4armmIe3cUdd+sBZ+4OSZ8= 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=pwQBK64i; arc=none smtp.client-ip=209.85.210.172 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="pwQBK64i" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-84eb992a881so1557243b3a.2 for ; Wed, 05 Aug 2026 19:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785982854; x=1786587654; 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:content-type; bh=rDAOxwq3ttzmOFNmqT41qJrWI/l0YQGgUcGKO+iJ9p8=; b=pwQBK64ihHou8hnoP8PrZQ9GcXXgSI3ff4u0QX412SlLZCH6Y/U3qMvU3tcoEGUTCg UnvLTxjWHYT37hfm7T7o1F4rbNC9LJhKYO5sTizWhMqP5ZlwSSqhDGDTADnogVpRSu2S 3JJSYd/aFt/Y5LJn6LdQGlux8VDU7Gky36yDQf8shu5k6bxkySNqDJj0zO+wVsXmoE3a bVhd0/aA5OubB0IJEeSDuCZXTpZfTleJAUqbh3khxCBhaA5dTQZ7bYdUceI/fueiM0NN EYqsVbG9OWkOFmG/Z7R8ZpYLTd7V9T20fF0vuRVd/qxb/JOxKZqrIzxdB3/0BvvMgd6D tQxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785982854; x=1786587654; 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:content-type; bh=rDAOxwq3ttzmOFNmqT41qJrWI/l0YQGgUcGKO+iJ9p8=; b=CqbV0sUB0SLYvb4ym7MOuDJxmDn056PZKJAXOuookCCcc6tu5iGq16SKMJn+4qpylm C5RCfqf6ihN7rNHxsqyVOfy8WkBRcBtDF3sjQW5cygSFl/aBQ8bqD36o2se2NQbbjtYI srWEMeXXD/r2jexcVNlcTZNqz1K3WxNP4f7qG21H5v6SSkutYizhEB4mtnY9O68SWE6N jcE3NoRThcCf2sQQ9XP3S6y8EbaCXv3h/7fPrQan26vSM7UYzIdfnfH8ekpb8QreQ/In uIkXoksyKV/A0PXx7IDW1/4vK0xDzTcfKOQcniuKNQQNLnY+/C6Hv5hQY5BCbphLyd5D klzA== X-Forwarded-Encrypted: i=1; AHgh+RqfXz7LcnNHca6hc4pQkKL/ZQcUIH3wKWPvNe5gVaHVt4YNPwr3WY+d5hvGKtGeTEM1vOVumoESlLtbT0o=@vger.kernel.org X-Gm-Message-State: AOJu0Yw23buBAvSQZ8fBLK4lUxHQx1KbrU8+YH98iVPwQzLK5dWK71W8 Anpb46MiYKZmQf1pPstJTLKVPf7ZF3TWiHXxlj6Me62cJQXL1L1SlhPX X-Gm-Gg: AR+sD13VvZkGLRwmiLZCbCJIgE5/jCvg20U/tPR9f7VHVqHYvkWXc5833DxZ48O6Jts B5uqr+HQltdN/VnF7+cldOBe/uiNI4wlLuNcIBZ2NL052eie9/e+sk3TAbd4z4riB0Pm3n0XEER TKXWxw2AW3ofsQ3ToK4Okr3fbazn43Q9CvnJkHgBVnCgNheiBH0HJEcyJLvFM4fuUQ7TH/C90S3 WMHj3AXlA0c+ymvzRPTirV0uaRQ4NDBCrmB8vJvhqp+7tXpT2PU8QWgPVpmdtJrthI2I4MfYVkj DtpCZR8CYddsCw+4BZW47cte4V0d/smiXJLxyMX9mfkuLNn+6TKbR7Mw5h9vLgjvh4K1aeErtw6 YLFaq+JEN9fQd+OV3BkNEBpGfTfKpd71lMoaL7aEvbKMr+IMaQqVnqnfaBvty8mMjllwWMyaMDp VKrgLWS5tepegxv5oYzMt/pAhMurdA3WbSgPOP8efpI7fzV5eh/yebp1TmdIVkx0+Wjzc4J/mT X-Received: by 2002:a05:6a00:4489:b0:84e:24df:3873 with SMTP id d2e1a72fcca58-84f2e0c9cbdmr12720996b3a.32.1785982854383; Wed, 05 Aug 2026 19:20:54 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f4538ba99sm323012b3a.9.2026.08.05.19.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 19:20:53 -0700 (PDT) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: Theodore Ts'o , Andreas Dilger , Joseph Qi Cc: Jan Kara , Baokun Li , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , Mark Fasheh , Joel Becker , Andrew Morton , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH 0/2] fs: fix readdir position truncation on 32-bit kernels Date: Thu, 6 Aug 2026 10:20:42 +0800 Message-ID: <20260806022044.167962-1-zhanxusheng@xiaomi.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: 8bit Both ext4 and ocfs2 rebuild the directory cookie in ->iterate with ctx->pos = (ctx->pos & ~(sb->s_blocksize - 1)) | offset; ctx->pos is loff_t (64-bit) but sb->s_blocksize is unsigned long. On 32-bit kernels unsigned long is 32-bit, so ~(sb->s_blocksize - 1) is a 32-bit value (e.g. 0xfffff000 for 4 KiB) and, under the usual arithmetic conversions, is zero-extended to 0x00000000fffff000 in the AND with the 64-bit ctx->pos. The high 32 bits of ctx->pos are silently cleared even though a directory may exceed 4 GiB. When readdir() crosses the 4 GiB boundary on a 32-bit kernel the position is reset back into the first 4 GiB, and the re-validation path then re-enumerates already-returned dirents indefinitely. These are the block-offset (non-hashed) readdir paths: ocfs2's extent-list path (ocfs2_dir_foreach_blk_el(), used for all non-inline directories) and ext4's linear path (non-indexed directories, or the ext4_dx_readdir() ERR_BAD_DX_DIR fallback). This is the same class of bug that commit 3dce5bb82c97 ("exfat: Fix bitwise operation having different size") fixed in exfat. Cast the mask operand to loff_t so the AND is performed in 64-bit. 64-bit kernels are unaffected. The two filesystems are independent; they are sent together only because the bug and the fix are identical, so each maintainer can pick the relevant patch. The truncation was verified with a freestanding 32-bit test mirroring the expression; not reproduced on a live 32-bit >4 GiB directory. Zhan Xusheng (2): ext4: fix readdir position truncation on 32-bit kernels ocfs2: fix readdir position truncation on 32-bit kernels fs/ext4/dir.c | 2 +- fs/ocfs2/dir.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.43.0