smb: client: fix OOB read due to invalid data_offset in CIFSSMBQAllEAs
Subsystems (2)
PATCH 1/1 smb: client: fix OOB read due to invalid data_offset in CIFSSMBQAllEAs
Due to insufficient validation of the server-supplied DataOffset, an invalid DataOffset could lead to OOB read of kernel memory.
Fix this by verifying that the DataOffset is at least long enough to cover the mandatory portion of the response header, but also leaves sufficient bytes to contain the response data.
--- fs/smb/client/cifssmb.c | 21 ++++++++++++++++++++- fs/smb/client/trace.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-)
fs/smb/client/cifssmb.c +20 -1
@@ -6286,9 +6286,28 @@ CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon,/* check that each element of each entry does not go beyond end of list */ /* validate_trans2_offsets() */ -/* BB check if start of smb + data_offset > &bcc+ bcc */ data_offset =le16_to_cpu (pSMBr->t2.DataOffset); +if (data_offset <offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset)) { +cifs_dbg (VFS ,"data_offset %u out of range [%zu, %zu]\n" , + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset), + (size_t )bytes_returned -sizeof (struct fealist )); + rc =smb_EIO2 (smb_eio_trace_qalleas_invalid_data_offset, + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset)); + goto QAllEAsOut; + }else if ((size_t )data_offset +sizeof (struct fealist ) > + (size_t )bytes_returned) { +cifs_dbg (VFS ,"data_offset %u out of range [%zu, %zu]\n" , + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset), + (size_t )bytes_returned -sizeof (struct fealist )); + rc =smb_EIO2 (smb_eio_trace_qalleas_invalid_data_offset, + (size_t )data_offset +sizeof (struct fealist ), + bytes_returned); + goto QAllEAsOut; + } ea_response_data = (struct fealist *) (((char *) &pSMBr->hdr.Protocol) + data_offset);
fs/smb/client/trace.h +1 -0
@@ -67,6 +67,7 @@ EM(smb_eio_trace_pend_del_fail, "pend_del_fail") \ EM(smb_eio_trace_qalleas_bcc_too_small, "qalleas_bcc_too_small") \ EM(smb_eio_trace_qalleas_ea_overlong, "qalleas_ea_overlong") \ + EM(smb_eio_trace_qalleas_invalid_data_offset, "qalleas_invalid_data_offset") \ EM(smb_eio_trace_qalleas_overlong, "qalleas_overlong") \ EM(smb_eio_trace_qfileinfo_bcc_too_small, "qfileinfo_bcc_too_small") \EM (smb_eio_trace_qfileinfo_invalid,"qfileinfo_invalid" ) \
Signature · 1 line
2.55.0
Sashiko is correct in both cases. I will need to fix up both of Sahiko's findings.
Frank
Quoted 59 lines · Frank Sorenson
Due to insufficient validation of the server-supplied DataOffset, an invalid DataOffset could lead to OOB read of kernel memory.
Fix this by verifying that the DataOffset is at least long enough to cover the mandatory portion of the response header, but also leaves sufficient bytes to contain the response data.
Signed-off-by Frank Sorenson <[email protected]>--- fs/smb/client/cifssmb.c | 21 ++++++++++++++++++++- fs/smb/client/trace.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-)fs/smb/client/cifssmb.c +20
-1@@ -6286,9 +6286,28 @@ CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon,/* check that each element of each entry does not go beyond end of list */ /* validate_trans2_offsets() */ -/* BB check if start of smb + data_offset > &bcc+ bcc */ data_offset =le16_to_cpu (pSMBr->t2.DataOffset); +if (data_offset <offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset)) { +cifs_dbg (VFS ,"data_offset %u out of range [%zu, %zu]\n" , + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset), + (size_t )bytes_returned -sizeof (struct fealist )); + rc =smb_EIO2 (smb_eio_trace_qalleas_invalid_data_offset, + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset)); + goto QAllEAsOut; + }else if ((size_t )data_offset +sizeof (struct fealist ) > + (size_t )bytes_returned) { +cifs_dbg (VFS ,"data_offset %u out of range [%zu, %zu]\n" , + data_offset, +offsetofend (TRANSACTION2_QPI_RSP , t2.DataOffset), + (size_t )bytes_returned -sizeof (struct fealist )); + rc =smb_EIO2 (smb_eio_trace_qalleas_invalid_data_offset, + (size_t )data_offset +sizeof (struct fealist ), + bytes_returned); + goto QAllEAsOut; + } ea_response_data = (struct fealist *) (((char *) &pSMBr->hdr.Protocol) + data_offset);fs/smb/client/trace.h +1
-0@@ -67,6 +67,7 @@ EM(smb_eio_trace_pend_del_fail, "pend_del_fail") \ EM(smb_eio_trace_qalleas_bcc_too_small, "qalleas_bcc_too_small") \ EM(smb_eio_trace_qalleas_ea_overlong, "qalleas_ea_overlong") \ + EM(smb_eio_trace_qalleas_invalid_data_offset, "qalleas_invalid_data_offset") \ EM(smb_eio_trace_qalleas_overlong, "qalleas_overlong") \ EM(smb_eio_trace_qfileinfo_bcc_too_small, "qfileinfo_bcc_too_small") \EM (smb_eio_trace_qfileinfo_invalid,"qfileinfo_invalid" ) \
Signature · 4 lines
Frank Sorenson [email protected] Principal Software Maintenance Engineer, filesystems Red Hat