Skip to contentSkip to conversation

cifs: fix bi-directional fsctl passthrough calls

PATCH In review Ronnie Sahlberg 3 participants 4 messages Apr 12, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 0b7e2be2a781..768f35ea63cf 100644
@@ -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
#1 lore raw
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 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 +0 -0
index 0b7e2be2a781..768f35ea63cf 100644

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 -0
 			rc = -EFAULT;
 			goto iqinf_exit;

}
--
2.13.6

#2 lore raw
Quoted 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 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 +2 -1
index 0b7e2be2a781..768f35ea63cf 100644
@@ -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 -0
                      rc = -EFAULT;
                      goto iqinf_exit;
              }

--
2.13.6

#3 lore raw
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 calls

Quoted 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 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 +2 -1
index 0b7e2be2a781..768f35ea63cf 100644
@@ -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_user handles 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 -0
                      rc = -EFAULT;
                      goto iqinf_exit;
              }

--
2.13.6