Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] smb: client: avoid dentry leak by not overwriting cfid->dentry
@ 2025-05-06 22:31 Henrique Carvalho
  2025-05-07  6:16 ` Paul Aurich
  0 siblings, 1 reply; 9+ messages in thread
From: Henrique Carvalho @ 2025-05-06 22:31 UTC (permalink / raw)
  To: ematsumiya, sfrench, smfrench
  Cc: pc, ronniesahlberg, sprasad, paul, bharathsm, linux-cifs,
	Henrique Carvalho

A race, likely between lease break and open, can cause cfid->dentry to
be valid when open_cached_dir() tries to set it again. This overwrites
the old dentry without dput(), leaking it.

Skip assignment if cfid->dentry is already set.

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
---
 fs/smb/client/cached_dir.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index 43228ec2424d..8c1f00a3fc29 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -219,16 +219,23 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 		goto out;
 	}
 
-	if (!npath[0]) {
-		dentry = dget(cifs_sb->root);
-	} else {
-		dentry = path_to_dentry(cifs_sb, npath);
-		if (IS_ERR(dentry)) {
-			rc = -ENOENT;
-			goto out;
+	/*
+	 * BB: cfid->dentry should be NULL here; if not, we're likely racing with
+	 * a lease break. This is a temporary workaround to avoid overwriting
+	 * a valid dentry. Needs proper fix.
+	 */
+	if (!cfid->dentry) {
+		if (!npath[0]) {
+			dentry = dget(cifs_sb->root);
+		} else {
+			dentry = path_to_dentry(cifs_sb, npath);
+			if (IS_ERR(dentry)) {
+				rc = -ENOENT;
+				goto out;
+			}
 		}
+		cfid->dentry = dentry;
 	}
-	cfid->dentry = dentry;
 	cfid->tcon = tcon;
 
 	/*
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-05-08 16:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 22:31 [PATCH] smb: client: avoid dentry leak by not overwriting cfid->dentry Henrique Carvalho
2025-05-07  6:16 ` Paul Aurich
2025-05-07 14:03   ` Henrique Carvalho
     [not found]   ` <CAH2r5muyz7zY=+Fgrtc_zOA6GR1ZSGpR-Z4pFzgqmfszhnywWQ@mail.gmail.com>
2025-05-07 17:01     ` Fwd: " Steve French
     [not found]     ` <CAH2r5msisxGqZCFpJUu1Bqv5Kgo+-HD2DEO+wzQeSqG6TS2J6Q@mail.gmail.com>
2025-05-07 19:38       ` Henrique Carvalho
2025-05-07 23:56   ` Steve French
2025-05-08 15:24   ` Shyam Prasad N
2025-05-08 15:53     ` Paul Aurich
2025-05-08 16:09       ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox