Skip to content

Commit b7bad08

Browse files
chleroyzx2c4
authored andcommitted
random: vDSO: avoid call to out of line memset()
With the current implementation, __cvdso_getrandom_data() calls memset() on certain architectures, which is unexpected in the VDSO. Rather than providing a memset(), simply rewrite opaque data initialization to avoid memset(). Signed-off-by: Christophe Leroy <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 81723e3 commit b7bad08

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/vdso/getrandom.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2022-2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
44
*/
55

6+
#include <linux/array_size.h>
67
#include <linux/cache.h>
78
#include <linux/kernel.h>
89
#include <linux/time64.h>
@@ -73,11 +74,12 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_
7374
u32 counter[2] = { 0 };
7475

7576
if (unlikely(opaque_len == ~0UL && !buffer && !len && !flags)) {
76-
*(struct vgetrandom_opaque_params *)opaque_state = (struct vgetrandom_opaque_params) {
77-
.size_of_opaque_state = sizeof(*state),
78-
.mmap_prot = PROT_READ | PROT_WRITE,
79-
.mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS
80-
};
77+
struct vgetrandom_opaque_params *params = opaque_state;
78+
params->size_of_opaque_state = sizeof(*state);
79+
params->mmap_prot = PROT_READ | PROT_WRITE;
80+
params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS;
81+
for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i)
82+
params->reserved[i] = 0;
8183
return 0;
8284
}
8385

0 commit comments

Comments
 (0)