From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
tglx@linutronix.de, linux-crypto@vger.kernel.org,
linux-api@vger.kernel.org, x86@kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
Carlos O'Donell <carlos@redhat.com>,
Florian Weimer <fweimer@redhat.com>,
Arnd Bergmann <arnd@arndb.de>, Jann Horn <jannh@google.com>,
Christian Brauner <brauner@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v14 0/7] implement getrandom() in vDSO
Date: Wed, 11 Jan 2023 17:23:56 -0500 [thread overview]
Message-ID: <Y782/D2WZJRR8SHY@localhost> (raw)
In-Reply-To: <20230101162910.710293-1-Jason@zx2c4.com>
On 01-Jan-2023 05:29:03 PM, Jason A. Donenfeld wrote:
[...]
> Two statements:
>
> 1) Userspace wants faster cryptographically secure random numbers of
> arbitrary size, big or small.
>
> 2) Userspace is currently unable to safely roll its own RNG with the
> same security profile as getrandom().
>
[...]
> API-wise, the vDSO gains this function:
>
> ssize_t vgetrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state);
>
> The return value and the first 3 arguments are the same as ordinary
> getrandom(), while the last argument is a pointer to some state
> allocated with vgetrandom_alloc(), explained below. Were all four
> arguments passed to the getrandom syscall, nothing different would
> happen, and the functions would have the exact same behavior.
>
> Then, we introduce a new syscall:
>
> void *vgetrandom_alloc(unsigned int *num, unsigned int *size_per_each,
> unsigned long addr, unsigned int flags);
>
> This takes a hinted number of opaque states in `num`, and returns a
> pointer to an array of opaque states, the number actually allocated back
> in `num`, and the size in bytes of each one in `size_per_each`, enabling
> a libc to slice up the returned array into a state per each thread. (The
> `flags` and `addr` arguments, as well as the `*size_per_each` input
> value, are reserved for the future and are forced to be zero for now.)
>
> Libc is expected to allocate a chunk of these on first use, and then
> dole them out to threads as they're created, allocating more when
> needed. The returned address of the first state may be passed to
> munmap(2) with a length of `num * size_per_each`, in order to deallocate
> the memory.
>
> We very intentionally do *not* leave state allocation up to the caller
> of vgetrandom, but provide vgetrandom_alloc for that allocation. There
> are too many weird things that can go wrong, and it's important that
> vDSO does not provide too generic of a mechanism. It's not going to
> store its state in just any old memory address. It'll do it only in ones
> it allocates.
[...]
Have you considered extending rseq(2) per-thread "struct rseq" with an
additional "prng_seed" pointer field, which would point to a per-thread
memory area accessible both from userspace (at address
__builtin_thread_pointer() + __rseq_offset) and from kernel's
return-to-userspace rseq notification code (which can handle page
faults) ?
This way, the kernel can update its content when returning to userspace
if an update is needed since the last update.
Would that be sufficient as prng seed for your security requirements ?
Implementation-wise, the semantic of the prng_seed could be entirely
internal to a vgetrandom vDSO implementation, but the allocation of the
memory holding this seed would be the responsibility of libc.
libc could query the size required by the kernel for this prng seed with
a new getauxval(3) entry, e.g. AT_RSEQ_PRNG_SIZE. By doing so, libc
would only allocate as much memory as needed by the kernel vDSO
implementation.
This would remove the need for any kind of vgetrandom_alloc system call
and all its associated complexity.
Thoughts ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
prev parent reply other threads:[~2023-01-11 22:23 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-01 16:29 [PATCH v14 0/7] implement getrandom() in vDSO Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 1/7] x86: lib: Separate instruction decoder MMIO type from MMIO trace Jason A. Donenfeld
2023-01-03 10:32 ` Ingo Molnar
2023-01-03 14:51 ` Jason A. Donenfeld
2023-01-03 17:00 ` Ingo Molnar
2023-01-03 17:29 ` Borislav Petkov
2023-01-03 17:30 ` Jason A. Donenfeld
2023-01-03 17:47 ` Ingo Molnar
2023-01-03 17:48 ` Jason A. Donenfeld
2023-01-04 20:25 ` Ingo Molnar
2023-01-04 20:29 ` Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 2/7] mm: add VM_DROPPABLE for designating always lazily freeable mappings Jason A. Donenfeld
2023-01-03 10:50 ` Ingo Molnar
2023-01-03 15:01 ` Jason A. Donenfeld
2023-01-03 18:15 ` Ingo Molnar
2023-01-03 18:51 ` Jason A. Donenfeld
2023-01-03 18:36 ` Andy Lutomirski
2023-01-03 19:05 ` Jason A. Donenfeld
2023-01-03 20:52 ` Andy Lutomirski
2023-01-03 19:19 ` Linus Torvalds
2023-01-03 19:35 ` Jason A. Donenfeld
2023-01-03 19:54 ` Linus Torvalds
2023-01-03 20:03 ` Jason A. Donenfeld
2023-01-03 20:15 ` Linus Torvalds
2023-01-03 20:25 ` Linus Torvalds
2023-01-03 20:44 ` Jason A. Donenfeld
2023-01-05 21:57 ` Yann Droneaud
2023-01-05 22:57 ` Jason A. Donenfeld
2023-01-06 1:02 ` Linus Torvalds
2023-01-06 2:08 ` Linus Torvalds
2023-01-06 2:42 ` Jason A. Donenfeld
2023-01-06 20:53 ` Andy Lutomirski
2023-01-06 21:10 ` Linus Torvalds
2023-01-10 11:01 ` Dr. Greg
2023-01-06 21:36 ` Jason A. Donenfeld
2023-01-06 21:42 ` Matthew Wilcox
2023-01-06 22:06 ` Linus Torvalds
2023-01-06 2:14 ` Jason A. Donenfeld
2023-01-09 10:34 ` Florian Weimer
2023-01-09 14:28 ` Linus Torvalds
2023-01-11 7:27 ` Eric Biggers
2023-01-11 12:07 ` Linus Torvalds
2023-01-01 16:29 ` [PATCH v14 3/7] x86: mm: Skip faulting instruction for VM_DROPPABLE faults Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 4/7] random: add vgetrandom_alloc() syscall Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 5/7] arch: allocate vgetrandom_alloc() syscall number Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 6/7] random: introduce generic vDSO getrandom() implementation Jason A. Donenfeld
2023-01-01 16:29 ` [PATCH v14 7/7] x86: vdso: Wire up getrandom() vDSO implementation Jason A. Donenfeld
2023-01-12 17:27 ` Christophe Leroy
2023-01-12 17:49 ` Jason A. Donenfeld
2023-01-11 22:23 ` Mathieu Desnoyers [this message]
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=Y782/D2WZJRR8SHY@localhost \
--to=mathieu.desnoyers@efficios.com \
--cc=Jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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).