From patchwork Thu Jul 22 13:22:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Isaev X-Patchwork-Id: 1508738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=l3NUpepX; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=A1XyC5nQ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GVtmy5V7Fz9sW5 for ; Thu, 22 Jul 2021 23:37:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=474ghdufVOgaUuyKxp0Tg8BjKqOGAIdgEIOsTnF9G5Y=; b=l3NUpepX87ta2R YgE0uaN1GBUi+8zxbGDkN/f4kAO4ti7o/d0mwMDfuzLVfPHQYGko1g72fSP7mwomhxZbqZGOUCfF9 FaeJ5XNOONhq0wlVbYgrEPhoBy4rce7gg8tfpqXDJO4TIRnXxb+vwRyGgDVrAQNn+4HPBwu6BbYo0 RBOC0JwU2dr7TbsKyjDWYOLPtepcEkepvo4c5lASv83wmjMLm2cEMwjrvdEg+T88Xgl6plMgpg8/Q 4290VUXe+SWJpNWDU3zg4LVXWtpxq82d11qqoSzitdyuIY5sOLEHx7HsVqb2jh6VwLdBmtOt2Z68T 8SSHfUZ/z4RlUET/x0vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Ytb-001hb2-Ti; Thu, 22 Jul 2021 13:37:51 +0000 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Yet-001duz-M2 for linux-snps-arc@lists.infradead.org; Thu, 22 Jul 2021 13:22:41 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A2D6A407CD; Thu, 22 Jul 2021 13:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1626960155; bh=unEHu/ZH5lIfTBmPdNJpMXwLTKglW367knbk584tfVw=; h=From:To:Cc:Subject:Date:From; b=A1XyC5nQ4zkEo6rkd9Nx7x8DxDu4IcnObjdZ3F7K9PfvSGm+d/KW/C5bi1R7eJ0fx FAgsQ+G4QTPgXmwVUYSWjzSOWjSoWvI8qkgrLZYP0rAfAPGvhLGHTs8lwkVO7SQuF3 DGLkZDLQ1atuOp2zqj62k2/TJ0iJTO2s1LhhZ/AIZGRAQXfvVIfeh5dOY6zpJLeHjl hcMWWrfjFDEiK5bue/at+6eQ4/+bd9apLQSi0+Kek4bByoiFnNVZ0onuJmbXWQZ/25 PnaCM1bpMRUt1vm/I/8C9L3rec5CT8qVOiDZnKmXkq/hKJ2zcX+wF0eoeFIXViZZXL J7AMeZQ9zTRFw== Received: from isaev-debian.internal.synopsys.com (unknown [10.121.15.30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 70EBEA005D; Thu, 22 Jul 2021 13:22:31 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Vladimir Isaev To: libc-alpha@sourceware.org Cc: linux-snps-arc@lists.infradead.org, Vladimir Isaev , Cupertino Miranda , Vineet Gupta Subject: [PATCH] elf: _dl_fixup*: make @reloc_arg 64-bit safe Date: Thu, 22 Jul 2021 16:22:00 +0300 Message-Id: <20210722132200.43895-1-isaev@synopsys.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210722_062239_795503_8396BD48 X-CRM114-Status: GOOD ( 13.70 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This came up during arc64 glibc bringup on qemu usermode. On ARC, lazy rezolver calls _dl_fixup() with 2nd argument as PC of the PLT entry beiing fixed up. Thus this needs to be full 64-bit value for arc64, however _dl_fixup() defines @reloc_arg as ElfW(Word [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [149.117.73.133 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This came up during arc64 glibc bringup on qemu usermode. On ARC, lazy rezolver calls _dl_fixup() with 2nd argument as PC of the PLT entry beiing fixed up. Thus this needs to be full 64-bit value for arc64, however _dl_fixup() defines @reloc_arg as ElfW(Word) which maps to Elf64_Word -> uint32_t causing gcc to truncate the value to 32-bits. This problem show on 64-bit ARC and not other arches likely due to the semantics of @reloc_arg. On ARC it is the runtime PC of PLT entry whereas for others it might be the index or something similar which doesn't need more than 32-bits. Reported-by: Cupertino Miranda Signed-off-by: Vladimir Isaev Signed-off-by: Vineet Gupta --- elf/dl-runtime.c | 6 +++--- sysdeps/hppa/dl-fptr.c | 2 +- sysdeps/i386/dl-machine.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index 9d0d941000..6099a44ffb 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -56,7 +56,7 @@ _dl_fixup ( # ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS ELF_MACHINE_RUNTIME_FIXUP_ARGS, # endif - struct link_map *l, ElfW(Word) reloc_arg) + struct link_map *l, uintptr_t reloc_arg) { const ElfW(Sym) *const symtab = (const void *) D_PTR (l, l_info[DT_SYMTAB]); @@ -152,7 +152,7 @@ _dl_profile_fixup ( #ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS ELF_MACHINE_RUNTIME_FIXUP_ARGS, #endif - struct link_map *l, ElfW(Word) reloc_arg, + struct link_map *l, uintptr_t reloc_arg, ElfW(Addr) retaddr, void *regs, long int *framesizep) { void (*mcount_fct) (ElfW(Addr), ElfW(Addr)) = _dl_mcount; @@ -484,7 +484,7 @@ _dl_profile_fixup ( #include void ARCH_FIXUP_ATTRIBUTE -_dl_call_pltexit (struct link_map *l, ElfW(Word) reloc_arg, +_dl_call_pltexit (struct link_map *l, uintptr_t reloc_arg, const void *inregs, void *outregs) { #ifdef SHARED diff --git a/sysdeps/hppa/dl-fptr.c b/sysdeps/hppa/dl-fptr.c index 62ef68b62b..bcab1bf100 100644 --- a/sysdeps/hppa/dl-fptr.c +++ b/sysdeps/hppa/dl-fptr.c @@ -321,7 +321,7 @@ _dl_unmap (struct link_map *map) map->l_mach.fptr_table = NULL; } -extern ElfW(Addr) _dl_fixup (struct link_map *, ElfW(Word)) attribute_hidden; +extern ElfW(Addr) _dl_fixup (struct link_map *, uintptr_t) attribute_hidden; static inline Elf32_Addr elf_machine_resolve (void) diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 590b41d8d7..8f73e0efda 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -130,10 +130,10 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused)) extern ElfW(Addr) _dl_fixup (struct link_map *l, - ElfW(Word) reloc_offset) + uintptr_t reloc_offset) ARCH_FIXUP_ATTRIBUTE; extern ElfW(Addr) _dl_profile_fixup (struct link_map *l, - ElfW(Word) reloc_offset, + uintptr_t reloc_offset, ElfW(Addr) retaddr, void *regs, long int *framesizep) ARCH_FIXUP_ATTRIBUTE;