2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00

selftests/vDSO: Fix GNU hash table entry size for s390x

Commit 14be4e6f35 ("selftests: vDSO: fix ELF hash table entry size for s390x")
changed the type of the ELF hash table entries to 64bit on s390x.
However the *GNU* hash tables entries are always 32bit.
The "bucket" pointer is shared between both hash algorithms.
On s390, this caused the GNU hash algorithm to access its 32-bit entries as if they
were 64-bit, triggering compiler warnings (assignment between "Elf64_Xword *" and
"Elf64_Word *") and runtime crashes.

Introduce a new dedicated "gnu_bucket" pointer which is used by the GNU hash.

Fixes: e0746bde6f ("selftests/vDSO: support DT_GNU_HASH")
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250217-selftests-vdso-s390-gnu-hash-v2-1-f6c2532ffe2a@linutronix.de
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
This commit is contained in:
Thomas Weißschuh 2025-02-17 14:04:18 +01:00 committed by Vasily Gorbik
parent 5623bc23a1
commit a22ee38d2e

View File

@ -53,7 +53,7 @@ static struct vdso_info
/* Symbol table */ /* Symbol table */
ELF(Sym) *symtab; ELF(Sym) *symtab;
const char *symstrings; const char *symstrings;
ELF(Word) *gnu_hash; ELF(Word) *gnu_hash, *gnu_bucket;
ELF_HASH_ENTRY *bucket, *chain; ELF_HASH_ENTRY *bucket, *chain;
ELF_HASH_ENTRY nbucket, nchain; ELF_HASH_ENTRY nbucket, nchain;
@ -185,7 +185,7 @@ void vdso_init_from_sysinfo_ehdr(uintptr_t base)
/* The bucket array is located after the header (4 uint32) and the bloom /* The bucket array is located after the header (4 uint32) and the bloom
* filter (size_t array of gnu_hash[2] elements). * filter (size_t array of gnu_hash[2] elements).
*/ */
vdso_info.bucket = vdso_info.gnu_hash + 4 + vdso_info.gnu_bucket = vdso_info.gnu_hash + 4 +
sizeof(size_t) / 4 * vdso_info.gnu_hash[2]; sizeof(size_t) / 4 * vdso_info.gnu_hash[2];
} else { } else {
vdso_info.nbucket = hash[0]; vdso_info.nbucket = hash[0];
@ -268,11 +268,11 @@ void *vdso_sym(const char *version, const char *name)
if (vdso_info.gnu_hash) { if (vdso_info.gnu_hash) {
uint32_t h1 = gnu_hash(name), h2, *hashval; uint32_t h1 = gnu_hash(name), h2, *hashval;
i = vdso_info.bucket[h1 % vdso_info.nbucket]; i = vdso_info.gnu_bucket[h1 % vdso_info.nbucket];
if (i == 0) if (i == 0)
return 0; return 0;
h1 |= 1; h1 |= 1;
hashval = vdso_info.bucket + vdso_info.nbucket + hashval = vdso_info.gnu_bucket + vdso_info.nbucket +
(i - vdso_info.gnu_hash[1]); (i - vdso_info.gnu_hash[1]);
for (;; i++) { for (;; i++) {
ELF(Sym) *sym = &vdso_info.symtab[i]; ELF(Sym) *sym = &vdso_info.symtab[i];