Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2890955pxa; Tue, 18 Aug 2020 00:12:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUIvWtwd9g5v7miO1mMuPpXBYuhvEc3qoGLMHqxbFbsBKCN0XqyuY4znOq5115qaZXsTl/ X-Received: by 2002:a17:906:4a07:: with SMTP id w7mr18184877eju.269.1597734775371; Tue, 18 Aug 2020 00:12:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597734775; cv=none; d=google.com; s=arc-20160816; b=u9lDn5YkZdRpGPoeAiAjqE9HkX6L2ahMlCtWibc+Y13uo8odZRQeQEMvUjjAX6kukt YYGEOG2kzrB2voB9maYdTBtYTiMC0xVr2Thpq1rvUBenpyI8DwO3nT/gxF0ftxs5F2Yy 4vUQelUNnhaBUON10gTunG5QiQMHuxcLnBlkFChq/AMXV+V6ckn0+Nu7jpoXifJUMQO2 2/mneVu43V3WvtPeYX/sqbmkaMQqNPShOFokn7JNuNtmhh+0ueVapBzKHwnkfXPLcgTM jsDtQ+CwZGO+WjbauNmWS7plogr6T5lWgHFnCttylFh966LaEkASCJVka92CUlabZAMz MdSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gN1c6Z5IJYvCIktGaxdXAKI//tisGqYnTLiA+pTgOt4=; b=j98VMUoWEKXDMrBdwaqLoIoGU3qgeesfxIJybd4529BsB7i19iIxqGyQD2G7cJjfAa Q9GxGD3wlHFZZcSFntThOeFeTfjTiEfhZNqy52/4LeWBdbKslu00T8LeFJdgUNqvScPB TT2Mn6Ts2tgCx1jsh/3Bco8F+YY8nkhgNOWbp1dIiYS+8QZAsOK+1+GgOzawxPYntVBb MeVNttoHZCdsNl1Utg7sKd8qgX2/jKGztZ44ZdSCSycPbT2WQwD7npKfG7Zto9tOc9we gslzzXLr4H+z5ASU8e0q+Rizf/kqvwAYpx65yLF1GAMhU8C9kPncEW028TImQidvpZo9 ku6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e0WLaNjp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m22si12016709edr.374.2020.08.18.00.12.31; Tue, 18 Aug 2020 00:12:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e0WLaNjp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgHRHKP (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 >