]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ksmbd: make __dir_empty() compatible with POSIX
authorHobin Woo <hobin.woo@samsung.com>
Wed, 4 Sep 2024 04:36:35 +0000 (13:36 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:29:48 +0000 (16:29 +0200)
commit ca4974ca954561e79f8871d220bb08f14f64f57c upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/server/vfs.c

index dceb4bc76a66ac4958437020830ed8efc7d9483d..3c190eba82002afde0e379b091adde3b6906a609 100644 (file)
@@ -1110,9 +1110,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;
 }
 
 /**
@@ -1132,7 +1133,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;