diff mbox series

[3/4] cifs: set the CREATE_NOT_FILE when opening the directory in use_cached_dir()

Message ID 20220509234207.2469586-4-lsahlber@redhat.com (mailing list archive)
State New, archived
Headers show
Series [1/4] cifs: move definition of cifs_fattr earlier in cifsglob.h | expand

Commit Message

Ronnie Sahlberg May 9, 2022, 11:42 p.m. UTC
This enforces that we can only do this for directories and not normal files
or else the server will return an error.
This means that we will have conditionally check IF the path refers
to a directory or not in all the call-sites where we are unsure.
Right now this check is for "" i.e. root.

Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2inode.c | 5 ++++-
 fs/cifs/smb2ops.c   | 5 +++--
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Steve French May 21, 2022, 5:26 p.m. UTC | #1
tentatively merged the first 3 of the series (still looking at patch
4) pending testing

On Mon, May 9, 2022 at 6:42 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> This enforces that we can only do this for directories and not normal files
> or else the server will return an error.
> This means that we will have conditionally check IF the path refers
> to a directory or not in all the call-sites where we are unsure.
> Right now this check is for "" i.e. root.
>
> Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
> Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2inode.c | 5 ++++-
>  fs/cifs/smb2ops.c   | 5 +++--
>  2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
> index fe5bfa245fa7..0c3e4d2c6207 100644
> --- a/fs/cifs/smb2inode.c
> +++ b/fs/cifs/smb2inode.c
> @@ -514,8 +514,11 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
>         if (smb2_data == NULL)
>                 return -ENOMEM;
>
> +       if (strcmp(full_path, ""))
> +               rc = -ENOENT;
> +       else
> +               rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
>         /* If it is a root and its handle is cached then use it */
> -       rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
>         if (!rc) {
>                 if (tcon->crfid.file_all_info_is_valid) {
>                         move_smb2_info_to_cifs(data,
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 2c93ee27d54d..cbe56ed35694 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -825,7 +825,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
>         rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
>
>         oparms.tcon = tcon;
> -       oparms.create_options = cifs_create_options(cifs_sb, 0);
> +       oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_FILE);
>         oparms.desired_access = FILE_READ_ATTRIBUTES;
>         oparms.disposition = FILE_OPEN;
>         oparms.fid = pfid;
> @@ -2696,7 +2696,8 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
>         resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
>         memset(rsp_iov, 0, sizeof(rsp_iov));
>
> -       rc = open_cached_dir(xid, tcon, path, cifs_sb, &cfid);
> +       if (!strcmp(path, ""))
> +               rc = open_cached_dir(xid, tcon, path, cifs_sb, &cfid);
>
>         memset(&open_iov, 0, sizeof(open_iov));
>         rqst[0].rq_iov = open_iov;
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
index fe5bfa245fa7..0c3e4d2c6207 100644
--- a/fs/cifs/smb2inode.c
+++ b/fs/cifs/smb2inode.c
@@ -514,8 +514,11 @@  smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
 	if (smb2_data == NULL)
 		return -ENOMEM;
 
+	if (strcmp(full_path, ""))
+		rc = -ENOENT;
+	else
+		rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
 	/* If it is a root and its handle is cached then use it */
-	rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
 	if (!rc) {
 		if (tcon->crfid.file_all_info_is_valid) {
 			move_smb2_info_to_cifs(data,
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 2c93ee27d54d..cbe56ed35694 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -825,7 +825,7 @@  int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
 	oparms.tcon = tcon;
-	oparms.create_options = cifs_create_options(cifs_sb, 0);
+	oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_FILE);
 	oparms.desired_access = FILE_READ_ATTRIBUTES;
 	oparms.disposition = FILE_OPEN;
 	oparms.fid = pfid;
@@ -2696,7 +2696,8 @@  smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
 	resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
 	memset(rsp_iov, 0, sizeof(rsp_iov));
 
-	rc = open_cached_dir(xid, tcon, path, cifs_sb, &cfid);
+	if (!strcmp(path, ""))
+		rc = open_cached_dir(xid, tcon, path, cifs_sb, &cfid);
 
 	memset(&open_iov, 0, sizeof(open_iov));
 	rqst[0].rq_iov = open_iov;