diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2024-08-29 03:59:18 +0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2024-08-29 03:59:18 +0200 |
commit | d5d547aa7b51467b15d9caa86b116f8c2507c72a (patch) | |
tree | 25d113e17cdc4cb6ae0ce061f02a22e3d834d3a8 /lib | |
parent | Merge tag 'loongarch-fixes-6.11-2' of git://git.kernel.org/pub/scm/linux/kern... (diff) | |
parent | random: vDSO: reject unknown getrandom() flags (diff) | |
download | linux-d5d547aa7b51467b15d9caa86b116f8c2507c72a.tar.xz linux-d5d547aa7b51467b15d9caa86b116f8c2507c72a.zip |
Merge tag 'random-6.11-rc6-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random
Pull random number generator fix from Jason Donenfeld:
"Reject invalid flags passed to vgetrandom() in the same way that
getrandom() does, so that the behavior is the same, from Yann.
The flags argument to getrandom() only has a behavioral effect on the
function if the RNG isn't initialized yet, so vgetrandom() falls back
to the syscall in that case. But if the RNG is initialized, all of the
flags behave the same way, so vgetrandom() didn't bother checking
them, and just ignored them entirely.
But that doesn't account for invalid flags passed in, which need to be
rejected so we can use them later"
* tag 'random-6.11-rc6-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random:
random: vDSO: reject unknown getrandom() flags
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vdso/getrandom.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c index b230f0b10832..e1db228bc4f0 100644 --- a/lib/vdso/getrandom.c +++ b/lib/vdso/getrandom.c @@ -85,6 +85,10 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ if (unlikely(((unsigned long)opaque_state & ~PAGE_MASK) + sizeof(*state) > PAGE_SIZE)) return -EFAULT; + /* Handle unexpected flags by falling back to the kernel. */ + if (unlikely(flags & ~(GRND_NONBLOCK | GRND_RANDOM | GRND_INSECURE))) + goto fallback_syscall; + /* If the caller passes the wrong size, which might happen due to CRIU, fallback. */ if (unlikely(opaque_len != sizeof(*state))) goto fallback_syscall; |