From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6ECBCA9EAF for ; Sun, 27 Oct 2019 21:27:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70E75205C9 for ; Sun, 27 Oct 2019 21:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211668; bh=haQrs3c9WFi14yzGlsrMHFdxnYCKCu3FeZbrAxy876Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GddA2xtLpms0sd71N1+WrViAcFuOTcilxH98HwoIngc04x5H7IMCSs/Kud9AAw7DM iMFjTYzH94qgEniXQ9rHiY/pdxlNT1LZmkn0I7OJIFOda5f8bIMtML6fdnm89y4z2t VZ1UMQotCiFTE4TUj3ZXwqZBWvg8PZNA2oKv0l1Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730810AbfJ0V1r (ORCPT ); Sun, 27 Oct 2019 17:27:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:45920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730777AbfJ0VYU (ORCPT ); Sun, 27 Oct 2019 17:24:20 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB76921726; Sun, 27 Oct 2019 21:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211459; bh=haQrs3c9WFi14yzGlsrMHFdxnYCKCu3FeZbrAxy876Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HPaQt6UMM9v8UDLdDsuRAIaX7bshgDYOJkAWijrgTWRe6njG7rrKANik/tJGstWs/ jc40jMRSU0jFSsCHob0+vDfYZoQy/qqIBYwYvc1fghaU73WuFq1UTsm0UAubczwaRc PeFEQAXoGINq1pgEt1/z1rmYILdZDS8/IE42s/Ow= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heiko Carstens , Gerald Schaefer , Vasily Gorbik Subject: [PATCH 5.3 159/197] s390/kaslr: add support for R_390_GLOB_DAT relocation type Date: Sun, 27 Oct 2019 22:01:17 +0100 Message-Id: <20191027203400.264805187@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gerald Schaefer commit ac49303d9ef0ad98b79867a380ef23480e48870b upstream. Commit "bpf: Process in-kernel BTF" in linux-next introduced an undefined __weak symbol, which results in an R_390_GLOB_DAT relocation type. That is not yet handled by the KASLR relocation code, and the kernel stops with the message "Unknown relocation type". Add code to detect and handle R_390_GLOB_DAT relocation types and undefined symbols. Fixes: 805bc0bc238f ("s390/kernel: build a relocatable kernel") Cc: # v5.2+ Acked-by: Heiko Carstens Signed-off-by: Gerald Schaefer Signed-off-by: Vasily Gorbik Signed-off-by: Greg Kroah-Hartman --- arch/s390/boot/startup.c | 14 +++++++++++--- arch/s390/kernel/machine_kexec_reloc.c | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) --- a/arch/s390/boot/startup.c +++ b/arch/s390/boot/startup.c @@ -101,10 +101,18 @@ static void handle_relocs(unsigned long dynsym = (Elf64_Sym *) vmlinux.dynsym_start; for (rela = rela_start; rela < rela_end; rela++) { loc = rela->r_offset + offset; - val = rela->r_addend + offset; + val = rela->r_addend; r_sym = ELF64_R_SYM(rela->r_info); - if (r_sym) - val += dynsym[r_sym].st_value; + if (r_sym) { + if (dynsym[r_sym].st_shndx != SHN_UNDEF) + val += dynsym[r_sym].st_value + offset; + } else { + /* + * 0 == undefined symbol table index (STN_UNDEF), + * used for R_390_RELATIVE, only add KASLR offset + */ + val += offset; + } r_type = ELF64_R_TYPE(rela->r_info); rc = arch_kexec_do_relocs(r_type, (void *) loc, val, 0); if (rc) --- a/arch/s390/kernel/machine_kexec_reloc.c +++ b/arch/s390/kernel/machine_kexec_reloc.c @@ -27,6 +27,7 @@ int arch_kexec_do_relocs(int r_type, voi *(u32 *)loc = val; break; case R_390_64: /* Direct 64 bit. */ + case R_390_GLOB_DAT: *(u64 *)loc = val; break; case R_390_PC16: /* PC relative 16 bit. */