From patchwork Mon Jun 29 06:18:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11630475 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 8A1A4913 for ; Mon, 29 Jun 2020 06:21:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61F6D23131 for ; Mon, 29 Jun 2020 06:21:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sdPzOgvW"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="htK3ULYA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61F6D23131 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References:List-Owner; bh=AxcFdI/A1WqXhb9ryorzPhqvNFRFf8xxRYqL3LYWkk4=; b=sdPzOgvWMu0i5EKM6G47z7mRXq P6xSYokrVWW7Ve3rA/kC8jnC4IosPm6dt6zpgYwxiVNLnN6/YykrFPo+l4JNnPgAlcLwXramQImJH 8o6tAFsZDyGcGV7hQNI6Yi8C6EvEnfUDle9l9ixdGPtbOQTm/dFFcnYGRXTB3zkp9vQWl7IdMNSO0 bZuo6MT++yHj0YnS0blHhYylw3uPfeUk7SVwslEXeBNHBbPmDKdkDSzyOoo0RXuKDeeomdvBKvCVs Feym/u+mP0l8wycgiW6FDysk1AKClPvnnUwc614kP6PI6orS4nLY11cjpjXYIT3OsKaKEZu8wjup4 JR7xAwrw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpn8J-0005vo-0C; Mon, 29 Jun 2020 06:19:11 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpn7x-0005pA-Et for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 06:18:55 +0000 Received: by mail-pj1-x1042.google.com with SMTP id c1so306940pja.5 for ; Sun, 28 Jun 2020 23:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=94PT4ZZxVDelwBmV/2g0OBn6aDN7DJybZdz+0cO8lSM=; b=htK3ULYAY8Ioor41oXa3s4blSCZQhPzhPSfKlTBtUmE8TmGgnEqgv1HDnW56PueYRY rwR1GLfBYtJVgCfVbVdlRKZw9HFOOqYtVMXabp/ZIu23+Ma7pTzfhehjfRcyDvmSDc9y XkOBFXJyJYHbtk5WAzkcIeQcKQoTVTt/3QCjU= 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:mime-version :content-transfer-encoding; bh=94PT4ZZxVDelwBmV/2g0OBn6aDN7DJybZdz+0cO8lSM=; b=PT/W5pVQE6QyA22ub38jDV7P6gGjXhxGd0wlCv8ikzy7SFnsXSmNM9zTugNyZsx0Iv RbwlOgXM4XrxP6Pa9NEXFoKTgB2XAzA0CcCfcMHHik6USKhPGbxtdOs4BaWBRwJKnOON WlA28lHShorQpi1vpqIMnnsxGnRoG6Vyd79lSumey+60dB1RbxN+kbhtFBePJ/PTOUiN Lc2nYtWP5oZLrpOEuMkuzK57hhTtS37lz13vAIASOVkAp2/PEa2TRhsFuKSIrkqE6jpO jwy8SWK+7iPOMi4HjFcXbqRiqJN0YKvLJB/TDuxp6I2HtM4lIqIT1Dip/6VGxF6fCCHc 40Nw== X-Gm-Message-State: AOAM532COkhRMcbSrzGU5w3Nn0cmeMVdj5R0CsDAqOovyVD4nq8vEgPZ IwhhSQatnaOqob7aDVOkxO0zLg== X-Google-Smtp-Source: ABdhPJy3RUB/apJg+B+3+3HZviihAw2PheDSpFiYSQqDcMDsJWYHNjl9Yj9fkPRQHuD3X2yCjYg2NQ== X-Received: by 2002:a17:90a:1acc:: with SMTP id p70mr5373622pjp.210.1593411526183; Sun, 28 Jun 2020 23:18:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v28sm14619872pgc.44.2020.06.28.23.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2020 23:18:44 -0700 (PDT) From: Kees Cook To: Will Deacon Subject: [PATCH v4 00/17] Warn on orphan section placement Date: Sun, 28 Jun 2020 23:18:23 -0700 Message-Id: <20200629061840.4065483-1-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1042 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, Kees Cook , Arnd Bergmann , Catalin Marinas , Masahiro Yamada , x86@kernel.org, Nick Desaulniers , Russell King , linux-kernel@vger.kernel.org, Nathan Chancellor , clang-built-linux@googlegroups.com, Arvind Sankar , Ingo Molnar , James Morse , Thomas Gleixner , Borislav Petkov , Peter Collingbourne , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org v4: - explicitly add .ARM.attributes - split up arm64 changes into separate patches - split up arm changes into separate patches - work around Clang section generation bug in -mbranch-protection - work around Clang section generation bug in KASAN and KCSAN - split "common" ELF sections out of STABS_DEBUG - changed relative position of .comment - add reviews/acks v3: https://lore.kernel.org/lkml/20200624014940.1204448-1-keescook@chromium.org/ v2: https://lore.kernel.org/lkml/20200622205815.2988115-1-keescook@chromium.org/ v1: https://lore.kernel.org/lkml/20200228002244.15240-1-keescook@chromium.org/ A recent bug[1] was solved for builds linked with ld.lld, and tracking it down took way longer than it needed to (a year). Ultimately, it boiled down to differences between ld.bfd and ld.lld's handling of orphan sections. Similarly, the recent FGKASLR series brough up orphan section handling too[2]. In both cases, it would have been nice if the linker was running with --orphan-handling=warn so that surprise sections wouldn't silently get mapped into the kernel image at locations up to the whim of the linker's orphan handling logic. Instead, all desired sections should be explicitly identified in the linker script (to be either kept or discarded) with any orphans throwing a warning. The powerpc architecture actually already does this, so this series extends coverage to x86, arm, and arm64. All three architectures depend on the first four commits (to vmlinux.lds.h), and arm64 depends on the 5th and 6th patches (to ctype, and efi/libstub). As such, I'd like to land this series as a whole. Given that two thirds of it is in the arm universe, perhaps this can land via the arm64 tree? If x86 -tip is preferred, that works too. Or I could just carry this myself in -next. In all cases, I would really appreciate reviews/acks/etc. :) Thanks! -Kees https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=linker/orphans/warn/v4 Kees Cook (17): vmlinux.lds.h: Add .gnu.version* to DISCARDS vmlinux.lds.h: Avoid KASAN and KCSAN's unwanted sections vmlinux.lds.h: Split ELF_DETAILS from STABS_DEBUG vmlinux.lds.h: Add .symtab, .strtab, and .shstrtab to ELF_DETAILS ctype: Work around Clang -mbranch-protection=none bug efi/libstub: Disable -mbranch-protection arm64/build: Use common DISCARDS in linker script arm64/mm: Remove needless section quotes arm64/build: Remove .eh_frame* sections due to unwind tables arm64/kernel: Remove needless Call Frame Information annotations arm64/build: Warn on orphan section placement arm/build: Refactor linker script headers arm/build: Explicitly keep .ARM.attributes sections arm/build: Warn on orphan section placement arm/boot: Warn on orphan section placement x86/build: Warn on orphan section placement x86/boot: Warn on orphan section placement arch/alpha/kernel/vmlinux.lds.S | 1 + arch/arc/kernel/vmlinux.lds.S | 1 + arch/arm/boot/compressed/Makefile | 2 ++ arch/arm/boot/compressed/vmlinux.lds.S | 18 +++++----- .../arm/{kernel => include/asm}/vmlinux.lds.h | 25 ++++++++++--- arch/arm/kernel/vmlinux-xip.lds.S | 6 ++-- arch/arm/kernel/vmlinux.lds.S | 6 ++-- arch/arm64/Makefile | 9 ++++- arch/arm64/kernel/smccc-call.S | 2 -- arch/arm64/kernel/vmlinux.lds.S | 17 ++++++--- arch/arm64/mm/mmu.c | 2 +- arch/csky/kernel/vmlinux.lds.S | 1 + arch/hexagon/kernel/vmlinux.lds.S | 1 + arch/ia64/kernel/vmlinux.lds.S | 1 + arch/mips/kernel/vmlinux.lds.S | 1 + arch/nds32/kernel/vmlinux.lds.S | 1 + arch/nios2/kernel/vmlinux.lds.S | 1 + arch/openrisc/kernel/vmlinux.lds.S | 1 + arch/parisc/boot/compressed/vmlinux.lds.S | 1 + arch/parisc/kernel/vmlinux.lds.S | 1 + arch/powerpc/kernel/vmlinux.lds.S | 2 +- arch/riscv/kernel/vmlinux.lds.S | 1 + arch/s390/kernel/vmlinux.lds.S | 1 + arch/sh/kernel/vmlinux.lds.S | 1 + arch/sparc/kernel/vmlinux.lds.S | 1 + arch/um/kernel/dyn.lds.S | 2 +- arch/um/kernel/uml.lds.S | 2 +- arch/unicore32/kernel/vmlinux.lds.S | 1 + arch/x86/Makefile | 8 ++++- arch/x86/boot/compressed/Makefile | 3 +- arch/x86/boot/compressed/vmlinux.lds.S | 12 +++++++ arch/x86/include/asm/asm.h | 6 +++- arch/x86/kernel/vmlinux.lds.S | 7 ++++ drivers/firmware/efi/libstub/Makefile | 3 +- include/asm-generic/vmlinux.lds.h | 35 +++++++++++++++++-- lib/ctype.c | 10 ++++++ 36 files changed, 154 insertions(+), 39 deletions(-) rename arch/arm/{kernel => include/asm}/vmlinux.lds.h (88%)