mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, Borislav Petkov <bp@suse.de>,
	Heiko Carstens <hca@linux.ibm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Johannes Berg <johannes@sipsolutions.net>
Subject: Re: [PATCH] random: discourage use of archrandom outside of rng
Date: Mon, 25 Jul 2022 14:02:14 +0100	[thread overview]
Message-ID: <Yt6UVkapnnJIThhj@FVFF77S0Q05N.cambridge.arm.com> (raw)
In-Reply-To: <20220725111038.720624-1-Jason@zx2c4.com>

On Mon, Jul 25, 2022 at 01:10:38PM +0200, Jason A. Donenfeld wrote:
> Borislav pointed out during the review of "random: handle archrandom
> with multiple longs" that people might actually use this function, which
> might not be good because the function has surprising semantics. This of
> course was also the case before that patch, and indeed RDSEED-like
> functions across architectures often behave surprisingly, failing often.
> While random.c has been written specifically to work with that behavior,
> not much else is well equipped for that.
> 
> So add a comment suggesting that this is not for general consumption.
> Fortunately, nobody uses this for general consumption anyway, and people
> who try quickly find themselves in trouble. But adding this comment out
> of an abundance of caution was nonetheless suggested, and it at least
> means there will be easier justification for cleaning up potential
> misuses of the function later.
> 
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Suggested-by: Borislav Petkov <bp@suse.de>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/include/asm/archrandom.h   | 13 +++++++++++++
>  arch/powerpc/include/asm/archrandom.h |  8 ++++++++
>  arch/s390/include/asm/archrandom.h    |  8 ++++++++
>  arch/um/include/asm/archrandom.h      |  8 ++++++++
>  arch/x86/include/asm/archrandom.h     |  9 ++++++---
>  include/asm-generic/archrandom.h      |  8 ++++++++
>  6 files changed, 51 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/archrandom.h
> index 109e2a4454be..0b5ee0e12a13 100644
> --- a/arch/arm64/include/asm/archrandom.h
> +++ b/arch/arm64/include/asm/archrandom.h
> @@ -58,6 +58,10 @@ static inline bool __arm64_rndrrs(unsigned long *v)
>  	return ok;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	/*
> @@ -71,6 +75,10 @@ static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t
>  	return 0;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	if (!max_longs)
> @@ -121,6 +129,11 @@ static inline bool __init __early_cpu_has_rndr(void)
>  	return (ftr >> ID_AA64ISAR0_EL1_RNDR_SHIFT) & 0xf;
>  }
>  
> +
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __init __must_check
>  arch_get_random_seed_longs_early(unsigned long *v, size_t max_longs)
>  {
> diff --git a/arch/powerpc/include/asm/archrandom.h b/arch/powerpc/include/asm/archrandom.h
> index 0e365c5b2396..7accfe346d49 100644
> --- a/arch/powerpc/include/asm/archrandom.h
> +++ b/arch/powerpc/include/asm/archrandom.h
> @@ -4,11 +4,19 @@
>  
>  #include <asm/machdep.h>
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	return 0;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	if (max_longs && ppc_md.get_random_seed && ppc_md.get_random_seed(v))
> diff --git a/arch/s390/include/asm/archrandom.h b/arch/s390/include/asm/archrandom.h
> index cf5e000df0a1..ae1efdd6f3a9 100644
> --- a/arch/s390/include/asm/archrandom.h
> +++ b/arch/s390/include/asm/archrandom.h
> @@ -18,11 +18,19 @@
>  DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
>  extern atomic64_t s390_arch_random_counter;
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	return 0;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	if (static_branch_likely(&s390_arch_random_available)) {
> diff --git a/arch/um/include/asm/archrandom.h b/arch/um/include/asm/archrandom.h
> index 24e16c979c51..d2b20bb0ed53 100644
> --- a/arch/um/include/asm/archrandom.h
> +++ b/arch/um/include/asm/archrandom.h
> @@ -7,6 +7,10 @@
>  /* This is from <os.h>, but better not to #include that in a global header here. */
>  ssize_t os_getrandom(void *buf, size_t len, unsigned int flags);
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	ssize_t ret;
> @@ -17,6 +21,10 @@ static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t
>  	return ret / sizeof(*v);
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	return 0;
> diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h
> index 02bae8e0758b..8352948e6412 100644
> --- a/arch/x86/include/asm/archrandom.h
> +++ b/arch/x86/include/asm/archrandom.h
> @@ -41,15 +41,18 @@ static inline bool __must_check rdseed_long(unsigned long *v)
>  }
>  
>  /*
> - * These are the generic interfaces; they must not be declared if the
> - * stubs in <linux/random.h> are to be invoked.
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
>   */
> -
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	return max_longs && static_cpu_has(X86_FEATURE_RDRAND) && rdrand_long(v) ? 1 : 0;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	return max_longs && static_cpu_has(X86_FEATURE_RDSEED) && rdseed_long(v) ? 1 : 0;
> diff --git a/include/asm-generic/archrandom.h b/include/asm-generic/archrandom.h
> index 3cd7f980cfdc..800b41639dd7 100644
> --- a/include/asm-generic/archrandom.h
> +++ b/include/asm-generic/archrandom.h
> @@ -2,11 +2,19 @@
>  #ifndef __ASM_GENERIC_ARCHRANDOM_H__
>  #define __ASM_GENERIC_ARCHRANDOM_H__
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
>  {
>  	return 0;
>  }
>  
> +/*
> + * This should only be used by drivers/char/random.c. Other drivers *must*
> + * use get_random_bytes() instead.
> + */
>  static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
>  {
>  	return 0;
> -- 
> 2.35.1
> 

  parent reply	other threads:[~2022-07-25 13:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-17 11:24 [PATCH] random: handle archrandom in plural words Jason A. Donenfeld
2022-07-17 11:43 ` Jason A. Donenfeld
2022-07-17 20:03   ` [PATCH v2] " Jason A. Donenfeld
2022-07-18  6:31     ` Michael Ellerman
2022-07-18  6:46       ` Gabriel Paubert
2022-07-20  3:03         ` Michael Ellerman
2022-07-19 12:42     ` Mark Rutland
2022-07-19 12:46       ` Jason A. Donenfeld
2022-07-19 13:02         ` [PATCH v3] random: handle archrandom with multiple longs Jason A. Donenfeld
2022-07-19 13:17           ` Mark Rutland
2022-07-19 13:48           ` Catalin Marinas
2022-07-22 12:06           ` Heiko Carstens
2022-07-24 22:47           ` Jason A. Donenfeld
2022-07-25  9:19           ` Borislav Petkov
2022-07-25  9:26             ` Jason A. Donenfeld
2022-07-25  9:36               ` David Laight
2022-07-25  9:37                 ` Jason A. Donenfeld
2022-07-25 11:10               ` [PATCH] random: discourage use of archrandom outside of rng Jason A. Donenfeld
2022-07-25 11:25                 ` Borislav Petkov
2022-07-25 11:33                 ` Heiko Carstens
2022-07-25 13:02                 ` Mark Rutland [this message]
2022-07-25 11:25           ` [PATCH v3] random: handle archrandom with multiple longs Borislav Petkov
2022-08-01 14:46           ` Harald Freudenberger
2022-08-01 14:50             ` Jason A. Donenfeld
2022-07-22  8:08     ` [PATCH v2] random: handle archrandom in plural words Holger Dengler
2022-07-22 11:22       ` Jason A. Donenfeld
2022-08-03 12:01         ` Holger Dengler

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=Yt6UVkapnnJIThhj@FVFF77S0Q05N.cambridge.arm.com \
    --to=mark.rutland@arm.com \
    --cc=Jason@zx2c4.com \
    --cc=bp@suse.de \
    --cc=catalin.marinas@arm.com \
    --cc=hca@linux.ibm.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    /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

all inboxes | Powered by JetHome®