ksmbd: smbd: validate buffer descriptor structures
Subsystems (2)
PATCH 1/1 ksmbd: smbd: validate buffer descriptor structures
Check ChannelInfoOffset and ChannelInfoLength
to validate buffer descriptor structures.
And add a debug log to print the structures'
content.
--- fs/ksmbd/smb2pdu.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
fs/ksmbd/smb2pdu.c +25 -6
@@ -6130,12 +6130,20 @@ static int smb2_set_remote_key_for_rdma(struct ksmbd_work *work, __le16 ChannelInfoOffset, __le16 ChannelInfoLength) { +unsigned int i, ch_count; +if (work->conn->dialect ==SMB30_PROT_ID && Channel !=SMB2_CHANNEL_RDMA_V1 )return -EINVAL ; -if (ChannelInfoOffset ==0 || -le16_to_cpu (ChannelInfoLength) <sizeof (*desc)) + ch_count =le16_to_cpu (ChannelInfoLength) /sizeof (*desc); +for (i =0 ; i < ch_count; i++) { +ksmbd_debug (RDMA ,"RDMA r/w request %#x: token %#x, length %#x\n" , + i, +le32_to_cpu (desc[i].token), +le32_to_cpu (desc[i].length)); + } +if (ch_count !=1 )return -EINVAL ; work->need_invalidate_rkey =
@@ -6189,9 +6197,15 @@ int smb2_read(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE || req->Channel ==SMB2_CHANNEL_RDMA_V1 ) { +unsigned int ch_offset =le16_to_cpu (req->ReadChannelInfoOffset); + +if (ch_offset < offsetof(struct smb2_read_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->ReadChannelInfoOffset, req->ReadChannelInfoLength);
@@ -6432,11 +6446,16 @@ int smb2_write(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1 || req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE ) { -if (req->Length !=0 || req->DataOffset !=0 ) -return -EINVAL ; +unsigned int ch_offset =le16_to_cpu (req->WriteChannelInfoOffset); + +if (req->Length !=0 || req->DataOffset !=0 || + ch_offset < offsetof(struct smb2_write_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->WriteChannelInfoOffset, req->WriteChannelInfoLength);
Signature · 1 line
2.25.1
Namjae Jeon
maintainer2022-01-20 0:01 GMT+09:00, Hyunchul Lee <[email protected]>:
Quoted 19 lines
Check ChannelInfoOffset and ChannelInfoLength
to validate buffer descriptor structures.
And add a debug log to print the structures'
content.Signed-off-by Hyunchul Lee <[email protected]>--- fs/ksmbd/smb2pdu.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)fs/ksmbd/smb2pdu.c +0
-0@@ -6130,12 +6130,20 @@ static int smb2_set_remote_key_for_rdma(structksmbd_work *work, __le16 ChannelInfoOffset, __le16 ChannelInfoLength) {
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct · line 6141
Quoted 10 lines
fs/ksmbd/smb2pdu.c +4
-2+unsigned int i, ch_count; +if (work->conn->dialect ==SMB30_PROT_ID && Channel !=SMB2_CHANNEL_RDMA_V1 )return -EINVAL ; -if (ChannelInfoOffset ==0 || -le16_to_cpu (ChannelInfoLength) <sizeof (*desc)) + ch_count =le16_to_cpu (ChannelInfoLength) /sizeof (*desc); +for (i =0 ; i < ch_count; i++) {
unneeded loop is executed on non-debug mode. I think that this loop is covered with rdma debug.
Please check this :
if (ksmbd_debug_types & KSMBD_DEBUG_RDMA) { }
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct ksmbd_work *work, · line 6146
Quoted 6 lines
fs/ksmbd/smb2pdu.c +6
-0+ksmbd_debug (RDMA ,"RDMA r/w request %#x: token %#x, length %#x\n" , + i, +le32_to_cpu (desc[i].token), +le32_to_cpu (desc[i].length)); + } +if (ch_count !=1 )
Need to add error print that ksmbd doesn't support multiple buffer desc yet.
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct · line 6148
Quoted 1 line
fs/ksmbd/smb2pdu.c +0
-0return -EINVAL ;
And multiple buffer desc support is required for a fundamental solution, but it is expected that it will take a very long time for you to implement it. Is that right? If so, first, find a way to set the optimal read/write size so that the client send a single buffer desc to ksmbd.
Quoted 43 lines
fs/ksmbd/smb2pdu.c +15
-5work->need_invalidate_rkey =@@ -6189,9 +6197,15 @@ int smb2_read(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE || req->Channel ==SMB2_CHANNEL_RDMA_V1 ) { +unsigned int ch_offset =le16_to_cpu (req->ReadChannelInfoOffset); + +if (ch_offset < offsetof(struct smb2_read_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->ReadChannelInfoOffset, req->ReadChannelInfoLength);@@ -6432,11 +6446,16 @@ int smb2_write(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1 || req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE ) { -if (req->Length !=0 || req->DataOffset !=0 ) -return -EINVAL ; +unsigned int ch_offset =le16_to_cpu (req->WriteChannelInfoOffset); + +if (req->Length !=0 || req->DataOffset !=0 || + ch_offset < offsetof(struct smb2_write_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->WriteChannelInfoOffset, req->WriteChannelInfoLength); --2.25.1
2022년 1월 20일 (목) 오전 11:56, Namjae Jeon <[email protected]>님이 작성:
Quoted 27 lines
2022-01-20 0:01 GMT+09:00, Hyunchul Lee <[email protected]>:
Quoted 25 lines
Check ChannelInfoOffset and ChannelInfoLength
to validate buffer descriptor structures.
And add a debug log to print the structures'
content.Signed-off-by Hyunchul Lee <[email protected]>--- fs/ksmbd/smb2pdu.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)fs/ksmbd/smb2pdu.c +2
-0@@ -6130,12 +6130,20 @@ static int smb2_set_remote_key_for_rdma(structksmbd_work *work, __le16 ChannelInfoOffset, __le16 ChannelInfoLength) { + unsigned int i, ch_count; +if (work->conn->dialect ==SMB30_PROT_ID && Channel !=SMB2_CHANNEL_RDMA_V1 )return -EINVAL ;
Quoted 9 lines
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct ksmbd_work *work, · line 6140
Quoted 4 lines
fs/ksmbd/smb2pdu.c +2
-2-if (ChannelInfoOffset ==0 || -le16_to_cpu (ChannelInfoLength) <sizeof (*desc)) + ch_count =le16_to_cpu (ChannelInfoLength) /sizeof (*desc); +for (i =0 ; i < ch_count; i++) {unneeded loop is executed on non-debug mode. I think that this loop is covered with rdma debug.
Please check this :
if (ksmbd_debug_types&KSMBD_DEBUG_RDMA) { }
Okay, I will change it.
Quoted 7 lines
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct ksmbd_work *work, · line 6146
Quoted 6 lines
fs/ksmbd/smb2pdu.c +6
-0+ksmbd_debug (RDMA ,"RDMA r/w request %#x: token %#x, length %#x\n" , + i, +le32_to_cpu (desc[i].token), +le32_to_cpu (desc[i].length)); + } +if (ch_count !=1 )Need to add error print that ksmbd doesn't support multiple buffer desc yet.
Okay, I will apply this.
Quoted 5 lines
fs/ksmbd/smb2pdu.c static int smb2_set_remote_key_for_rdma(struct · line 6148
Quoted 1 line
fs/ksmbd/smb2pdu.c +0
-0return -EINVAL ;And multiple buffer desc support is required for a fundamental solution, but it is expected that it will take a very long time for you to implement it. Is that right? If so, first, find a way to set
I will re-start implementing it and complete it by next week or the middle of February.
Quoted 2 lines
the optimal read/write size so that the client send a single buffer desc to ksmbd.
I thought about it, but there seems to be no solution because it is caused by a client device's limitation.
Quoted 43 lines
Quoted 43 lines
fs/ksmbd/smb2pdu.c +15
-5work->need_invalidate_rkey =@@ -6189,9 +6197,15 @@ int smb2_read(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE || req->Channel ==SMB2_CHANNEL_RDMA_V1 ) { +unsigned int ch_offset =le16_to_cpu (req->ReadChannelInfoOffset); + +if (ch_offset < offsetof(struct smb2_read_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->ReadChannelInfoOffset, req->ReadChannelInfoLength);@@ -6432,11 +6446,16 @@ int smb2_write(struct ksmbd_work *work)if (req->Channel ==SMB2_CHANNEL_RDMA_V1 || req->Channel ==SMB2_CHANNEL_RDMA_V1_INVALIDATE ) { -if (req->Length !=0 || req->DataOffset !=0 ) -return -EINVAL ; +unsigned int ch_offset =le16_to_cpu (req->WriteChannelInfoOffset); + +if (req->Length !=0 || req->DataOffset !=0 || + ch_offset < offsetof(struct smb2_write_req , Buffer)) { + err = -EINVAL ; + goto out; + } err =smb2_set_remote_key_for_rdma (work, (struct smb2_buffer_desc_v1 *) - &req->Buffer[0 ], + ((char *)req + ch_offset), req->Channel, req->WriteChannelInfoOffset, req->WriteChannelInfoLength); --2.25.1
Signature · 2 lines
Thanks, Hyunchul