Add RNG support to AF_ALG
Review
Quoted 8 lines · ----- "Neil Horman
(quoted diff) +8
-0+static int rng_recvmsg(struct kiocb *unused, struct socket *sock, + struct msghdr *msg, size_t len, int flags) +{ + struct sock *sk = sock->sk; + struct alg_sock *ask = alg_sk(sk); + struct rng_ctx *ctx = ask->private; + int rc, i; + u8 *data = kzalloc(len, GFP_KERNEL);
There probably should be an upper limit on the allocation - perhaps just always allocate a single page.
Review
Quoted 5 lines
(quoted diff) +5
-0+static void rng_release(void *private) +{ + struct rng_ctx *ctx = private; + crypto_free_rng(ctx->ctx); + kfree(ctx->seed);
Is a seed secret enough that it should be zeroed before freeing? (Same in setkey, accept_parent).
Mirek
Quoted 11 lines · Miloslav Trmac
Review
Quoted 8 lines · ----- "Neil Horman
(quoted diff) +8
-0+static int rng_recvmsg(struct kiocb *unused, struct socket *sock, + struct msghdr *msg, size_t len, int flags) +{ + struct sock *sk = sock->sk; + struct alg_sock *ask = alg_sk(sk); + struct rng_ctx *ctx = ask->private; + int rc, i; + u8 *data = kzalloc(len, GFP_KERNEL);There probably should be an upper limit on the allocation - perhaps just always allocate a single page.
I'd rather allocate the explicit amount needed, just to avoid added memory pressure allocating memory that we won't use, but yes, I can definately add an upper limit to how much data can be requested in a single call.
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static void rng_release(void *private) +{ + struct rng_ctx *ctx = private; + crypto_free_rng(ctx->ctx); + kfree(ctx->seed);Is a seed secret enough that it should be zeroed before freeing? (Same in setkey,
accept_parent).
I don't think that nececcecary, strictly speaking, but it couldn't hurt. Actually looking at it, I don't really need to duplicate the seed at all in accept_parent. I can probaby shrink that down considerably.
Thanks for the notes Mirek, I'll post an updated version shortly. Neil
Quoted 2 lines
Mirek
Quoted 12 lines · ----- "Neil Horman
Quoted 2 lines · Miloslav Trmac
Quoted 1 line · ----- "Neil Horman
+static int rng_recvmsg(struct kiocb *unused, struct socket
*sock,
Quoted 8 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ struct msghdr *msg, size_t len, int flags) +{ + struct sock *sk = sock->sk; + struct alg_sock *ask = alg_sk(sk); + struct rng_ctx *ctx = ask->private; + int rc, i; + u8 *data = kzalloc(len, GFP_KERNEL);There probably should be an upper limit on the allocation - perhaps
Quoted 5 lines
just always allocate a single page.
Quoted 1 line
I'd rather allocate the explicit amount needed, just to avoid added memory pressure allocating memory that we won't use, but yes, I can definately add an upper limit to how much data can be requested in a single call.
Please allow arbitrarily large requests. rng_recvmsg can easily use a smaller buffer by filling the user-space destination one buffer-size at a time, on the other hand handling an arbitrary upper limit in user-space would be unnecessarily complex.
Mirek