From patchwork Wed Jan 6 20:08:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 358127 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED 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 CDCDFC433DB for ; Wed, 6 Jan 2021 20:09:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A56123132 for ; Wed, 6 Jan 2021 20:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbhAFUJc (ORCPT ); Wed, 6 Jan 2021 15:09:32 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:25291 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbhAFUJb (ORCPT ); Wed, 6 Jan 2021 15:09:31 -0500 Date: Wed, 06 Jan 2021 20:08:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1609963729; bh=6daANB2TdyPWX84b10kSOB7FgmMFj+I2EXYLQzC8gJ4=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=TkLX+2cYrliZ7AE5My32Qk4RkH4BfJnd4n9ged0uMiGci5zxNJ4Sg5qJvIOAL8EbL kqi62uleA/uWUErUm0/NidwKUafttFxjzfYY9TSf9NC2kfG58beRzR/4TAQnSnk03k 6pWmWasRk9Tc5B5rvuK/GHXeXIuW5YJH2Vm7l6TDVtsJ1HXNhomzAy/Ld+VGDusd1f Dk18DmfBMUbjoxb//UNi0/jgTDQW8xBO45uXh3tk5UR/euvz3YAVfAK+RWPE+F4uWJ mMLNFjmcV2Ei9AA+P/dc1VOKE6YVjXiY+WD7JmX4uCMC9QBrKu6GsUKjyhPvV58WJ6 G3UosHlozAnsA== To: Thomas Bogendoerfer From: Alexander Lobakin Cc: Alexander Lobakin , Nathan Chancellor , Kees Cook , Fangrui Song , Jiaxun Yang , Alex Smith , Ralf Baechle , Markos Chandras , linux-mips@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Message-ID: <20210106200801.31993-3-alobakin@pm.me> In-Reply-To: <20210106200801.31993-1-alobakin@pm.me> References: <20210106200713.31840-1-alobakin@pm.me> <20210106200801.31993-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn or .rela.dyn and check for these sections to be zero-sized at link time. At least two of them were noticed in real builds: mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' from `init/main.o' being placed in section `.rel.dyn' ld.lld: warning: :(.got) is being placed in '.got' Adopted from x86/kernel/vmlinux.lds.S. Reported-by: Nathan Chancellor # .got Suggested-by: Fangrui Song # .rel.dyn Signed-off-by: Alexander Lobakin --- arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 5d6563970ab2..05eda9d9a7d5 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -227,4 +227,39 @@ SECTIONS *(.pdr) *(.reginfo) } + + /* + * Sections that should stay zero sized, which is safer to + * explicitly check instead of blindly discarding. + */ + + .got : { + *(.got) + *(.igot.*) + } + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") + + .got.plt (INFO) : { + *(.got.plt) + } + ASSERT(SIZEOF(.got.plt) == 0, "Unexpected GOT/PLT entries detected!") + + .plt : { + *(.plt) + *(.plt.*) + *(.iplt) + } + ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") + + .rel.dyn : { + *(.rel.*) + *(.rel_*) + } + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") + + .rela.dyn : { + *(.rela.*) + *(.rela_*) + } + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") }