Skip to content

Commit 3776658

Browse files
committed
crypto: af_alg - Add nokey compatibility path
This patch adds a compatibility path to support old applications that do acept(2) before setkey. Cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent a383292 commit 3776658

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crypto/af_alg.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ int af_alg_register_type(const struct af_alg_type *type)
7676
goto unlock;
7777

7878
type->ops->owner = THIS_MODULE;
79+
if (type->ops_nokey)
80+
type->ops_nokey->owner = THIS_MODULE;
7981
node->type = type;
8082
list_add(&node->list, &alg_types);
8183
err = 0;
@@ -267,6 +269,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
267269
const struct af_alg_type *type;
268270
struct sock *sk2;
269271
int err;
272+
bool nokey;
270273

271274
lock_sock(sk);
272275
type = ask->type;
@@ -285,19 +288,27 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
285288
security_sk_clone(sk, sk2);
286289

287290
err = type->accept(ask->private, sk2);
291+
292+
nokey = err == -ENOKEY;
293+
if (nokey && type->accept_nokey)
294+
err = type->accept_nokey(ask->private, sk2);
295+
288296
if (err)
289297
goto unlock;
290298

291299
sk2->sk_family = PF_ALG;
292300

293-
if (!ask->refcnt++)
301+
if (nokey || !ask->refcnt++)
294302
sock_hold(sk);
295303
alg_sk(sk2)->parent = sk;
296304
alg_sk(sk2)->type = type;
297305

298306
newsock->ops = type->ops;
299307
newsock->state = SS_CONNECTED;
300308

309+
if (nokey)
310+
newsock->ops = type->ops_nokey;
311+
301312
err = 0;
302313

303314
unlock:

include/crypto/if_alg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ struct af_alg_type {
5252
void (*release)(void *private);
5353
int (*setkey)(void *private, const u8 *key, unsigned int keylen);
5454
int (*accept)(void *private, struct sock *sk);
55+
int (*accept_nokey)(void *private, struct sock *sk);
5556
int (*setauthsize)(void *private, unsigned int authsize);
5657

5758
struct proto_ops *ops;
59+
struct proto_ops *ops_nokey;
5860
struct module *owner;
5961
char name[14];
6062
};

0 commit comments

Comments
 (0)