cifs: fix bi-directional fsctl passthrough calls
Subsystems (2)
PATCH 1/1 cifs: fix bi-directional fsctl passthrough calls
SMB2 Ioctl responses from servers may respond with both the request blob from the client followed by the actual reply blob for ioctls that are bi-directional.
In that case we can not assume that the reply blob comes immediately after the ioctl response structure.
This fixes FSCTLs such as SMB2:FSCTL_QUERY_ALLOCATED_RANGES
--- fs/cifs/smb2ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/smb2ops.c +3 -1
@@ -1467,7 +1467,9 @@ smb2_ioctl_query_info(const unsigned int xid, rc = -EFAULT ; goto iqinf_exit; } -if (copy_to_user (pqi +1 , &io_rsp[1 ], qi.input_buffer_length)) { +if (copy_to_user ((char *)pqi +sizeof (struct smb_query_info ), + (char *)io_rsp +le32_to_cpu (io_rsp->OutputOffset), + qi.input_buffer_length)) { rc = -EFAULT ; goto iqinf_exit; }
Signature · 1 line
2.13.6
Quoted 29 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Ronnie Sahlberg
Sent: Thursday, April 11, 2019 11:06 PM
To: linux-cifs <[email protected]>
Cc: Steve French <[email protected]>; Ronnie Sahlberg <[email protected]>
Subject: [PATCH] cifs: fix bi-directional fsctl passthrough callsSMB2 Ioctl responses from servers may respond with both the request blob from
the client followed by the actual reply blob for ioctls that are bi-directional.In that case we can not assume that the reply blob comes immediately after the
ioctl response structure.This fixes FSCTLs such as SMB2:FSCTL_QUERY_ALLOCATED_RANGES
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/cifs/smb2ops.c +0
-0
fs/cifs/smb2ops.c smb2_ioctl_query_info(const unsigned int xid, · line 1473
Quoted 8 lines
fs/cifs/smb2ops.c +3
-1@@ -1467,7 +1467,9 @@ smb2_ioctl_query_info(const unsigned int xid, rc = -EFAULT ; goto iqinf_exit; } -if (copy_to_user (pqi +1 , &io_rsp[1 ], qi.input_buffer_length)) { +if (copy_to_user ((char *)pqi +sizeof (struct smb_query_info ), + (char *)io_rsp +le32_to_cpu (io_rsp- >OutputOffset), + qi.input_buffer_length)) {
Shouldn't this validate that OutputOffset, for a length of input_buffer_length, falls completely within the bounds of the response, before copying?
Quoted 5 lines
fs/cifs/smb2ops.c +0
-0rc = -EFAULT ; goto iqinf_exit;}
--
2.13.6
ronnie sahlberg
reviewerQuoted 36 lines · Tom Talpey
Quoted 36 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Ronnie Sahlberg
Sent: Thursday, April 11, 2019 11:06 PM
To: linux-cifs <[email protected]>
Cc: Steve French <[email protected]>; Ronnie Sahlberg <[email protected]>
Subject: [PATCH] cifs: fix bi-directional fsctl passthrough callsSMB2 Ioctl responses from servers may respond with both the request blob from
the client followed by the actual reply blob for ioctls that are bi-directional.In that case we can not assume that the reply blob comes immediately after the
ioctl response structure.This fixes FSCTLs such as SMB2:FSCTL_QUERY_ALLOCATED_RANGES
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/cifs/smb2ops.c +2
-1@@ -1467,7 +1467,9 @@ smb2_ioctl_query_info(const unsigned int xid, rc = -EFAULT ; goto iqinf_exit; } -if (copy_to_user (pqi +1 , &io_rsp[1 ], qi.input_buffer_length)) { + if (copy_to_user((char *)pqi + sizeof(struct smb_query_info), + (char *)io_rsp + le32_to_cpu(io_rsp-
Quoted 4 lines
fs/cifs/smb2ops.c smb2_ioctl_query_info(const unsigned int xid, · line 1473
Quoted 2 lines
fs/cifs/smb2ops.c +1
-0>OutputOffset), + qi.input_buffer_length)) {Shouldn't this validate that OutputOffset, for a length of
input_buffer_length, falls completely within the bounds of the response, before copying?
I think copy_to_user handles that
Quoted 8 lines
Quoted 7 lines
fs/cifs/smb2ops.c +0
-0rc = -EFAULT ; goto iqinf_exit;}--
2.13.6
Quoted 46 lines
-----Original Message-----
From: ronnie sahlberg <[email protected]>
Sent: Friday, April 12, 2019 9:38 AM
To: Tom Talpey <[email protected]>
Cc: Ronnie Sahlberg <[email protected]>; linux-cifs <linux- [email protected]>; Steve French <[email protected]>
Subject: Re: [PATCH] cifs: fix bi-directional fsctl passthrough callsQuoted 3 lines · Tom Talpey
Quoted 3 lines
-----Original Message-----
From: [email protected] <[email protected]>On
Quoted 33 lines
Quoted 33 lines
Behalf Of Ronnie Sahlberg
Sent: Thursday, April 11, 2019 11:06 PM
To: linux-cifs <[email protected]>
Cc: Steve French <[email protected]>; Ronnie Sahlberg <[email protected]>
Subject: [PATCH] cifs: fix bi-directional fsctl passthrough callsSMB2 Ioctl responses from servers may respond with both the request blob from
the client followed by the actual reply blob for ioctls that are bi-directional.In that case we can not assume that the reply blob comes immediately after the
ioctl response structure.This fixes FSCTLs such as SMB2:FSCTL_QUERY_ALLOCATED_RANGES
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/cifs/smb2ops.c +2
-1@@ -1467,7 +1467,9 @@ smb2_ioctl_query_info(const unsigned int xid, rc = -EFAULT ; goto iqinf_exit; } -if (copy_to_user (pqi +1 , &io_rsp[1 ], qi.input_buffer_length)) { + if (copy_to_user((char *)pqi + sizeof(struct smb_query_info), + (char *)io_rsp + le32_to_cpu(io_rsp-
Quoted 7 lines
Quoted 4 lines
fs/cifs/smb2ops.c smb2_ioctl_query_info(const unsigned int xid, · line 1473
Quoted 2 lines
fs/cifs/smb2ops.c +1
-0>OutputOffset), + qi.input_buffer_length)) {Shouldn't this validate that OutputOffset, for a length of
input_buffer_length,falls completely within the bounds of the response, before copying?
I think
copy_to_userhandles that
Absolutely not - copy_to_user cannot validate SMB2 messages, and only handles user faults (destination buffer not source).
If the server is buggy or evil, OutputOffset might lie outside the response.
If the response payload is shorter than qi.input_buffer_length, this code will copy kernel memory, or may walk off the end of a kernel page.
Both very bad things?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
fs/cifs/smb2ops.c +0
-0rc = -EFAULT ; goto iqinf_exit;}--
2.13.6