stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
       [not found] <20200817220212.338670-1-ndesaulniers@google.com>
@ 2020-08-17 22:02 ` Nick Desaulniers
  2020-08-17 22:31   ` H. Peter Anvin
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Nick Desaulniers @ 2020-08-17 22:02 UTC (permalink / raw)
  To: Masahiro Yamada, Andrew Morton, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov
  Cc: Michal Marek, linux-kbuild, linux-kernel, Kees Cook, Tony Luck,
	Dmitry Vyukov, Michael Ellerman, Joe Perches, Joel Fernandes,
	Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, x86, H . Peter Anvin,
	Ard Biesheuvel, Paul E . McKenney, Daniel Kiper, Bruce Ashfield,
	Marco Elver, Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, Nick Desaulniers, stable, Sami Tolvanen

LLVM implemented a recent "libcall optimization" that lowers calls to
`sprintf(dest, "%s", str)` where the return value is used to
`stpcpy(dest, str) - dest`. This generally avoids the machinery involved
in parsing format strings. This optimization was introduced into
clang-12. Because the kernel does not provide an implementation of
stpcpy, we observe linkage failures for almost all targets when building
with ToT clang.

The interface is unsafe as it does not perform any bounds checking.
Disable this "libcall optimization" via `-fno-builtin-stpcpy`.

Unlike
commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
which cited failures with `-fno-builtin-*` flags being retained in LLVM
LTO, that bug seems to have been fixed by
https://reviews.llvm.org/D71193, so the above sha can now be reverted in
favor of `-fno-builtin-bcmp`.

Cc: stable@vger.kernel.org # 4.4
Link: https://bugs.llvm.org/show_bug.cgi?id=47162
Link: https://github.com/ClangBuiltLinux/linux/issues/1126
Link: https://reviews.llvm.org/D85963
Reported-by: Sami Tolvanen <samitolvanen@google.com>
Suggested-by: Dávid Bolvanský <david.bolvansky@gmail.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Makefile b/Makefile
index 9cac6fde3479..211a1b6f6478 100644
--- a/Makefile
+++ b/Makefile
@@ -959,6 +959,12 @@ ifdef CONFIG_RETPOLINE
 KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
 endif
 
+# The compiler may "libcall optimize" certain function calls into the below
+# functions, for architectures that don't use -ffreestanding. If we don't plan
+# to provide implementations of these routines, then prevent the compiler from
+# emitting calls to what will be undefined symbols.
+KBUILD_CFLAGS	+= -fno-builtin-stpcpy
+
 # include additional Makefiles when needed
 include-y			:= scripts/Makefile.extrawarn
 include-$(CONFIG_KASAN)		+= scripts/Makefile.kasan
-- 
2.28.0.220.ged08abb693-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-17 22:02 ` [PATCH 1/4] Makefile: add -fno-builtin-stpcpy Nick Desaulniers
@ 2020-08-17 22:31   ` H. Peter Anvin
  2020-08-17 23:36     ` Nick Desaulniers
  2020-08-18 19:21     ` Kees Cook
  2020-08-18  7:10   ` Ard Biesheuvel
  2020-08-18 19:23   ` Kees Cook
  2 siblings, 2 replies; 9+ messages in thread
From: H. Peter Anvin @ 2020-08-17 22:31 UTC (permalink / raw)
  To: Nick Desaulniers, Masahiro Yamada, Andrew Morton,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: Michal Marek, linux-kbuild, linux-kernel, Kees Cook, Tony Luck,
	Dmitry Vyukov, Michael Ellerman, Joe Perches, Joel Fernandes,
	Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, x86, Ard Biesheuvel,
	Paul E . McKenney, Daniel Kiper, Bruce Ashfield, Marco Elver,
	Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, stable, Sami Tolvanen

On 2020-08-17 15:02, Nick Desaulniers wrote:
> LLVM implemented a recent "libcall optimization" that lowers calls to
> `sprintf(dest, "%s", str)` where the return value is used to
> `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> in parsing format strings. This optimization was introduced into
> clang-12. Because the kernel does not provide an implementation of
> stpcpy, we observe linkage failures for almost all targets when building
> with ToT clang.
> 
> The interface is unsafe as it does not perform any bounds checking.
> Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> 
> Unlike
> commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> which cited failures with `-fno-builtin-*` flags being retained in LLVM
> LTO, that bug seems to have been fixed by
> https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> favor of `-fno-builtin-bcmp`.
> 

stpcpy() and (to a lesser degree) mempcpy() are fairly useful routines
in general. Perhaps we *should* provide them?

	-hpa


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-17 22:31   ` H. Peter Anvin
@ 2020-08-17 23:36     ` Nick Desaulniers
  2020-08-18 19:21     ` Kees Cook
  1 sibling, 0 replies; 9+ messages in thread
