From patchwork Wed Sep 19 06:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10605385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BCE15A4 for ; Wed, 19 Sep 2018 06:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0809B2B41C for ; Wed, 19 Sep 2018 06:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F046A2B45B; Wed, 19 Sep 2018 06:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 445822B41C for ; Wed, 19 Sep 2018 06:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=QJGgGipgeY2DrvCYDE95ngETyWYjdDXbCf5zlyOaPBw=; b=IAyKKLti/gnMJwmIWIYQpPNUb7 0JHsPdcvN8zmZTN7+Hmc8OPK/oh9xs6r07YishmrGxM732OM7RzU7MtDhpMOODDlNclAvsSM+1mZh 0h3Vuv9tCDUYuQyEF1AYa0AgFfQnW08ENUdiu1aaIhGQ5A/vXZ0ce80ypBlJjHp8i9LG2yF5vWLjO dxZY3bde54e7oefI8x7S7fy5tepN6GJjBNXR2yLVraG9Dw0idp1Fwq7KwgSVU1l4URjLt2C41RVga /h7f+81ERMKYvcgTueLW4TOgtq2pYvt5uY6vXbKhrgrg7O0/ee9OErBTEhk+tLxWoWrYDqTkMMgEb fEpObaaA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2WON-0003HK-N9; Wed, 19 Sep 2018 06:55:19 +0000 Received: from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2WLj-0001aj-A2 for linux-arm-kernel@lists.infradead.org; Wed, 19 Sep 2018 06:52:58 +0000 Received: by mail-it0-x243.google.com with SMTP id e14-v6so6858434itf.1 for ; Tue, 18 Sep 2018 23:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vjlNGgKK+hdQ2oIOvWFpRpQO96t5oT9NlwIzOhMdM8o=; b=DhDtIlRo84pAR/lLfZZdTtSpY4IbWrE2M7Q3fbmY0W8iqGZiJJMONls0dIy7dmO7yE VpiQJ9v47+5DZd1eceatrZ7qN+PeX+XwJhjOIasK6oYUVfSk2VmSzZffnSJbDgZ302fQ 3dX12Q4QmLBeuTPo7bvGVMxg5fjcnMLlZmt1I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vjlNGgKK+hdQ2oIOvWFpRpQO96t5oT9NlwIzOhMdM8o=; b=RGE+tVuiipyulsVeZAM5j3SISoIeTtyvLdB46dFT/U47WUFycTFr6CVdhLCOy6zu1g 2Q9eRQh0CHCXTz76wrxfVS9JYeOKKLw3NZdnt9WPB1A2wxDnnbnt2e2F9k7BsRMLNRrs +0uxkRJwlwYqAy3SnLHcIEwVvlmGyTSYXuTM+PX5Laa/uoO6RLqS47ARGHPR0sQvT3jw uMw9AlnmiDdDgELvXl861hbML6fQbBjxZG44B9p3aIpf1pNHVSsU1+/DybQ3wGaNWhYA iH73RWJmoX3tSNa9Kj32xHaQLla3qtWg6rWtAiLA5dlDilAf2JWjt2WR1pqQXVCG7TgZ 0fAA== X-Gm-Message-State: APzg51DQLxEzda8uUAKpChHde6VniC9ZpfEEDsX2hoBLiIT4jub4zDkO m5X3Ut44u3Savi6OCX+IVyfOQw== X-Google-Smtp-Source: ANB0VdZWATphTVUC1+4j99sUxsajCdozbe7MZlE824KEJq2nWkZ2xrHiXZt4gPP7GQ6W6ipwFJV7ZA== X-Received: by 2002:a24:4a83:: with SMTP id k125-v6mr19923669itb.121.1537339944194; Tue, 18 Sep 2018 23:52:24 -0700 (PDT) Received: from localhost.localdomain ([209.82.80.116]) by smtp.gmail.com with ESMTPSA id x68-v6sm7939477ita.2.2018.09.18.23.52.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 23:52:23 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH v3 4/9] x86: add support for 64-bit place relative relocations Date: Tue, 18 Sep 2018 23:51:39 -0700 Message-Id: <20180919065144.25010-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180919065144.25010-1-ard.biesheuvel@linaro.org> References: <20180919065144.25010-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180918_235235_406914_10777AE8 X-CRM114-Status: GOOD ( 16.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, Kees Cook , Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Will Deacon , Jessica Yu , Heiko Carstens , Steven Rostedt , Ingo Molnar , Catalin Marinas , Martin Schwidefsky , Thomas Gleixner , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for R_X86_64_PC64 relocations, which operate on 64-bit quantities holding a relative symbol reference. Also remove the definition of R_X86_64_NUM: given that it is currently unused, it is unclear what the new value should be. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/elf.h | 3 +-- arch/x86/kernel/module.c | 6 ++++++ arch/x86/tools/relocs.c | 10 ++++++++++ arch/x86/um/asm/elf.h | 3 +-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 0d157d2a1e2a..a357031d85b5 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -62,8 +62,7 @@ typedef struct user_fxsr_struct elf_fpxregset_t; #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ #define R_X86_64_8 14 /* Direct 8 bit sign extended */ #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ - -#define R_X86_64_NUM 16 +#define R_X86_64_PC64 24 /* Place relative 64-bit signed */ /* * These are used to set parameters in the core dumps. diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index f58336af095c..b052e883dd8c 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -201,6 +201,12 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, goto overflow; #endif break; + case R_X86_64_PC64: + if (*(u64 *)loc != 0) + goto invalid_relocation; + val -= (u64)loc; + *(u64 *)loc = val; + break; default: pr_err("%s: Unknown rela relocation: %llu\n", me->name, ELF64_R_TYPE(rel[i].r_info)); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 3a6c8ebc8032..0b08067c45f3 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -196,6 +196,7 @@ static const char *rel_type(unsigned type) #if ELF_BITS == 64 REL_TYPE(R_X86_64_NONE), REL_TYPE(R_X86_64_64), + REL_TYPE(R_X86_64_PC64), REL_TYPE(R_X86_64_PC32), REL_TYPE(R_X86_64_GOT32), REL_TYPE(R_X86_64_PLT32), @@ -782,6 +783,15 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, add_reloc(&relocs32neg, offset); break; + case R_X86_64_PC64: + /* + * Only used by jump labels + */ + if (is_percpu_sym(sym, symname)) + die("Invalid R_X86_64_PC64 relocation against per-CPU symbol %s\n", + symname); + break; + case R_X86_64_32: case R_X86_64_32S: case R_X86_64_64: diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h index 548197212a45..413f3519d9a1 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -116,8 +116,7 @@ do { \ #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ #define R_X86_64_8 14 /* Direct 8 bit sign extended */ #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ - -#define R_X86_64_NUM 16 +#define R_X86_64_PC64 24 /* Place relative 64-bit signed */ /* * This is used to ensure we don't load something for the wrong architecture.