Skip to content

Commit 28f5df2

Browse files
ydroneaudzx2c4
authored andcommitted
random: vDSO: reject unknown getrandom() flags
Like the getrandom() syscall, vDSO getrandom() must also reject unknown flags. [1] It would be possible to return -EINVAL from vDSO itself, but in the possible case that a new flag is added to getrandom() syscall in the future, it would be easier to get the behavior from the syscall, instead of erroring until the vDSO is extended to support the new flag or explicitly falling back. [1] Designing the API: Planning for Extension https://docs.kernel.org/process/adding-syscalls.html#designing-the-api-planning-for-extension Signed-off-by: Yann Droneaud <yann@droneaud.fr> [Jason: reworded commit message] Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent dc1c803 commit 28f5df2

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/vdso/getrandom.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_
8585
if (unlikely(((unsigned long)opaque_state & ~PAGE_MASK) + sizeof(*state) > PAGE_SIZE))
8686
return -EFAULT;
8787

88+
/* Handle unexpected flags by falling back to the kernel. */
89+
if (unlikely(flags & ~(GRND_NONBLOCK | GRND_RANDOM | GRND_INSECURE)))
90+
goto fallback_syscall;
91+
8892
/* If the caller passes the wrong size, which might happen due to CRIU, fallback. */
8993
if (unlikely(opaque_len != sizeof(*state)))
9094
goto fallback_syscall;

0 commit comments

Comments
 (0)