From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 3BE63C433DF for ; Mon, 29 Jun 2020 15:37:00 +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 097C1252AE for ; Mon, 29 Jun 2020 15:37:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="m//xJHA5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nk7CylUI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 097C1252AE 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+linux-arm-kernel=archiver.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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SdXXyJyED9bRej2eCS63o8q3cla7TIJK3U/MpuG/V84=; b=m//xJHA5R/u96963JCKt5Y229 TMiPf1J7FFqLor46OHuxvNKeSRfmzq9RTCN/SGeFjKjt6esDTJmglg1Zp/e7xScnep+WXwumTQ/Rq uao6z5NFjai4rYUZjdPj6w0rhpMiEZIm4MtbmUjlrHLandC2DkUGYU3IcVZZ82Nxkr9M1Qq5LhZ8l kIcpHr1bdiCkaKaLrEkgEktDzGCZcRrFROh5NQx+OtbHIUQnfK5hT0OntVimEVm8BaMtTT0BppByu V6Wi370MpgdGNINiYOu0Edhyn6VHCRse0xzs6366aAvzu31FvkoO+tbkmMViCrkJsbkm0G3nZ2ASA IMWOA5qzg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpvoF-0006Ab-IK; Mon, 29 Jun 2020 15:35:03 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpvW7-0005hZ-Be for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 15:16:20 +0000 Received: by mail-pg1-x544.google.com with SMTP id e18so8436585pgn.7 for ; Mon, 29 Jun 2020 08:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MxaNfZcFdjnvVV9s2OR4TuJBb8g/A2/WCgXRT+sBVvY=; b=nk7CylUIcFnEwl5nB4/G5eY3eTfe+ai1vqc9c2oHqQv4ujDhnGbvygMoukja2YJeTA Behh520t8HD22lZYDSBnHBH/f6ixKRtHxv0pfn4T/BmYVAQOTxVbX7Z9rZvHEBo6l93a E+iuEmf9QZ+Em88RxG8BW0CKDFvQ0aMPdc3WY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MxaNfZcFdjnvVV9s2OR4TuJBb8g/A2/WCgXRT+sBVvY=; b=Ibgb4kDh9c7BFcqCu4wfjP8NjjzdF62dphf0sdBYGA0aWaqmaiSZ1EGbnoKpaX5rbB B2WbUFxTIt7O/ZwAuSn2j7hSno6Oi5Usqc1gxY6h1SmaJNEj1NVNv9yIPe0agnjecG0x 0bbnjMCgVHNgas3BZUL4M7tir37e5Knc70qDa+dI03dwuRDIw4EoNgviD8Y1GN7No6hk lQunTN6fZ1NWyD5CaLzEqhRKfeFTtjJ92rXtGZ9MhqkneWsAtjBcugJbRu7sge4jix+w eZgKKNAi4hbdPbTMMW5SZKbjh19Swh1ENCePEnMtlecQnIYhMpzdxYbcVZHYWlhUyyWv 2zzQ== X-Gm-Message-State: AOAM530Y31DSwqKkPyH9g8A2fksdtwfMBGVVFHbeIwEAdTXJ/YlRS17m LvQvul6/nCSSo/cignGsl6XToZ5mwyU= X-Google-Smtp-Source: ABdhPJzl56xBWX+ZegSv6wfP3UWa6a04vIxQa32bykuqiHWYdo9SW8enChklIBMtsq7sSXudFroy9w== X-Received: by 2002:a63:d74c:: with SMTP id w12mr11040695pgi.260.1593443776376; Mon, 29 Jun 2020 08:16:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z19sm227265pjn.55.2020.06.29.08.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 08:16:15 -0700 (PDT) Date: Mon, 29 Jun 2020 08:16:14 -0700 From: Kees Cook To: Ard Biesheuvel Subject: Re: [PATCH v4 05/17] ctype: Work around Clang -mbranch-protection=none bug Message-ID: <202006290815.E0E4850@keescook> References: <20200629061840.4065483-1-keescook@chromium.org> <20200629061840.4065483-6-keescook@chromium.org> <202006290806.3BDE2A8@keescook> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 , linux-efi , Arnd Bergmann , Peter Collingbourne , Masahiro Yamada , X86 ML , Nick Desaulniers , Russell King , Linux Kernel Mailing List , Nathan Chancellor , clang-built-linux , Arvind Sankar , Ingo Molnar , James Morse , Catalin Marinas , Thomas Gleixner , Borislav Petkov , Will Deacon , Dave Martin , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jun 29, 2020 at 05:08:03PM +0200, Ard Biesheuvel wrote: > On Mon, 29 Jun 2020 at 17:06, Kees Cook wrote: > > > > On Mon, Jun 29, 2020 at 10:15:47AM +0200, Ard Biesheuvel wrote: > > > On Mon, 29 Jun 2020 at 08:18, Kees Cook wrote: > > > > > > > > In preparation for building efi/libstub with -mbranch-protection=none > > > > (EFI does not support branch protection features[1]), add no-op code > > > > to work around a Clang bug that emits an unwanted .note.gnu.property > > > > section for object files without code[2]. > > > > > > > > [1] https://lore.kernel.org/lkml/CAMj1kXHck12juGi=E=P4hWP_8vQhQ+-x3vBMc3TGeRWdQ-XkxQ@mail.gmail.com > > > > [2] https://bugs.llvm.org/show_bug.cgi?id=46480 > > > > > > > > Cc: Ard Biesheuvel > > > > Cc: Will Deacon > > > > Cc: Dave Martin > > > > Cc: clang-built-linux@googlegroups.com > > > > Signed-off-by: Kees Cook > > > > --- > > > > lib/ctype.c | 10 ++++++++++ > > > > 1 file changed, 10 insertions(+) > > > > > > > > diff --git a/lib/ctype.c b/lib/ctype.c > > > > index c819fe269eb2..21245ed57d90 100644 > > > > --- a/lib/ctype.c > > > > +++ b/lib/ctype.c > > > > @@ -36,3 +36,13 @@ _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ > > > > _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ > > > > > > > > EXPORT_SYMBOL(_ctype); > > > > + > > > > +/* > > > > + * Clang will generate .note.gnu.property sections for object files > > > > + * without code, even in the presence of -mbranch-protection=none. > > > > + * To work around this, define an unused static function. > > > > + * https://bugs.llvm.org/show_bug.cgi?id=46480 > > > > + */ > > > > +#ifdef CONFIG_CC_IS_CLANG > > > > +void __maybe_unused __clang_needs_code_here(void) { } > > > > +#endif > > > > -- > > > > 2.25.1 > > > > > > > > > > I take it we don't need this horrible hack if we build the EFI stub > > > with branch protections and filter out the .note.gnu.property section > > > explicitly? > > > > > > Sorry to backpedal, but that is probably a better approach after all, > > > given that the instructions don't hurt, and we will hopefully be able > > > to arm them once UEFI (as well as PE/COFF) gets around to describing > > > this in a way that both the firmware and the OS can consume. > > > > How does this look? > > > > > > commit 051ef0b75a386c3fe2f216d16246468147a48c5b > > Author: Kees Cook > > Date: Tue Jun 23 18:02:56 2020 -0700 > > > > efi/libstub: Disable -mbranch-protection > > > > In preparation for adding --orphan-handling=warn to more architectures, > > disable -mbranch-protection, as EFI does not yet support it[1]. This was > > noticed due to it producing unwanted .note.gnu.property sections (prefixed > > with .init due to the objcopy build step). > > > > However, we must also work around a bug in Clang where the section is > > still emitted for code-less object files[2], so also remove the section > > during the objcopy. > > > > [1] https://lore.kernel.org/lkml/CAMj1kXHck12juGi=E=P4hWP_8vQhQ+-x3vBMc3TGeRWdQ-XkxQ@mail.gmail.com > > [2] https://bugs.llvm.org/show_bug.cgi?id=46480 > > > > Cc: Ard Biesheuvel > > Cc: Arvind Sankar > > Cc: Atish Patra > > Cc: linux-efi@vger.kernel.org > > Signed-off-by: Kees Cook > > > > diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile > > index 75daaf20374e..f9f1922f8f28 100644 > > --- a/drivers/firmware/efi/libstub/Makefile > > +++ b/drivers/firmware/efi/libstub/Makefile > > @@ -18,7 +18,8 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \ > > # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly > > # disable the stackleak plugin > > cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ > > - -fpie $(DISABLE_STACKLEAK_PLUGIN) > > + -fpie $(DISABLE_STACKLEAK_PLUGIN) \ > > + $(call cc-option,-mbranch-protection=none) > > cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ > > -fno-builtin -fpic \ > > $(call cc-option,-mno-single-pic-base) > > @@ -66,6 +67,12 @@ lib-$(CONFIG_X86) += x86-stub.o > > CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) > > CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) > > > > +# Even when -mbranch-protection=none is set, Clang will generate a > > +# .note.gnu.property for code-less object files (like lib/ctype.c), > > +# so work around this by explicitly removing the unwanted section. > > +# https://bugs.llvm.org/show_bug.cgi?id=46480 > > +STUBCOPY_FLAGS-y += --remove-section=.note.gnu.property > > + > > # > > # For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the > > # .bss section, so the .bss section of the EFI stub needs to be included in the > > > > > Looks fine > > Acked-by: Ard Biesheuvel Thanks! > if you want to keep it with the set, or I can take it as a EFI fix. My current plan is to just keep it all together. -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel