cifs: sanitize length checking in coalesce_t2 (try #3)
authorJeff Layton <jlayton@redhat.com>
Wed, 27 Apr 2011 17:29:49 +0000 (13:29 -0400)
committerSteve Conklin <sconklin@canonical.com>
Thu, 2 Jun 2011 19:23:19 +0000 (14:23 -0500)
commite9d09c386a30f10b0c8f61a16e2f39afd2b53b16
treefda3002272ce4d0acb19bb11fadcb1064247058f
parentaff107bfdbf233669b43e3cc122f85703964cfcf
cifs: sanitize length checking in coalesce_t2 (try #3)

BugLink: http://bugs.launchpad.net/bugs/788691

commit 2a2047bc94d0efc316401170c3d078d9edc20dc4 upstream.

There are a couple of places in this code where these values can wrap or
go negative, and that could potentially end up overflowing the buffer.
Ensure that that doesn't happen. Do all of the length calculation and
checks first, and only perform the memcpy after they pass.

Also, increase some stack variables to 32 bits to ensure that they don't
wrap without being detected.

Finally, change the error codes to be a bit more descriptive of any
problems detected. -EINVAL isn't very accurate.

Reported-and-Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Steve Conklin <sconklin@canonical.com>
fs/cifs/connect.c