Skip to contentSkip to conversation

cifs: fix possible memory corruption in CIFSFindNext

PATCH In review Jeff Layton 3 participants 4 messages Aug 23, 2011 2 messages not in the archive

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

PATCH 1/1 cifs: fix possible memory corruption in CIFSFindNext

The name_len variable in CIFSFindNext is a signed int that gets set to the resume_name_len in the cifs_search_info. The resume_name_len however is unsigned and for some infolevels is populated directly from a 32 bit value sent by the server.

If the server sends a very large value for this, then that value could look negative when converted to a signed int. That would make that value pass the PATH_MAX check later in CIFSFindNext. The name_len would then be used as a length value for a memcpy. It would then be treated as unsigned again, and the memcpy scribbles over a ton of memory.

Fix this by making the name_len an unsigned value in CIFSFindNext.

---
 fs/cifs/cifssmb.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/cifs/cifssmb.c +2 -1
index f4d0988..950464d 100644
@@ -4089,7 +4089,8 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
 	T2_FNEXT_RSP_PARMS *parms;
 	char *response_data;
 	int rc = 0;
-	int bytes_returned, name_len;
+	int bytes_returned;
+	unsigned int name_len;
 	__u16 params, byte_count;
 
 	cFYI(1, "In FindNext");
Signature · 1 line
1.7.6
#2 lore raw
In reply to a message not in the archive

merged

Quoted 38 lines · Jeff Layton

The name_len variable in CIFSFindNext is a signed int that gets set to the resume_name_len in the cifs_search_info. The resume_name_len however is unsigned and for some infolevels is populated directly from a 32 bit value sent by the server.

If the server sends a very large value for this, then that value could look negative when converted to a signed int. That would make that value pass the PATH_MAX check later in CIFSFindNext. The name_len would then be used as a length value for a memcpy. It would then be treated as unsigned again, and the memcpy scribbles over a ton of memory.

Fix this by making the name_len an unsigned value in CIFSFindNext.

---
 fs/cifs/cifssmb.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
fs/cifs/cifssmb.c +2 -2
index f4d0988..950464d 100644
@@ -4089,7 +4089,8 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
        T2_FNEXT_RSP_PARMS *parms;
        char *response_data;
        int rc = 0;
-       int bytes_returned, name_len;
+       int bytes_returned;
+       unsigned int name_len;
        __u16 params, byte_count;
 
        cFYI(1, "In FindNext");
--

1.7.6

Signature · 3 lines
Thanks,

Steve
#3 lore raw
In reply to a message not in the archive
Quoted 25 lines · Jeff Layton

The name_len variable in CIFSFindNext is a signed int that gets set to the resume_name_len in the cifs_search_info. The resume_name_len however is unsigned and for some infolevels is populated directly from a 32 bit value sent by the server.

If the server sends a very large value for this, then that value could look negative when converted to a signed int. That would make that value pass the PATH_MAX check later in CIFSFindNext. The name_len would then be used as a length value for a memcpy. It would then be treated as unsigned again, and the memcpy scribbles over a ton of memory.

Fix this by making the name_len an unsigned value in CIFSFindNext.

---
 fs/cifs/cifssmb.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/cifs/cifssmb.c +0 -0
index f4d0988..950464d 100644

fs/cifs/cifssmb.c int CIFSFindNext(const int xid, struct cifs_tcon *tcon, · line 4093

Quoted 6 lines
fs/cifs/cifssmb.c +2 -1
@@ -4089,7 +4089,8 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
 	T2_FNEXT_RSP_PARMS *parms;
 	char *response_data;
 	int rc = 0;
-	int bytes_returned, name_len;
+	int bytes_returned;
+	unsigned int name_len;

Looks obviously correct. Just curious when does the server sends a very large resume_name_len? Does it try to overload with some other info in such circumstances?

Signature · 1 line
Suresh Jayaraman
#5 lore raw
In reply to a message not in the archive
Quoted 21 lines · On Tue, 23 Aug 2011 17:55:25 +0530 Suresh Jayaraman…
Quoted 20 lines · Jeff Layton

The name_len variable in CIFSFindNext is a signed int that gets set to the resume_name_len in the cifs_search_info. The resume_name_len however is unsigned and for some infolevels is populated directly from a 32 bit value sent by the server.

If the server sends a very large value for this, then that value could look negative when converted to a signed int. That would make that value pass the PATH_MAX check later in CIFSFindNext. The name_len would then be used as a length value for a memcpy. It would then be treated as unsigned again, and the memcpy scribbles over a ton of memory.

Fix this by making the name_len an unsigned value in CIFSFindNext.

---
 fs/cifs/cifssmb.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Quoted 16 lines

fs/cifs/cifssmb.c int CIFSFindNext(const int xid, struct cifs_tcon *tcon, · line 4093

Quoted 11 lines
fs/cifs/cifssmb.c +2 -1
index f4d0988..950464d 100644
@@ -4089,7 +4089,8 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
 	T2_FNEXT_RSP_PARMS *parms;
 	char *response_data;
 	int rc = 0;
-	int bytes_returned, name_len;
+	int bytes_returned;
+	unsigned int name_len;

Looks obviously correct. Just curious when does the server sends a very large resume_name_len? Does it try to overload with some other info in such circumstances?

It's hard to imagine that a properly functioning server ever would. More likely this would be the result of a malicious or broken server.

We have a case where this occurred but it's unfortunately marked private so I can't share the details. In that situation though I believe the environment was using an asian language codepage on the server. My suspicions is that this may have happened as the result of another client or server bug that threw the alignment of the response off.

Signature · 1 line
Jeff Layton <[email protected]>