From: Dan Carpenter Date: Mon, 19 Mar 2018 11:07:45 +0000 (+0300) Subject: staging: ncpfs: memory corruption in ncp_read_kernel() X-Git-Tag: v4.1.52~369 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f67d1bdb52086230095895d6d0034953967cad78;p=thirdparty%2Fkernel%2Fstable.git staging: ncpfs: memory corruption in ncp_read_kernel() [ Upstream commit 4c41aa24baa4ed338241d05494f2c595c885af8f ] 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 Signed-off-by: Dan Carpenter Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- diff --git a/fs/ncpfs/ncplib_kernel.c b/fs/ncpfs/ncplib_kernel.c index 88dbbc9fcf4d6..f571570a2e72c 100644 --- a/fs/ncpfs/ncplib_kernel.c +++ b/fs/ncpfs/ncplib_kernel.c @@ -980,6 +980,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);