linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Stephan Mueller <smueller@chronox.de>
Cc: Daniel Borkmann <dborkman@redhat.com>,
	'Quentin Gouchet' <quentin.gouchet@gmail.com>,
	'LKML' <linux-kernel@vger.kernel.org>,
	linux-crypto@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [PATCH v4 4/5] crypto: AF_ALG: add random number generator support
Date: Fri, 5 Dec 2014 23:53:59 +0800	[thread overview]
Message-ID: <20141205155359.GA30224@gondor.apana.org.au> (raw)
In-Reply-To: <1480776.TeURZV8VLa@tachyon.chronox.de>

On Wed, Dec 03, 2014 at 08:59:01PM +0100, Stephan Mueller wrote:
>
> +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 err = -EFAULT;
> +
> +	if (len == 0)
> +		return 0;
> +	if (len > MAXSIZE)
> +		len = MAXSIZE;
> +
> +	lock_sock(sk);

This lock simply protects ctx->result.  Since you're using a
tiny buffer why not just put it on the stack?

> +		u8 *buf = kmalloc(seedsize, GFP_KERNEL);
> +		if (!buf)
> +			goto err;
> +		get_random_bytes(buf, seedsize);
> +		ret = crypto_rng_reset(private, buf, len);

I think you should leave the seeding and the seed to the user.
Perhaps do it through setsockopt (on the parent socket).

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2014-12-05 15:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-03 19:54 [PATCH v4 0/5] crypto: AF_ALG: add AEAD and RNG support Stephan Mueller
2014-12-03 19:55 ` [PATCH v4 1/5] crypto: AF_ALG: add user space interface for AEAD Stephan Mueller
     [not found]   ` <4746255.Vltg6sM4x3-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-12-05 16:01     ` Herbert Xu
     [not found] ` <2105559.EmODblLYuY-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-12-03 19:57   ` [PATCH v4 2/5] crypto: AF_ALG: add AEAD support Stephan Mueller
2014-12-05 15:46     ` Herbert Xu
2014-12-05 21:51       ` Stephan Mueller
2014-12-06 20:08         ` Stephan Mueller
     [not found]           ` <1677221.HN3xC7fa4q-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-12-06 23:27             ` Herbert Xu
     [not found]         ` <45756810.oFuGYtKPb9-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-12-06 23:28           ` Herbert Xu
     [not found]       ` <20141205154606.GA30180-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-12-07 12:56         ` Stephan Mueller
2014-12-03 19:58 ` [PATCH v4 3/5] crypto: AF_ALG: enable AEAD interface compilation Stephan Mueller
2014-12-03 19:59 ` [PATCH v4 4/5] crypto: AF_ALG: add random number generator support Stephan Mueller
2014-12-05 15:53   ` Herbert Xu [this message]
     [not found]     ` <20141205155359.GA30224-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-12-05 22:02       ` Stephan Mueller
2014-12-03 19:59 ` [PATCH v4 5/5] crypto: AF_ALG: enable RNG interface compilation Stephan Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141205155359.GA30224@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dborkman@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin.gouchet@gmail.com \
    --cc=smueller@chronox.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).