]> git.pld-linux.org Git - packages/cryptsetup.git/blob - 0002-Fix-kernel-crypto-backend-to-set-key-before-accept-c.patch
- rel 3; adopt to kernel API changes; seems needed for all stable kernel lines (ie...
[packages/cryptsetup.git] / 0002-Fix-kernel-crypto-backend-to-set-key-before-accept-c.patch
1 From 4dc88e8ffb6442ebba7ad8d14fa55691734371e0 Mon Sep 17 00:00:00 2001
2 From: Milan Broz <gmazyland@gmail.com>
3 Date: Mon, 4 Jan 2016 14:19:50 +0100
4 Subject: [PATCH] Fix kernel crypto backend to set key before accept call even
5  for HMAC.
6
7 ---
8  lib/crypto_backend/crypto_kernel.c | 20 +++++++++++---------
9  1 file changed, 11 insertions(+), 9 deletions(-)
10
11 diff --git a/lib/crypto_backend/crypto_kernel.c b/lib/crypto_backend/crypto_kernel.c
12 index 4fbc578..4d9d075 100644
13 --- a/lib/crypto_backend/crypto_kernel.c
14 +++ b/lib/crypto_backend/crypto_kernel.c
15 @@ -68,7 +68,8 @@ struct crypt_hmac {
16         int hash_len;
17  };
18  
19 -static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd)
20 +static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd,
21 +                                   const void *key, size_t key_length)
22  {
23         *tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
24         if (*tfmfd < 0)
25 @@ -80,6 +81,12 @@ static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *op
26                 return -ENOENT;
27         }
28  
29 +       if (key && setsockopt(*tfmfd, SOL_ALG, ALG_SET_KEY, key, key_length) < 0) {
30 +               close(*tfmfd);
31 +               *tfmfd = -1;
32 +               return -EINVAL;
33 +       }
34 +
35         *opfd = accept(*tfmfd, NULL, 0);
36         if (*opfd < 0) {
37                 close(*tfmfd);
38 @@ -106,7 +113,7 @@ int crypt_backend_init(struct crypt_device *ctx)
39         if (uname(&uts) == -1 || strcmp(uts.sysname, "Linux"))
40                 return -EINVAL;
41  
42 -       if (crypt_kernel_socket_init(&sa, &tfmfd, &opfd) < 0)
43 +       if (crypt_kernel_socket_init(&sa, &tfmfd, &opfd, NULL, 0) < 0)
44                 return -EINVAL;
45  
46         close(tfmfd);
47 @@ -171,7 +178,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
48  
49         strncpy((char *)sa.salg_name, ha->kernel_name, sizeof(sa.salg_name));
50  
51 -       if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
52 +       if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd, NULL, 0) < 0) {
53                 free(h);
54                 return -EINVAL;
55         }
56 @@ -246,16 +253,11 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
57         snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
58                  "hmac(%s)", ha->kernel_name);
59  
60 -       if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
61 +       if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd, buffer, length) < 0) {
62                 free(h);
63                 return -EINVAL;
64         }
65  
66 -       if (setsockopt(h->tfmfd, SOL_ALG, ALG_SET_KEY, buffer, length) < 0) {
67 -               crypt_hmac_destroy(h);
68 -               return -EINVAL;
69 -       }
70 -
71         *ctx = h;
72         return 0;
73  }
74 -- 
75 2.7.1
76
This page took 0.06368 seconds and 3 git commands to generate.