Skip to content

Commit

Permalink
ksmbd: make __dir_empty() compatible with POSIX
Browse files Browse the repository at this point in the history
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.

Cc: stable@vger.kernel.org # v6.1+
Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Hobin Woo authored and Steve French committed Sep 14, 2024
1 parent ee426bf commit ca4974c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/smb/server/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit ca4974c

Please sign in to comment.