From: Nick Desaulniers @ 2020-08-17 23:36 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Masahiro Yamada, Andrew Morton, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Michal Marek, Linux Kbuild mailing list, LKML,
	Kees Cook, Tony Luck, Dmitry Vyukov, Michael Ellerman,
	Joe Perches, Joel Fernandes, Daniel Axtens, Arvind Sankar,
	Andy Shevchenko, Alexandru Ardelean, Yury Norov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Ard Biesheuvel, Paul E . McKenney, Daniel Kiper, Bruce Ashfield,
	Marco Elver, Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, # 3.4.x, Sami Tolvanen

On Mon, Aug 17, 2020 at 3:31 PM H. Peter Anvin <hpa@zytor.com> wrote:
>
> On 2020-08-17 15:02, Nick Desaulniers wrote:
> > LLVM implemented a recent "libcall optimization" that lowers calls to
> > `sprintf(dest, "%s", str)` where the return value is used to
> > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> > in parsing format strings. This optimization was introduced into
> > clang-12. Because the kernel does not provide an implementation of
> > stpcpy, we observe linkage failures for almost all targets when building
> > with ToT clang.
> >
> > The interface is unsafe as it does not perform any bounds checking.
> > Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> >
> > Unlike
> > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> > which cited failures with `-fno-builtin-*` flags being retained in LLVM
> > LTO, that bug seems to have been fixed by
> > https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> > favor of `-fno-builtin-bcmp`.
> >
>
> stpcpy() and (to a lesser degree) mempcpy() are fairly useful routines
> in general. Perhaps we *should* provide them?

Sorry, I forgot to provide context of the previous thread, which is
worth a read.  To answer this question specifically (or at least for
stpcpy), the answer from the previous thread was (via Kees): "No;
please no more unbounded string.h routines":
https://lore.kernel.org/lkml/202008150921.B70721A359@keescook/
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-17 22:02 ` [PATCH 1/4] Makefile: add -fno-builtin-stpcpy Nick Desaulniers
  2020-08-17 22:31   ` H. Peter Anvin
@ 2020-08-18  7:10   ` Ard Biesheuvel
  2020-08-18  7:25     ` Greg KH
  2020-08-18 19:23   ` Kees Cook
  2 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2020-08-18  7:10 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Andrew Morton, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Michal Marek, linux-kbuild,
	Linux Kernel Mailing List, Kees Cook, Tony Luck, Dmitry Vyukov,
	Michael Ellerman, Joe Perches, Joel Fernandes, Daniel Axtens,
	Arvind Sankar, Andy Shevchenko, Alexandru Ardelean, Yury Norov,
	X86 ML, H . Peter Anvin, Paul E . McKenney, Daniel Kiper,
	Bruce Ashfield, Marco Elver, Vamshi K Sthambamkadi, Andi Kleen,
	Linus Torvalds, Dávid Bolvanský,
	Eli Friedman, # 3.4.x, Sami Tolvanen

On Tue, 18 Aug 2020 at 00:02, Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> LLVM implemented a recent "libcall optimization" that lowers calls to
> `sprintf(dest, "%s", str)` where the return value is used to
> `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> in parsing format strings. This optimization was introduced into
> clang-12. Because the kernel does not provide an implementation of
> stpcpy, we observe linkage failures for almost all targets when building
> with ToT clang.
>
> The interface is unsafe as it does not perform any bounds checking.
> Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
>
> Unlike
> commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> which cited failures with `-fno-builtin-*` flags being retained in LLVM
> LTO, that bug seems to have been fixed by
> https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> favor of `-fno-builtin-bcmp`.
>
> Cc: stable@vger.kernel.org # 4.4

Why does a fix for Clang-12 have to be backported all the way to v4.4?
How does that meet the requirements for stable patches?

