From e96ef3c831fef685cacc0422a7a59782c41f8288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vivek=20Das=C2=A0Mohapatra?= <vivek@collabora.co.uk> Date: Wed, 24 May 2017 18:33:12 +0100 Subject: [PATCH] capsule-dlmopen.c: add some debug output to ELF DSO type checking Dump out the class (ELFCLASS32 vs ELFCLASS64) and the machine (eg EM_386 vs EM_X86_64) of candidate DSOs. This matters when the target file tree is multi-arch, anc can contaim different classes and machines. x86 hardware typically has 3: ELFCLASS32/EM_386 - old school i[3456]86 binary ELFCLASS64/EM_X86_64 - straightforward x86-64 binary ELFCLASS32/EM_X86_64 - x32 (32 bit word size using x86-64 registers) But we don't want to open any that don't match the category we actually are. --- capsule/capsule-dlmopen.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/capsule/capsule-dlmopen.c b/capsule/capsule-dlmopen.c index dab375ed8..49da62c89 100644 --- a/capsule/capsule-dlmopen.c +++ b/capsule/capsule-dlmopen.c @@ -289,13 +289,16 @@ static int check_elf_constraints (ldlibs_t *ldlibs, int idx) { GElf_Ehdr ehdr = {}; + int eclass; // bogus ELF DSO - no ehdr available? if( !gelf_getehdr( ldlibs->needed[ 0 ].dso, &ehdr ) ) return 0; + eclass = gelf_getclass( ldlibs->needed[ idx ].dso ); + // check class (32 vs 64 bit) - if( ldlibs->elf_class != gelf_getclass( ldlibs->needed[ idx ].dso ) ) + if( ldlibs->elf_class != eclass ) return 0; // check target architecture (i386, x86-64) @@ -303,6 +306,11 @@ check_elf_constraints (ldlibs_t *ldlibs, int idx) if( ldlibs->elf_machine != ehdr.e_machine ) return 0; + DEBUG( DEBUG_ELF, "constraints: class %d; machine: %d;", + ldlibs->elf_class, ldlibs->elf_machine ); + DEBUG( DEBUG_ELF, "results : class %d; machine: %d;", + eclass, ehdr.e_machine ); + // both the class (word size) and machine (architecture) match return 1; } -- GitLab