CIFS: Adjustments for smb2_ioctl_query_info()
Subsystems (3)
cover CIFS: Adjustments for smb2_ioctl_query_info()
From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 22:32:23 +0100
Two update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Use memdup_user() rather than duplicating its implementation Use common error handling code in smb2_ioctl_query_info()
fs/cifs/smb2ops.c | 58 ++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 31 deletions(-)
--
2.24.0
PATCH 1/2 CIFS: Use memdup_user() rather than duplicating its implementation
From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 21:30:25 +0100
Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
--- fs/cifs/smb2ops.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
fs/cifs/smb2ops.c +4 -9
@@ -1413,15 +1413,10 @@ smb2_ioctl_query_info(const unsigned int xid,if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; - buffer =kmalloc (qi.output_buffer_length,GFP_KERNEL ); -if (buffer ==NULL ) -return -ENOMEM ; - -if (copy_from_user (buffer, arg +sizeof (struct smb_query_info ), - qi.output_buffer_length)) { - rc = -EFAULT ; - goto iqinf_exit; - } + buffer =memdup_user (arg +sizeof (struct smb_query_info ), + qi.output_buffer_length); +if (IS_ERR (buffer)) +return PTR_ERR (buffer);/* Open */ memset (&open_iov,0 ,sizeof (open_iov));
--
2.24.0
PATCH 2/2 CIFS: Use common error handling code in smb2_ioctl_query_info()
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 22:26:53 +0100
Move the same error code assignments so that such exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- fs/cifs/smb2ops.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
fs/cifs/smb2ops.c +23 -22
@@ -1535,35 +1535,32 @@ smb2_ioctl_query_info(const unsigned int xid,if (le32_to_cpu (io_rsp->OutputCount) < qi.input_buffer_length) qi.input_buffer_length =le32_to_cpu (io_rsp->OutputCount);if (qi.input_buffer_length >0 && -le32_to_cpu (io_rsp->OutputOffset) + qi.input_buffer_length > rsp_iov[1 ].iov_len) { - rc = -EFAULT ; - goto iqinf_exit; - } -if (copy_to_user (&pqi->input_buffer_length, &qi.input_buffer_length, -sizeof (qi.input_buffer_length))) { - rc = -EFAULT ; - goto iqinf_exit; - } +le32_to_cpu (io_rsp->OutputOffset) + qi.input_buffer_length + > rsp_iov[1 ].iov_len) + goto e_fault; + +if (copy_to_user (&pqi->input_buffer_length, + &qi.input_buffer_length, +sizeof (qi.input_buffer_length))) + goto e_fault; +if (copy_to_user ((void __user *)pqi +sizeof (struct smb_query_info ), (const void *)io_rsp +le32_to_cpu (io_rsp->OutputOffset), - qi.input_buffer_length)) { - rc = -EFAULT ; - goto iqinf_exit; - } + qi.input_buffer_length)) + goto e_fault; }else { pqi = (struct smb_query_info __user *)arg; qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1 ].iov_base;if (le32_to_cpu (qi_rsp->OutputBufferLength) < qi.input_buffer_length) qi.input_buffer_length =le32_to_cpu (qi_rsp->OutputBufferLength); -if (copy_to_user (&pqi->input_buffer_length, &qi.input_buffer_length, -sizeof (qi.input_buffer_length))) { - rc = -EFAULT ; - goto iqinf_exit; - } -if (copy_to_user (pqi +1 , qi_rsp->Buffer, qi.input_buffer_length)) { - rc = -EFAULT ; - goto iqinf_exit; - } +if (copy_to_user (&pqi->input_buffer_length, + &qi.input_buffer_length, +sizeof (qi.input_buffer_length))) + goto e_fault; + +if (copy_to_user (pqi +1 , qi_rsp->Buffer, + qi.input_buffer_length)) + goto e_fault; } iqinf_exit:
@@ -1579,6 +1576,10 @@ smb2_ioctl_query_info(const unsigned int xid,free_rsp_buf (resp_buftype[1 ], rsp_iov[1 ].iov_base);free_rsp_buf (resp_buftype[2 ], rsp_iov[2 ].iov_base);return rc; + +e_fault: + rc = -EFAULT ; + goto iqinf_exit; } static ssize_t
--
2.24.0
Steve French
Appliedmerged into cifs-2.6.git for-next
Quoted 17 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 22:32:23 +0100Two update suggestions were taken into account
from static source code analysis.Markus Elfring (2):
Usememdup_user()rather than duplicating its implementation Use common error handling code insmb2_ioctl_query_info()fs/cifs/smb2ops.c | 58 ++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 31 deletions(-)--
2.24.0
Signature · 3 lines
Thanks, Steve
Quoted 1 line
merged into cifs-2.6.git for-next
Thanks for your positive feedback.
How are the chances to take another look at any more update suggestions also from my selection of change possibilities?
https://lkml.org/lkml/2017/8/20/104
Regards,
Markus