@@ -1335,8 +1335,7 @@ static int ntlm_negotiate(struct ksmbd_work *work,
13351335 return rc ;
13361336
13371337 sz = le16_to_cpu (rsp -> SecurityBufferOffset );
1338- chgblob =
1339- (struct challenge_message * )((char * )& rsp -> hdr .ProtocolId + sz );
1338+ chgblob = (struct challenge_message * )rsp -> Buffer ;
13401339 memset (chgblob , 0 , sizeof (struct challenge_message ));
13411340
13421341 if (!work -> conn -> use_spnego ) {
@@ -1369,9 +1368,7 @@ static int ntlm_negotiate(struct ksmbd_work *work,
13691368 goto out ;
13701369 }
13711370
1372- sz = le16_to_cpu (rsp -> SecurityBufferOffset );
1373- unsafe_memcpy ((char * )& rsp -> hdr .ProtocolId + sz , spnego_blob , spnego_blob_len ,
1374- /* alloc is larger than blob, see smb2_allocate_rsp_buf() */ );
1371+ memcpy (rsp -> Buffer , spnego_blob , spnego_blob_len );
13751372 rsp -> SecurityBufferLength = cpu_to_le16 (spnego_blob_len );
13761373
13771374out :
@@ -1453,10 +1450,7 @@ static int ntlm_authenticate(struct ksmbd_work *work,
14531450 if (rc )
14541451 return - ENOMEM ;
14551452
1456- sz = le16_to_cpu (rsp -> SecurityBufferOffset );
1457- unsafe_memcpy ((char * )& rsp -> hdr .ProtocolId + sz , spnego_blob ,
1458- spnego_blob_len ,
1459- /* alloc is larger than blob, see smb2_allocate_rsp_buf() */ );
1453+ memcpy (rsp -> Buffer , spnego_blob , spnego_blob_len );
14601454 rsp -> SecurityBufferLength = cpu_to_le16 (spnego_blob_len );
14611455 kfree (spnego_blob );
14621456 }
@@ -2058,18 +2052,20 @@ int smb2_tree_connect(struct ksmbd_work *work)
20582052 * @access: file access flags
20592053 * @disposition: file disposition flags
20602054 * @may_flags: set with MAY_ flags
2061- * @is_dir: is creating open flags for directory
2055+ * @coptions: file creation options
2056+ * @mode: file mode
20622057 *
20632058 * Return: file open flags
20642059 */
20652060static int smb2_create_open_flags (bool file_present , __le32 access ,
20662061 __le32 disposition ,
20672062 int * may_flags ,
2068- bool is_dir )
2063+ __le32 coptions ,
2064+ umode_t mode )
20692065{
20702066 int oflags = O_NONBLOCK | O_LARGEFILE ;
20712067
2072- if (is_dir ) {
2068+ if (coptions & FILE_DIRECTORY_FILE_LE || S_ISDIR ( mode ) ) {
20732069 access &= ~FILE_WRITE_DESIRE_ACCESS_LE ;
20742070 ksmbd_debug (SMB , "Discard write access to a directory\n" );
20752071 }
@@ -2086,7 +2082,7 @@ static int smb2_create_open_flags(bool file_present, __le32 access,
20862082 * may_flags = MAY_OPEN | MAY_READ ;
20872083 }
20882084
2089- if (access == FILE_READ_ATTRIBUTES_LE )
2085+ if (access == FILE_READ_ATTRIBUTES_LE || S_ISBLK ( mode ) || S_ISCHR ( mode ) )
20902086 oflags |= O_PATH ;
20912087
20922088 if (file_present ) {
@@ -3181,8 +3177,8 @@ int smb2_open(struct ksmbd_work *work)
31813177 open_flags = smb2_create_open_flags (file_present , daccess ,
31823178 req -> CreateDisposition ,
31833179 & may_flags ,
3184- req -> CreateOptions & FILE_DIRECTORY_FILE_LE ||
3185- ( file_present && S_ISDIR ( d_inode (path .dentry )-> i_mode )) );
3180+ req -> CreateOptions ,
3181+ file_present ? d_inode (path .dentry )-> i_mode : 0 );
31863182
31873183 if (!test_tree_conn_flag (tcon , KSMBD_TREE_CONN_FLAG_WRITABLE )) {
31883184 if (open_flags & (O_CREAT | O_TRUNC )) {
@@ -3531,8 +3527,9 @@ int smb2_open(struct ksmbd_work *work)
35313527 memcpy (fp -> create_guid , dh_info .CreateGuid ,
35323528 SMB2_CREATE_GUID_SIZE );
35333529 if (dh_info .timeout )
3534- fp -> durable_timeout = min (dh_info .timeout ,
3535- DURABLE_HANDLE_MAX_TIMEOUT );
3530+ fp -> durable_timeout =
3531+ min_t (unsigned int , dh_info .timeout ,
3532+ DURABLE_HANDLE_MAX_TIMEOUT );
35363533 else
35373534 fp -> durable_timeout = 60 ;
35383535 }
@@ -4586,7 +4583,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
45864583 path = & fp -> filp -> f_path ;
45874584 /* single EA entry is requested with given user.* name */
45884585 if (req -> InputBufferLength ) {
4589- if (le32_to_cpu (req -> InputBufferLength ) <
4586+ if (le32_to_cpu (req -> InputBufferLength ) <=
45904587 sizeof (struct smb2_ea_info_req ))
45914588 return - EINVAL ;
45924589
@@ -8090,7 +8087,7 @@ int smb2_ioctl(struct ksmbd_work *work)
80908087 goto out ;
80918088 }
80928089
8093- if (in_buf_len < sizeof (struct copychunk_ioctl_req )) {
8090+ if (in_buf_len <= sizeof (struct copychunk_ioctl_req )) {
80948091 ret = - EINVAL ;
80958092 goto out ;
80968093 }
0 commit comments