From patchwork Fri Feb 28 00:22:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411213 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29A191805 for ; Fri, 28 Feb 2020 00:23:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08503246A1 for ; Fri, 28 Feb 2020 00:23:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JT0Br7NK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730413AbgB1AWw (ORCPT ); Thu, 27 Feb 2020 19:22:52 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:40169 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730140AbgB1AWv (ORCPT ); Thu, 27 Feb 2020 19:22:51 -0500 Received: by mail-pj1-f67.google.com with SMTP id 12so498431pjb.5 for ; Thu, 27 Feb 2020 16:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ez79u0H95d7ehsU8Q6LXSGZw/ZiYxtURwwXuqb7McBM=; b=JT0Br7NKTOUA+nKOUR3kxByruQX68VKIehHVXqVVhKCbfrDUGawo16Sa3Z6WcHnQZE y1biceMyRdxWDQk+6EXypwYNBPqlrWDKMmnCqpMw9cnF2nSNIF6WOmlDvRjSHvtm0AYe cUNtMHvTvp1pA6un7KPrhVESojEL+IC+Da808= 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:mime-version:content-transfer-encoding; bh=ez79u0H95d7ehsU8Q6LXSGZw/ZiYxtURwwXuqb7McBM=; b=o4JfvV0E4TZ4/pa+7T9F18Bft+wSB0zfCAZlnleA2cZLLaqPbynv2thHUvzXB5jX5z QM24tBJsHDorTMzG5nO8W7AoqwbXOVZYxSfIEUcTYUhKr6L2sRWafyiuKfV3wjZnjxz6 4v+wSxO4acwwJt+UCdTd1ikn0oXqAVcJ5hqDPMiQssRWJU+48yVKYupBEJJv40EmXNGa vgQGS30BkNb9IeDvIG1BB0dPdeyjUKHfkyAbo3aZQCZ7jlUCrUOFvRFHAT0aggig7TZ8 dhA/ILkksTED4S/5qz6fOz1C9xvePSDN3XTd5ASp30Fkz6bjjasjxWlLahr7Xb6W8nvf ttpw== X-Gm-Message-State: APjAAAWRFiJUK4Oc7tfkl/AsG9XDvo8rKwtu8LL4sBa6sVrdIGcf/2E4 GSqsLXcFlu6o2nN2XAtm+aqVWw== X-Google-Smtp-Source: APXvYqzYAj+CjU1Xxuv+xsBd/M7yvFwmBBzsC7seqTL50y8NxU4tBl30dNubdcD9vIp3lpLiWut6dg== X-Received: by 2002:a17:90a:be03:: with SMTP id a3mr1544230pjs.99.1582849369865; Thu, 27 Feb 2020 16:22:49 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 196sm8572448pfy.86.2020.02.27.16.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:48 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/9] scripts/link-vmlinux.sh: Delay orphan handling warnings until final link Date: Thu, 27 Feb 2020 16:22:36 -0800 Message-Id: <20200228002244.15240-2-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Right now, powerpc adds "--orphan-handling=warn" to LD_FLAGS_vmlinux to detect when there are unexpected sections getting added to the kernel image. There is no need to report these warnings more than once, so it can be removed until the final link stage. This helps pave the way for other architectures to enable this, with the end goal of enabling this warning by default for vmlinux for all architectures. Signed-off-by: Kees Cook --- scripts/link-vmlinux.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 1919c311c149..416968fea685 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -255,6 +255,11 @@ info GEN modules.builtin tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin + +# Do not warn about orphan sections until the final link stage. +saved_LDFLAGS_vmlinux="${LDFLAGS_vmlinux}" +LDFLAGS_vmlinux="$(echo "${LDFLAGS_vmlinux}" | sed -E 's/ --orphan-handling=warn( |$)/ /g')" + btf_vmlinux_bin_o="" if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then if gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then @@ -306,6 +311,7 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then fi fi +LDFLAGS_vmlinux="${saved_LDFLAGS_vmlinux}" vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o} if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then From patchwork Fri Feb 28 00:22:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411211 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA0E214B7 for ; Fri, 28 Feb 2020 00:23:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B95FD246A1 for ; Fri, 28 Feb 2020 00:23:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GkeoYAU8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730431AbgB1AXU (ORCPT ); Thu, 27 Feb 2020 19:23:20 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40441 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730028AbgB1AWx (ORCPT ); Thu, 27 Feb 2020 19:22:53 -0500 Received: by mail-pf1-f193.google.com with SMTP id b185so726850pfb.7 for ; Thu, 27 Feb 2020 16:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6fHzEreEHEKZLIitB5E8ew7g5jiGLQoDWIhz+OknFf0=; b=GkeoYAU8e8z3RjiVy/lNoEzHu3xfZdCSskh8kGhFyVvHqzRnbnRbxbrn4TM4McSa26 b5dJvQCjoNTHztfI/3Yk8649TLr/Dejr2bVo8DdGFJbM/WkYGZ0CJ7NMkfa4SauXTXqM Nv+INQ8nhKoWxsj1wa0sdOVKRnF3rnDP62/0w= 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:mime-version:content-transfer-encoding; bh=6fHzEreEHEKZLIitB5E8ew7g5jiGLQoDWIhz+OknFf0=; b=POTbMtsCLCc1Pzflu5BK4jlvhJe9VYOu7cAbJfBRqWsPFWtpp3jNdjaa4J0asMmU/g pmpOEY4WJEpwQe8f42OhFZrEW/9yo0EpRtXFmguxtVe5Ux5YvGvDA9y35vR+94Un+ilQ 6VMgKCWXx32ZtN3t+UgNwjRnVK6MSGVHUdhr28ky+w/6Cx+0JAtCrBkXYBSjtdt90GXd 1OwhUihWzV/kAMgrV5saMZ9+uciEyObDTUZ2bzdsNxxc7rDKQU8+787ZeI44fIW3brF+ UK17UNfrC2azPBxY+LlJiSs+KAgImVmc4mrxIGpA2ffzkzvtQ02wRGceAKb7lIGtWqxo Ma0A== X-Gm-Message-State: APjAAAVmIpxlQW5jZkfzDClenrGRCdOtshN5fEpd53bAkZkAP9DmqG64 1auw9vmL6B8K8ihcmHP0cMf/Rg== X-Google-Smtp-Source: APXvYqznb6YTTAlhNn7JqjD0ERUnnj6NxCnvI3DxIeFfKY/2l5deXUBraE5hW9O+0SqGg2RsiPTeNw== X-Received: by 2002:aa7:9891:: with SMTP id r17mr1670426pfl.205.1582849372029; Thu, 27 Feb 2020 16:22:52 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z30sm8485301pff.131.2020.02.27.16.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:48 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/9] vmlinux.lds.h: Add .gnu.version* to DISCARDS Date: Thu, 27 Feb 2020 16:22:37 -0800 Message-Id: <20200228002244.15240-3-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org For vmlinux linking, no architecture uses the .gnu.version* section, so remove it via the common DISCARDS macro in preparation for adding --orphan-handling=warn more widely. Signed-off-by: Kees Cook --- include/asm-generic/vmlinux.lds.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index e00f41aa8ec4..303597e51396 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -902,6 +902,7 @@ *(.discard) \ *(.discard.*) \ *(.modinfo) \ + *(.gnu.version*) \ } /** From patchwork Fri Feb 28 00:22:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8025D14BC for ; Fri, 28 Feb 2020 00:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F795246A6 for ; Fri, 28 Feb 2020 00:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aprtzyrZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730423AbgB1AWw (ORCPT ); Thu, 27 Feb 2020 19:22:52 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36952 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730028AbgB1AWw (ORCPT ); Thu, 27 Feb 2020 19:22:52 -0500 Received: by mail-pf1-f196.google.com with SMTP id p14so732483pfn.4 for ; Thu, 27 Feb 2020 16:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uceCceIOG2DmkN987H8EhCgiSZQG4q+SFGBRris4xG0=; b=aprtzyrZ60FGeJNkJNjVIQbc99c/fsdw9OKOw87YzHK/0SfhsWmA8PcyTPqZq9ptEL 0CNjt4bV3uQWUOlnulxZY8ZKsGjdFr3XpcUK9eN4hf7vx57s1iHQvbosRZGY9/LJNRxo MYhTtklU93oiIUE0nKY046nfAGvZw6E1IkunM= 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:mime-version:content-transfer-encoding; bh=uceCceIOG2DmkN987H8EhCgiSZQG4q+SFGBRris4xG0=; b=gGtfCpopz+bKMrLaBKafFClgqP4Bfc3PjTKzVxFUzgzKSFKCpld/nL/iRcpjcqNisT fKLq9JzIzUZOWRXfuNbFEmHFn1I8QfjJMEt81gQnF+BavXB1nYK543ITB6zO83u0ik0E AyVX/B7zOm07o/cFgmdIdGG+UjGM5ko2to6mpElow8y4FIfvChWcydasNqZLZ5LcR4X8 UoDIDCj8TCdP4+/CaFDG22Rk33WWH6nQoeTi8Z/0UN8qyAJ+TSvvdKClsRYHjaH85RMu NaPxSFp28igI9kWSNvFAB1WSgKv0HqiqnCWuUCskM0f7s79rDm5OCNJHdBrke5WE/phb 1nNQ== X-Gm-Message-State: APjAAAXGXnck6Snk/7l9dhqZJ9p1n12z8/9azsGzCxgszEnHuhThNDyh p7MUnD127HD2Q2gE8UAtgsGskw== X-Google-Smtp-Source: APXvYqyjOck/5wJSSqU+VYB+XqwXzBg0gQ0/fmVPRW162tG0JSVUcNPf0a5ewRShW9E52SJeL0B9Pg== X-Received: by 2002:aa7:9f90:: with SMTP id z16mr1671592pfr.161.1582849370382; Thu, 27 Feb 2020 16:22:50 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j12sm3646141pjd.4.2020.02.27.16.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:48 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/9] x86/build: Warn on orphan section placement Date: Thu, 27 Feb 2020 16:22:38 -0800 Message-Id: <20200228002244.15240-4-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Discards the unused rela, plt, and got sections that are not needed in the final vmlinux, and enable orphan section warnings. Signed-off-by: Kees Cook --- arch/x86/Makefile | 4 ++++ arch/x86/kernel/vmlinux.lds.S | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 94df0868804b..b2c8becadce5 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -51,6 +51,10 @@ ifdef CONFIG_X86_NEED_RELOCS LDFLAGS_vmlinux := --emit-relocs --discard-none endif +# We never want expected sections to be placed heuristically by the +# linker. All sections should be explicitly named in the linker script. +LDFLAGS_vmlinux += --orphan-handling=warn + # # Prevent GCC from generating any FP code by mistake. # diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 5cab3a29adcb..1e345f302a46 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -412,6 +412,12 @@ SECTIONS DWARF_DEBUG DISCARDS + /DISCARD/ : { + *(.rela.*) *(.rela_*) + *(.rel.*) *(.rel_*) + *(.got) *(.got.*) + *(.igot.*) *(.iplt) + } } From patchwork Fri Feb 28 00:22:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 710FD14B7 for ; Fri, 28 Feb 2020 00:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 50C8E246A0 for ; Fri, 28 Feb 2020 00:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nHZ4Y7Yb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730123AbgB1AWu (ORCPT ); Thu, 27 Feb 2020 19:22:50 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46476 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729984AbgB1AWu (ORCPT ); Thu, 27 Feb 2020 19:22:50 -0500 Received: by mail-pf1-f193.google.com with SMTP id o24so710507pfp.13 for ; Thu, 27 Feb 2020 16:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oFQSSd8joQB26Yle3LRphyYOwCqM8lXqrwgR7KUB2ZM=; b=nHZ4Y7YbhF6uEk5/uFndEuekX2vKGSTC1OQpgCF1rYdVz1hL9KwhWsI6HLQwltLv2c olhA+OX8/TcWhf7cu831s2b1jUqHSYSvZqA7RHqWjI7TZURQ1M6+nuep8zkL0yqIzO/G rYLC+NOCo0eRuvYBoJQwHOB1tY/rFRwdZY/+s= 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:mime-version:content-transfer-encoding; bh=oFQSSd8joQB26Yle3LRphyYOwCqM8lXqrwgR7KUB2ZM=; b=ewUfinuGjVPXiW2xR6ErnNL1lk7HzE6s6JccnISKuOosn1PTWBLhcjOyqlRYWDvvlJ ke8MMldubKZSi2VFQAd7buiuyPQbawFoXDu7uqcPWW+D5NDkiD2QJiGlM/43AvExLyBf pN5RAMuABTjPKdfUPwO3njk8qrVV3YKwmPwrPnMZPl5Q1xpt0e/BsW+o9PHyOHYhiK/s rEiTx4jSX29dmg54pA9VYdJ+qdAifJ/MmPgnEjy1YfCRaPlSiSJmZx+ENoZfXAlPp214 hpb4oWzx8wNbUDT4Ff2v+ylP4h4wOm9JyN2N2nktr1s/laQNB7sDICDIlJuRzZE0sAsl nvwQ== X-Gm-Message-State: APjAAAV+k3I/lmbG7gCEKsNbpjkYtr6DRAprDC8h2A1bgykhR3kpYuDv 7OO5sQU+GV/wEfIKhpivok20gQ== X-Google-Smtp-Source: APXvYqw6fCWM2xfT4DJ+VFMmyrDy6sPXs7ZYweUNi5l07x3V/XFaixY8I4K8wHA9HcWwEBIBYQBH6A== X-Received: by 2002:a63:5713:: with SMTP id l19mr1913060pgb.216.1582849369348; Thu, 27 Feb 2020 16:22:49 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h5sm7577879pgi.28.2020.02.27.16.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:48 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 4/9] x86/boot: Warn on orphan section placement Date: Thu, 27 Feb 2020 16:22:39 -0800 Message-Id: <20200228002244.15240-5-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Add the common debugging sections. Discard the unused note, rel, plt, dyn, and hash sections that are not needed in the compressed vmlinux. Disable .eh_frame generation in the linker and enable orphan section warnings. Signed-off-by: Kees Cook --- arch/x86/boot/compressed/Makefile | 3 ++- arch/x86/boot/compressed/vmlinux.lds.S | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index c33111341325..e0ea6b0924e8 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -46,6 +46,7 @@ GCOV_PROFILE := n UBSAN_SANITIZE :=n KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) +KBUILD_LDFLAGS += --no-ld-generated-unwind-info # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. ifeq ($(CONFIG_X86_32),y) @@ -57,7 +58,7 @@ else KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ && echo "-z noreloc-overflow -pie --no-dynamic-linker") endif -LDFLAGS_vmlinux := -T +LDFLAGS_vmlinux := --orphan-handling=warn -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 508cfa6828c5..b5406a8cebe0 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -73,4 +73,17 @@ SECTIONS #endif . = ALIGN(PAGE_SIZE); /* keep ZO size page aligned */ _end = .; + + STABS_DEBUG + DWARF_DEBUG + + DISCARDS + /DISCARD/ : { + *(.note.*) + *(.rela.*) *(.rela_*) + *(.rel.*) *(.rel_*) + *(.plt) *(.plt.*) + *(.dyn*) + *(.hash) *(.gnu.hash) + } } From patchwork Fri Feb 28 00:22:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411207 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B56C014BC for ; Fri, 28 Feb 2020 00:23:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95489246AF for ; Fri, 28 Feb 2020 00:23:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Kf+gX5xd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730266AbgB1AXG (ORCPT ); Thu, 27 Feb 2020 19:23:06 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33854 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730445AbgB1AW4 (ORCPT ); Thu, 27 Feb 2020 19:22:56 -0500 Received: by mail-pf1-f195.google.com with SMTP id i6so741000pfc.1 for ; Thu, 27 Feb 2020 16:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A992AjdJWLXJEjwtDWIJFXaA8r8Mu1S3gNtRzAo3spo=; b=Kf+gX5xddQKiKpPCh8bEqjWUqToYjUe3/Z9DWP7hzU0kpjC0HzX02FDHpmOXXOwPyC RQr5vgHl1MrkXOGQjyy45mc7XGMezFVZ2pKsfS+w2wtn0sI0CA8B9URb5ueTsQrTkFPO zN9DFPXLMUeWvltrwG3QFCbnPtEHU7Jjtr6Jo= 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:mime-version:content-transfer-encoding; bh=A992AjdJWLXJEjwtDWIJFXaA8r8Mu1S3gNtRzAo3spo=; b=ASwhqcgpImPLMTaq/3A35VPB4oqyq2Km+ZYSAjD0ZDI5YkVO6tz5sPBCbKYMMAg9/F k3QS7a6vuSkcYAqAMg2v/yFD4TkShVJmWL1oaPTA8sDytvwwzp73pdN0jP+JKbaFpXoJ tXccEgR4gIIQEmihN+E8HSWL/XW/szEjpYXVeB8obSb7Cza6LhPhXDeIDkpLOgkelXS3 5ycno1IID4ulyS8eUKyXST8iCbDvFV4VZnF6VpzbftlEvfKXcIJIgWdAlQ60PiPXUfaJ 9fox9uWHVTY2fvFvVy2LxjspWzWiARvxvRqUtrbsF3nnZ86/3wPRC2X7mC0x4W0eGZQh Z/Eg== X-Gm-Message-State: APjAAAUgVZpcRjXT1mWtd9D6pnhiKc9OgOTSvtFDqnGkh//IQtap37Mt b599MrdJ3/HT6zlhgumaer5R8g== X-Google-Smtp-Source: APXvYqxORpz2NBO4YgeiTAddpXfXe3J/AmESIDy/gZRMg/FCrltSGt039dZiZFkPpl/Q4pPd1+W1MA== X-Received: by 2002:a63:7207:: with SMTP id n7mr1872186pgc.253.1582849375359; Thu, 27 Feb 2020 16:22:55 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b3sm8714061pft.73.2020.02.27.16.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:52 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 5/9] Add RUNTIME_DISCARD_EXIT to generic DISCARDS Date: Thu, 27 Feb 2020 16:22:40 -0800 Message-Id: <20200228002244.15240-6-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: "H.J. Lu" In x86 kernel, .exit.text and .exit.data sections are discarded at runtime, not by linker. Add RUNTIME_DISCARD_EXIT to generic DISCARDS and define it in x86 kernel linker script to keep them. Signed-off-by: H.J. Lu Link: https://lore.kernel.org/r/20200130224337.4150-1-hjl.tools@gmail.com Signed-off-by: Kees Cook --- arch/x86/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 1e345f302a46..1e12c097d09b 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -21,6 +21,7 @@ #define LOAD_OFFSET __START_KERNEL_map #endif +#define RUNTIME_DISCARD_EXIT #define EMITS_PT_NOTE #define RO_EXCEPTION_TABLE_ALIGN 16 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 303597e51396..1797f2c9bb41 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -894,10 +894,16 @@ * section definitions so that such archs put those in earlier section * definitions. */ +#ifdef RUNTIME_DISCARD_EXIT +#define EXIT_DISCARDS +#else +#define EXIT_DISCARDS \ + EXIT_TEXT \ + EXIT_DATA +#endif #define DISCARDS \ /DISCARD/ : { \ - EXIT_TEXT \ - EXIT_DATA \ + EXIT_DISCARDS \ EXIT_CALL \ *(.discard) \ *(.discard.*) \ From patchwork Fri Feb 28 00:22:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2B6414B7 for ; Fri, 28 Feb 2020 00:23:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92728246C0 for ; Fri, 28 Feb 2020 00:23:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V36B51rI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730144AbgB1AW7 (ORCPT ); Thu, 27 Feb 2020 19:22:59 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38973 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730470AbgB1AW6 (ORCPT ); Thu, 27 Feb 2020 19:22:58 -0500 Received: by mail-pg1-f195.google.com with SMTP id j15so542419pgm.6 for ; Thu, 27 Feb 2020 16:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=njo/Fx4CsF+NQ0G1u7AY1RWSg6ZNLRJXLnHS1KzoDiw=; b=V36B51rI6uTfIFQ393op65AYhJqQDQrYEJ6cMpkwv1fytwIQq5RcV2b2ckkCtE1sw0 YM1LYtZD4DrhdU/Ea540khr3HPTpC+38/5GLj40jxxNahTYQDym9BttSb/i6IQdZFITg acSRiJiho/Jbfz/18SE8Y1nmC78EHYUE05Ibw= 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:mime-version:content-transfer-encoding; bh=njo/Fx4CsF+NQ0G1u7AY1RWSg6ZNLRJXLnHS1KzoDiw=; b=OW0SdmHA7JubXoPmcudgiEzTefxYLihM3EuwulKAp1oLzobCY3IruC7++q59fH68E7 Bcfv0ZKSgNNF0Z3FK/VDAprOce5hupE8LAsF3aNu6Oqri4pPYyXqIq28u0yfa+UElBP2 jNA6UVlT0UvKLtw8iIpmcrjrgGhY6fBaEuuztyr9j7VUfEcBCQQFzvLShGLDaHns+r6P XDfu3Opgg8xxqldOhm5k03jQ8IEIxNLiqWDE0B4udbGptdARiDSL2YXhFiUoZS9nkVSA biZQlcIPMYg3bBPgWexPQsnfZ916o05zlvebiGen1lQ760T+F6cwSoqIYCr2mqBHQcCw yKRg== X-Gm-Message-State: APjAAAXz5B+zr4bLc1z3M0roVl36XPrqKzQRwNOm4+EHZlZDrvYISidm 1Z1FeLW/Ql/q5o9KKBF36LXRtQ== X-Google-Smtp-Source: APXvYqx0VisnNsuBsLs1eNzqbgYv6zuOJyCgm5lqaZQuPJuf7INJygLV6ti12PFdMfz+LSKcLevlLw== X-Received: by 2002:a63:f403:: with SMTP id g3mr1948825pgi.62.1582849373921; Thu, 27 Feb 2020 16:22:53 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g14sm4184582pfo.154.2020.02.27.16.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:52 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] arm64/build: Use common DISCARDS in linker script Date: Thu, 27 Feb 2020 16:22:41 -0800 Message-Id: <20200228002244.15240-7-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Use the common DISCARDS rule for the linker script in an effort to regularize the linker script to prepare for warning on orphaned sections. Signed-off-by: Kees Cook Acked-by: Will Deacon --- arch/arm64/kernel/vmlinux.lds.S | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 497f9675071d..c61d9ab3211c 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -6,6 +6,7 @@ */ #define RO_EXCEPTION_TABLE_ALIGN 8 +#define RUNTIME_DISCARD_EXIT #include #include @@ -19,7 +20,6 @@ /* .exit.text needed in case of alternative patching */ #define ARM_EXIT_KEEP(x) x -#define ARM_EXIT_DISCARD(x) OUTPUT_ARCH(aarch64) ENTRY(_text) @@ -94,12 +94,8 @@ SECTIONS * matching the same input section name. There is no documented * order of matching. */ + DISCARDS /DISCARD/ : { - ARM_EXIT_DISCARD(EXIT_TEXT) - ARM_EXIT_DISCARD(EXIT_DATA) - EXIT_CALL - *(.discard) - *(.discard.*) *(.interp .dynamic) *(.dynsym .dynstr .hash .gnu.hash) *(.eh_frame) From patchwork Fri Feb 28 00:22:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411209 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBF9314BC for ; Fri, 28 Feb 2020 00:23:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB0FA246A6 for ; Fri, 28 Feb 2020 00:23:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="krC6xmNg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730520AbgB1AXN (ORCPT ); Thu, 27 Feb 2020 19:23:13 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34139 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730432AbgB1AWy (ORCPT ); Thu, 27 Feb 2020 19:22:54 -0500 Received: by mail-pl1-f193.google.com with SMTP id j7so499165plt.1 for ; Thu, 27 Feb 2020 16:22:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zVpHeuxipIPK/qd0iCdiGqFiQMqEhmX8CGXx2I34f0o=; b=krC6xmNgw5C2QYlaOO7YN2OpvJP+ov9IyIlPgq0DXWrHV9QPfrB/V2c9HARqDeyVlZ sbobrSdf3PuOxYRxxISvcUJUmQP1jaLlm2A+bGY0UwvmvfbkOinG7qJ0aqiD+JNnfd8f ebMF68HeaLLIxb73BOCWdAV1jFz++pJGNFM2U= 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:mime-version:content-transfer-encoding; bh=zVpHeuxipIPK/qd0iCdiGqFiQMqEhmX8CGXx2I34f0o=; b=tnZpf0ngwqz/CgLNuZWPX/ZpPJ7yN0mVQGGXtcp82XlD4RLzCVmOkHm/eTOcQtqrmn yeRq54UTW2PiNxbHIU7Duwv5ICbT0ZZNiDJMGVVFbWwP4jGWFtXUDlS2IgdMIVRkAbkb /YSsnJTjDueyw0ZgugCC0f/MfERLm78CNA8aXMWGnIkK/O0aWW1r8umAVTDAEnlzRfg3 /ZS5APDdtYYu+4l6lSVZJZShvU31PSMAGnGBq7uJTzlSXDFcDQ4M6CxvwJ8M120Reisi FPprxatS+L1cDxWR2fLxrlJ0bwSCR9UzMRWfwgxq5ZL7tUp7vzndeOZBQiaZMr52w1qZ /c9g== X-Gm-Message-State: APjAAAWhnKDGFCKcetUffdo04Pj/H+uO8NmwEFKO+eXRuZxZZkAylS6i Ac9aZ5jGEQBvdnYAG6NUssaOJQ== X-Google-Smtp-Source: APXvYqwL7Pts9z/sbRgRZgMFUPPpjfZxHHeQCL3ybGBJta4uKv6RUba5OOEn0ffoF3CqGS5GRVG4Qw== X-Received: by 2002:a17:902:a588:: with SMTP id az8mr1413232plb.123.1582849373376; Thu, 27 Feb 2020 16:22:53 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e28sm8072097pgn.21.2020.02.27.16.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:52 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 7/9] arm64/build: Warn on orphan section placement Date: Thu, 27 Feb 2020 16:22:42 -0800 Message-Id: <20200228002244.15240-8-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Explicitly include debug sections when they're present. Add .eh_frame* to discard as it seems that these are still generated even though -fno-asynchronous-unwind-tables is being specified. Add .plt and .data.rel.ro to discards as they are not actually used. Add .got.plt to the image as it does appear to be mapped near .data. Finally enable orphan section warnings. Signed-off-by: Kees Cook --- arch/arm64/Makefile | 4 ++++ arch/arm64/kernel/vmlinux.lds.S | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index dca1a97751ab..c682a65b3ab8 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -30,6 +30,10 @@ LDFLAGS_vmlinux += --fix-cortex-a53-843419 endif endif +# We never want expected sections to be placed heuristically by the +# linker. All sections should be explicitly named in the linker script. +LDFLAGS_vmlinux += --orphan-handling=warn + ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y) ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y) $(warning LSE atomics not supported by binutils) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index c61d9ab3211c..6141d5b72f8f 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -98,7 +98,8 @@ SECTIONS /DISCARD/ : { *(.interp .dynamic) *(.dynsym .dynstr .hash .gnu.hash) - *(.eh_frame) + *(.plt) *(.data.rel.ro) + *(.eh_frame) *(.init.eh_frame) } . = KIMAGE_VADDR + TEXT_OFFSET; @@ -212,6 +213,7 @@ SECTIONS _data = .; _sdata = .; RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) + .got.plt : ALIGN(8) { *(.got.plt) } /* * Data written with the MMU off but read with the MMU on requires @@ -246,6 +248,7 @@ SECTIONS _end = .; STABS_DEBUG + DWARF_DEBUG HEAD_SYMBOLS } From patchwork Fri Feb 28 00:22:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E631A1805 for ; Fri, 28 Feb 2020 00:23:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC259246C0 for ; Fri, 28 Feb 2020 00:23:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SxadLoRd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730470AbgB1AW7 (ORCPT ); Thu, 27 Feb 2020 19:22:59 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40446 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730443AbgB1AW5 (ORCPT ); Thu, 27 Feb 2020 19:22:57 -0500 Received: by mail-pf1-f195.google.com with SMTP id b185so726898pfb.7 for ; Thu, 27 Feb 2020 16:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwIdnSLxc1IQxbb7lR9quaS2Zk4ZIexbe3LplVopvDU=; b=SxadLoRdLQDFU2sMtSW2VbvnGgGtZ9nCv8JDVG6dgim+vwQxXd5tD6x6EYwmtVgnK9 g0afBGuHNACAm2YpVUqCMSfGYmfEu6veqLTy8Q0Ov4wLLVzwWKqU96E24PsO03T2q6E/ qQhzi6HA8L+yEMS6HEOrD8/pM84qK/Fk9wGbg= 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:mime-version:content-transfer-encoding; bh=AwIdnSLxc1IQxbb7lR9quaS2Zk4ZIexbe3LplVopvDU=; b=hY0txrwpckNzdkU+VVZbBzvcU7Xp8AIxzK5BQAZnCS25uQaytjzRrn5qkPEMqBcADo nDI6ZZ8oJUBmp31UTRgXWi6j9cLCTiw6rPEgbmFflv/R3bzTuRF6xvDnowEJgeq74FLg I792Y0L7TSaiKQza5zy2FVUrQ1+0uIgTeGUUCG9aKvJgKVcas+B/2txexoTgJEG4euwH GG4g6CwjCoIz8ebbIAKavwX6vzzGL6n10aC/37kAw4yjx/EKA3CNQ522Po6CI5wjiJSi UxpkxKcUMqZe5xsIpmTxMTVJuFEAetdU50YVoqYdCTOdDHqgNTNLbcFwzJMzKpLMBGj0 +8RA== X-Gm-Message-State: APjAAAV77CoTKm57zrSYVlv7UTMqoR2hgJpS1QTJeQvIhV/A6k2HRlac toa7qO5gDuQv4a1bK9EOkdN5nw== X-Google-Smtp-Source: APXvYqyXge8yxc0byOAFcYYogqDHBcP8WReHRi7mz3K+YWkdQcq5DXiV06dtqt1g148mFGy5LeYCug== X-Received: by 2002:a63:ef03:: with SMTP id u3mr1816813pgh.77.1582849374784; Thu, 27 Feb 2020 16:22:54 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r11sm8163080pgi.9.2020.02.27.16.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:52 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 8/9] arm/build: Warn on orphan section placement Date: Thu, 27 Feb 2020 16:22:43 -0800 Message-Id: <20200228002244.15240-9-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Specifically, this would have made a recently fixed bug very obvious: ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' Refactor linker script include file for use in standard and XIP linker scripts, as well as in the coming boot linker script changes. Add debug sections explicitly. Create ARM_COMMON_DISCARD macro with unneeded sections .ARM.attributes, .iplt, .rel.iplt, .igot.plt, and .modinfo. Create ARM_STUBS_TEXT macro with missed text stub sections .vfp11_veneer, and .v4_bx. Finally enable orphan section warning. Signed-off-by: Kees Cook --- arch/arm/Makefile | 4 ++++ .../arm/{kernel => include/asm}/vmlinux.lds.h | 22 ++++++++++++++----- arch/arm/kernel/vmlinux-xip.lds.S | 5 ++--- arch/arm/kernel/vmlinux.lds.S | 5 ++--- 4 files changed, 25 insertions(+), 11 deletions(-) rename arch/arm/{kernel => include/asm}/vmlinux.lds.h (92%) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index db857d07114f..f1622bea987a 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -16,6 +16,10 @@ LDFLAGS_vmlinux += --be8 KBUILD_LDFLAGS_MODULE += --be8 endif +# We never want expected sections to be placed heuristically by the +# linker. All sections should be explicitly named in the linker script. +LDFLAGS_vmlinux += --orphan-handling=warn + ifeq ($(CONFIG_ARM_MODULE_PLTS),y) KBUILD_LDS_MODULE += $(srctree)/arch/arm/kernel/module.lds endif diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/include/asm/vmlinux.lds.h similarity index 92% rename from arch/arm/kernel/vmlinux.lds.h rename to arch/arm/include/asm/vmlinux.lds.h index 8247bc15addc..3ae2cf2e351b 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/include/asm/vmlinux.lds.h @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #ifdef CONFIG_HOTPLUG_CPU #define ARM_CPU_DISCARD(x) @@ -46,6 +47,13 @@ *(.hyp.idmap.text) \ __hyp_idmap_text_end = .; +#define ARM_COMMON_DISCARD \ + *(.ARM.attributes) \ + *(.iplt) *(.rel.iplt) *(.igot.plt) \ + *(.modinfo) \ + *(.discard) \ + *(.discard.*) + #define ARM_DISCARD \ *(.ARM.exidx.exit.text) \ *(.ARM.extab.exit.text) \ @@ -58,8 +66,14 @@ EXIT_CALL \ ARM_MMU_DISCARD(*(.text.fixup)) \ ARM_MMU_DISCARD(*(__ex_table)) \ - *(.discard) \ - *(.discard.*) + ARM_COMMON_DISCARD + +#define ARM_STUBS_TEXT \ + *(.gnu.warning) \ + *(.glue_7t) \ + *(.glue_7) \ + *(.vfp11_veneer) \ + *(.v4_bx) #define ARM_TEXT \ IDMAP_TEXT \ @@ -74,9 +88,7 @@ LOCK_TEXT \ HYPERVISOR_TEXT \ KPROBES_TEXT \ - *(.gnu.warning) \ - *(.glue_7) \ - *(.glue_7t) \ + ARM_STUBS_TEXT \ . = ALIGN(4); \ *(.got) /* Global offset table */ \ ARM_CPU_KEEP(PROC_INFO) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 21b8b271c80d..8e9ac99a4335 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -9,15 +9,13 @@ #include -#include +#include #include #include #include #include #include -#include "vmlinux.lds.h" - OUTPUT_ARCH(arm) ENTRY(stext) @@ -152,6 +150,7 @@ SECTIONS _end = .; STABS_DEBUG + DWARF_DEBUG } /* diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 319ccb10846a..f1c6f66e8e6c 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -8,7 +8,7 @@ #include "vmlinux-xip.lds.S" #else -#include +#include #include #include #include @@ -16,8 +16,6 @@ #include #include -#include "vmlinux.lds.h" - OUTPUT_ARCH(arm) ENTRY(stext) @@ -151,6 +149,7 @@ SECTIONS _end = .; STABS_DEBUG + DWARF_DEBUG } #ifdef CONFIG_STRICT_KERNEL_RWX From patchwork Fri Feb 28 00:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11411203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 017D114B7 for ; Fri, 28 Feb 2020 00:23:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5DBE246A1 for ; Fri, 28 Feb 2020 00:23:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NdpfQ9E7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730383AbgB1AXA (ORCPT ); Thu, 27 Feb 2020 19:23:00 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:55991 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730484AbgB1AW5 (ORCPT ); Thu, 27 Feb 2020 19:22:57 -0500 Received: by mail-pj1-f67.google.com with SMTP id a18so494357pjs.5 for ; Thu, 27 Feb 2020 16:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5pMXhDd5WkHmc2Nd9+Jjb38fhh7Zetn6tk9gX3pPvjM=; b=NdpfQ9E77BQQDeLbRe4C0kneiRaa4BRWlG/661nY6+36gEg6ulvyK6zJdrM6FlpkLx rZnuOrOoXJH6eCy0PMi8rot0VETFWym5wj0fDsIe9QVrzJg7KEO+1C0QPBYDgIEB4mcg xFYZAsgdnMK5ZAzxXgLUxelkrt9eHsy30qa9U= 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:mime-version:content-transfer-encoding; bh=5pMXhDd5WkHmc2Nd9+Jjb38fhh7Zetn6tk9gX3pPvjM=; b=RHWT2IiWgUorRcmYIjCHK5OfuBCaR2FgQ3nyBqYYFRPfyuSb08OfHdrwRBCCOeDNwO Pz5MjyGycxCM3pMLvXvvwg/78Cq0TUsDM2dMtLKo9kiNi/VaSYf69Heox1tKHoL/yICr Y8uwKVBFk1XX60pHvW/WXm5lLojA/vZeIByBm5mqnQ8RvMtYBPII6Nk89tB9l2aD/x00 QBC3xbi7SxZ0A9RFKaphuWXr7WEDY1twH1rbThzJluasj0Z0OeMylq88+b32FUICXDns VpII790o7DAArK1x4VwmUgHbPkK0kAZfMt012beTCb02RDSTN9YLkhwA7Y9Jq9nmUkB9 tL1w== X-Gm-Message-State: APjAAAVoY7Y2ZH4/4hurrtb/C2FEkRGVDlYglwyw6seq+DKP8RZYpotr OyQp6qBV7THWL4Z1rBVjJGN96Q== X-Google-Smtp-Source: APXvYqzuOX0XiyVaOeVuugXOJBvn7E6Nhu05xm90KTUN/qkQ34/SDiQ4lE0A5jOUkXzf88ArP2HuXA== X-Received: by 2002:a17:902:694b:: with SMTP id k11mr1375405plt.334.1582849375873; Thu, 27 Feb 2020 16:22:55 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 3sm8455845pfi.13.2020.02.27.16.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:22:52 -0800 (PST) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , "H.J. Lu" , Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , James Morse , Arnd Bergmann , Masahiro Yamada , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 9/9] arm/boot: Warn on orphan section placement Date: Thu, 27 Feb 2020 16:22:44 -0800 Message-Id: <20200228002244.15240-10-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228002244.15240-1-keescook@chromium.org> References: <20200228002244.15240-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Use common macros for debug sections, discards, and text stubs. Add discards for unwanted .note, and .rel sections. Finally, enable orphan section warning. Signed-off-by: Kees Cook --- arch/arm/boot/compressed/Makefile | 2 ++ arch/arm/boot/compressed/vmlinux.lds.S | 17 +++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index da599c3a1193..7faa2b5e7e16 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -136,6 +136,8 @@ endif LDFLAGS_vmlinux += --no-undefined # Delete all temporary local symbols LDFLAGS_vmlinux += -X +# Report orphan sections +LDFLAGS_vmlinux += --orphan-handling=warn # Next argument is a linker script LDFLAGS_vmlinux += -T diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S index fc7ed03d8b93..a6a51b5d2328 100644 --- a/arch/arm/boot/compressed/vmlinux.lds.S +++ b/arch/arm/boot/compressed/vmlinux.lds.S @@ -2,6 +2,7 @@ /* * Copyright (C) 2000 Russell King */ +#include #ifdef CONFIG_CPU_ENDIAN_BE8 #define ZIMAGE_MAGIC(x) ( (((x) >> 24) & 0x000000ff) | \ @@ -17,8 +18,11 @@ ENTRY(_start) SECTIONS { /DISCARD/ : { + ARM_COMMON_DISCARD *(.ARM.exidx*) *(.ARM.extab*) + *(.note.*) + *(.rel.*) /* * Discard any r/w data - this produces a link error if we have any, * which is required for PIC decompression. Local data generates @@ -37,9 +41,7 @@ SECTIONS *(.text) *(.text.*) *(.fixup) - *(.gnu.warning) - *(.glue_7t) - *(.glue_7) + ARM_STUBS_TEXT } .table : ALIGN(4) { _table_start = .; @@ -124,12 +126,7 @@ SECTIONS PROVIDE(__pecoff_data_size = ALIGN(512) - ADDR(.data)); PROVIDE(__pecoff_end = ALIGN(512)); - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } + STABS_DEBUG + DWARF_DEBUG } ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");