diff mbox series

cifs: potential buffer overflow in handling symlinks

Message ID 20220412043823.57037-1-harshit.m.mogalapalli@oracle.com (mailing list archive)
State New, archived
Headers show
Series cifs: potential buffer overflow in handling symlinks | expand

Commit Message

Harshit Mogalapalli April 12, 2022, 4:38 a.m. UTC
Smatch printed a warning:
	arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error:
	__memcpy() 'dctx->buf' too small (16 vs u32max)

It's caused because Smatch marks 'link_len' as untrusted since it comes
from sscanf(). Add a check to ensure that 'link_len' is not larger than
the size of the 'link_str' buffer.

Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 fs/cifs/link.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 852e54e..ebfedae 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -85,6 +85,9 @@ 
 	if (rc != 1)
 		return -EINVAL;
 
+	if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
+		return -EINVAL;
+
 	rc = symlink_hash(link_len, link_str, md5_hash);
 	if (rc) {
 		cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);