Skip to contentSkip to conversation

ncpfs: memory corruption in ncp_read_kernel()

PATCH In review Dan Carpenter 2 participants 2 messages Mar 19, 2018 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CA+ygN1LiXW3uNuMS-eRv5Y_WJNyyr77+Rgycec4Y-Ju2VGrNWA@mail.gmail.com

#1 lore raw

PATCH 1/1 ncpfs: memory corruption in ncp_read_kernel()

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 <[email protected]>
drivers/staging/ncpfs/ncplib_kernel.c +4 -0
index 804adfebba2f..3e047eb4cc7c 100644
@@ -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);
#2 lore raw

drivers/staging/ncpfs/ncplib_kernel.c

Quoted 11 lines · Dan Carpenter

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 <[email protected]>
drivers/staging/ncpfs/ncplib_kernel.c +0 -0
index 804adfebba2f..3e047eb4cc7c 100644

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