From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796010612; b=CK5m5cdTt8gp5623Nndj7jr2d7/w6qdr5++0EftVMrOnWHYSm/h/qP6nxJZzosccalqb hkPmwAPutzxbdi4T7Q5mCz2lx8UEvOQMNOt9N0fneZZUI4mdQLPbzgZnR5z9SQ7epihIs 5oLsio853pH7+JD/dL+a2ofu3K8RmEhicOei4Ly4EEQsGGEWhPsvJ4GvR7p64QOl25tiC dk/axPDGQvOCPXXrddCz3k8UDe5O+nnsdgagXU+yOHgbi5rineepTFWY+z4ylc1bNQY/1 Dow3gPOauDP1T+Ig42uZdVCpdYI7FPvZrjR6I9okczmCmcaTZOOWp3/Smf62UkPUcvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010612; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:X-Originating-IP:X-CM-SenderInfo; bh=+Bsy/xwyQsw7sWPau9Y7GEYtEvZ+XcqmNeKMRB0BZxI=; b=5lxi9oK88zvUIR/0lTtK6pX+BzXVLY4aqQ8kqXA57o+vGXQhRT3T8c82z9z2NJHPMq63 +IhzROesF4NQWCI7O3DUOejXnCpaHJGkLVcnIn8KI4G72cIHAo4r0fFn/wwWUHv24IIGw +zoZbPUlpqR8+yNKFFyDXkb0A+NFml5Xvxo0GQuLleKdzjATR1iyIb/wWjAip4GLUA7YV wJHT0VL3Gl/L5SGPyw4T4VvJ1v/ccli0X6Dxku4O8t1bwcJWAXUxySJlo4GoDjPUNl51P XTkFA1wCisZ2ldHX9gdeVEaJnhmjL0XtKc8RQYI4UA/L7CmyUJ/sLTJsWh8J4ru0GSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=mz8qyw34; arc=none smtp.remote-ip=220.197.31.4 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E61D4606A32A; Mon, 30 Nov 2026 03:50:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E61D4606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=mz8qyw34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From: Content-Type; bh=+Bsy/xwyQsw7sWPau9Y7GEYtEvZ+XcqmNeKMRB0BZxI=; b=mz8qyw34JlaYtxJhgLW04sveDRqNNXaqz16+Cqth9Ref5MLiLFGy8p0cfsfjjG hAc7/Uzy0aBqV13Y489QNWNIvRhLApF720q1+2mpqO2I09CRyAPmxLx7XfRpczJX 93mc3xXeYqSJYuZwL2t865jRuBHCDky8NqEzzZrovms3k= Received: from [IPV6:2409:8900:6ae:3295:bdf5:7149:7d26:d2ca] (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgBX5Jdg8gxryLXKIw--.64039S2; Mon, 30 Nov 2026 11:49:53 +0800 (CST) Message-ID: Date: Mon, 30 Nov 2026 11:49:52 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 5/6] ntfs: serialize the mmap write fault initialized size update To: Hongling Zeng , linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Baolin Liu References: <20261130030708.59798-1-zenghongling@kylinos.cn> <20261130030708.59798-6-zenghongling@kylinos.cn> Content-Language: en-US From: liubaolin In-Reply-To: <20261130030708.59798-6-zenghongling@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:QCgvCgBX5Jdg8gxryLXKIw--.64039S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCFy8Aw47tF4fCFy5Gw18Grg_yoW5XF1xpr 9F9FZxGr1xXry2qws3K34rJa4Fvw18Cr47Wr15Cr13ArZ5tw1vqF15Ka48urW8trW8AF10 qF4q93yxC3W3Zr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jrZ2-UUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6gGyfWsM8mH2OAAA3e 在 2026/11/30 11:07, Hongling Zeng 写道: > The mmap write fault path checks whether the faulting range extends > past ni->initialized_size with an unlocked read and then calls > ntfs_attr_set_initialized_size(), which rewrites the field and the > MFT record with its argument unconditionally. The call is made > without the MFT record lock that every other caller of the function > holds, and a buffered write or a second fault extending the > initialized size between the read and the rewrite can make the > rewrite shrink the field again, which exposes initialized data as > uninitialized. > > Hold the MFT record lock across the check and the update and read > initialized_size under size_lock inside the critical section, so the > decision is made on the value that is current for the record and the > field can no longer regress through the fault path. > > Fixes: b041ca562526 ("ntfs: update iomap and address space operations") > Cc: stable@vger.kernel.org > Signed-off-by: Hongling Zeng > Reviewed-by: Baolin Liu > --- > fs/ntfs/attrib.c | 1 + > fs/ntfs/iomap.c | 15 +++++++++++---- > 2 files changed, 12 insertions(+), 4 deletions(-) > > diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c > index 081ce3e829f2..56df3049a386 100644 > --- a/fs/ntfs/attrib.c > +++ b/fs/ntfs/attrib.c > @@ -2431,6 +2431,7 @@ int ntfs_attr_set(struct ntfs_inode *ni, s64 ofs, s64 cnt, const u8 val) > return ret; > } > > +/* The caller must hold the base inode's mft record lock. */ > int ntfs_attr_set_initialized_size(struct ntfs_inode *ni, loff_t new_size) > { > struct ntfs_attr_search_ctx *ctx; > diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c > index a9c04fb964ba..f191bd5c444e 100644 > --- a/fs/ntfs/iomap.c > +++ b/fs/ntfs/iomap.c > @@ -669,10 +669,17 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode, > return err; > } > > - if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE && > - iomap->offset + iomap->length > ni->initialized_size) { > - err = ntfs_attr_set_initialized_size(ni, > - iomap->offset + iomap->length); > + if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE) { > + loff_t initialized_size; > + > + mutex_lock(&mrec_ni->mrec_lock); > + read_lock_irqsave(&ni->size_lock, irqflags); > + initialized_size = ni->initialized_size; > + read_unlock_irqrestore(&ni->size_lock, irqflags); > + if (iomap->offset + iomap->length > initialized_size) > + err = ntfs_attr_set_initialized_size(ni, > + iomap->offset + iomap->length); > + mutex_unlock(&mrec_ni->mrec_lock); > } > > return err; Looks good to me. Reviewed-by: Baolin Liu