Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cifs: Fix invalid check in __cifs_calc_signature()

The following check would never evaluate to true:
> if (i == 0 && iov[0].iov_len <= 4)

Because 'i' always starts at 1.

This patch fixes it and also move the header checks outside the for loop
- which makes more sense.

Signed-off-by: Paulo Alcantara <palcantara@suse.de>
Signed-off-by: Steve French <stfrench@microsoft.com>

authored by

Paulo Alcantara and committed by
Steve French
83ffdead 35e2cc1b

+6 -9
+6 -9
fs/cifs/cifsencrypt.c
··· 48 48 49 49 /* iov[0] is actual data and not the rfc1002 length for SMB2+ */ 50 50 if (is_smb2) { 51 - rc = crypto_shash_update(shash, 52 - iov[0].iov_base, iov[0].iov_len); 51 + if (iov[0].iov_len <= 4) 52 + return -EIO; 53 + i = 0; 53 54 } else { 54 55 if (n_vec < 2 || iov[0].iov_len != 4) 55 56 return -EIO; 57 + i = 1; /* skip rfc1002 length */ 56 58 } 57 59 58 - for (i = 1; i < n_vec; i++) { 60 + for (; i < n_vec; i++) { 59 61 if (iov[i].iov_len == 0) 60 62 continue; 61 63 if (iov[i].iov_base == NULL) { 62 64 cifs_dbg(VFS, "null iovec entry\n"); 63 65 return -EIO; 64 66 } 65 - if (is_smb2) { 66 - if (i == 0 && iov[0].iov_len <= 4) 67 - break; /* nothing to sign or corrupt header */ 68 - } else 69 - if (i == 1 && iov[1].iov_len <= 4) 70 - break; /* nothing to sign or corrupt header */ 67 + 71 68 rc = crypto_shash_update(shash, 72 69 iov[i].iov_base, iov[i].iov_len); 73 70 if (rc) {