]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
95179230336112b26a6e8b125f786bab96ab9984
[thirdparty/kernel/stable-queue.git] /
1 From b02989f37fc5e865ceeee9070907e4493b3a21e2 Mon Sep 17 00:00:00 2001
2 From: "Longpeng(Mike)" <longpeng2@huawei.com>
3 Date: Tue, 2 Jun 2020 15:04:59 +0800
4 Subject: crypto: virtio: Fix src/dst scatterlist calculation in __virtio_crypto_skcipher_do_req()
5
6 From: Longpeng(Mike) <longpeng2@huawei.com>
7
8 commit b02989f37fc5e865ceeee9070907e4493b3a21e2 upstream.
9
10 The system will crash when the users insmod crypto/tcrypt.ko with mode=38
11 ( testing "cts(cbc(aes))" ).
12
13 Usually the next entry of one sg will be @sg@ + 1, but if this sg element
14 is part of a chained scatterlist, it could jump to the start of a new
15 scatterlist array. Fix it by sg_next() on calculation of src/dst
16 scatterlist.
17
18 Fixes: dbaf0624ffa5 ("crypto: add virtio-crypto driver")
19 Reported-by: LABBE Corentin <clabbe@baylibre.com>
20 Cc: Herbert Xu <herbert@gondor.apana.org.au>
21 Cc: "Michael S. Tsirkin" <mst@redhat.com>
22 Cc: Jason Wang <jasowang@redhat.com>
23 Cc: "David S. Miller" <davem@davemloft.net>
24 Cc: virtualization@lists.linux-foundation.org
25 Cc: linux-kernel@vger.kernel.org
26 Cc: stable@vger.kernel.org
27 Link: https://lore.kernel.org/r/20200123101000.GB24255@Red
28 Signed-off-by: Gonglei <arei.gonglei@huawei.com>
29 Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
30 Link: https://lore.kernel.org/r/20200602070501.2023-2-longpeng2@huawei.com
31 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34 ---
35 drivers/crypto/virtio/virtio_crypto_algs.c | 15 ++++++++++-----
36 1 file changed, 10 insertions(+), 5 deletions(-)
37
38 --- a/drivers/crypto/virtio/virtio_crypto_algs.c
39 +++ b/drivers/crypto/virtio/virtio_crypto_algs.c
40 @@ -350,13 +350,18 @@ __virtio_crypto_skcipher_do_req(struct v
41 int err;
42 unsigned long flags;
43 struct scatterlist outhdr, iv_sg, status_sg, **sgs;
44 - int i;
45 u64 dst_len;
46 unsigned int num_out = 0, num_in = 0;
47 int sg_total;
48 uint8_t *iv;
49 + struct scatterlist *sg;
50
51 src_nents = sg_nents_for_len(req->src, req->cryptlen);
52 + if (src_nents < 0) {
53 + pr_err("Invalid number of src SG.\n");
54 + return src_nents;
55 + }
56 +
57 dst_nents = sg_nents(req->dst);
58
59 pr_debug("virtio_crypto: Number of sgs (src_nents: %d, dst_nents: %d)\n",
60 @@ -443,12 +448,12 @@ __virtio_crypto_skcipher_do_req(struct v
61 vc_sym_req->iv = iv;
62
63 /* Source data */
64 - for (i = 0; i < src_nents; i++)
65 - sgs[num_out++] = &req->src[i];
66 + for (sg = req->src; src_nents; sg = sg_next(sg), src_nents--)
67 + sgs[num_out++] = sg;
68
69 /* Destination data */
70 - for (i = 0; i < dst_nents; i++)
71 - sgs[num_out + num_in++] = &req->dst[i];
72 + for (sg = req->dst; sg; sg = sg_next(sg))
73 + sgs[num_out + num_in++] = sg;
74
75 /* Status */
76 sg_init_one(&status_sg, &vc_req->status, sizeof(vc_req->status));