ksmbd: prevent rename with empty string
authorNamjae Jeon <linkinjeon@kernel.org>
Wed, 30 Apr 2025 02:18:28 +0000 (11:18 +0900)
committerSteve French <stfrench@microsoft.com>
Thu, 1 May 2025 23:58:48 +0000 (18:58 -0500)
Client can send empty newname string to ksmbd server.
It will cause a kernel oops from d_alloc.
This patch return the error when attempting to rename
a file or directory with an empty new name string.

Cc: stable@vger.kernel.org
Reported-by: Norbert Szetei <norbert@doyensec.com>
Tested-by: Norbert Szetei <norbert@doyensec.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c

index 46aa082457424b5e3997446a2f19ce200d80c0e6..f2a2be8467c66900fbaa215ba8b954193b8d93ee 100644 (file)
@@ -633,6 +633,11 @@ smb2_get_name(const char *src, const int maxlen, struct nls_table *local_nls)
                return name;
        }
 
+       if (*name == '\0') {
+               kfree(name);
+               return ERR_PTR(-EINVAL);
+       }
+
        if (*name == '\\') {
                pr_err("not allow directory name included leading slash\n");
                kfree(name);