From patchwork Wed Mar 23 00:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 52240 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A9DD3857C42 for ; Wed, 23 Mar 2022 00:27:47 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 9C8753858401 for ; Wed, 23 Mar 2022 00:27:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C8753858401 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x09.wildebeest.org [172.31.17.139]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 7BC5B302FB81; Wed, 23 Mar 2022 01:27:38 +0100 (CET) Received: by reform (Postfix, from userid 1000) id F00EB2E81FF6; Wed, 23 Mar 2022 01:27:37 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] libelf: Correct alignment of ELF_T_GNUHASH data for ELFCLASS64 Date: Wed, 23 Mar 2022 01:27:35 +0100 Message-Id: <20220323002735.208471-1-mark@klomp.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" ELF_T_GNUHASH data is just 32bit words for ELFCLASS32. But for ELFCLASS64 it is a mix of 32bit and 64bit words. In the elf_cvt_gnuhash function we rely on the alignment of the whole to be 64bit word aligned, even though the first 4 words are 32bits. Otherwise we might try to convert an unaligned 64bit word. Signed-off-by: Mark Wielaard --- libelf/ChangeLog | 5 +++++ libelf/elf_getdata.c | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index ea204e2b..5ea1e41e 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2022-03-22 Mark Wielaard + + * elf_getdata.c (__libelf_type_aligns): ELF_T_GNUHASH has different + alignment for ELFCLASS32 and ELFCLASS64. + 2022-03-20 Mark Wielaard * version_xlate.h (elf_cvt_Verdef): Make sure aux_offset and diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c index 475c6ded..a704aae3 100644 --- a/libelf/elf_getdata.c +++ b/libelf/elf_getdata.c @@ -1,5 +1,6 @@ /* Return the next data element from the section after possibly converting it. Copyright (C) 1998-2005, 2006, 2007, 2015, 2016 Red Hat, Inc. + Copyright (C) 2022 Mark J. Wielaard This file is part of elfutils. Written by Ulrich Drepper , 1998. @@ -77,7 +78,6 @@ static const Elf_Type shtype_map[TYPEIDX (SHT_HISUNW) + 1] = const uint_fast8_t __libelf_type_aligns[ELFCLASSNUM - 1][ELF_T_NUM] = { # define TYPE_ALIGNS(Bits) \ - { \ [ELF_T_ADDR] = __alignof__ (ElfW2(Bits,Addr)), \ [ELF_T_EHDR] = __alignof__ (ElfW2(Bits,Ehdr)), \ [ELF_T_HALF] = __alignof__ (ElfW2(Bits,Half)), \ @@ -100,13 +100,17 @@ const uint_fast8_t __libelf_type_aligns[ELFCLASSNUM - 1][ELF_T_NUM] = [ELF_T_MOVE] = __alignof__ (ElfW2(Bits,Move)), \ [ELF_T_LIB] = __alignof__ (ElfW2(Bits,Lib)), \ [ELF_T_NHDR] = __alignof__ (ElfW2(Bits,Nhdr)), \ - [ELF_T_GNUHASH] = __alignof__ (Elf32_Word), \ [ELF_T_AUXV] = __alignof__ (ElfW2(Bits,auxv_t)), \ [ELF_T_CHDR] = __alignof__ (ElfW2(Bits,Chdr)), \ - [ELF_T_NHDR8] = 8 /* Special case for GNU Property note. */ \ - } - [ELFCLASS32 - 1] = TYPE_ALIGNS (32), - [ELFCLASS64 - 1] = TYPE_ALIGNS (64), + [ELF_T_NHDR8] = 8 /* Special case for GNU Property note. */ + [ELFCLASS32 - 1] = { + TYPE_ALIGNS (32), + [ELF_T_GNUHASH] = __alignof__ (Elf32_Word), + }, + [ELFCLASS64 - 1] = { + TYPE_ALIGNS (64), + [ELF_T_GNUHASH] = __alignof__ (Elf64_Xword), + }, # undef TYPE_ALIGNS };