linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BPF RNG
@ 2019-04-16 13:54 Kees Cook
  2019-04-16 13:55 ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2019-04-16 13:54 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Hannes Frederic Sowa, Alexei Starovoitov, LKML, Ingo Molnar,
	Reshetova, Elena

Hi,

In looking at prandom_u32() users, I noticed that BPF uses its own
state variable with bpf_user_rnd_u32(). It appears that this state is
never reseeded like regular prandom_u32(). (See __prandom_timer().) Is
this intentional, or should reseeding be happening?

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: BPF RNG
  2019-04-16 13:54 BPF RNG Kees Cook
@ 2019-04-16 13:55 ` Kees Cook
  2019-04-16 14:44   ` Daniel Borkmann
  2019-04-16 15:06   ` Theodore Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Kees Cook @ 2019-04-16 13:55 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Hannes Frederic Sowa, LKML, Ingo Molnar, Reshetova, Elena,
	Alexei Starovoitov

[correcting Alexei's email address and resending...]

On Tue, Apr 16, 2019 at 8:54 AM Kees Cook <keescook@google.com> wrote:
>
> Hi,
>
> In looking at prandom_u32() users, I noticed that BPF uses its own
> state variable with bpf_user_rnd_u32(). It appears that this state is
> never reseeded like regular prandom_u32(). (See __prandom_timer().) Is
> this intentional, or should reseeding be happening?
>
> -Kees
>
> --
> Kees Cook



-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: BPF RNG
  2019-04-16 13:55 ` Kees Cook
@ 2019-04-16 14:44   ` Daniel Borkmann
  2019-04-16 22:58     ` Kees Cook
  2019-04-16 15:06   ` Theodore Ts'o
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2019-04-16 14:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Hannes Frederic Sowa, LKML, Ingo Molnar, Reshetova, Elena,
	Alexei Starovoitov

On 04/16/2019 03:55 PM, Kees Cook wrote:
> [correcting Alexei's email address and resending...]
> 
> On Tue, Apr 16, 2019 at 8:54 AM Kees Cook <keescook@google.com> wrote:
>>
>> Hi,
>>
>> In looking at prandom_u32() users, I noticed that BPF uses its own
>> state variable with bpf_user_rnd_u32(). It appears that this state is

Correct, we split that off from the main one.

>> never reseeded like regular prandom_u32(). (See __prandom_timer().) Is
>> this intentional, or should reseeding be happening?

The prng is not to be used in any security-critical context. That said,
we optionally could perform reseeding from time to time, though that
should probably be done generically, so that all "external"
prandom_u32_state() users could register themselves upon init whether
they opt-in for periodic reseeding or not.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: BPF RNG
  2019-04-16 13:55 ` Kees Cook
  2019-04-16 14:44   ` Daniel Borkmann
@ 2019-04-16 15:06   ` Theodore Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2019-04-16 15:06 UTC (permalink / raw)
  To: Kees Cook
  Cc: Daniel Borkmann, Hannes Frederic Sowa, LKML, Ingo Molnar,
	Reshetova, Elena, Alexei Starovoitov

On Tue, Apr 16, 2019 at 08:55:59AM -0500, Kees Cook wrote:
> [correcting Alexei's email address and resending...]
> On Tue, Apr 16, 2019 at 8:54 AM Kees Cook <keescook@google.com> wrote:
> >
> > In looking at prandom_u32() users, I noticed that BPF uses its own
> > state variable with bpf_user_rnd_u32(). It appears that this state is
> > never reseeded like regular prandom_u32(). (See __prandom_timer().) Is
> > this intentional, or should reseeding be happening?

It looks like this isn't the only place where prandom's machinery is
being used w/o reseeding.  See also net/netfilter/nft_meta.c and
net/netfilter/nft_numgen.c.

That being said, guarantees we give for prandom are extremely weak.
The only reason why we reseed for net_rand_state was they wanted
something sorta-kinda secure, but they weren't willing to pay the cost
of calling get_random_u64() or get_random_u32().

So I don't think we should be encouraging people to think that
reseeding should actually be happening, at least with some explicit
explanation of documentation somewhere about why it's needed, and what
security guarantees people should be expecting.  (e.g., for the
networking subsystem, the claim is that it's trying to make certain
DOS attackers harder, and it shouldn't be mistaken for real security).

In fact, why we're supporting multiple prandom per-cpu state families
makes me worried we're going in the wrong direction.  I suspect the
reason why people are settng up separate prandom states is because
they don't want to leak knowledge about the prandom internal state to
an external attacker.  That should only matter for a small set of
network stack users; so maybe we should just have two prandom states.
One for the vast majority of users where there should be no security
concerns around using prandom (because if there are, 99% of the time
they should be get_random_u32), and then for those people who want
get_random_fast_but_maybe_insecure_u64() --- and maybe for those
architectures where there is some instruction like RDRAND which is
really super-fast, it would use RDRAND for the
get_random_fast_but_maybe_insecure_u64().

						- Ted

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: BPF RNG
  2019-04-16 14:44   ` Daniel Borkmann
@ 2019-04-16 22:58     ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2019-04-16 22:58 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Hannes Frederic Sowa, LKML, Ingo Molnar, Reshetova, Elena,
	Alexei Starovoitov

On Tue, Apr 16, 2019 at 10:13 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 04/16/2019 03:55 PM, Kees Cook wrote:
> > [correcting Alexei's email address and resending...]
> >
> > On Tue, Apr 16, 2019 at 8:54 AM Kees Cook <keescook@google.com> wrote:
> >>
> >> Hi,
> >>
> >> In looking at prandom_u32() users, I noticed that BPF uses its own
> >> state variable with bpf_user_rnd_u32(). It appears that this state is
>
> Correct, we split that off from the main one.
>
> >> never reseeded like regular prandom_u32(). (See __prandom_timer().) Is
> >> this intentional, or should reseeding be happening?
>
> The prng is not to be used in any security-critical context. That said,
> we optionally could perform reseeding from time to time, though that
> should probably be done generically, so that all "external"
> prandom_u32_state() users could register themselves upon init whether
> they opt-in for periodic reseeding or not.

Yeah, it seemed like it should be built into the API. I'll add this to
the TODO list. ;)

Thanks for double-checking.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-16 22:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16 13:54 BPF RNG Kees Cook
2019-04-16 13:55 ` Kees Cook
2019-04-16 14:44   ` Daniel Borkmann
2019-04-16 22:58     ` Kees Cook
2019-04-16 15:06   ` Theodore Ts'o

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).