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=-15.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 D63ECC433E1 for ; Tue, 18 Aug 2020 07:10:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5D8F20738 for ; Tue, 18 Aug 2020 07:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597734615; bh=nvaUJNFyV4vcax39lj23nhAOIb3Ku6tgS77eD620sJU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=piPML4Q2QjB9Rmw2ulHOmeUnvtNA8mmQPwaqE5AhNaDnxvfeDrvB/lAge1YIhJkkn 8D19U7aq4rNAD0V0Pnw4sMiOmEoWHZSSEKV/5G0XaHXLkCK561K24+1NNAGWYinXKP c6tWUBTIW5WlUPzuVGbRzci4vLGjcRuEykk3qJ9A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726043AbgHRHKP (ORCPT ); Tue, 18 Aug 2020 03:10:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726391AbgHRHKO (ORCPT ); Tue, 18 Aug 2020 03:10:14 -0400 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E913C20888; Tue, 18 Aug 2020 07:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597734613; bh=nvaUJNFyV4vcax39lj23nhAOIb3Ku6tgS77eD620sJU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=e0WLaNjpcYHgH6zXxnkBdlCKn0O944BaciZPf+JQNO980yc9TgQNPCD2TcMz5Pjkf Ng1v9pjMccdNPSQIJmrbgszTNpWm98fB8zsrHqS3oJ9WA0AnTwXeqzUbYFQ0iRtMCS k5wTh75UzMHUECYh/LBWGl0S/F3lWeQnb49qTWoU= Received: by mail-oi1-f178.google.com with SMTP id h3so17066677oie.11; Tue, 18 Aug 2020 00:10:12 -0700 (PDT) X-Gm-Message-State: AOAM531HtQ/KuLTl1RIBRkciRlKShYAop4G7xC4vAJWJeTbMUa/AFgkS K1be+miq1s4YjGdubq47giNmA8Zj2QotONObPfA= X-Google-Smtp-Source: ABdhPJw9HzTUd9lQlRMwnPZQSdMbm1DoI/CKErme58AW//8FBa3prxqrmj0wo63+SxVt1FSeD/n6r9X9HX4Sh4zSvqE= X-Received: by 2002:aca:d8c5:: with SMTP id p188mr11327582oig.47.1597734612072; Tue, 18 Aug 2020 00:10:12 -0700 (PDT) MIME-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> <20200817220212.338670-2-ndesaulniers@google.com> In-Reply-To: <20200817220212.338670-2-ndesaulniers@google.com> From: Ard Biesheuvel Date: Tue, 18 Aug 2020 09:10:01 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy To: Nick Desaulniers Cc: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Michal Marek , linux-kbuild@vger.kernel.org, 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 , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman , "# 3.4.x" , Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org On Tue, 18 Aug 2020 at 00:02, Nick Desaulniers wr= ote: > > 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=3D47162 > Link: https://github.com/ClangBuiltLinux/linux/issues/1126 > Link: https://reviews.llvm.org/D85963 > Reported-by: Sami Tolvanen > Suggested-by: D=C3=A1vid Bolvansk=C3=BD > Suggested-by: Kees Cook > Signed-off-by: Nick Desaulniers > --- > 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 +=3D $(call cc-option,-fcf-protection=3Dnone) > endif > > +# The compiler may "libcall optimize" certain function calls into the be= low > +# functions, for architectures that don't use -ffreestanding. If we don'= t plan > +# to provide implementations of these routines, then prevent the compile= r from > +# emitting calls to what will be undefined symbols. > +KBUILD_CFLAGS +=3D -fno-builtin-stpcpy > + > # include additional Makefiles when needed > include-y :=3D scripts/Makefile.extrawarn > include-$(CONFIG_KASAN) +=3D scripts/Makefile.kasan > -- > 2.28.0.220.ged08abb693-goog >