Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1978399pxb; Fri, 5 Mar 2021 04:38:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyClTx/SP05BeQjy2zvUEnk76GLP9z9nKXvMc5MS9uU+0Kf9Gn4NqGCKS0iKhfYi4D5ObhJ X-Received: by 2002:a17:906:d19b:: with SMTP id c27mr1993582ejz.304.1614947888258; Fri, 05 Mar 2021 04:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947888; cv=none; d=google.com; s=arc-20160816; b=YXqAlzG2/8AqSd3FQiXC+E3SyR1bPcWHNQg0AAxGvmQCJH6dVXsII5TMavJts5f7eo nGVvWSiFPrenCEgMu3/LvFP70hXYy4FJ2vc08TpZsA+cdt4jhDd/WOn/+zZ9mMCYouQd N4iomddJ5qpYAwN4DdS6TTfOw8QLO9NmlQXJSa8je8o50d5rgjl/x1aOTJS+WFlal0gA 9q7acfSQ+OvI9pKbeAfHKw/ycopn9hUmxWl9G6fhPIzN+lQtg8xsDAo4LB4QI7mT+gzN C1F3pRPyA+b9xNvswIEMM3Stsomo/cuOcsRK7kpntILF2mrqFmsJQc322aPWqTFXFCrr 9ooQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2jdgp4HnJPdiLS/VVvItPa+P1QRMGP5QHDo/DozZdig=; b=t224fXRL3O2JvSo9OwjwuJVuZXfnxwoF+Cn3eFRdvz3l1gKw2+lowxXEPgPFGL4vxh ZAnVYZ6Pqp9NriaEpojk42iLUlgYUsawD0fXY8Q0DOrawgbWcYoq/fQ893S411E0dB+e iBjxt+y0nQjtu8rKQr/GbEDHE5RGxNnxLApx46C0Es1Kl1ys6cZ4PFowI7aqR4u8/m0v ro9YKHJ0rEXOt2nAa5Oytz7oUXcKmMfpPbx8spaDBsGhT7gZ9u4/NxgQiBvigF3gt2Fr a3qCaZg3pUAWww5Qf/1TotsCeo3UVt0yeYQ338MykmhU9s8PjbMIi8Gr+ek0BpBqRdQK rlkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hqICJ/Ts"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si1353681edd.316.2021.03.05.04.37.43; Fri, 05 Mar 2021 04:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hqICJ/Ts"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232624AbhCEMez (ORCPT + 99 others); Fri, 5 Mar 2021 07:34:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:45650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbhCEMeM (ORCPT ); Fri, 5 Mar 2021 07:34:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 115FA6501A; Fri, 5 Mar 2021 12:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947650; bh=ab743HrExBB7Fs1DpCqWthyMd0Pqm5fAj1cPQ33lqDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hqICJ/TsqrM628hHA5bsapR4lKFLaRChkjNksl3N02xPXZm0UdaA0ZpzsK8SRK0N/ V71oeSzFwWmxVEbmh1bRj7L24gVMSBSDV8/jwpUpNijtKKmM5124518MVnfZQ46fRG ESN+SngGToNsLMlKhiKgbSQ5YXKn7sGtAVAFsHCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Fangrui Song , Borislav Petkov , Nick Desaulniers , Nathan Chancellor , Sedat Dilek , Sasha Levin Subject: [PATCH 5.4 35/72] x86/build: Treat R_386_PLT32 relocation as R_386_PC32 Date: Fri, 5 Mar 2021 13:21:37 +0100 Message-Id: <20210305120859.054503454@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120857.341630346@linuxfoundation.org> References: <20210305120857.341630346@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fangrui Song [ Upstream commit bb73d07148c405c293e576b40af37737faf23a6a ] This is similar to commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32") but for i386. As far as the kernel is concerned, R_386_PLT32 can be treated the same as R_386_PC32. R_386_PLT32/R_X86_64_PLT32 are PC-relative relocation types which can only be used by branches. If the referenced symbol is defined externally, a PLT will be used. R_386_PC32/R_X86_64_PC32 are PC-relative relocation types which can be used by address taking operations and branches. If the referenced symbol is defined externally, a copy relocation/canonical PLT entry will be created in the executable. On x86-64, there is no PIC vs non-PIC PLT distinction and an R_X86_64_PLT32 relocation is produced for both `call/jmp foo` and `call/jmp foo@PLT` with newer (2018) GNU as/LLVM integrated assembler. This avoids canonical PLT entries (st_shndx=0, st_value!=0). On i386, there are 2 types of PLTs, PIC and non-PIC. Currently, the GCC/GNU as convention is to use R_386_PC32 for non-PIC PLT and R_386_PLT32 for PIC PLT. Copy relocations/canonical PLT entries are possible ABI issues but GCC/GNU as will likely keep the status quo because (1) the ABI is legacy (2) the change will drop a GNU ld diagnostic for non-default visibility ifunc in shared objects. clang-12 -fno-pic (since [1]) can emit R_386_PLT32 for compiler generated function declarations, because preventing canonical PLT entries is weighed over the rare ifunc diagnostic. Further info for the more interested: https://github.com/ClangBuiltLinux/linux/issues/1210 https://sourceware.org/bugzilla/show_bug.cgi?id=27169 https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6 [1] [ bp: Massage commit message. ] Reported-by: Arnd Bergmann Signed-off-by: Fangrui Song Signed-off-by: Borislav Petkov Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nick Desaulniers Tested-by: Nathan Chancellor Tested-by: Sedat Dilek Link: https://lkml.kernel.org/r/20210127205600.1227437-1-maskray@google.com Signed-off-by: Sasha Levin --- arch/x86/kernel/module.c | 1 + arch/x86/tools/relocs.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index d5c72cb877b3..77dabedaa9d1 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -114,6 +114,7 @@ int apply_relocate(Elf32_Shdr *sechdrs, *location += sym->st_value; break; case R_386_PC32: + case R_386_PLT32: /* Add the value, subtract its position */ *location += sym->st_value - (uint32_t)location; break; diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index ce7188cbdae5..1c3a1962cade 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -867,9 +867,11 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, case R_386_PC32: case R_386_PC16: case R_386_PC8: + case R_386_PLT32: /* - * NONE can be ignored and PC relative relocations don't - * need to be adjusted. + * NONE can be ignored and PC relative relocations don't need + * to be adjusted. Because sym must be defined, R_386_PLT32 can + * be treated the same way as R_386_PC32. */ break; @@ -910,9 +912,11 @@ static int do_reloc_real(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, case R_386_PC32: case R_386_PC16: case R_386_PC8: + case R_386_PLT32: /* - * NONE can be ignored and PC relative relocations don't - * need to be adjusted. + * NONE can be ignored and PC relative relocations don't need + * to be adjusted. Because sym must be defined, R_386_PLT32 can + * be treated the same way as R_386_PC32. */ break; -- 2.30.1