> Link: https://bugs.llvm.org/show_bug.cgi?id=47162
> Link: https://github.com/ClangBuiltLinux/linux/issues/1126
> Link: https://reviews.llvm.org/D85963
> Reported-by: Sami Tolvanen <samitolvanen@google.com>
> Suggested-by: Dávid Bolvanský <david.bolvansky@gmail.com>
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  Makefile | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 9cac6fde3479..211a1b6f6478 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -959,6 +959,12 @@ ifdef CONFIG_RETPOLINE
>  KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
>  endif
>
> +# The compiler may "libcall optimize" certain function calls into the below
> +# functions, for architectures that don't use -ffreestanding. If we don't plan
> +# to provide implementations of these routines, then prevent the compiler from
> +# emitting calls to what will be undefined symbols.
> +KBUILD_CFLAGS  += -fno-builtin-stpcpy
> +
>  # include additional Makefiles when needed
>  include-y                      := scripts/Makefile.extrawarn
>  include-$(CONFIG_KASAN)                += scripts/Makefile.kasan
> --
> 2.28.0.220.ged08abb693-goog
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-18  7:10   ` Ard Biesheuvel
@ 2020-08-18  7:25     ` Greg KH
  2020-08-18  7:29       ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2020-08-18  7:25 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Nick Desaulniers, Masahiro Yamada, Andrew Morton,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Michal Marek,
	linux-kbuild, Linux Kernel Mailing List, Kees Cook, Tony Luck,
	Dmitry Vyukov, Michael Ellerman, Joe Perches, Joel Fernandes,
	Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, X86 ML, H . Peter Anvin,
	Paul E . McKenney, Daniel Kiper, Bruce Ashfield, Marco Elver,
	Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, # 3.4.x, Sami Tolvanen

On Tue, Aug 18, 2020 at 09:10:01AM +0200, Ard Biesheuvel wrote:
> On Tue, 18 Aug 2020 at 00:02, Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > LLVM implemented a recent "libcall optimization" that lowers calls to
> > `sprintf(dest, "%s", str)` where the return value is used to
> > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> > in parsing format strings. This optimization was introduced into
> > clang-12. Because the kernel does not provide an implementation of
> > stpcpy, we observe linkage failures for almost all targets when building
> > with ToT clang.
> >
> > The interface is unsafe as it does not perform any bounds checking.
> > Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> >
> > Unlike
> > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> > which cited failures with `-fno-builtin-*` flags being retained in LLVM
> > LTO, that bug seems to have been fixed by
> > https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> > favor of `-fno-builtin-bcmp`.
> >
> > Cc: stable@vger.kernel.org # 4.4
> 
> Why does a fix for Clang-12 have to be backported all the way to v4.4?
> How does that meet the requirements for stable patches?

Because people like to build older kernels with new compliler versions.

And those "people" include me, who doesn't want to keep around old
compilers just because my distro moved to the latest one...

We've been doing this for the past 4+ years, for new versions of gcc,
keeping 4.4.y building properly with the bleeding edge of that compiler,
why is clang any different here?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-18  7:25     ` Greg KH
@ 2020-08-18  7:29       ` Ard Biesheuvel
  2020-08-18  7:34         ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2020-08-18  7:29 UTC (permalink / raw)
  To: Greg KH
  Cc: Nick Desaulniers, Masahiro Yamada, Andrew Morton,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Michal Marek,
	linux-kbuild, Linux Kernel Mailing List, Kees Cook, Tony Luck,
	Dmitry Vyukov, Michael Ellerman, Joe Perches, Joel Fernandes,
	Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, X86 ML, H . Peter Anvin,
	Paul E . McKenney, Daniel Kiper, Bruce Ashfield, Marco Elver,
	Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, # 3.4.x, Sami Tolvanen

On Tue, 18 Aug 2020 at 09:25, Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Tue, Aug 18, 2020 at 09:10:01AM +0200, Ard Biesheuvel wrote:
> > On Tue, 18 Aug 2020 at 00:02, Nick Desaulniers <ndesaulniers@google.com> wrote:
> > >
> > > LLVM implemented a recent "libcall optimization" that lowers calls to
> > > `sprintf(dest, "%s", str)` where the return value is used to
> > > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> > > in parsing format strings. This optimization was introduced into
> > > clang-12. Because the kernel does not provide an implementation of
> > > stpcpy, we observe linkage failures for almost all targets when building
> > > with ToT clang.
> > >
> > > The interface is unsafe as it does not perform any bounds checking.
> > > Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> > >
> > > Unlike
> > > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> > > which cited failures with `-fno-builtin-*` flags being retained in LLVM
> > > LTO, that bug seems to have been fixed by
> > > https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> > > favor of `-fno-builtin-bcmp`.
> > >
> > > Cc: stable@vger.kernel.org # 4.4
> >
> > Why does a fix for Clang-12 have to be backported all the way to v4.4?
> > How does that meet the requirements for stable patches?
>
> Because people like to build older kernels with new compliler versions.
>
> And those "people" include me, who doesn't want to keep around old
> compilers just because my distro moved to the latest one...
>
> We've been doing this for the past 4+ years, for new versions of gcc,
> keeping 4.4.y building properly with the bleeding edge of that compiler,
> why is clang any different here?
>

Fair enough. I am just struggling to match stable-kernel-rules.rst
with the actual practices - perhaps it is time to update that
document?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-18  7:29       ` Ard Biesheuvel
@ 2020-08-18  7:34         ` Greg KH
  0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2020-08-18  7:34 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Nick Desaulniers, Masahiro Yamada, Andrew Morton,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Michal Marek,
	linux-kbuild, Linux Kernel Mailing List, Kees Cook, Tony Luck,
	Dmitry Vyukov, Michael Ellerman, Joe Perches, Joel Fernandes,
	Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, X86 ML, H . Peter Anvin,
	Paul E . McKenney, Daniel Kiper, Bruce Ashfield, Marco Elver,
	Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, # 3.4.x, Sami Tolvanen

On Tue, Aug 18, 2020 at 09:29:39AM +0200, Ard Biesheuvel wrote:
> On Tue, 18 Aug 2020 at 09:25, Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Tue, Aug 18, 2020 at 09:10:01AM +0200, Ard Biesheuvel wrote:
> > > On Tue, 18 Aug 2020 at 00:02, Nick Desaulniers <ndesaulniers@google.com> wrote:
> > > >
> > > > LLVM implemented a recent "libcall optimization" that lowers calls to
> > > > `sprintf(dest, "%s", str)` where the return value is used to
> > > > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> > > > in parsing format strings. This optimization was introduced into
> > > > clang-12. Because the kernel does not provide an implementation of
> > > > stpcpy, we observe linkage failures for almost all targets when building
> > > > with ToT clang.
> > > >
> > > > The interface is unsafe as it does not perform any bounds checking.
> > > > Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> > > >
> > > > Unlike
> > > > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> > > > which cited failures with `-fno-builtin-*` flags being retained in LLVM
> > > > LTO, that bug seems to have been fixed by
> > > > https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> > > > favor of `-fno-builtin-bcmp`.
> > > >
> > > > Cc: stable@vger.kernel.org # 4.4
> > >
> > > Why does a fix for Clang-12 have to be backported all the way to v4.4?
> > > How does that meet the requirements for stable patches?
> >
> > Because people like to build older kernels with new compliler versions.
> >
> > And those "people" include me, who doesn't want to keep around old
> > compilers just because my distro moved to the latest one...
> >
> > We've been doing this for the past 4+ years, for new versions of gcc,
> > keeping 4.4.y building properly with the bleeding edge of that compiler,
> > why is clang any different here?
> >
> 
> Fair enough. I am just struggling to match stable-kernel-rules.rst
> with the actual practices - perhaps it is time to update that
> document?

The rules are tiny and simple for 99% of the issues involved.  Stuff
like "add patches to fix build failures and warnings for newer compiler
versions" are so rare (they only happen every 2 years or so), it's not
worth it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-17 22:31   ` H. Peter Anvin
  2020-08-17 23:36     ` Nick Desaulniers
@ 2020-08-18 19:21     ` Kees Cook
  1 sibling, 0 replies; 9+ messages in thread
From: Kees Cook @ 2020-08-18 19:21 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Nick Desaulniers, Masahiro Yamada, Andrew Morton,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Michal Marek,
	linux-kbuild, linux-kernel, Tony Luck, Dmitry Vyukov,
	Michael Ellerman, Joe Perches, Joel Fernandes, Daniel Axtens,
	Arvind Sankar, Andy Shevchenko, Alexandru Ardelean, Yury Norov,
	x86, Ard Biesheuvel, Paul E . McKenney, Daniel Kiper,
	Bruce Ashfield, Marco Elver, Vamshi K Sthambamkadi, Andi Kleen,
	Linus Torvalds, Dávid Bolvanský,
	Eli Friedman, stable, Sami Tolvanen

On Mon, Aug 17, 2020 at 03:31:26PM -0700, H. Peter Anvin wrote:
> On 2020-08-17 15:02, Nick Desaulniers wrote:
> > LLVM implemented a recent "libcall optimization" that lowers calls to
> > `sprintf(dest, "%s", str)` where the return value is used to
> > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> > in parsing format strings. This optimization was introduced into
> > clang-12. Because the kernel does not provide an implementation of
> > stpcpy, we observe linkage failures for almost all targets when building
> > with ToT clang.
> > 
> > The interface is unsafe as it does not perform any bounds checking.
> > Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> > 
> > Unlike
> > commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> > which cited failures with `-fno-builtin-*` flags being retained in LLVM
> > LTO, that bug seems to have been fixed by
> > https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> > favor of `-fno-builtin-bcmp`.
> > 
> 
> stpcpy() and (to a lesser degree) mempcpy() are fairly useful routines
> in general. Perhaps we *should* provide them?

As Nick mentioned, I really don't want to expand the already bad
interfaces from libc. We have enough messes to clean up already, and I
don't want to add more. The kernel already uses a subset of C, we have
(several) separate non-libc memory allocators, we're using strscpy() and
scnprintf() widely in favor of their buggy libc counterparts, etc. We
don't need to match the libc string interfaces especially when they're
arguably bug-prone foot-guns. :)

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy
  2020-08-17 22:02 ` [PATCH 1/4] Makefile: add -fno-builtin-stpcpy Nick Desaulniers
  2020-08-17 22:31   ` H. Peter Anvin
  2020-08-18  7:10   ` Ard Biesheuvel
@ 2020-08-18 19:23   ` Kees Cook
  2 siblings, 0 replies; 9+ messages in thread
From: Kees Cook @ 2020-08-18 19:23 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Andrew Morton, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Michal Marek, linux-kbuild, linux-kernel,
	Tony Luck, Dmitry Vyukov, Michael Ellerman, Joe Perches,
	Joel Fernandes, Daniel Axtens, Arvind Sankar, Andy Shevchenko,
	Alexandru Ardelean, Yury Norov, x86, H . Peter Anvin,
	Ard Biesheuvel, Paul E . McKenney, Daniel Kiper, Bruce Ashfield,
	Marco Elver, Vamshi K Sthambamkadi, Andi Kleen, Linus Torvalds,
	Dávid Bolvanský,
	Eli Friedman, stable, Sami Tolvanen

On Mon, Aug 17, 2020 at 03:02:09PM -0700, Nick Desaulniers wrote:
> LLVM implemented a recent "libcall optimization" that lowers calls to
> `sprintf(dest, "%s", str)` where the return value is used to
> `stpcpy(dest, str) - dest`. This generally avoids the machinery involved
> in parsing format strings. This optimization was introduced into
> clang-12. Because the kernel does not provide an implementation of
> stpcpy, we observe linkage failures for almost all targets when building
> with ToT clang.
> 
> The interface is unsafe as it does not perform any bounds checking.
> Disable this "libcall optimization" via `-fno-builtin-stpcpy`.
> 
> Unlike
> commit 5f074f3e192f ("lib/string.c: implement a basic bcmp")
> which cited failures with `-fno-builtin-*` flags being retained in LLVM
> LTO, that bug seems to have been fixed by
> https://reviews.llvm.org/D71193, so the above sha can now be reverted in
> favor of `-fno-builtin-bcmp`.
> 
> Cc: stable@vger.kernel.org # 4.4
> Link: https://bugs.llvm.org/show_bug.cgi?id=47162
> Link: https://github.com/ClangBuiltLinux/linux/issues/1126
> Link: https://reviews.llvm.org/D85963
> Reported-by: Sami Tolvanen <samitolvanen@google.com>
> Suggested-by: Dávid Bolvanský <david.bolvansky@gmail.com>
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-08-18 19:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200817220212.338670-1-ndesaulniers@google.com>
2020-08-17 22:02 ` [PATCH 1/4] Makefile: add -fno-builtin-stpcpy Nick Desaulniers
2020-08-17 22:31   ` H. Peter Anvin
2020-08-17 23:36     ` Nick Desaulniers
2020-08-18 19:21     ` Kees Cook
2020-08-18  7:10   ` Ard Biesheuvel
2020-08-18  7:25     ` Greg KH
2020-08-18  7:29       ` Ard Biesheuvel
2020-08-18  7:34         ` Greg KH
2020-08-18 19:23   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).