From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 AB10C30DEAC for ; Sat, 30 May 2026 14:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780151737; cv=none; b=TXRDPr2fBMzQLjORwlzTI2Zq7NWQLCWouuf4Sqm2DvASntONl+O7XOl7PKu7NXJ04mlFvtWAZ2vhBW6fxQEZE0LttNhwtx74+SqLhx1/iebd90FHHRL5Uj6jDesXcvZfGNYin+c6GAIZWRNlMJJVxOneDgFvltWRz2Y5qQAoogI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780151737; c=relaxed/simple; bh=sVgzmvJrwwfRTA5jIT18ZQAVVs4t/EJoipsudjW5zlc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OoFMRgGYz8O8LFy21jeXqb0aea12mfG35Fervlmyf3fYq86zFQqyHKCifyVimRXjTFQ56tLtGzCq6DIiw/IgA/efbEMpWZjEXjV5gDlk4AMC9me2Wc++qYIQzHqh/kYpFLrrsltfTGlhHK45NVmxm3mmJpWAuGGqBj1PW1yGnqs= 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=pPNePyYG; arc=none smtp.client-ip=209.85.216.48 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="pPNePyYG" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-36ba9f46338so270345a91.0 for ; Sat, 30 May 2026 07:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780151735; x=1780756535; 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; bh=P0z7rLBKen5DM92a4OaucYeckexSO2wBy9x5XZ4xp3g=; b=pPNePyYG6N/9VS/yimSWKEuw6neIwiXrtXdYdB8DOSQNWqbzl1ayH2qeBE/jVnlpot pH78ObKsTiT1SDZ1dM7yJrWz/nV+YLNXw1c2qYFnUecp3H+pgEEnOPMTI5AUyNtjsNyg 9JTbBPrcBZIH0jTMSYN7Gmy+Y9DieB+lwpytQ1SKf/zXqWEk2r756bMArSxIgbsdpKos voQz03DSD8RQII33t+pOSdOKaR9Of1MLDwEqplFapccn0sisyjUyTqGrz3O2GDtSsEBQ YgKOpJ3DOF7+T6wi6dtpfjGVopriKncJcfOBaNOpCzEcQzvVpQtu5Rm/T9PnNWcOh8yx p1bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780151735; x=1780756535; 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; bh=P0z7rLBKen5DM92a4OaucYeckexSO2wBy9x5XZ4xp3g=; b=BJkVxlnrZjUA2m/vsVuoR/V9jV77yie27EZqc2KmS7GndI9Fp/BdUutKfwoWUakS20 QK5IUTkyfwglcobsn2LHsdTKXxiSISf7K8sDVaKrmDCErUmDQevbNmE+/SB/iCXaYrCY TSFejOA1Coa0WM8ZvTkTHfnbnj579oCfGJf6ZjhvMXwC9w8QYDI1141d5id7Ik91nTdC TkNT+SX4E3sCPSBXCApZ/3NtBE9VR7scnGfHTAZU8E015JwYUR+wj490l5FvJgtqwGZe lqBjQ2zlEkHnAOHtaFZmBEU8vSvxs1Q8HA3FtNdmd1ZpMJs1o9SxVPSzIKpJky3b+kCY Uajg== X-Forwarded-Encrypted: i=1; AFNElJ9QQZyCdhY318Caf9Rd7NRdomexlrdBCJ4KMSwGlZRN4JqGtqlwwAEUFJILotiOw8EwIg+Q45qhgEEJFkw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/z/aBYQdEmFCZiDcEFv9XRFRgTtmnCCOnOt+9MWIQK03tuCZq 5dkXieTyvZUuBVFtW5Lw3lQAnsjVQO+7tkzpn/TTStp4plCVd1jkx28DNh9O7g== X-Gm-Gg: Acq92OGgjETfIgs5rCN2VcAiuOr68ICIQNRxanE1S2fR1FRwsWgjvQsVhGO8oGujcEJ wElVi2g43fLHPfjjC+HwrFx5qOMJJg1hZiGvaYXb6+jsCFlZAYhdlYfFrc+A5HRKMlZ94m2m31a M3k+5HyIVFAWEd/zgT++0PvVNFDK1UcwkUAnvd7AzXNwrPWMpQqOmlAgdK3WXNEdOUhJy0c1YPS DHjxd6KjvTf0GU8+LikLWJGYSiBJ4Cm7//CFVkC32ui7LWAgQCt6q9a1tZcXQE69WfAP1a9V960 cRyoqWV3N54w094g71qpKD0CZAVnkyxwdo0rBj8LyrzjB6c7CQ7oDAYJkrR5u8pMSXBYTBNxMff rvSlPVGLciWxALsL63ZR+M7D9PYKrEMBR0ctTG7gfWfrsq8V+m8eOwPNt+mg2KxF27OeMWS8Svv qXiRv5fR9IAmzCIJdPIKPDw0ewMvc= X-Received: by 2002:a05:6a00:124b:b0:835:41f3:f434 with SMTP id d2e1a72fcca58-84225333915mr1897126b3a.1.1780151734907; Sat, 30 May 2026 07:35:34 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214b2acb7sm5832280b3a.13.2026.05.30.07.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2026 07:35:34 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon , Hyunchul Lee Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, DaeMyung Kang Subject: [PATCH v4 5/6] ntfs: update index root allocated size before shrink Date: Sat, 30 May 2026 23:35:13 +0900 Message-ID: <20260530143514.3083601-6-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260530143514.3083601-1-charsyam@gmail.com> References: <20260530143514.3083601-1-charsyam@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 ntfs_ir_truncate() currently shrinks the resident $INDEX_ROOT value first and only updates index.allocated_size after re-looking up the attribute. During that relookup, the resident value_length can already be smaller while index.allocated_size still contains the old larger size. That leaves a transiently inconsistent $INDEX_ROOT layout and prevents lookup-time $INDEX_ROOT validation from being enabled: validation can correctly reject allocated_size extending past the newly shrunk resident value. When shrinking, lower index.allocated_size before shrinking value_length. If the truncate fails, restore the old allocated_size. Keep the existing grow ordering because the old allocated_size remains within the enlarged resident value until it is updated after the relookup. The shrink path is safe because the new value_length still covers struct index_root, so the index.allocated_size field remains present while it is updated first. Signed-off-by: DaeMyung Kang --- fs/ntfs/index.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/ntfs/index.c b/fs/ntfs/index.c index 146e011c1a41..068c68a0f9cf 100644 --- a/fs/ntfs/index.c +++ b/fs/ntfs/index.c @@ -1280,9 +1280,16 @@ static int ntfs_ir_reparent(struct ntfs_index_context *icx) static int ntfs_ir_truncate(struct ntfs_index_context *icx, int data_size) { int ret; + u32 old_allocated_size; + bool shrink; ntfs_debug("Entering\n"); + old_allocated_size = le32_to_cpu(icx->ir->index.allocated_size); + shrink = data_size < old_allocated_size; + if (shrink) + icx->ir->index.allocated_size = cpu_to_le32(data_size); + /* * INDEX_ROOT must be resident and its entries can be moved to * struct index_block, so ENOSPC isn't a real error. @@ -1294,9 +1301,14 @@ static int ntfs_ir_truncate(struct ntfs_index_context *icx, int data_size) if (!icx->ir) return -ENOENT; - icx->ir->index.allocated_size = cpu_to_le32(data_size); - } else if (ret != -ENOSPC) - ntfs_error(icx->idx_ni->vol->sb, "Failed to truncate INDEX_ROOT"); + if (!shrink) + icx->ir->index.allocated_size = cpu_to_le32(data_size); + } else { + if (shrink) + icx->ir->index.allocated_size = cpu_to_le32(old_allocated_size); + if (ret != -ENOSPC) + ntfs_error(icx->idx_ni->vol->sb, "Failed to truncate INDEX_ROOT"); + } return ret; } -- 2.43.0