ksmbd: remove internal.h include
Subsystems (3)
Namjae Jeon
maintainerPATCH 1/4 ksmbd: remove internal.h include
Since vfs_path_lookup() is exported, It should not be internal. Move vfs_path_lookup prototype in internal.h to linux/namei.h.
--- fs/internal.h | 2 -- fs/ksmbd/vfs.c | 2 -- include/linux/namei.h | 2 ++ 3 files changed, 2 insertions(+), 4 deletions(-)
fs/internal.h +0 -2
@@ -58,8 +58,6 @@ extern int finish_clean_context(struct fs_context *fc);*/ extern int filename_lookup (int dfd,struct filename *name,unsigned flags,struct path *path,struct path *root); -extern int vfs_path_lookup (struct dentry *,struct vfsmount *, -const char *,unsigned int ,struct path *);int do_rmdir (int dfd,struct filename *name);int do_unlinkat (int dfd,struct filename *name);int may_linkat (struct user_namespace *mnt_userns,struct path *link);
fs/ksmbd/vfs.c +0 -2
@@ -19,8 +19,6 @@#include <linux/sched/xacct.h> #include <linux/crc32c.h> -#include "../internal.h" /* for vfs_path_lookup */ -#include "glob.h" #include "oplock.h" #include "connection.h"
include/linux/namei.h +2 -0
@@ -63,6 +63,8 @@ extern struct dentry *kern_path_create(int, const char *, struct path *, unsigneextern struct dentry *user_path_create (int ,const char __user *,struct path *,unsigned int );extern void done_path_create (struct path *,struct dentry *);extern struct dentry *kern_path_locked (const char *,struct path *); +int vfs_path_lookup (struct dentry *,struct vfsmount *,const char *, +unsigned int ,struct path *);extern struct dentry *try_lookup_one_len (const char *,struct dentry *,int );extern struct dentry *lookup_one_len (const char *,struct dentry *,int );
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/4 ksmbd: remove filename in ksmbd_file
If the filename is change by underlying rename the server, fp->filename and real filename can be different. This patch remove the uses of fp->filename in ksmbd and replace it with d_path().
--- fs/ksmbd/misc.c | 40 +++++++++++++++++++++++++++++++--------- fs/ksmbd/misc.h | 3 ++- fs/ksmbd/oplock.c | 30 ------------------------------ fs/ksmbd/oplock.h | 2 -- fs/ksmbd/smb2pdu.c | 21 +++++++-------------- fs/ksmbd/vfs.c | 6 ++---- fs/ksmbd/vfs_cache.c | 1 - fs/ksmbd/vfs_cache.h | 1 - 8 files changed, 42 insertions(+), 62 deletions(-)
fs/ksmbd/misc.c +31 -9
@@ -158,19 +158,41 @@ int parse_stream_name(char *filename, char **stream_name, int *s_type)* Return : windows path string or error */ -char *convert_to_nt_pathname (char *filename) +char *convert_to_nt_pathname (struct ksmbd_share_config *share, +struct path *path) { -char *ab_pathname; +char *pathname, *ab_pathname, *nt_pathname =NULL ; +int share_path_len =strlen (share->path); -if (strlen (filename) ==0 ) - filename ="\\" ; + pathname =kmalloc (PATH_MAX ,GFP_KERNEL ); +if (!pathname) +return ERR_PTR (-EACCES ); - ab_pathname =kstrdup (filename,GFP_KERNEL ); -if (!ab_pathname) -return NULL ; + ab_pathname =d_path (path, pathname,PATH_MAX ); +if (IS_ERR (ab_pathname)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + +if (strncmp (ab_pathname, share->path, share_path_len)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + + nt_pathname =kzalloc (strlen (&ab_pathname[share_path_len]) +1 ,GFP_KERNEL ); +if (!nt_pathname) { + nt_pathname =ERR_PTR (-ENOMEM ); + goto free_pathname; + } +if (ab_pathname[share_path_len] =='\0' ) +strcpy (nt_pathname,"/" ); +strcat (nt_pathname, &ab_pathname[share_path_len]); + +ksmbd_conv_path_to_windows (nt_pathname); -ksmbd_conv_path_to_windows (ab_pathname); -return ab_pathname; +free_pathname: +kfree (pathname); +return nt_pathname; }int get_nlink (struct kstat *st)
fs/ksmbd/misc.h +2 -1
@@ -14,7 +14,8 @@ struct ksmbd_file;int match_pattern (const char *str,size_t len,const char *pattern);int ksmbd_validate_filename (char *filename);int parse_stream_name (char *filename,char **stream_name,int *s_type); -char *convert_to_nt_pathname (char *filename); +char *convert_to_nt_pathname (struct ksmbd_share_config *share, +struct path *path);int get_nlink (struct kstat *st);void ksmbd_conv_path_to_unix (char *path);void ksmbd_strip_last_slash (char *path);
fs/ksmbd/oplock.c +0 -30
@@ -1694,33 +1694,3 @@ struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,read_unlock (&lease_list_lock);return ret_op; } - -int smb2_check_durable_oplock (struct ksmbd_file *fp, -struct lease_ctx_info *lctx,char *name) -{ -struct oplock_info *opinfo =opinfo_get (fp); -int ret =0 ; - -if (opinfo && opinfo->is_lease) { -if (!lctx) { -pr_err ("open does not include lease\n" ); - ret = -EBADF ; - goto out; - } -if (memcmp (opinfo->o_lease->lease_key, lctx->lease_key, -SMB2_LEASE_KEY_SIZE )) { -pr_err ("invalid lease key\n" ); - ret = -EBADF ; - goto out; - } -if (name &&strcmp (fp->filename, name)) { -pr_err ("invalid name reconnect %s\n" , name); - ret = -EINVAL ; - goto out; - } - } -out: -if (opinfo) -opinfo_put (opinfo); -return ret; -}
fs/ksmbd/oplock.h +0 -2
@@ -124,6 +124,4 @@ struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,int find_same_lease_key (struct ksmbd_session *sess,struct ksmbd_inode *ci,struct lease_ctx_info *lctx);void destroy_lease_table (struct ksmbd_conn *conn); -int smb2_check_durable_oplock (struct ksmbd_file *fp, -struct lease_ctx_info *lctx,char *name);#endif /* __KSMBD_OPLOCK_H */
fs/ksmbd/smb2pdu.c +7 -14
@@ -2922,7 +2922,6 @@ int smb2_open(struct ksmbd_work *work) goto err_out; } - fp->filename = name; fp->cdoption = req->CreateDisposition; fp->daccess = daccess; fp->saccess = req->ShareAccess;
@@ -3274,14 +3273,13 @@ int smb2_open(struct ksmbd_work *work)if (!rsp->hdr.Status) rsp->hdr.Status =STATUS_UNEXPECTED_IO_ERROR ; -if (!fp || !fp->filename) -kfree (name);if (fp)ksmbd_fd_put (work, fp);smb2_set_err_rsp (work);ksmbd_debug (SMB ,"Error response: %x\n" , rsp->hdr.Status); } +kfree (name);kfree (lc);return 0 ;
@@ -3901,8 +3899,6 @@ int smb2_query_dir(struct ksmbd_work *work)ksmbd_debug (SMB ,"Search pattern is %s\n" , srch_ptr); } -ksmbd_debug (SMB ,"Directory name is %s\n" , dir_fp->filename); -if (srch_flag &SMB2_REOPEN || srch_flag &SMB2_RESTART_SCANS ) {ksmbd_debug (SMB ,"Restart directory scan\n" );generic_file_llseek (dir_fp->filp,0 ,SEEK_SET );
@@ -4396,9 +4392,9 @@ static int get_file_all_info(struct ksmbd_work *work,return -EACCES ; } - filename =convert_to_nt_pathname (fp->filename); -if (!filename) -return -ENOMEM ; + filename =convert_to_nt_pathname (work->tcon->share_conf, &fp->filp->f_path); +if (IS_ERR (filename)) +return PTR_ERR (filename); inode =file_inode (fp->filp);generic_fillattr (file_mnt_user_ns (fp->filp), inode, &stat);
@@ -5689,8 +5685,7 @@ static int set_file_allocation_info(struct ksmbd_work *work, size =i_size_read (inode); rc =ksmbd_vfs_truncate (work, fp, alloc_blks *512 );if (rc) { -pr_err ("truncate failed! filename : %s, err %d\n" , - fp->filename, rc); +pr_err ("truncate failed!, err %d\n" , rc);return rc; }if (size < alloc_blks *512 )
@@ -5720,12 +5715,10 @@ static int set_end_of_file_info(struct ksmbd_work *work, struct ksmbd_file *fp,* truncated range. */ if (inode->i_sb->s_magic !=MSDOS_SUPER_MAGIC ) { -ksmbd_debug (SMB ,"filename : %s truncated to newsize %lld\n" , - fp->filename, newsize); +ksmbd_debug (SMB ,"truncated to newsize %lld\n" , newsize); rc =ksmbd_vfs_truncate (work, fp, newsize);if (rc) { -ksmbd_debug (SMB ,"truncate failed! filename : %s err %d\n" , - fp->filename, rc); +ksmbd_debug (SMB ,"truncate failed!, err %d\n" , rc);if (rc != -EAGAIN ) rc = -EBADF ;return rc;
fs/ksmbd/vfs.c +2 -4
@@ -397,8 +397,7 @@ int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count, nbytes =kernel_read (filp, rbuf, count, pos);if (nbytes <0 ) { -pr_err ("smb read failed for (%s), err = %zd\n" , - fp->filename, nbytes); +pr_err ("smb read failed, err = %zd\n" , nbytes);return nbytes; }
@@ -874,8 +873,7 @@ int ksmbd_vfs_truncate(struct ksmbd_work *work, err =vfs_truncate (&filp->f_path, size);if (err) -pr_err ("truncate failed for filename : %s err %d\n" , - fp->filename, err); +pr_err ("truncate failed, err %d\n" , err);return err; }
fs/ksmbd/vfs_cache.c +0 -1
@@ -328,7 +328,6 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp)kfree (smb_lock); } -kfree (fp->filename);if (ksmbd_stream_fd (fp))kfree (fp->stream.name);kmem_cache_free (filp_cache, fp);
fs/ksmbd/vfs_cache.h +0 -1
@@ -62,7 +62,6 @@ struct ksmbd_inode {struct ksmbd_file {struct file *filp; -char *filename;u64 persistent_id;u64 volatile_id;
Signature · 1 line
2.25.1
Sergey Senozhatsky
reviewerRe: [PATCH 2/4] ksmbd: remove filename in ksmbd_file
Quoted 35 lines · Namjae Jeon
fs/ksmbd/misc.c +25
-7-char *convert_to_nt_pathname (char *filename) +char *convert_to_nt_pathname (struct ksmbd_share_config *share, +struct path *path) { -char *ab_pathname; +char *pathname, *ab_pathname, *nt_pathname =NULL ; +int share_path_len =strlen (share->path); -if (strlen (filename) ==0 ) - filename ="\\" ; + pathname =kmalloc (PATH_MAX ,GFP_KERNEL ); +if (!pathname) +return ERR_PTR (-EACCES ); - ab_pathname =kstrdup (filename,GFP_KERNEL ); -if (!ab_pathname) -return NULL ; + ab_pathname =d_path (path, pathname,PATH_MAX ); +if (IS_ERR (ab_pathname)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + +if (strncmp (ab_pathname, share->path, share_path_len)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + + nt_pathname =kzalloc (strlen (&ab_pathname[share_path_len]) +1 ,GFP_KERNEL ); +if (!nt_pathname) { + nt_pathname =ERR_PTR (-ENOMEM ); + goto free_pathname; + } +if (ab_pathname[share_path_len] =='\0' ) +strcpy (nt_pathname,"/" );
fs/ksmbd/misc.c int parse_stream_name(char *filename, char **stream_name, int *s_type) · line 196
Quoted 10 lines
fs/ksmbd/misc.c +6
-2+strcat (nt_pathname, &ab_pathname[share_path_len]); + +ksmbd_conv_path_to_windows (nt_pathname); -ksmbd_conv_path_to_windows (ab_pathname); -return ab_pathname; +free_pathname: +kfree (pathname); +return nt_pathname; }
convert_to_nt_pathname() can return NULL
fs/ksmbd/smb2pdu.c static int get_file_all_info(struct ksmbd_work *work, · line 4397
Quoted 3 lines
fs/ksmbd/smb2pdu.c +3
-0+ filename =convert_to_nt_pathname (work->tcon->share_conf, &fp->filp->f_path); +if (IS_ERR (filename)) +return PTR_ERR (filename);
I don't think this will catch NULL nt_pathname return.
Namjae Jeon
maintainerRe: [PATCH 2/4] ksmbd: remove filename in ksmbd_file
2022-03-01 13:14 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 41 lines · Namjae Jeon
Quoted 40 lines
fs/ksmbd/misc.c +19
-7-char *convert_to_nt_pathname (char *filename) +char *convert_to_nt_pathname (struct ksmbd_share_config *share, +struct path *path) { -char *ab_pathname; +char *pathname, *ab_pathname, *nt_pathname =NULL ; +int share_path_len =strlen (share->path); -if (strlen (filename) ==0 ) - filename ="\\" ; + pathname =kmalloc (PATH_MAX ,GFP_KERNEL ); +if (!pathname) +return ERR_PTR (-EACCES ); - ab_pathname =kstrdup (filename,GFP_KERNEL ); -if (!ab_pathname) -return NULL ; + ab_pathname =d_path (path, pathname,PATH_MAX ); +if (IS_ERR (ab_pathname)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + +if (strncmp (ab_pathname, share->path, share_path_len)) { + nt_pathname =ERR_PTR (-EACCES ); + goto free_pathname; + } + + nt_pathname = kzalloc(strlen(&ab_pathname[share_path_len]) + 1,
GFP_KERNEL);fs/ksmbd/misc.c +9
-0+if (!nt_pathname) { + nt_pathname =ERR_PTR (-ENOMEM ); + goto free_pathname; + } +if (ab_pathname[share_path_len] =='\0' ) +strcpy (nt_pathname,"/" ); +strcat (nt_pathname, &ab_pathname[share_path_len]); + +ksmbd_conv_path_to_windows (nt_pathname);
Quoted 8 lines
fs/ksmbd/misc.c int parse_stream_name(char *filename, char **stream_name, int *s_type) · line 196
Quoted 6 lines
fs/ksmbd/misc.c +3
-2-ksmbd_conv_path_to_windows (ab_pathname); -return ab_pathname; +free_pathname: +kfree (pathname); +return nt_pathname; }
convert_to_nt_pathname()can return NULL
I can not find where this function return NULL.. Initializing NULL for nt_pathname is unnecessary.
Quoted 8 lines
fs/ksmbd/smb2pdu.c static int get_file_all_info(struct ksmbd_work *work, · line 4397
Quoted 5 lines
(quoted diff) +1
-0+ filename = convert_to_nt_pathname(work->tcon->share_conf,
&fp->filp->f_path);fs/ksmbd/smb2pdu.c +2
-0+if (IS_ERR (filename)) +return PTR_ERR (filename);I don't think this will catch NULL
nt_pathnamereturn.
Sergey Senozhatsky
reviewerRe: [PATCH 2/4] ksmbd: remove filename in ksmbd_file
Quoted 5 lines · Namjae Jeon
2022-03-01 13:14 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 3 lines · Namjae Jeon
convert_to_nt_pathname()can return NULLI can not find where this function return NULL..
Oh... Yes, you are right.
Quoted 1 line
Initializing NULL for
nt_pathnameis unnecessary.
Right.
Namjae Jeon
maintainerPATCH 3/4 ksmbd: increment reference count of parent fp
In reply to Namjae JeonAdd missing increment reference count of parent fp in ksmbd_lookup_fd_inode().
--- fs/ksmbd/smb2pdu.c | 2 ++ fs/ksmbd/vfs_cache.c | 1 + 2 files changed, 3 insertions(+)
fs/ksmbd/smb2pdu.c +2 -0
@@ -5764,8 +5764,10 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,if (parent_fp) {if (parent_fp->daccess &FILE_DELETE_LE ) {pr_err ("parent dir is opened with delete access\n" ); +ksmbd_fd_put (work, parent_fp);return -ESHARE ; } +ksmbd_fd_put (work, parent_fp); } next: return smb2_rename(work, fp, user_ns, rename_info,
fs/ksmbd/vfs_cache.c +1 -0
@@ -496,6 +496,7 @@ struct ksmbd_file *ksmbd_lookup_fd_inode(struct inode *inode)list_for_each_entry (lfp, &ci->m_fp_list, node) {if (inode ==file_inode (lfp->filp)) {atomic_dec (&ci->m_count); + lfp =ksmbd_fp_get (lfp);read_unlock (&ci->m_lock);return lfp; }
Signature · 1 line
2.25.1
Sergey Senozhatsky
reviewerRe: [PATCH 3/4] ksmbd: increment reference count of parent fp
fs/ksmbd/smb2pdu.c static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp, · line 5771
Quoted 13 lines · Namjae Jeon
fs/ksmbd/smb2pdu.c +2
-0@@ -5764,8 +5764,10 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,if (parent_fp) {if (parent_fp->daccess &FILE_DELETE_LE ) {pr_err ("parent dir is opened with delete access\n" ); +ksmbd_fd_put (work, parent_fp);return -ESHARE ; } +ksmbd_fd_put (work, parent_fp); }
And also in ksmbd_validate_entry_in_use()?
Quoted 17 lines
fs/ksmbd/smb2pdu.c +0
-0next: return smb2_rename(work, fp, user_ns, rename_info,fs/ksmbd/vfs_cache.c +1
-0@@ -496,6 +496,7 @@ struct ksmbd_file *ksmbd_lookup_fd_inode(struct inode *inode)list_for_each_entry (lfp, &ci->m_fp_list, node) {if (inode ==file_inode (lfp->filp)) {atomic_dec (&ci->m_count); + lfp =ksmbd_fp_get (lfp);read_unlock (&ci->m_lock);return lfp; }Signature · 1 line
2.25.1
Namjae Jeon
maintainerRe: [PATCH 3/4] ksmbd: increment reference count of parent fp
2022-03-01 13:21 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 9 lines · Namjae Jeon
Quoted 8 lines
fs/ksmbd/smb2pdu.c +0
-0@@ -5764,8 +5764,10 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp, if (parent_fp) {if (parent_fp->daccess &FILE_DELETE_LE ) {
Quoted 8 lines
fs/ksmbd/smb2pdu.c static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp, · line 5771
Quoted 6 lines
fs/ksmbd/smb2pdu.c +2
-0pr_err ("parent dir is opened with delete access\n" ); +ksmbd_fd_put (work, parent_fp);return -ESHARE ; } +ksmbd_fd_put (work, parent_fp); }And also in
ksmbd_validate_entry_in_use()?
ksmbd_validate_entry_in_use() is removed in 4/4 patch. I need to change the order of the patches to avoid confusion.
Thanks!
Quoted 20 lines
Quoted 19 lines
fs/ksmbd/smb2pdu.c +0
-0next:fs/ksmbd/smb2pdu.c +0
-0return smb2_rename(work, fp, user_ns, rename_info,fs/ksmbd/vfs_cache.c +1
-0@@ -496,6 +496,7 @@ struct ksmbd_file *ksmbd_lookup_fd_inode(struct inode *inode)list_for_each_entry (lfp, &ci->m_fp_list, node) {if (inode ==file_inode (lfp->filp)) {atomic_dec (&ci->m_count); + lfp =ksmbd_fp_get (lfp);read_unlock (&ci->m_lock);return lfp;}
--
2.25.1
Namjae Jeon
maintainerPATCH v3 4/4 ksmbd: fix racy issue from using ->d_parent and ->d_name
In reply to Namjae JeonAl pointed out that ksmbd has racy issue from using ->d_parent and ->d_name in ksmbd_vfs_unlink and smb2_vfs_rename(). add dget_parent() in ksmbd_vfs_unlink() and use take_dentry_name_snapshot() to check underlying rename for lookup. Introduce vfs_path_parent_lookup helper to avoid out of share access and export vfs functions like the following ones to use vfs_path_parent_lookup().
- __lookup_hash().
- getname_kernel() and putname().
vfs_path_parent_lookup() is used for parent lookup of destination file using absolute pathname given from FILE_RENAME_INFORMATION request.
---
v3:
- use dget_parent + take_dentry_name_snapshot() to check stability of source rename in smb2_vfs_rename().
v2:
- add filename_lock to avoid racy issue from fp->filename. (Sergey Senozhatsky)
- fix warning: variable 'old_dentry' is used uninitialized (kernel test robot)
fs/ksmbd/smb2pdu.c | 105 ++---------------- fs/ksmbd/vfs.c | 253 +++++++++++++++++++----------------------- fs/ksmbd/vfs.h | 7 +- fs/ksmbd/vfs_cache.c | 5 +- fs/namei.c | 41 ++++++- include/linux/namei.h | 4 + 6 files changed, 167 insertions(+), 248 deletions(-)
fs/ksmbd/smb2pdu.c +10 -95
@@ -5365,44 +5365,19 @@ int smb2_echo(struct ksmbd_work *work)static int smb2_rename (struct ksmbd_work *work,struct ksmbd_file *fp, -struct user_namespace *user_ns,struct smb2_file_rename_info *file_info,struct nls_table *local_nls) {struct ksmbd_share_config *share = fp->tcon->share_conf; -char *new_name =NULL , *abs_oldname =NULL , *old_name =NULL ; -char *pathname =NULL ; -struct path path; -bool file_present = true; -int rc; +char *new_name =NULL ; +int rc, flags =0 ;ksmbd_debug (SMB ,"setting FILE_RENAME_INFO\n" ); - pathname =kmalloc (PATH_MAX ,GFP_KERNEL ); -if (!pathname) -return -ENOMEM ; - - abs_oldname =d_path (&fp->filp->f_path, pathname,PATH_MAX ); -if (IS_ERR (abs_oldname)) { - rc = -EINVAL ; - goto out; - } - old_name =strrchr (abs_oldname,'/' ); -if (old_name && old_name[1 ] !='\0' ) { - old_name++; - }else { -ksmbd_debug (SMB ,"can't get last component in path %s\n" , - abs_oldname); - rc = -ENOENT ; - goto out; - } - new_name =smb2_get_name (file_info->FileName,le32_to_cpu (file_info->FileNameLength), local_nls); -if (IS_ERR (new_name)) { - rc =PTR_ERR (new_name); - goto out; - } +if (IS_ERR (new_name)) +return PTR_ERR (new_name);if (strchr (new_name,':' )) {int s_type;
@@ -5428,7 +5403,7 @@ static int smb2_rename(struct ksmbd_work *work,if (rc) goto out; - rc =ksmbd_vfs_setxattr (user_ns, + rc =ksmbd_vfs_setxattr (file_mnt_user_ns (fp->filp), fp->filp->f_path.dentry, xattr_stream_name,NULL ,0 ,0 );
@@ -5443,47 +5418,18 @@ static int smb2_rename(struct ksmbd_work *work, }ksmbd_debug (SMB ,"new name %s\n" , new_name); - rc =ksmbd_vfs_kern_path (work, new_name,LOOKUP_NO_SYMLINKS , &path,1 ); -if (rc) { -if (rc != -ENOENT ) - goto out; - file_present = false; - }else { -path_put (&path); - } -if (ksmbd_share_veto_filename (share, new_name)) { rc = -ENOENT ;ksmbd_debug (SMB ,"Can't rename vetoed file: %s\n" , new_name); goto out; } -if (file_info->ReplaceIfExists) { -if (file_present) { - rc =ksmbd_vfs_remove_file (work, new_name); -if (rc) { -if (rc != -ENOTEMPTY ) - rc = -EINVAL ; -ksmbd_debug (SMB ,"cannot delete %s, rc %d\n" , - new_name, rc); - goto out; - } - } - }else { -if (file_present && -strncmp (old_name, path.dentry->d_name.name,strlen (old_name))) { - rc = -EEXIST ; -ksmbd_debug (SMB , -"cannot rename already existing file\n" ); - goto out; - } - } +if (!file_info->ReplaceIfExists) + flags =RENAME_NOREPLACE ; - rc =ksmbd_vfs_fp_rename (work, fp, new_name); + rc =ksmbd_vfs_rename (work, &fp->filp->f_path, new_name, flags); out: -kfree (pathname); -if (!IS_ERR (new_name)) -kfree (new_name); +kfree (new_name);return rc; }
@@ -5731,12 +5677,6 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp, struct smb2_file_rename_info *rename_info, unsigned int buf_len) { -struct user_namespace *user_ns; -struct ksmbd_file *parent_fp; -struct dentry *parent; -struct dentry *dentry = fp->filp->f_path.dentry; -int ret; -if (!(fp->daccess &FILE_DELETE_LE )) {pr_err ("no right to delete : 0x%x\n" , fp->daccess);return -EACCES ;
@@ -5746,32 +5686,7 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp, le32_to_cpu(rename_info->FileNameLength)) return -EINVAL; - user_ns =file_mnt_user_ns (fp->filp); -if (ksmbd_stream_fd (fp)) - goto next; - - parent =dget_parent (dentry); - ret =ksmbd_vfs_lock_parent (user_ns, parent, dentry); -if (ret) { -dput (parent); -return ret; - } - - parent_fp =ksmbd_lookup_fd_inode (d_inode (parent)); -inode_unlock (d_inode (parent)); -dput (parent); - -if (parent_fp) { -if (parent_fp->daccess &FILE_DELETE_LE ) { -pr_err ("parent dir is opened with delete access\n" ); -ksmbd_fd_put (work, parent_fp); -return -ESHARE ; - } -ksmbd_fd_put (work, parent_fp); - } -next: -return smb2_rename (work, fp, user_ns, rename_info, - work->sess->conn->local_nls); +return smb2_rename (work, fp, rename_info, work->sess->conn->local_nls); } static int set_file_disposition_info(struct ksmbd_file *fp,
fs/ksmbd/vfs.c +114 -139
313 lines not on this page · raw message
fs/ksmbd/vfs.h +3 -4
@@ -86,8 +86,8 @@ int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name);int ksmbd_vfs_link (struct ksmbd_work *work,const char *oldname,const char *newname);int ksmbd_vfs_getattr (struct path *path,struct kstat *stat); -int ksmbd_vfs_fp_rename (struct ksmbd_work *work,struct ksmbd_file *fp, -char *newname); +int ksmbd_vfs_rename (struct ksmbd_work *work,struct path *old_path, +char *newname,int flags);int ksmbd_vfs_truncate (struct ksmbd_work *work,struct ksmbd_file *fp,loff_t size);struct srv_copychunk ;
@@ -129,8 +129,7 @@ struct file_allocated_range_buffer;int ksmbd_vfs_fqar_lseek (struct ksmbd_file *fp,loff_t start,loff_t length,struct file_allocated_range_buffer *ranges,unsigned int in_count,unsigned int *out_count); -int ksmbd_vfs_unlink (struct user_namespace *user_ns, -struct dentry *dir,struct dentry *dentry); +int ksmbd_vfs_unlink (struct file *filp);void *ksmbd_vfs_init_kstat (char **p,struct ksmbd_kstat *ksmbd_kstat); int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, struct user_namespace *user_ns,
fs/ksmbd/vfs_cache.c +1 -4
@@ -243,7 +243,6 @@ void ksmbd_release_inode_hash(void)static void __ksmbd_inode_close (struct ksmbd_file *fp) { -struct dentry *dir, *dentry;struct ksmbd_inode *ci = fp->f_ci;int err;struct file *filp;
@@ -262,11 +261,9 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp)if (atomic_dec_and_test (&ci->m_count)) {write_lock (&ci->m_lock);if (ci->m_flags & (S_DEL_ON_CLS |S_DEL_PENDING )) { - dentry = filp->f_path.dentry; - dir = dentry->d_parent; ci->m_flags &= ~(S_DEL_ON_CLS |S_DEL_PENDING );write_unlock (&ci->m_lock); -ksmbd_vfs_unlink (file_mnt_user_ns (filp), dir, dentry); +ksmbd_vfs_unlink (filp);write_lock (&ci->m_lock); }write_unlock (&ci->m_lock);
fs/namei.c +35 -6
89 lines not on this page · raw message
include/linux/namei.h +4 -0
@@ -57,12 +57,16 @@ static inline int user_path_at(int dfd, const char __user *name, unsigned flags,return user_path_at_empty (dfd, name, flags, path,NULL ); } +struct dentry *__lookup_hash (const struct qstr *name,struct dentry *base, +unsigned int flags);extern int kern_path (const char *,unsigned ,struct path *);extern struct dentry *kern_path_create (int ,const char *,struct path *,unsigned int );extern struct dentry *user_path_create (int ,const char __user *,struct path *,unsigned int );extern void done_path_create (struct path *,struct dentry *);extern struct dentry *kern_path_locked (const char *,struct path *); +int vfs_path_parent_lookup (struct filename *,unsigned int ,struct path *,\ +struct qstr *,int *,const struct path *);int vfs_path_lookup (struct dentry *,struct vfsmount *,const char *,unsigned int ,struct path *);
Signature · 1 line
2.25.1