From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796007748; b=s/eRnh/+xaGjenxAS+pTBa06Ut5G+068SMYjOixydcwB7ngSTajYHA9/AD1emdgCtdL6 yxMXMB08+ZiHak+wb6QKrueYhZbB1qQuCKUU/ySXTsL4Ah5gKkQdOYBdT/nish+1rmFbT b36svQxWk8fj65XAZ3ply2FeWjTtH5mbKziexrMq4Ba6V49KdM9X7aVDh1zDt10u7y2q/ Bck4qzVM3C0/mCTKxdYDP0N21596olU3m8cAVgombpnQa+O/4d1MIgutjuoapCbNzFhzp fTvHxVlL9zOBWp72TwV6UjYrerLWT7rIJ/fm4XD+9a5Ms6gVofsJj1xRQ/elVHl7vKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007748; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=N+98l3m31AxWbFOI1i3QqwS1m/mTsUt5xjHBwRZpvPw=; b=qLER6zqFg4e/I/MzDtgDa7SYNhbPZc0KzYhjOU7z/KaTtf7z/GUnK4+IjVEFRkXlcUvl s3r0/2Cvc1t0gQxzQqEUhaz5GBe6CrspewIV25C80tNksT3eqBPNpQPi5sasMUFECiQpe Td08EH3Ib8Vr3TteHeIBsjTBpua07myjlakoIW7VssB0P71Row44v5QLmOfe8pWuJTQzG SBfHzwsUvS2GYNWr8GwVHv6cVYJ57hJl1YfG8Ux7xtbUhPaO9/gqaooLabdHXdVjUld5E cSmqm48am6yxoft0w+Hc4Ni3GixRdRoTlsT/HnU04dRbgFSf3yrrCRDt0FLuomj0Y0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GORxBI43; arc=none smtp.remote-ip=209.85.215.180 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B0E2606A325 for ; Mon, 30 Nov 2026 03:02:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9B0E2606A325 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.a=rsa-sha256 header.s=20260707 header.b=GORxBI43 Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-cc4aa18f9afso3785575a12.3 for ; Sun, 29 Nov 2026 19:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796007747; x=1796612547; 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=N+98l3m31AxWbFOI1i3QqwS1m/mTsUt5xjHBwRZpvPw=; b=GORxBI43rp3qaWg4IMxje2lKrPLCfjFPi5GU/bF/c1fVmL2B2j+UpHPP1pzQuz67Xm VhLohvFvLi4SL1QSfOSGyv2jdhDgp55y3BzIYseo5wq876w2Rz2GaJXPJmcvhsXWiSSp exrjmwuC1GSj2Cjql6vDI/Q9Jm2Ckufq3gnjo4G+QbVdBK8MlRVd1DsKiWCFZTgy2uXm tTv0HX1s3s/Rru42dRsO8VszNSbaqE+DzQVg3bVMlaTGNWSZyi/T7KAZEKVwLeXmirCg djs4JyQ8UXG4c99BkSkXbVXWn+/SELxLSnTO8EvBeODOOmp44HUJYHPRF9W/rs2m66ZA wTdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796007747; x=1796612547; 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=N+98l3m31AxWbFOI1i3QqwS1m/mTsUt5xjHBwRZpvPw=; b=U8NXhM4eQaFayCswpM6O8BPn9/F/swVllyh2UBUBCmsmjv/6hSWVW/BD/gaaSSm26S n9MdpJe+5gSNg5zk4GygIIBxjnlxmLrMmLkdmxAco+AlL/GaHAb19CIKpRm3nN2T5IK1 R0JSdzETEWMnmTqwWDTOlhVF9Vwsr5q4HkBThNSnjM/+guTkhdrNbfenLGSOQ2pvlAoY 3axHKmunnPP3XK8yUer2eT48eDhf3vipkSjAc/lv4QrXzejGgfKwGJww+xLcxJyRm5Lm I7yh6kUHnxqhch41zqPvDg93swP/o1le+EDIM/kwIxJoys0Ex2N/iFzjSUFMKfHh7ABM +Z9A== X-Forwarded-Encrypted: i=1; AL+hErHzCTFU6xzmo+a7k0DSJXlkE4HLoyWnZK4kokMLqUjzh/zHzsMXh+KOhvn+lbz2xwWbmHpUkt1YIRsizhI=@vger.kernel.org X-Gm-Message-State: APuU4Z+Cexchv72dJ1QCLuxEPO84P4VzwZ8kCSmZrlvXC6EGBGNW7xUW QTTIwuTnK+FbfO6kePINDdqZVcKCGUGempxF5llusV//wHI6itq+CfSu X-Gm-Gg: AZFdTZfo157Eoqwa9tA71+OLtvNcBJi5NAW6a5fMkbZvOCcnedfO7gGyhpNR69RjV20 hVIt/zxfAwNmJ0wokXi0dTEU06L2vfLx/0gR3pF3JSXZRCwnj6ynzOeIiW+Qd6xZ5DrGOSMuuPv g82r2xqFaFvFsc5w1bPP2Ygj/IKifJUsLPFnC/LQIGqtDgRtAkcT3jRTBpmFm+iQqEoWC3XyDZy VvV42ucOMVOW1oPryKv4n3pOloNODAv2u5TT5o2QFS6qzoCl9yZmNoLsRgCevCh91q2byPNbfdE CMZ+hmFq/Arsk+4BvbZLjTq+DP824kMptcYc/h+Bypd+l4DW+hb7kA4aPbedi9uNqnrIXt3sT2o bv5T447lN6HTEsqQHSMnYlEf0X2cxV2Cbks+jDBWQoBQ+Oi+UksnEwSAE8gNaDUsOxA6ibavzFf /k02ElJQhH2aEuvIWBFRtNZUCbWi+5vTXcOpS+WbYbcwX9xgq9jGpPW8U/k8pYwthWPA26CgNr8 sbmmY/ND1hRyMr+Tc7pHYAgzHeEmbHnZv0nNWM+I51Ws70wznBM8zjy5ANm7gGmNoChi4mUFzsg PzFuz/kw+9um6MDEY+KwhfujlRDcol2KsHzgBvSnzVTUDQ== X-Received: by 2002:a17:90a:e7d0:b0:3ac:929e:691 with SMTP id 98e67ed59e1d1-3b41c8d5a52mr30070755a91.17.1796007746850; Sun, 29 Nov 2026 19:02:26 -0800 (PST) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b6fc28asm25012012a91.1.2026.11.29.19.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 19:02:26 -0800 (PST) From: Zhan Xusheng To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: liubaolin12138@163.com, ernest.borowski.git@proton.me, ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com, stable@vger.kernel.org Subject: [PATCH] ntfs: zero up to a page that a shared mapping makes writable Date: Mon, 30 Nov 2026 11:02:20 +0800 Message-ID: <20261130030220.1100209-1-zhanxusheng1024@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhan Xusheng A page fault that makes a page of a shared mapping writable moves the initialized size to the end of that page. If the page starts past the initialized size, nothing zeroes the range in between, and the allocated tail of the cluster holding the old initialized size becomes readable with whatever the disk held before. This needs clusters larger than a page. For example, with 64K clusters, write 4K to a new file, map it 4M MAP_SHARED, grow it to 4M with ftruncate() and store 8 bytes at 2M through the mapping. After msync() and a remount, [4K, 64K) reads back the old contents of the cluster. Zero the gap with ntfs_extend_initialized_size() before the fault takes the invalidate lock, as a write past the initialized size does. Fixes: b041ca562526 ("ntfs: update iomap and address space operations") Cc: stable@vger.kernel.org --- Tested in a VM on ntfs-next 8b42a85768e9, with all free space filled with a known pattern first. The example above, bytes of old data in [0, 64K) after remount: ntfs-next patched 4K clusters 0 0 64K clusters 61440 0 The 4K written first and the bytes stored at 2M are kept in both. A pwrite() of one byte at 2M instead of the store gives 0 with and without the patch. Shared mappings made writable with mprotect(), the killed and stalled writer cases, fsx (buffered and O_DIRECT), insert/collapse range and the partial O_DIRECT cases give the same results with and without the patch. No lockdep or KASAN reports. This only runs for a page past the initialized size. ntfs_file_mmap_prepare() already moves it to the end of the mapping, so that takes a file grown after mmap(). fs/ntfs/file.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 612498b45fbb..d0da022d0860 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -993,6 +993,7 @@ static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf) struct inode *inode = file_inode(vmf->vma->vm_file); struct address_space *mapping = inode->i_mapping; bool stream = ntfs_inode_is_named_stream(NTFS_I(inode)); + loff_t pos; int err; vm_fault_t ret; @@ -1011,6 +1012,20 @@ static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf) file_update_time(vmf->vma->vm_file); } + /* + * Making the page writable moves the initialized size up to its end. + * If the page starts past the initialized size, zero what lies between + * first, as a write there would, or the tail of the last initialized + * cluster becomes readable with whatever the disk held. + */ + pos = (loff_t)vmf->pgoff << PAGE_SHIFT; + if (NInoNonResident(NTFS_I(inode)) && + pos > NTFS_I(inode)->initialized_size) { + err = ntfs_extend_initialized_size(inode, pos, pos); + if (err) + goto out_error; + } + /* * Serialize against truncate/fallocate which hold the lock * exclusively while invalidating pagecache and changing extents. -- 2.43.0