Commit e1bbcab4 authored by Christophe Leroy's avatar Christophe Leroy Committed by Jason A. Donenfeld
Browse files

selftests: vDSO: look for arch-specific function name in getrandom test



Don't hard-code x86 specific names. Rather, use vdso_config definitions
to find the correct function matching the architecture.

Add random VDSO function names in names[][]. Remove the #ifdef
CONFIG_VDSO32, as having the name there all the time is harmless and
guaranties a steady index for following strings.

Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
[Jason: add [6] to variable declaration rather than each usage site.]
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
parent f8d92fc5
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -68,16 +68,15 @@ static const char *versions[7] = {
	"LINUX_5.10"
};

static const char *names[2][6] = {
static const char *names[2][7] = {
	{
		"__kernel_gettimeofday",
		"__kernel_clock_gettime",
		"__kernel_time",
		"__kernel_clock_getres",
		"__kernel_getcpu",
#if defined(VDSO_32BIT)
		"__kernel_clock_gettime64",
#endif
		"__kernel_getrandom",
	},
	{
		"__vdso_gettimeofday",
@@ -85,9 +84,8 @@ static const char *names[2][6] = {
		"__vdso_time",
		"__vdso_clock_getres",
		"__vdso_getcpu",
#if defined(VDSO_32BIT)
		"__vdso_clock_gettime64",
#endif
		"__vdso_getrandom",
	},
};

+6 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include "../kselftest.h"
#include "parse_vdso.h"
#include "vdso_config.h"

#ifndef timespecsub
#define	timespecsub(tsp, usp, vsp)					\
@@ -100,15 +101,18 @@ static void vgetrandom_put_state(void *state)

static void vgetrandom_init(void)
{
	const char *version = versions[VDSO_VERSION];
	const char *name = names[VDSO_NAMES][6];
	unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);

	if (!sysinfo_ehdr) {
		printf("AT_SYSINFO_EHDR is not present!\n");
		exit(KSFT_SKIP);
	}
	vdso_init_from_sysinfo_ehdr(sysinfo_ehdr);
	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym("LINUX_2.6", "__vdso_getrandom");
	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
	if (!vgrnd.fn) {
		printf("__vdso_getrandom is missing!\n");
		printf("%s is missing!\n", name);
		exit(KSFT_FAIL);
	}
	if (vgrnd.fn(NULL, 0, 0, &vgrnd.params, ~0UL) != 0) {