lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250304102536.GB2529736@ax162>
Date: Tue, 4 Mar 2025 11:25:36 +0100
From: Nathan Chancellor <nathan@...nel.org>
To: Thomas Weißschuh <linux@...ssschuh.net>
Cc: Kees Cook <kees@...nel.org>, Nick Desaulniers <ndesaulniers@...gle.com>,
	Bill Wendling <morbo@...gle.com>,
	Justin Stitt <justinstitt@...gle.com>,
	Masahiro Yamada <masahiroy@...nel.org>,
	Nicolas Schier <nicolas@...sle.eu>, llvm@...ts.linux.dev,
	linux-kbuild@...r.kernel.org, David Gow <davidgow@...gle.com>,
	linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] kbuild: clang: Support building UM with SUBARCH=i386

On Mon, Mar 03, 2025 at 11:29:58PM +0100, Thomas Weißschuh wrote:
> On 2025-03-03 13:52:41-0800, Kees Cook wrote:
> > The UM builds distinguish i386 from x86_64 via SUBARCH, but we don't
> > support building i386 directly with Clang. To make SUBARCH work for
> > i386 UM, we need to explicitly test for it.
> > 
> > This lets me run i386 KUnit tests with Clang:
> > 
> > $ ./tools/testing/kunit/kunit.py run \
> > 	--make_options LLVM=1 \
> > 	--make_options SUBARCH=i386
> > ...
> > 
> > Fixes: c7500c1b53bf ("um: Allow builds with Clang")
> > Signed-off-by: Kees Cook <kees@...nel.org>
> > ---
> > I could not find a cleaner way to do this without hardcoding a test
> > for i386 UM. Does anyone see a more sane way to accomplish this? The
> > comment above the CLANG_TARGET_FLAGS seems like it can't be done with
> > UM's Makefile...
> 
> This seems to work for me:
> 
> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> index 2435efae67f5..8e349bf30fa8 100644
> --- a/scripts/Makefile.clang
> +++ b/scripts/Makefile.clang
> @@ -12,6 +12,7 @@ CLANG_TARGET_FLAGS_riscv      := riscv64-linux-gnu
>  CLANG_TARGET_FLAGS_s390                := s390x-linux-gnu
>  CLANG_TARGET_FLAGS_sparc       := sparc64-linux-gnu
>  CLANG_TARGET_FLAGS_x86         := x86_64-linux-gnu
> +CLANG_TARGET_FLAGS_i386                := i386-linux-gnu
>  CLANG_TARGET_FLAGS_um          := $(CLANG_TARGET_FLAGS_$(SUBARCH))
>  CLANG_TARGET_FLAGS             := $(CLANG_TARGET_FLAGS_$(SRCARCH))

Yeah, I think I prefer this. As the comment at the top of this file
notes, we normally want '-m32' and '-m64' to control the word size,
which happens for regular x86 but not UML. Since UML is already weird
here, I think going this route for simplicity rather than consistency is
not that big of a deal. I would probably add a comment it is only there
for ARCH=um SUBARCH=i386 though just so we do not accidentally remove
it.

> This is also what exists in tools/testing/selftests/lib.mk.
> Minus the missing CONFIG_FORTIFY_SOURCE on clang x86_32
> and a failure of overflow.DEFINE_FLEX_test (clang 19.1.7).

Does Kees's other patch resolve the second issue? It'll obviously fix
the first :P

https://lore.kernel.org/20250303214929.work.499-kees@kernel.org/

> > Cc: Nathan Chancellor <nathan@...nel.org>
> > Cc: Nick Desaulniers <ndesaulniers@...gle.com>
> > Cc: Bill Wendling <morbo@...gle.com>
> > Cc: Justin Stitt <justinstitt@...gle.com>
> > Cc: Masahiro Yamada <masahiroy@...nel.org>
> > Cc: Nicolas Schier <nicolas@...sle.eu>
> > Cc: llvm@...ts.linux.dev
> > Cc: linux-kbuild@...r.kernel.org
> > ---
> >  scripts/Makefile.clang | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> > index 2435efae67f5..fa6f9a9be4ac 100644
> > --- a/scripts/Makefile.clang
> > +++ b/scripts/Makefile.clang
> > @@ -12,8 +12,12 @@ CLANG_TARGET_FLAGS_riscv	:= riscv64-linux-gnu
> >  CLANG_TARGET_FLAGS_s390		:= s390x-linux-gnu
> >  CLANG_TARGET_FLAGS_sparc	:= sparc64-linux-gnu
> >  CLANG_TARGET_FLAGS_x86		:= x86_64-linux-gnu
> > +ifeq ($(SRCARCH):$(SUBARCH),um:i386)
> > +CLANG_TARGET_FLAGS		:= i386-linux-gnu
> > +else
> >  CLANG_TARGET_FLAGS_um		:= $(CLANG_TARGET_FLAGS_$(SUBARCH))
> >  CLANG_TARGET_FLAGS		:= $(CLANG_TARGET_FLAGS_$(SRCARCH))
> > +endif
> >  
> >  ifeq ($(CLANG_TARGET_FLAGS),)
> >  $(error add '--target=' option to scripts/Makefile.clang)
> > -- 
> > 2.34.1
> > 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