selftests/vDSO: prevent SIGFPE if vdso_info.nbucket is zero
Subsystems (2)
PATCH 1/2 selftests/vDSO: prevent SIGFPE if vdso_info.nbucket is zero
If vdso_info can't be parsed correctly, vdso_info.nbucket might contain zero. Add a check and return NULL which will fail the symbol lookup.
Signed-off-by Sven Schnelle <[email protected]>
--- tools/testing/selftests/vDSO/parse_vdso.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/vDSO/parse_vdso.c +3 -0
@@ -226,6 +226,9 @@ void *vdso_sym(const char *version, const char *name)return 0 ; ver_hash =elf_hash (version); +if (!vdso_info.nbucket) +return NULL ; +ELF (Word) chain = vdso_info.bucket[elf_hash (name) % vdso_info.nbucket];for (; chain !=STN_UNDEF ; chain = vdso_info.chain[chain]) {
Signature · 1 line
2.17.1
PATCH 2/2 selftests/vDSO: make vDSO test work on s390x
s390x used 8 byte (Elf64_Xword) sized hash table entries. Add some code to the vdso test to handle that properly.
Signed-off-by Sven Schnelle <[email protected]>
--- tools/testing/selftests/vDSO/parse_vdso.c | 14 ++++++++++---- tools/testing/selftests/vDSO/vdso_test.c | 11 +++++++---- 2 files changed, 17 insertions(+), 8 deletions(-)
tools/testing/selftests/vDSO/parse_vdso.c +10 -4
@@ -58,6 +58,12 @@ extern void *vdso_sym(const char *version, const char *name);#define ELF_BITS_XFORM (bits, x) ELF_BITS_XFORM2(bits, x)#define ELF (x) ELF_BITS_XFORM(ELF_BITS, x) +#if defined(__s390x__) +#define ELF_HASH_TYPE ELF(Xword) +#else +#define ELF_HASH_TYPE ELF(Word) +#endif + static struct vdso_info { bool valid;
@@ -69,8 +75,8 @@ static struct vdso_info/* Symbol table */ ELF (Sym) *symtab;const char *symstrings; -ELF (Word) *bucket, *chain; -ELF (Word) nbucket, nchain; +ELF_HASH_TYPE *bucket, *chain; +ELF_HASH_TYPE nbucket, nchain;/* Version table */ ELF (Versym) *versym;
@@ -131,7 +137,7 @@ void vdso_init_from_sysinfo_ehdr(uintptr_t base)/* * Fish out the useful bits of the dynamic table. */ -ELF (Word) *hash =0 ; +ELF_HASH_TYPE *hash =0 ; vdso_info.symstrings =0 ; vdso_info.symtab =0 ; vdso_info.versym =0 ;
@@ -149,7 +155,7 @@ void vdso_init_from_sysinfo_ehdr(uintptr_t base) + vdso_info.load_offset);break ;case DT_HASH : - hash = (ELF (Word) *) + hash = (ELF_HASH_TYPE *) ((uintptr_t )dyn[i].d_un.d_ptr + vdso_info.load_offset);break ;
tools/testing/selftests/vDSO/vdso_test.c +7 -4
@@ -22,11 +22,14 @@ extern void vdso_init_from_sysinfo_ehdr(uintptr_t base);extern void vdso_init_from_auxv (void *auxv);/* -* ARM64's vDSO exports its gettimeofday() implementation with a different -* name and version from other architectures, so we need to handle it as -* a special case. +* Both ARM64's and s390x' vDSO exports its gettimeofday() implementation +* with a different name and version from other architectures, so we need +* to handle them as a special case. */ -#if defined(__aarch64__) +#if defined(__s390x__) +const char *version ="LINUX_2.6.29" ; +const char *name ="__kernel_gettimeofday" ; +#elif defined(__aarch64__)const char *version ="LINUX_2.6.39" ;const char *name ="__kernel_gettimeofday" ;#else
Signature · 1 line
2.17.1
Re: [PATCH 2/2] selftests/vDSO: make vDSO test work on s390x
Quoted 2 lines · Sven Schnelle
s390x used 8 byte (
Elf64_Xword) sized hash table entries. Add some code to the vdso test to handle that properly.
Ping?
Quoted 78 lines
Signed-off-by Sven Schnelle <[email protected]>--- tools/testing/selftests/vDSO/parse_vdso.c | 14 ++++++++++---- tools/testing/selftests/vDSO/vdso_test.c | 11 +++++++---- 2 files changed, 17 insertions(+), 8 deletions(-)tools/testing/selftests/vDSO/parse_vdso.c +10
-4@@ -58,6 +58,12 @@ extern void *vdso_sym(const char *version, const char *name);#define ELF_BITS_XFORM (bits, x) ELF_BITS_XFORM2(bits, x)#define ELF (x) ELF_BITS_XFORM(ELF_BITS, x) +#if defined(__s390x__) +#define ELF_HASH_TYPE ELF(Xword) +#else +#define ELF_HASH_TYPE ELF(Word) +#endif + static struct vdso_info { bool valid;@@ -69,8 +75,8 @@ static struct vdso_info/* Symbol table */ ELF (Sym) *symtab;const char *symstrings; -ELF (Word) *bucket, *chain; -ELF (Word) nbucket, nchain; +ELF_HASH_TYPE *bucket, *chain; +ELF_HASH_TYPE nbucket, nchain;/* Version table */ ELF (Versym) *versym;@@ -131,7 +137,7 @@ void vdso_init_from_sysinfo_ehdr(uintptr_t base)/* * Fish out the useful bits of the dynamic table. */ -ELF (Word) *hash =0 ; +ELF_HASH_TYPE *hash =0 ; vdso_info.symstrings =0 ; vdso_info.symtab =0 ; vdso_info.versym =0 ;@@ -149,7 +155,7 @@ void vdso_init_from_sysinfo_ehdr(uintptr_t base) + vdso_info.load_offset);break ;case DT_HASH : - hash = (ELF (Word) *) + hash = (ELF_HASH_TYPE *) ((uintptr_t )dyn[i].d_un.d_ptr + vdso_info.load_offset);break ;tools/testing/selftests/vDSO/vdso_test.c +7
-4@@ -22,11 +22,14 @@ extern void vdso_init_from_sysinfo_ehdr(uintptr_t base);extern void vdso_init_from_auxv (void *auxv);/* -* ARM64's vDSO exports its gettimeofday() implementation with a different -* name and version from other architectures, so we need to handle it as -* a special case. +* Both ARM64's and s390x' vDSO exports its gettimeofday() implementation +* with a different name and version from other architectures, so we need +* to handle them as a special case. */ -#if defined(__aarch64__) +#if defined(__s390x__) +const char *version ="LINUX_2.6.29" ; +const char *name ="__kernel_gettimeofday" ; +#elif defined(__aarch64__)const char *version ="LINUX_2.6.39" ;const char *name ="__kernel_gettimeofday" ;#else Signature · 1 line
2.17.1
Quoted 3 lines · Sven Schnelle
If
vdso_infocan't be parsed correctly, vdso_info.nbucket might contain zero. Add a check and return NULL which will fail the symbol lookup.
Ping?
Quoted 23 lines
Signed-off-by Sven Schnelle <[email protected]>--- tools/testing/selftests/vDSO/parse_vdso.c | 3 +++ 1 file changed, 3 insertions(+)tools/testing/selftests/vDSO/parse_vdso.c +3
-0@@ -226,6 +226,9 @@ void *vdso_sym(const char *version, const char *name)return 0 ; ver_hash =elf_hash (version); +if (!vdso_info.nbucket) +return NULL ; +ELF (Word) chain = vdso_info.bucket[elf_hash (name) % vdso_info.nbucket];for (; chain !=STN_UNDEF ; chain = vdso_info.chain[chain]) {Signature · 1 line
2.17.1