Skip to content

Commit 06deeec

Browse files
amlutosmfrench
authored andcommitted
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>
1 parent 96a988f commit 06deeec

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

fs/cifs/smbencrypt.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2424
*/
2525

26-
#include <crypto/skcipher.h>
26+
#include <linux/crypto.h>
2727
#include <linux/module.h>
2828
#include <linux/slab.h>
2929
#include <linux/fs.h>
@@ -69,46 +69,22 @@ str_to_key(unsigned char *str, unsigned char *key)
6969
static int
7070
smbhash(unsigned char *out, const unsigned char *in, unsigned char *key)
7171
{
72-
int rc;
7372
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;
7774

7875
str_to_key(key, key2);
7976

80-
tfm_des = crypto_alloc_skcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC);
77+
tfm_des = crypto_alloc_cipher("des", 0, 0);
8178
if (IS_ERR(tfm_des)) {
82-
rc = PTR_ERR(tfm_des);
83-
cifs_dbg(VFS, "could not allocate des crypto API\n");
84-
goto smbhash_err;
85-
}
86-
87-
req = skcipher_request_alloc(tfm_des, GFP_KERNEL);
88-
if (!req) {
89-
rc = -ENOMEM;
9079
cifs_dbg(VFS, "could not allocate des crypto API\n");
91-
goto smbhash_free_skcipher;
80+
return PTR_ERR(tfm_des);
9281
}
9382

94-
crypto_skcipher_setkey(tfm_des, key2, 8);
95-
96-
sg_init_one(&sgin, in, 8);
97-
sg_init_one(&sgout, out, 8);
83+
crypto_cipher_setkey(tfm_des, key2, 8);
84+
crypto_cipher_encrypt_one(tfm_des, out, in);
85+
crypto_free_cipher(tfm_des);
9886

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;
11288
}
11389

11490
static int

0 commit comments

Comments
 (0)