From: Frank Sorenson <sorenson@redhat.com>
To: linux-cifs@vger.kernel.org, stfrench@microsoft.com, pc@manguebit.org
Cc: stable@vger.kernel.org, Paulo Alcantara <pc@manguebit.com>
Subject: [PATCH 2/3] cifs: don't update i_size in cifs_do_truncate() without a cached handle
Date: Thu, 6 Aug 2026 18:43:05 -0500 [thread overview]
Message-ID: <20260806234306.3662175-3-sorenson@redhat.com> (raw)
In-Reply-To: <20260806234306.3662175-1-sorenson@redhat.com>
When cifs_do_truncate() is called from cifs_open() for an O_TRUNC open
and find_writable_file() returns NULL (no cached writable handle),
cifs_file_flush() returns 0 without sending a server set_file_size
request. The outer "if (!rc)" block then falls through unconditionally
to cifs_setsize(), setting the local inode size to 0 even though the
server has not yet been told to truncate the file.
If the subsequent network open in cifs_open() fails (e.g.
STATUS_ACCESS_DENIED from cifs_nt_open()), the caller receives an error
but the local inode remains at size 0 while the server file is still at
its original size.
When cfile is NULL, the O_TRUNC flag in the subsequent cifs_open()
request tells the server to truncate; i_size is updated from the open
response. Move the size update inside the "if (cfile)" arm so that it
only runs when the server has been explicitly told to truncate, and call
cifs_invalidate_cache() in the no-handle case to flush stale pages
before the open is sent.
Fixes: 110fee6b9bb5 ("smb: client: fix missing timestamp updates with O_TRUNC")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.com>
Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
fs/smb/client/file.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 389083f9ce00..acabe2ae237e 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -1012,10 +1012,19 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
server = tcon->ses->server;
rc = server->ops->set_file_size(xid, tcon,
cfile, 0, false);
- }
- if (!rc) {
- netfs_resize_file(&cinode->netfs, 0, true);
- cifs_setsize(inode, 0);
+ if (!rc) {
+ netfs_resize_file(&cinode->netfs, 0, true);
+ cifs_setsize(inode, 0);
+ cifs_invalidate_cache(inode, 0);
+ }
+ } else {
+ /*
+ * No cached handle; the server truncates as part of the
+ * O_TRUNC open request that follows. Invalidate stale
+ * pages now so they are not written back after the
+ * truncation; i_size is updated from the server's open
+ * response.
+ */
cifs_invalidate_cache(inode, 0);
}
}
--
2.55.0
next prev parent reply other threads:[~2026-08-06 23:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 23:43 [PATCH 0/3] cifs: three size-management bug fixes Frank Sorenson
2026-08-06 23:43 ` [PATCH 1/3] cifs: clear tcon after cifsFileInfo_put() in cifs_file_set_size() Frank Sorenson
2026-08-06 23:43 ` Frank Sorenson [this message]
2026-08-06 23:43 ` [PATCH 3/3] cifs: fix loff_t underflow in cifs_remap_file_range() when len == 0 Frank Sorenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260806234306.3662175-3-sorenson@redhat.com \
--to=sorenson@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pc@manguebit.com \
--cc=pc@manguebit.org \
--cc=stable@vger.kernel.org \
--cc=stfrench@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox