Message ID | 3ca525852ce14a8e04949ff115cb6ec28c8f120b.1671098103.git.baskov@ispras.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp326056wrn; Thu, 15 Dec 2022 04:39:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UL3LfX1fSBLon6GivXRLS/D7Gpb6aHd99lNbozQRdu9KGxK4ZQzYKW2VgXVK5mqRCAX0P X-Received: by 2002:a05:6a20:6f08:b0:a2:df6d:e56b with SMTP id gt8-20020a056a206f0800b000a2df6de56bmr12728274pzb.14.1671107990727; Thu, 15 Dec 2022 04:39:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671107990; cv=none; d=google.com; s=arc-20160816; b=ev037NXOWN67kabRpuVFhe/cS20OgzBf38QPh2FQJaW4bCQFD8q8BDkEqLMHMUWPeC Ro9eq/BQzZPRavJNSmFM2FE1fpDd1Dc//3aXeLRCMl92BL/eOjfMeJdfpRGd1gSRrwzI d0EZq5wciZ20NBf2SspJRaYCRLzuQbzvPKWHlGod7tl0N9FugId95zBCi17krPvAbeTj vuR3h5cVFTJ9bFVwKt8Ax7P0w5KdCViT6U86JzqhOq2yQWHapcmT9e2Nv6LzAu0jHlYr jzq7ZAWXmn5XToT1ivtsPELAusgBNOXxAt5SNi6BfvRkWP1xl31eH/1d5ZH5+oSgt5iG pmFA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=aytHXLPe5WFTxHpmffbYFL3H8M/KUu6PP4gNt7AoPJg=; b=Q8DE8wwe+El6nSuHg5FN24TaOOOMNPiLZgwW5epvOcjVZNi2XSU5MFWlg1dyaN6uPv IaS97sGFvjsg0e/D81F3XjMpzeVi9+d5fBnZQJApkSuViGyQINzyX9oJ+KlZMLnVWeM3 kwjGyaOH6/NgJWjlhc9SRTyflqQ2XhSempAM+stq/6WHHwZCRmDKg8vc70IBQCZ/9J27 gZfvMv1WpPUQrqQ4WM+fuzst5OVsIeOmacu3CYML1iDMq+CZNH202nL/tdwT8MzdPlYY dDJjyUdSQVaD1f7dqVgVzNoYRLhbdMLpj1w7GqRMmKW6z9XXy5/XhNVDDT+kGHmDkIxy 20TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=cDcOgTU8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a63504c000000b00478add2c2a6si2686271pgl.653.2022.12.15.04.39.36; Thu, 15 Dec 2022 04:39:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=cDcOgTU8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbiLOMjQ (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Thu, 15 Dec 2022 07:39:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbiLOMiq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Dec 2022 07:38:46 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 332362F007; Thu, 15 Dec 2022 04:38:29 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id BDB8F40737AF; Thu, 15 Dec 2022 12:38:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru BDB8F40737AF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671107902; bh=aytHXLPe5WFTxHpmffbYFL3H8M/KUu6PP4gNt7AoPJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDcOgTU86qfkkn+GkGXQbTgcmNdsXr3SsKorZvfOGrPtndS75vMdtsk/bvB1QJW0Y T2KXVmJJay7h8hUyXr7tTDtj1syOzP6X9Yp+MDvxEUr+/sY+5PUSO/g0hKwV0XM17g BeYkQvie4yzPmMvIeTjfXjikHG6Ry6iRRfX/3bxw= From: Evgeniy Baskov <baskov@ispras.ru> To: Ard Biesheuvel <ardb@kernel.org> Cc: Evgeniy Baskov <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Dave Hansen <dave.hansen@linux.intel.com>, Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Alexey Khoroshilov <khoroshilov@ispras.ru>, Peter Jones <pjones@redhat.com>, "Limonciello, Mario" <mario.limonciello@amd.com>, joeyli <jlee@suse.com>, lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 07/26] x86/build: Check W^X of vmlinux during build Date: Thu, 15 Dec 2022 15:37:58 +0300 Message-Id: <3ca525852ce14a8e04949ff115cb6ec28c8f120b.1671098103.git.baskov@ispras.ru> X-Mailer: git-send-email 2.37.4 In-Reply-To: <cover.1671098103.git.baskov@ispras.ru> References: <cover.1671098103.git.baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752283732691483486?= X-GMAIL-MSGID: =?utf-8?q?1752283732691483486?= |
Series |
x86_64: Improvements at compressed kernel stage
|
|
Commit Message
Evgeniy Baskov
Dec. 15, 2022, 12:37 p.m. UTC
Check if there are simultaneously writable and executable program segments in vmlinux ELF image and fail build if there are any. This would prevent accidental introduction of RWX segments. Tested-by: Mario Limonciello <mario.limonciello@amd.com> Tested-by: Peter Jones <pjones@redhat.com> Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> --- arch/x86/boot/compressed/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
Comments
On Thu, 15 Dec 2022 at 13:38, Evgeniy Baskov <baskov@ispras.ru> wrote: > > Check if there are simultaneously writable and executable > program segments in vmlinux ELF image and fail build if there are any. > > This would prevent accidental introduction of RWX segments. > > Tested-by: Mario Limonciello <mario.limonciello@amd.com> > Tested-by: Peter Jones <pjones@redhat.com> > Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> > --- > arch/x86/boot/compressed/Makefile | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index 1acff356d97a..4dcab38f5a38 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -112,11 +112,17 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o > vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o > vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > > +quiet_cmd_wx_check = WXCHK $< > +cmd_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; \ > + then (echo >&2 "$<: Simultaneously writable and executable sections are prohibited"; \ > + /bin/false); fi > + > $(obj)/vmlinux: $(vmlinux-objs-y) FORCE > $(call if_changed,ld) > > OBJCOPYFLAGS_vmlinux.bin := -R .comment -S > $(obj)/vmlinux.bin: vmlinux FORCE > + $(call cmd,wx_check) This breaks the way we track dependencies between make targets: the FORCE will result in the check being performed every time, even if nothing gets rebuilt. Better to do something like the below (apologies for the alphabet soup) --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -112,18 +112,17 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a -quiet_cmd_wx_check = WXCHK $< -cmd_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; \ - then (echo >&2 "$<: Simultaneously writable and executable sections are prohibited"; \ - /bin/false); fi +quiet_cmd_objcopy_and_wx_check = $(quiet_cmd_objcopy) + cmd_objcopy_and_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; then \ + (echo >&2 "$<: Simultaneously writable and executable sections are prohibited"; \ + /bin/false); else $(cmd_objcopy); fi $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld) OBJCOPYFLAGS_vmlinux.bin := -R .comment -S $(obj)/vmlinux.bin: vmlinux FORCE - $(call cmd,wx_check) - $(call if_changed,objcopy) + $(call if_changed,objcopy_and_wx_check)
On 2023-03-08 12:34, Ard Biesheuvel wrote: > On Thu, 15 Dec 2022 at 13:38, Evgeniy Baskov <baskov@ispras.ru> wrote: >> >> Check if there are simultaneously writable and executable >> program segments in vmlinux ELF image and fail build if there are any. >> >> This would prevent accidental introduction of RWX segments. >> >> Tested-by: Mario Limonciello <mario.limonciello@amd.com> >> Tested-by: Peter Jones <pjones@redhat.com> >> Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> >> --- >> arch/x86/boot/compressed/Makefile | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/arch/x86/boot/compressed/Makefile >> b/arch/x86/boot/compressed/Makefile >> index 1acff356d97a..4dcab38f5a38 100644 >> --- a/arch/x86/boot/compressed/Makefile >> +++ b/arch/x86/boot/compressed/Makefile >> @@ -112,11 +112,17 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o >> vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o >> vmlinux-objs-$(CONFIG_EFI_STUB) += >> $(objtree)/drivers/firmware/efi/libstub/lib.a >> >> +quiet_cmd_wx_check = WXCHK $< >> +cmd_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; \ >> + then (echo >&2 "$<: Simultaneously writable and >> executable sections are prohibited"; \ >> + /bin/false); fi >> + >> $(obj)/vmlinux: $(vmlinux-objs-y) FORCE >> $(call if_changed,ld) >> >> OBJCOPYFLAGS_vmlinux.bin := -R .comment -S >> $(obj)/vmlinux.bin: vmlinux FORCE >> + $(call cmd,wx_check) > > This breaks the way we track dependencies between make targets: the > FORCE will result in the check being performed every time, even if > nothing gets rebuilt. > > Better to do something like the below (apologies for the alphabet soup) > > > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -112,18 +112,17 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o > vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o > vmlinux-objs-$(CONFIG_EFI_STUB) += > $(objtree)/drivers/firmware/efi/libstub/lib.a > > -quiet_cmd_wx_check = WXCHK $< > -cmd_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; \ > - then (echo >&2 "$<: Simultaneously writable and > executable sections are prohibited"; \ > - /bin/false); fi > +quiet_cmd_objcopy_and_wx_check = $(quiet_cmd_objcopy) > + cmd_objcopy_and_wx_check = if $(OBJDUMP) -p $< | grep "flags > .wx" > /dev/null; then \ > + (echo >&2 "$<: Simultaneously > writable and executable sections are prohibited"; \ > + /bin/false); else > $(cmd_objcopy); fi > > $(obj)/vmlinux: $(vmlinux-objs-y) FORCE > $(call if_changed,ld) > > OBJCOPYFLAGS_vmlinux.bin := -R .comment -S > $(obj)/vmlinux.bin: vmlinux FORCE > - $(call cmd,wx_check) > - $(call if_changed,objcopy) > + $(call if_changed,objcopy_and_wx_check) Thank you for suggestion! I will fix it.
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 1acff356d97a..4dcab38f5a38 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -112,11 +112,17 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +quiet_cmd_wx_check = WXCHK $< +cmd_wx_check = if $(OBJDUMP) -p $< | grep "flags .wx" > /dev/null; \ + then (echo >&2 "$<: Simultaneously writable and executable sections are prohibited"; \ + /bin/false); fi + $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld) OBJCOPYFLAGS_vmlinux.bin := -R .comment -S $(obj)/vmlinux.bin: vmlinux FORCE + $(call cmd,wx_check) $(call if_changed,objcopy) targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs