[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3l9MXCO02/rOpFx@zx2c4.com>
Date: Sun, 20 Nov 2022 02:04:49 +0100
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: Eric Biggers <ebiggers@...nel.org>
Cc: linux-kernel@...r.kernel.org, patches@...ts.linux.dev,
linux-crypto@...r.kernel.org, x86@...nel.org,
Thomas Gleixner <tglx@...utronix.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Adhemerval Zanella Netto <adhemerval.zanella@...aro.org>,
Carlos O'Donell <carlos@...hat.com>
Subject: Re: [PATCH v5 2/3] random: introduce generic vDSO getrandom()
implementation
On Sun, Nov 20, 2022 at 01:53:53AM +0100, Jason A. Donenfeld wrote:
> I'm not quite sure what the best approach here is. One idea would be to
> just note that libcs should wait until vgetrandom() has returned
> everywhere before forking, using its atfork functionality.
To elaborate on this idea a bit, the way this looks is:
rwlock_t l;
pid_t fork(void)
{
pid_t pid;
write_lock(&l);
pid = syscall_fork();
write_unlock(&l);
return pid;
}
ssize_t getrandom(...)
{
ssize_t ret;
...
if (!read_try_lock(&l))
return syscall_getrandom(...);
ret = vdso_getrandom(...);
read_unlock(&l);
return ret;
}
So maybe that doesn't seem that bad, especially considering libc already
has the kind of infrastructure in place to do that somewhat easily.
Maybe there's a priority locking thing to get right here -- the writer
should immediately starve out all future readers, so it's not unbound --
but that seems par for the course.
Jason
Powered by blists - more mailing lists