@@ -634,31 +634,17 @@ static char *
634634smb2_get_name (struct ksmbd_share_config * share , const char * src ,
635635 const int maxlen , struct nls_table * local_nls )
636636{
637- char * name , * norm_name , * unixname ;
637+ char * name ;
638638
639639 name = smb_strndup_from_utf16 (src , maxlen , 1 , local_nls );
640640 if (IS_ERR (name )) {
641641 pr_err ("failed to get name %ld\n" , PTR_ERR (name ));
642642 return name ;
643643 }
644644
645- /* change it to absolute unix name */
646- norm_name = ksmbd_conv_path_to_unix (name );
647- if (IS_ERR (norm_name )) {
648- kfree (name );
649- return norm_name ;
650- }
651- kfree (name );
652-
653- unixname = convert_to_unix_name (share , norm_name );
654- kfree (norm_name );
655- if (!unixname ) {
656- pr_err ("can not convert absolute name\n" );
657- return ERR_PTR (- ENOMEM );
658- }
659-
660- ksmbd_debug (SMB , "absolute name = %s\n" , unixname );
661- return unixname ;
645+ ksmbd_conv_path_to_unix (name );
646+ ksmbd_strip_last_slash (name );
647+ return name ;
662648}
663649
664650int setup_async_work (struct ksmbd_work * work , void (* fn )(void * * ), void * * arg )
@@ -2352,7 +2338,7 @@ static int smb2_creat(struct ksmbd_work *work, struct path *path, char *name,
23522338 return rc ;
23532339 }
23542340
2355- rc = ksmbd_vfs_kern_path (name , 0 , path , 0 );
2341+ rc = ksmbd_vfs_kern_path (work , name , 0 , path , 0 );
23562342 if (rc ) {
23572343 pr_err ("cannot get linux path (%s), err = %d\n" ,
23582344 name , rc );
@@ -2427,7 +2413,7 @@ int smb2_open(struct ksmbd_work *work)
24272413 struct oplock_info * opinfo ;
24282414 __le32 * next_ptr = NULL ;
24292415 int req_op_level = 0 , open_flags = 0 , may_flags = 0 , file_info = 0 ;
2430- int rc = 0 , len = 0 ;
2416+ int rc = 0 ;
24312417 int contxt_cnt = 0 , query_disk_id = 0 ;
24322418 int maximal_access_ctxt = 0 , posix_ctxt = 0 ;
24332419 int s_type = 0 ;
@@ -2499,17 +2485,11 @@ int smb2_open(struct ksmbd_work *work)
24992485 goto err_out1 ;
25002486 }
25012487 } else {
2502- len = strlen (share -> path );
2503- ksmbd_debug (SMB , "share path len %d\n" , len );
2504- name = kmalloc (len + 1 , GFP_KERNEL );
2488+ name = kstrdup ("" , GFP_KERNEL );
25052489 if (!name ) {
2506- rsp -> hdr .Status = STATUS_NO_MEMORY ;
25072490 rc = - ENOMEM ;
25082491 goto err_out1 ;
25092492 }
2510-
2511- memcpy (name , share -> path , len );
2512- * (name + len ) = '\0' ;
25132493 }
25142494
25152495 req_op_level = req -> RequestedOplockLevel ;
@@ -2632,7 +2612,7 @@ int smb2_open(struct ksmbd_work *work)
26322612 goto err_out1 ;
26332613 }
26342614
2635- rc = ksmbd_vfs_kern_path (name , LOOKUP_NO_SYMLINKS , & path , 1 );
2615+ rc = ksmbd_vfs_kern_path (work , name , LOOKUP_NO_SYMLINKS , & path , 1 );
26362616 if (!rc ) {
26372617 if (req -> CreateOptions & FILE_DELETE_ON_CLOSE_LE ) {
26382618 /*
@@ -2661,11 +2641,8 @@ int smb2_open(struct ksmbd_work *work)
26612641 }
26622642
26632643 if (rc ) {
2664- if (rc == - EACCES ) {
2665- ksmbd_debug (SMB ,
2666- "User does not have right permission\n" );
2644+ if (rc != - ENOENT )
26672645 goto err_out ;
2668- }
26692646 ksmbd_debug (SMB , "can not get linux path for %s, rc = %d\n" ,
26702647 name , rc );
26712648 rc = 0 ;
@@ -3161,7 +3138,7 @@ int smb2_open(struct ksmbd_work *work)
31613138 rsp -> hdr .Status = STATUS_INVALID_PARAMETER ;
31623139 else if (rc == - EOPNOTSUPP )
31633140 rsp -> hdr .Status = STATUS_NOT_SUPPORTED ;
3164- else if (rc == - EACCES || rc == - ESTALE )
3141+ else if (rc == - EACCES || rc == - ESTALE || rc == - EXDEV )
31653142 rsp -> hdr .Status = STATUS_ACCESS_DENIED ;
31663143 else if (rc == - ENOENT )
31673144 rsp -> hdr .Status = STATUS_OBJECT_NAME_INVALID ;
@@ -4277,8 +4254,7 @@ static int get_file_all_info(struct ksmbd_work *work,
42774254 return - EACCES ;
42784255 }
42794256
4280- filename = convert_to_nt_pathname (fp -> filename ,
4281- work -> tcon -> share_conf -> path );
4257+ filename = convert_to_nt_pathname (fp -> filename );
42824258 if (!filename )
42834259 return - ENOMEM ;
42844260
@@ -4733,7 +4709,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
47334709 int rc = 0 , len ;
47344710 int fs_infoclass_size = 0 ;
47354711
4736- rc = ksmbd_vfs_kern_path (share -> path , LOOKUP_NO_SYMLINKS , & path , 0 );
4712+ rc = kern_path (share -> path , LOOKUP_NO_SYMLINKS , & path );
47374713 if (rc ) {
47384714 pr_err ("cannot create vfs path\n" );
47394715 return - EIO ;
@@ -5282,7 +5258,7 @@ static int smb2_rename(struct ksmbd_work *work,
52825258 goto out ;
52835259
52845260 len = strlen (new_name );
5285- if (new_name [len - 1 ] != '/' ) {
5261+ if (len > 0 && new_name [len - 1 ] != '/' ) {
52865262 pr_err ("not allow base filename in rename\n" );
52875263 rc = - ESHARE ;
52885264 goto out ;
@@ -5310,11 +5286,14 @@ static int smb2_rename(struct ksmbd_work *work,
53105286 }
53115287
53125288 ksmbd_debug (SMB , "new name %s\n" , new_name );
5313- rc = ksmbd_vfs_kern_path (new_name , LOOKUP_NO_SYMLINKS , & path , 1 );
5314- if (rc )
5289+ rc = ksmbd_vfs_kern_path (work , new_name , LOOKUP_NO_SYMLINKS , & path , 1 );
5290+ if (rc ) {
5291+ if (rc != - ENOENT )
5292+ goto out ;
53155293 file_present = false;
5316- else
5294+ } else {
53175295 path_put (& path );
5296+ }
53185297
53195298 if (ksmbd_share_veto_filename (share , new_name )) {
53205299 rc = - ENOENT ;
@@ -5384,11 +5363,14 @@ static int smb2_create_link(struct ksmbd_work *work,
53845363 }
53855364
53865365 ksmbd_debug (SMB , "target name is %s\n" , target_name );
5387- rc = ksmbd_vfs_kern_path (link_name , LOOKUP_NO_SYMLINKS , & path , 0 );
5388- if (rc )
5366+ rc = ksmbd_vfs_kern_path (work , link_name , LOOKUP_NO_SYMLINKS , & path , 0 );
5367+ if (rc ) {
5368+ if (rc != - ENOENT )
5369+ goto out ;
53895370 file_present = false;
5390- else
5371+ } else {
53915372 path_put (& path );
5373+ }
53925374
53935375 if (file_info -> ReplaceIfExists ) {
53945376 if (file_present ) {
@@ -5548,7 +5530,7 @@ static int set_file_allocation_info(struct ksmbd_work *work,
55485530 * inode size is retained by backup inode size.
55495531 */
55505532 size = i_size_read (inode );
5551- rc = ksmbd_vfs_truncate (work , NULL , fp , alloc_blks * 512 );
5533+ rc = ksmbd_vfs_truncate (work , fp , alloc_blks * 512 );
55525534 if (rc ) {
55535535 pr_err ("truncate failed! filename : %s, err %d\n" ,
55545536 fp -> filename , rc );
@@ -5585,7 +5567,7 @@ static int set_end_of_file_info(struct ksmbd_work *work, struct ksmbd_file *fp,
55855567 if (inode -> i_sb -> s_magic != MSDOS_SUPER_MAGIC ) {
55865568 ksmbd_debug (SMB , "filename : %s truncated to newsize %lld\n" ,
55875569 fp -> filename , newsize );
5588- rc = ksmbd_vfs_truncate (work , NULL , fp , newsize );
5570+ rc = ksmbd_vfs_truncate (work , fp , newsize );
55895571 if (rc ) {
55905572 ksmbd_debug (SMB , "truncate failed! filename : %s err %d\n" ,
55915573 fp -> filename , rc );
@@ -5862,7 +5844,7 @@ int smb2_set_info(struct ksmbd_work *work)
58625844 return 0 ;
58635845
58645846err_out :
5865- if (rc == - EACCES || rc == - EPERM )
5847+ if (rc == - EACCES || rc == - EPERM || rc == - EXDEV )
58665848 rsp -> hdr .Status = STATUS_ACCESS_DENIED ;
58675849 else if (rc == - EINVAL )
58685850 rsp -> hdr .Status = STATUS_INVALID_PARAMETER ;
0 commit comments