Skip to contentSkip to conversation

ksmbd: make __dir_empty() compatible with POSIX

PATCH Applied Hobin Woo 2 participants 2 messages Sep 4, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20240904043639epcas1p27080078eed3604d12cff3b01d7636343@epcas1p2.samsung.com

Hobin Woo

author
#1 lore raw

PATCH v2 1/1 ksmbd: make __dir_empty() compatible with POSIX

Some file systems may not provide dot (.) and dot-dot (..) as they are optional in POSIX. ksmbd can misjudge emptiness of a directory in those file systems, since it assumes there are always at least two entries:
dot and dot-dot.
Just don't count dot and dot-dot.

---
v2:
- Just don't count dot and dot-dot.

 fs/smb/server/vfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/smb/server/vfs.c +4 -3
index 9e859ba010cf..62de668cd1e1 100644
@@ -1115,9 +1115,10 @@ static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen,
 	struct ksmbd_readdir_data *buf;
 
 	buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
-	buf->dirent_count++;
+	if (!is_dot_dotdot(name, namlen))
+		buf->dirent_count++;
 
-	return buf->dirent_count <= 2;
+	return !buf->dirent_count;
 }
 
 /**
@@ -1137,7 +1138,7 @@ int ksmbd_vfs_empty_dir(struct ksmbd_file *fp)
 	readdir_data.dirent_count = 0;
 
 	err = iterate_dir(fp->filp, &readdir_data.ctx);
-	if (readdir_data.dirent_count > 2)
+	if (readdir_data.dirent_count)
 		err = -ENOTEMPTY;
 	else
 		err = 0;
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw
Quoted 8 lines · Hobin Woo

Some file systems may not provide dot (.) and dot-dot (..) as they are optional in POSIX. ksmbd can misjudge emptiness of a directory in those file systems, since it assumes there are always at least two entries:
dot and dot-dot.
Just don't count dot and dot-dot.

Applied it to #ksmbd-for-next-next.
Thanks for your patch!