From nobody Sun Feb 8 13:32:42 2026 Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 787A51DC997 for ; Sat, 27 Dec 2025 18:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858630; cv=none; b=RufMiYZAWkA0tnMn6I5MqVVFgExIn2Gny6FfGCzT1rIXpRl8lRxO5/E77RUhYIYAI/8akOKaB4GzdQEI0XrnKuAiHxHju8WK4zYc9zKVwfMJjitZLZ+zNEPWN5nyLNbr2qp8OVB6ZdJ7oFxxV58ABfQloRy2XWB6Nb2YfK4tYvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858630; c=relaxed/simple; bh=1iKk4TlQYaaPuFEkr999UB1HWYWKTOM5VBvK7CsTtEc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Kg9gh9wvh+SLs7GVmpKNKuA/HQGg2Sj2RHfewpm+2LlAInvkGJtUhShKiPhF3Yi/JFJvH4c4ntqpHdfKG2YCtlsKojigTnLRh7l/HyoKE5+NoDTMcdyYLxgevRdvWx8MmAYoGLPEJbDKCqNggLY0DXOX9eQtCvez2Hiv/TY4fWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=barre.sh; spf=pass smtp.mailfrom=barre.sh; dkim=pass (2048-bit key) header.d=barre.sh header.i=@barre.sh header.b=L5+4a3zw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LiRa6qb0; arc=none smtp.client-ip=202.12.124.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=barre.sh Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=barre.sh Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=barre.sh header.i=@barre.sh header.b="L5+4a3zw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LiRa6qb0" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id B1E9C7A009B; Sat, 27 Dec 2025 13:03:47 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sat, 27 Dec 2025 13:03:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=barre.sh; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm3; t=1766858627; x=1766945027; bh=wsC30HRMM02X32a9o5jCY TRr4CIHL44A+GaMuiIgznE=; b=L5+4a3zwEqtuTBePIXQIiah1epxNkVRPXVhAY N2PCdleCSfKdM6hDQoIZK81jCjvaNTf/VDUAdUqdZcZYwyrmx2XcKk8+UkXLupXq PH1z7AnqO0lkCPeCUVH22y112t6hqLruKW/7XPFkbDrcgINyK9Rn115+HSyVxSkF 7TD9etckEAeFxv50M+DxPa83dxy/CyvpSR2eDpCEM77m9L7UxLAC6Zy/mSTicoaG fwOsG/KWk592rLMqm/Fda6RfUK0RQkM70qDX+j+aYA5UcEFm5pzRftwQ3+6WlW7h e8JjQ3MXiLymXvTfGS+2yT4DaWvSzIyFqVJ50UHJLJ+IkG0XQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1766858627; x=1766945027; bh=wsC30HRMM02X32a9o5jCYTRr4CIHL44A+Ga MuiIgznE=; b=LiRa6qb00d6YyawYRGvXXZ7IpGb0y1NiU6SGqKavlvm+uuY/chR neLuVW+tXrZWjy0r/aD4BkPKamOLNlcE5Nl8ETHX8NAuYJdTqPRQj6vNrR2Sp7vD 1PbHHl6rgvQkvVCnoBkVgDE2hYmScFFKg0WYvEnwtY+iG7tQ04Os0kRK3+YpibKT H/TAvKGSwFHVBWBNEhoCp2L2MWF2D8jX+WOlfyI1IzthVFGEa98MpKlqcUc4pIZ+ BnZeSiYfwsxZFxKSpPwRxywO89I217RYD9knmCmwckygN4DZOEUacSZLHKHohP89 ZTIcKMs4rx4M+1GI8jm4wU7DjBlOG2cOCtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdejvddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgggfestdekredtredttd enucfhrhhomheprfhivghrrhgvuceurghrrhgvuceophhivghrrhgvsegsrghrrhgvrdhs hheqnecuggftrfgrthhtvghrnhepueekiefggfelueeihedvtdfhvddutdejfefhueevhf ehjedvuddvgeevkeehgffgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepphhivghrrhgvsegsrghrrhgvrdhshhdpnhgspghrtghpthhtohepje dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepvghrihgtvhhhsehkvghrnhgvlhdr ohhrghdprhgtphhtthhopehluhgthhhosehiohhnkhhovhdrnhgvthdprhgtphhtthhope grshhmrgguvghushestghouggvfihrvggtkhdrohhrghdprhgtphhtthhopehlihhnuhig pghoshhssegtrhhuuggvsgihthgvrdgtohhmpdhrtghpthhtohepvhelfhhssehlihhsth hsrdhlihhnuhigrdguvghvpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphhivghrrhgvsegsrghrrhgvrdhshh X-ME-Proxy: Feedback-ID: i97614980:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 27 Dec 2025 13:03:46 -0500 (EST) From: Pierre Barre To: ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org Cc: linux_oss@crudebyte.com, v9fs@lists.linux.dev, linux-kernel@vger.kernel.org, Pierre Barre Subject: [PATCH v2] 9p: fix i_size update race in getattr with writeback caching Date: Sat, 27 Dec 2025 19:01:37 +0100 Message-ID: <20251227180137.730385-1-pierre@barre.sh> 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: quoted-printable Content-Type: text/plain; charset="utf-8" With writeback caching (cache=3Dmmap), v9fs_stat2inode() and v9fs_stat2inode_dotl() unconditionally overwrite i_size from the server response, even when dirty pages may exist locally. This causes processes using lseek(SEEK_END) to see incorrect file sizes, leading to data corruption when extending files while concurrent stat() calls occur. Fix by passing V9FS_STAT2INODE_KEEP_ISIZE when CACHE_WRITEBACK is enabled to preserve the client's authoritative i_size. Signed-off-by: Pierre Barre --- fs/9p/vfs_inode.c | 7 ++++++- fs/9p/vfs_inode_dotl.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 97abe65bf7c1..bfba21f5d8a9 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -993,7 +993,12 @@ v9fs_vfs_getattr(struct mnt_idmap *idmap, const struct= path *path, if (IS_ERR(st)) return PTR_ERR(st); =20 - v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0); + /* + * With writeback caching, the client is authoritative for i_size. + * Don't let the server overwrite it with a potentially stale value. + */ + v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, + (v9ses->cache & CACHE_WRITEBACK) ? V9FS_STAT2INODE_KEEP_ISIZE : 0); generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat); =20 p9stat_free(st); diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 643e759eacb2..67a0ded2e223 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -453,7 +453,12 @@ v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap, if (IS_ERR(st)) return PTR_ERR(st); =20 - v9fs_stat2inode_dotl(st, d_inode(dentry), 0); + /* + * With writeback caching, the client is authoritative for i_size. + * Don't let the server overwrite it with a potentially stale value. + */ + v9fs_stat2inode_dotl(st, d_inode(dentry), + (v9ses->cache & CACHE_WRITEBACK) ? V9FS_STAT2INODE_KEEP_ISIZE : 0); generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat); /* Change block size to what the server returned */ stat->blksize =3D st->st_blksize; --=20 2.43.0