ksmbd: add support for read compound
Subsystems (2)
Namjae Jeon
maintainerPATCH v2 1/1 ksmbd: add support for read compound
MacOS sends a compound request including read to the server (e.g. open-read-close). So far, ksmbd has not handled read as a compound request. For compatibility between ksmbd and an OS that supports SMB, This patch provides compound support for read requests.
Signed-off-by Namjae Jeon <[email protected]>
Signed-off-by Steve French <[email protected]>
---
v2:
fix the warnings from Coverity Scan. (memleak, unused value,
uninitialized variable, checked return)
fs/smb/server/auth.c | 6 +- fs/smb/server/connection.c | 54 +--- fs/smb/server/connection.h | 2 +- fs/smb/server/ksmbd_work.c | 90 ++++++- fs/smb/server/ksmbd_work.h | 34 ++- fs/smb/server/oplock.c | 17 +- fs/smb/server/server.c | 5 +- fs/smb/server/smb2pdu.c | 501 ++++++++++++++++--------------------- fs/smb/server/smb_common.c | 13 +- fs/smb/server/vfs.c | 4 +- fs/smb/server/vfs.h | 4 +- 11 files changed, 366 insertions(+), 364 deletions(-)
fs/smb/server/auth.c +5 -1
@@ -1029,11 +1029,15 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec, {struct scatterlist *sg;unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -20 ; -int i, nr_entries[3 ] = {0 }, total_entries =0 , sg_idx =0 ; +int i, *nr_entries, total_entries =0 , sg_idx =0 ;if (!nvec)return NULL ; + nr_entries =kcalloc (nvec,sizeof (int ),GFP_KERNEL ); +if (!nr_entries) +return NULL ; +for (i =0 ; i < nvec -1 ; i++) {unsigned long kaddr = (unsigned long )iov[i +1 ].iov_base;
fs/smb/server/connection.c +13 -41
82 lines not on this page · raw message
fs/smb/server/connection.h +1 -1
@@ -158,7 +158,7 @@ int ksmbd_conn_rdma_write(struct ksmbd_conn *conn,struct smb2_buffer_desc_v1 *desc, unsigned int desc_len);void ksmbd_conn_enqueue_request (struct ksmbd_work *work); -int ksmbd_conn_try_dequeue_request (struct ksmbd_work *work); +void ksmbd_conn_try_dequeue_request (struct ksmbd_work *work);void ksmbd_conn_init_server_callbacks (struct ksmbd_conn_ops *ops);int ksmbd_conn_handler_loop (void *p);int ksmbd_conn_transport_init (void );
fs/smb/server/ksmbd_work.c +89 -1
110 lines not on this page · raw message
fs/smb/server/ksmbd_work.h +26 -8
@@ -19,6 +19,11 @@ enum { KSMBD_WORK_CLOSED, }; +struct aux_read { +void *buf; +struct list_head entry; +}; +/* one of these for every pending CIFS request at the connection */ struct ksmbd_work {/* Server corresponding to this mid */
@@ -31,13 +36,19 @@ struct ksmbd_work {/* Response buffer */ void *response_buf; -/* Read data buffer */ -void *aux_payload_buf; +struct list_head aux_read_list; + +struct kvec *iov; +int iov_alloc_cnt; +int iov_cnt; +int iov_idx;/* Next cmd hdr in compound req buf*/ int next_smb2_rcv_hdr_off;/* Next cmd hdr in compound rsp buf*/ int next_smb2_rsp_hdr_off; +/* Current cmd hdr in compound rsp buf*/ +int curr_smb2_rsp_hdr_off;/* * Current Local FID assigned compound response if SMB2 CREATE
@@ -53,16 +64,11 @@ struct ksmbd_work {unsigned int credits_granted;/* response smb header size */ -unsigned int resp_hdr_sz;unsigned int response_sz; -/* Read data count */ -unsigned int aux_payload_sz;void *tr_buf;unsigned char state; -/* Multiple responses for one request e.g. SMB ECHO */ - bool multiRsp:1;/* No response for cancelled request */ bool send_no_response:1;/* Request is encrypted */
@@ -95,6 +101,15 @@ static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)return work->response_buf + work->next_smb2_rsp_hdr_off +4 ; } +/** +* ksmbd_resp_buf_curr - Get current buffer on compound response. +* @work: smb work containing response buffer +*/ +static inline void *ksmbd_resp_buf_curr (struct ksmbd_work *work) +{ +return work->response_buf + work->curr_smb2_rsp_hdr_off +4 ; +} +/** * ksmbd_req_buf_next - Get next buffer on compound request. * @work: smb work containing response buffer
@@ -113,5 +128,8 @@ int ksmbd_work_pool_init(void);int ksmbd_workqueue_init (void );void ksmbd_workqueue_destroy (void );bool ksmbd_queue_work (struct ksmbd_work *work); - +int ksmbd_iov_pin_rsp_read (struct ksmbd_work *work,void *ib,int len, +void *aux_buf,unsigned int aux_size); +int ksmbd_iov_pin_rsp (struct ksmbd_work *work,void *ib,int len); +void ksmbd_iov_reset (struct ksmbd_work *work);#endif /* __KSMBD_WORK_H__ */
fs/smb/server/oplock.c +8 -9
@@ -639,7 +639,6 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) {struct smb2_oplock_break *rsp =NULL ; struct ksmbd_work *work = container_of(wk, struct ksmbd_work, work); -struct ksmbd_conn *conn = work->conn;struct oplock_break_info *br_info = work->request_buf;struct smb2_hdr *rsp_hdr;struct ksmbd_file *fp;
@@ -656,8 +655,6 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp_hdr =smb2_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); - *(__be32 *)work->response_buf = -cpu_to_be32 (conn->vals->header_size); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 );
@@ -684,13 +681,15 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp->PersistentFid = fp->persistent_id; rsp->VolatileFid = fp->volatile_id; -inc_rfc1001_len (work->response_buf,24 ); +ksmbd_fd_put (work, fp); +if (ksmbd_iov_pin_rsp (work, (void *)rsp, +sizeof (struct smb2_oplock_break ))) + goto out;ksmbd_debug (OPLOCK ,"sending oplock break v_id %llu p_id = %llu lock level = %d\n" , rsp->VolatileFid, rsp->PersistentFid, rsp->OplockLevel); -ksmbd_fd_put (work, fp);ksmbd_conn_write (work); out:
@@ -751,7 +750,6 @@ static void __smb2_lease_break_noti(struct work_struct *wk)struct smb2_lease_break *rsp =NULL ; struct ksmbd_work *work = container_of(wk, struct ksmbd_work, work);struct lease_break_info *br_info = work->request_buf; -struct ksmbd_conn *conn = work->conn;struct smb2_hdr *rsp_hdr;if (allocate_oplock_break_buf (work)) {
@@ -761,8 +759,6 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp_hdr =smb2_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); - *(__be32 *)work->response_buf = -cpu_to_be32 (conn->vals->header_size); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 );
@@ -791,7 +787,9 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp->AccessMaskHint =0 ; rsp->ShareMaskHint =0 ; -inc_rfc1001_len (work->response_buf,44 ); +if (ksmbd_iov_pin_rsp (work, (void *)rsp, +sizeof (struct smb2_lease_break ))) + goto out;ksmbd_conn_write (work);
@@ -845,6 +843,7 @@ static int smb2_lease_break_noti(struct oplock_info *opinfo)setup_async_work (in_work,NULL ,NULL );smb2_send_interim_resp (in_work,STATUS_PENDING );list_del (&in_work->interim_entry); +ksmbd_iov_reset (in_work); }INIT_WORK (&work->work, __smb2_lease_break_noti);ksmbd_queue_work (work);
fs/smb/server/server.c +4 -1
@@ -163,6 +163,7 @@ static void __handle_ksmbd_work(struct ksmbd_work *work, {u16 command =0 ;int rc; +bool is_chained = false;if (conn->ops->allocate_rsp_buf (work))return ;
@@ -229,11 +230,13 @@ static void __handle_ksmbd_work(struct ksmbd_work *work, } } + is_chained =is_chained_smb2_message (work); +if (work->sess && (work->sess->sign ||smb3_11_final_sess_setup_resp (work) || conn->ops->is_sign_req (work, command))) conn->ops->set_sign_rsp (work); - }while (is_chained_smb2_message (work)); + }while (is_chained == true);if (work->send_no_response)return ;
fs/smb/server/smb2pdu.c +212 -289
1,258 lines not on this page · raw message
fs/smb/server/smb_common.c +4 -9
@@ -319,12 +319,6 @@ static int init_smb1_rsp_hdr(struct ksmbd_work *work)struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf;struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; -/* -* Remove 4 byte direct TCP header. -*/ - *(__be32 *)work->response_buf = -cpu_to_be32 (sizeof (struct smb_hdr ) -4 ); - rsp_hdr->Command =SMB_COM_NEGOTIATE ; *(__le32 *)rsp_hdr->Protocol =SMB1_PROTO_NUMBER ; rsp_hdr->Flags =SMBFLG_RESPONSE ;
@@ -560,10 +554,11 @@ static int smb_handle_negotiate(struct ksmbd_work *work)ksmbd_debug (SMB ,"Unsupported SMB1 protocol\n" ); -/* Add 2 byte bcc and 2 byte DialectIndex. */ -inc_rfc1001_len (work->response_buf,4 ); - neg_rsp->hdr.Status.CifsError =STATUS_SUCCESS ; +if (ksmbd_iov_pin_rsp (work, (void *)neg_rsp, +sizeof (struct smb_negotiate_rsp ) -4 )) +return -ENOMEM ; + neg_rsp->hdr.Status.CifsError =STATUS_SUCCESS ; neg_rsp->hdr.WordCount =1 ; neg_rsp->DialectIndex =cpu_to_le16 (work->conn->dialect); neg_rsp->ByteCount =0 ;
fs/smb/server/vfs.c +2 -2
@@ -367,15 +367,15 @@ static int check_lock_range(struct file *filp, loff_t start, loff_t end,* @fid: file id of open file * @count: read byte count * @pos: file pos +* @rbuf: read data buffer * * Return: number of read bytes on success, otherwise error */ int ksmbd_vfs_read (struct ksmbd_work *work,struct ksmbd_file *fp,size_t count, -loff_t *pos) +loff_t *pos,char *rbuf) {struct file *filp = fp->filp;ssize_t nbytes =0 ; -char *rbuf = work->aux_payload_buf;struct inode *inode =file_inode (filp);if (S_ISDIR (inode->i_mode))
fs/smb/server/vfs.h +2 -2
@@ -76,8 +76,8 @@ void ksmbd_vfs_query_maximal_access(struct mnt_idmap *idmap, struct dentry *dentry, __le32 *daccess);int ksmbd_vfs_create (struct ksmbd_work *work,const char *name,umode_t mode);int ksmbd_vfs_mkdir (struct ksmbd_work *work,const char *name,umode_t mode); -int ksmbd_vfs_read (struct ksmbd_work *work,struct ksmbd_file *fp, -size_t count,loff_t *pos); +int ksmbd_vfs_read (struct ksmbd_work *work,struct ksmbd_file *fp,size_t count, +loff_t *pos,char *rbuf);int ksmbd_vfs_write (struct ksmbd_work *work,struct ksmbd_file *fp,char *buf,size_t count,loff_t *pos,bool sync,ssize_t *written);
Signature · 1 line
2.25.1