cifs: Fix smbencrypt() to stop pointing a scatterlist at the stack

smbencrypt() points a scatterlist to the stack, which is breaks if
CONFIG_VMAP_STACK=y.

Fix it by switching to crypto_cipher_encrypt_one(). The new code
should be considerably faster as an added benefit.

This code is nearly identical to some code that Eric Biggers
suggested.

Cc: stable@vger.kernel.org # 4.9 only
Reported-by: Eric Biggers <ebiggers3@gmail.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>

authored by Andy Lutomirski and committed by Steve French 06deeec7 96a988ff

+8 -32
+8 -32
fs/cifs/smbencrypt.c
··· 23 23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 24 */ 25 25 26 - #include <crypto/skcipher.h> 26 + #include <linux/crypto.h> 27 27 #include <linux/module.h> 28 28 #include <linux/slab.h> 29 29 #include <linux/fs.h> ··· 69 69 static int 70 70 smbhash(unsigned char *out, const unsigned char *in, unsigned char *key) 71 71 { 72 - int rc; 73 72 unsigned char key2[8]; 74 - struct crypto_skcipher *tfm_des; 75 - struct scatterlist sgin, sgout; 76 - struct skcipher_request *req; 73 + struct crypto_cipher *tfm_des; 77 74 78 75 str_to_key(key, key2); 79 76 80 - tfm_des = crypto_alloc_skcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC); 77 + tfm_des = crypto_alloc_cipher("des", 0, 0); 81 78 if (IS_ERR(tfm_des)) { 82 - rc = PTR_ERR(tfm_des); 83 79 cifs_dbg(VFS, "could not allocate des crypto API\n"); 84 - goto smbhash_err; 80 + return PTR_ERR(tfm_des); 85 81 } 86 82 87 - req = skcipher_request_alloc(tfm_des, GFP_KERNEL); 88 - if (!req) { 89 - rc = -ENOMEM; 90 - cifs_dbg(VFS, "could not allocate des crypto API\n"); 91 - goto smbhash_free_skcipher; 92 - } 83 + crypto_cipher_setkey(tfm_des, key2, 8); 84 + crypto_cipher_encrypt_one(tfm_des, out, in); 85 + crypto_free_cipher(tfm_des); 93 86 94 - crypto_skcipher_setkey(tfm_des, key2, 8); 95 - 96 - sg_init_one(&sgin, in, 8); 97 - sg_init_one(&sgout, out, 8); 98 - 99 - skcipher_request_set_callback(req, 0, NULL, NULL); 100 - skcipher_request_set_crypt(req, &sgin, &sgout, 8, NULL); 101 - 102 - rc = crypto_skcipher_encrypt(req); 103 - if (rc) 104 - cifs_dbg(VFS, "could not encrypt crypt key rc: %d\n", rc); 105 - 106 - skcipher_request_free(req); 107 - 108 - smbhash_free_skcipher: 109 - crypto_free_skcipher(tfm_des); 110 - smbhash_err: 111 - return rc; 87 + return 0; 112 88 } 113 89 114 90 static int