Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Bharath SM <bharathsm.hsk@gmail.com>
To: pc@cjr.nz, sfrench@samba.org, nspmangalore@gmail.com,
	lsahlber@redhat.com, smfrench@gmail.com, tom@talpey.com,
	linux-cifs@vger.kernel.org, bharathsm@microsoft.com
Subject: [PATCH] cifs: prevent updating file size from server if we have a read/write lease
Date: Mon, 26 Feb 2024 10:20:10 +0530	[thread overview]
Message-ID: <20240226045010.30908-1-bharathsm@microsoft.com> (raw)

In cases of large directories, the readdir operation may span multiple
round trips to retrieve contents. This introduces a potential race
condition in case of concurrent write and readdir operations. If the
readdir operation initiates before a write has been processed by the
server, it may update the file size attribute to an older value.
Address this issue by avoiding file size updates from server when a
read/write lease.

Scenario:
1) process1: open dir xyz
2) process1: readdir instance 1 on xyz
3) process2: create file.txt for write
4) process2: write x bytes to file.txt
5) process2: close file.txt
6) process2: open file.txt for read
7) process1: readdir 2 - overwrites file.txt inode size to 0
8) process2: read contents of file.txt - bug, short read with 0 bytes

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
 fs/smb/client/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index f2db4a1f81ad..e742d0d0e579 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -2952,7 +2952,8 @@ bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file)
 	if (!cifsInode)
 		return true;
 
-	if (is_inode_writable(cifsInode)) {
+	if (is_inode_writable(cifsInode) ||
+			((cifsInode->oplock & CIFS_CACHE_RW_FLG) != 0)) {
 		/* This inode is open for write at least once */
 		struct cifs_sb_info *cifs_sb;
 
-- 
2.34.1


             reply	other threads:[~2024-02-26  4:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26  4:50 Bharath SM [this message]
2024-02-26  5:13 ` [PATCH] cifs: prevent updating file size from server if we have a read/write lease Steve French
2024-02-28 10:27   ` Bharath SM
2024-02-29 17:52     ` Bharath SM
2024-02-29 17:53       ` Bharath SM
2024-03-05  9:40         ` Shyam Prasad N
2024-03-11  0:32           ` Steve French

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=20240226045010.30908-1-bharathsm@microsoft.com \
    --to=bharathsm.hsk@gmail.com \
    --cc=bharathsm@microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=nspmangalore@gmail.com \
    --cc=pc@cjr.nz \
    --cc=sfrench@samba.org \
    --cc=smfrench@gmail.com \
    --cc=tom@talpey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).