Debian Codegraph @

kernel-patches/4.14-rc1/asym/v9-0002-crypto-AF_ALG-add-setpubkey-setsockopt-call.patch

raw
1 From f75ddb25ae3722284bbdca10e88b748f0623d89b Mon Sep 17 00:00:00 2001
2 From: Stephan Mueller <[email protected]>
3 Date: Thu, 10 Aug 2017 08:18:26 +0200
4 Subject: [PATCH v9 2/3] crypto: AF_ALG -- add setpubkey setsockopt call
5
6 For supporting asymmetric ciphers, user space must be able to set the
7 public key. The patch adds a new setsockopt call for setting the public
8 key.
9
10 Signed-off-by: Stephan Mueller <[email protected]>
11 ---
12 crypto/af_alg.c | 18 +++++++++++++-----
13 include/crypto/if_alg.h | 1 +
14 include/uapi/linux/if_alg.h | 1 +
15 3 files changed, 15 insertions(+), 5 deletions(-)
16
17 diff --git a/crypto/af_alg.c b/crypto/af_alg.c
18 index cbb348e15a17..8173c005e0b1 100644
19 --- a/crypto/af_alg.c
20 +++ b/crypto/af_alg.c
21 @@ -203,13 +203,17 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
22 }
23
24 static int alg_setkey(struct sock *sk, char __user *ukey,
25 - unsigned int keylen)
26 + unsigned int keylen,
27 + int (*setkey)(void *private, const u8 *key,
28 + unsigned int keylen))
29 {
30 struct alg_sock *ask = alg_sk(sk);
31 - const struct af_alg_type *type = ask->type;
32 u8 *key;
33 int err;
34
35 + if (!setkey)
36 + return -ENOPROTOOPT;
37 +
38 key = sock_kmalloc(sk, keylen, GFP_KERNEL);
39 if (!key)
40 return -ENOMEM;
41 @@ -218,7 +222,7 @@ static int alg_setkey(struct sock *sk, char __user *ukey,
42 if (copy_from_user(key, ukey, keylen))
43 goto out;
44
45 - err = type->setkey(ask->private, key, keylen);
46 + err = setkey(ask->private, key, keylen);
47
48 out:
49 sock_kzfree_s(sk, key, keylen);
50 @@ -248,10 +252,14 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
51 case ALG_SET_KEY:
52 if (sock->state == SS_CONNECTED)
53 goto unlock;
54 - if (!type->setkey)
55 +
56 + err = alg_setkey(sk, optval, optlen, type->setkey);
57 + break;
58 + case ALG_SET_PUBKEY:
59 + if (sock->state == SS_CONNECTED)
60 goto unlock;
61
62 - err = alg_setkey(sk, optval, optlen);
63 + err = alg_setkey(sk, optval, optlen, type->setpubkey);
64 break;
65 case ALG_SET_AEAD_AUTHSIZE:
66 if (sock->state == SS_CONNECTED)
67 diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
68 index 50a21488f3ba..d1de8ed3e77b 100644
69 --- a/include/crypto/if_alg.h
70 +++ b/include/crypto/if_alg.h
71 @@ -55,6 +55,7 @@ struct af_alg_type {
72 void *(*bind)(const char *name, u32 type, u32 mask);
73 void (*release)(void *private);
74 int (*setkey)(void *private, const u8 *key, unsigned int keylen);
75 + int (*setpubkey)(void *private, const u8 *key, unsigned int keylen);
76 int (*accept)(void *private, struct sock *sk);
77 int (*accept_nokey)(void *private, struct sock *sk);
78 int (*setauthsize)(void *private, unsigned int authsize);
79 diff --git a/include/uapi/linux/if_alg.h b/include/uapi/linux/if_alg.h
80 index d81dcca5bdd7..02e61627e089 100644
81 --- a/include/uapi/linux/if_alg.h
82 +++ b/include/uapi/linux/if_alg.h
83 @@ -34,6 +34,7 @@ struct af_alg_iv {
84 #define ALG_SET_OP 3
85 #define ALG_SET_AEAD_ASSOCLEN 4
86 #define ALG_SET_AEAD_AUTHSIZE 5
87 +#define ALG_SET_PUBKEY 6
88
89 /* Operations */
90 #define ALG_OP_DECRYPT 0
91 --
92 2.13.5
93