Skip to content

Commit

Permalink
ksmbd: move leading slash check to smb2_get_name()
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Jun 9, 2024
1 parent 18f1b87 commit ddb1df1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ smb2_get_name(const char *src, const int maxlen, struct nls_table *local_nls)
return name;
}

if (*name == '\\') {
pr_err("not allow directory name included leading slash\n");
kfree(name);
return ERR_PTR(-EINVAL);
}

ksmbd_conv_path_to_unix(name);
ksmbd_strip_last_slash(name);
return name;
Expand Down Expand Up @@ -2939,20 +2945,11 @@ int smb2_open(struct ksmbd_work *work)
}

if (req->NameLength) {
if ((req->CreateOptions & FILE_DIRECTORY_FILE_LE) &&
*(char *)req->Buffer == '\\') {
pr_err("not allow directory name included leading slash\n");
rc = -EINVAL;
goto err_out2;
}

name = smb2_get_name((char *)req + le16_to_cpu(req->NameOffset),
le16_to_cpu(req->NameLength),
work->conn->local_nls);
if (IS_ERR(name)) {
rc = PTR_ERR(name);
if (rc != -ENOMEM)
rc = -ENOENT;
name = NULL;
goto err_out2;
}
Expand Down

0 comments on commit ddb1df1

Please sign in to comment.