netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ncpfs: memory corruption in ncp_read_kernel()
       [not found] <CA+ygN1LiXW3uNuMS-eRv5Y_WJNyyr77+Rgycec4Y-Ju2VGrNWA@mail.gmail.com>
@ 2018-03-19 11:07 ` Dan Carpenter
  2018-03-19 13:56   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-03-19 11:07 UTC (permalink / raw)
  To: Petr Vandrovec
  Cc: devel, security, Greg Kroah-Hartman, netdev, Philippe Ombredanne,
	Thomas Gleixner, David S. Miller

If the server is malicious then *bytes_read could be larger than the
size of the "target" buffer.  It would lead to memory corruption when we
do the memcpy().

Reported-by: Dr Silvio Cesare of InfoSect <Silvio Cesare <silvio.cesare@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/staging/ncpfs/ncplib_kernel.c b/drivers/staging/ncpfs/ncplib_kernel.c
index 804adfebba2f..3e047eb4cc7c 100644
--- a/drivers/staging/ncpfs/ncplib_kernel.c
+++ b/drivers/staging/ncpfs/ncplib_kernel.c
@@ -981,6 +981,10 @@ ncp_read_kernel(struct ncp_server *server, const char *file_id,
 		goto out;
 	}
 	*bytes_read = ncp_reply_be16(server, 0);
+	if (*bytes_read > to_read) {
+		result = -EINVAL;
+		goto out;
+	}
 	source = ncp_reply_data(server, 2 + (offset & 1));
 
 	memcpy(target, source, *bytes_read);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ncpfs: memory corruption in ncp_read_kernel()
  2018-03-19 11:07 ` [PATCH] ncpfs: memory corruption in ncp_read_kernel() Dan Carpenter
@ 2018-03-19 13:56   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2018-03-19 13:56 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: devel, security, netdev, Philippe Ombredanne, Thomas Gleixner,
	Petr Vandrovec, David S. Miller

On Mon, Mar 19, 2018 at 02:07:45PM +0300, Dan Carpenter wrote:
> If the server is malicious then *bytes_read could be larger than the
> size of the "target" buffer.  It would lead to memory corruption when we
> do the memcpy().
> 
> Reported-by: Dr Silvio Cesare of InfoSect <Silvio Cesare <silvio.cesare@gmail.com>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/staging/ncpfs/ncplib_kernel.c b/drivers/staging/ncpfs/ncplib_kernel.c
> index 804adfebba2f..3e047eb4cc7c 100644
> --- a/drivers/staging/ncpfs/ncplib_kernel.c
> +++ b/drivers/staging/ncpfs/ncplib_kernel.c

Ugh, I have like 2 more months before I delete this code :)

Anyway, nice find, and fix, I'll go queue it up now, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-19 13:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CA+ygN1LiXW3uNuMS-eRv5Y_WJNyyr77+Rgycec4Y-Ju2VGrNWA@mail.gmail.com>
2018-03-19 11:07 ` [PATCH] ncpfs: memory corruption in ncp_read_kernel() Dan Carpenter
2018-03-19 13:56   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).