]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cifs: potential buffer overflow in handling symlinks
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Wed, 13 Apr 2022 11:42:51 +0000 (04:42 -0700)
committerSteve French <stfrench@microsoft.com>
Wed, 13 Apr 2022 17:00:49 +0000 (12:00 -0500)
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>
Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/link.c

index 852e54ee82c28279c00e6013b19916f3815a8b70..bbdf3281559c8f53c0e2c9d281f8fd5b4921e11b 100644 (file)
@@ -85,6 +85,9 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
        if (rc != 1)
                return -EINVAL;
 
+       if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
+               return -EINVAL;
+
        rc = symlink_hash(link_len, link_str, md5_hash);
        if (rc) {
                cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);