-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86: vdso: Wire up getrandom() vDSO implementation
Hook up the generic vDSO implementation to the x86 vDSO data page. Since the existing vDSO infrastructure is heavily based on the timekeeping functionality, which works over arrays of bases, a new macro is introduced for vvars that are not arrays. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
- Loading branch information
Showing
7 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (C) 2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
*/ | ||
#include <linux/kernel.h> | ||
#include <linux/types.h> | ||
|
||
#include "../../../../lib/vdso/getrandom.c" | ||
|
||
ssize_t __vdso_getrandom(void *buffer, size_t len, unsigned int flags, void *state) | ||
{ | ||
return __cvdso_getrandom(buffer, len, flags, state); | ||
} | ||
|
||
ssize_t getrandom(void *, size_t, unsigned int, void *) | ||
__attribute__((weak, alias("__vdso_getrandom"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (C) 2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
*/ | ||
#ifndef __ASM_VDSO_GETRANDOM_H | ||
#define __ASM_VDSO_GETRANDOM_H | ||
|
||
#ifndef __ASSEMBLY__ | ||
|
||
#include <asm/unistd.h> | ||
#include <asm/vvar.h> | ||
|
||
static __always_inline ssize_t | ||
getrandom_syscall(void *buffer, size_t len, unsigned int flags) | ||
{ | ||
long ret; | ||
|
||
asm ("syscall" : "=a" (ret) : | ||
"0" (__NR_getrandom), "D" (buffer), "S" (len), "d" (flags) : | ||
"rcx", "r11", "memory"); | ||
|
||
return ret; | ||
} | ||
|
||
#define __vdso_rng_data (VVAR(_vdso_rng_data)) | ||
|
||
static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(void) | ||
{ | ||
if (__vdso_data->clock_mode == VDSO_CLOCKMODE_TIMENS) | ||
return (void *)&__vdso_rng_data + | ||
((void *)&__timens_vdso_data - (void *)&__vdso_data); | ||
return &__vdso_rng_data; | ||
} | ||
|
||
#endif /* !__ASSEMBLY__ */ | ||
|
||
#endif /* __ASM_VDSO_GETRANDOM_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters