From patchwork Mon Aug 17 22:02:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 11719421 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51982109B for ; Mon, 17 Aug 2020 22:04:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A3A420738 for ; Mon, 17 Aug 2020 22:04:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LiE9k63v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729278AbgHQWE4 (ORCPT ); Mon, 17 Aug 2020 18:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729277AbgHQWCY (ORCPT ); Mon, 17 Aug 2020 18:02:24 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5233EC061342 for ; Mon, 17 Aug 2020 15:02:24 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x6so15139677ybp.10 for ; Mon, 17 Aug 2020 15:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=UpYGtC8VuPYbMUYzVChohylhl5f+DwA/jtv3WLbpTdU=; b=LiE9k63vyCkhMTzCYeoaOM75uDKE+XeLSj2h/3vVFNBtsbG28nLNlqtKpTLxlj5faJ AAYS7sxuGNAA16qzVg1TR2Xrv4mJvPmQInmvyq957XguEVvW2RlgPL24OfTHYZyM7jTd aYh3VfLRRQofH8X4nGmNCAahxvnwi+L5GwOV6amHL6jODkxTtu+gCzfcVlnUcpjEhjLv i4zVI2Y07P0ZX3H26HpgtYeiV+DfeXO+PoBd/WycXbEG4u3e1rv9smrAfL1pQ1kMTEaR eD9vQkiLdGUIg/t0Cz5lu6Ku1Wop0JRuKdYyFaNxzSm3dlF/+n1KvP2pYqjs2LUfecLh dzLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=UpYGtC8VuPYbMUYzVChohylhl5f+DwA/jtv3WLbpTdU=; b=sNKuQ8n5gRPDaesJalXxDoqd1ACGRB3djTafARNjrRgqoQ5uWByghdNqh4XIq5f0vE eSe/nkhAspPmQfK9fX0Y/TV9A7fHL9eu/9nAg9CcYKs0j4q8ZB7PQVL6OyhgKTqh3byl jQYpZxRSidwZF58sgqYPHEZPitcleFPXkTLwwgvDVXcDzQ1JeSdvrekqyJp3MoUZzz3b n3MociYQTDfmAA/85ajgqB7ywBmUWUb57uLmyFcrB2VPSPGTfEUcEfDZpcjktsx6kOSN NH26nWqRQv53qqyilUVW55kBSGoiW1iA7aVjNOZKIvSqEjfWhpdW+KWn+cuxUUkZ+TIt PkTA== X-Gm-Message-State: AOAM533HU5bPMN1OLU+po4KJM+pppFIfT/XdQD30m7xRejiJ+Kjw5mkH RztuXsOkW5m5PRrwCDq8CQERFywI2chJPaf37EM= X-Google-Smtp-Source: ABdhPJxizyp67lNME36xRZPdIHp+ZAc9h1Guk5DKKetBtfDNGZaI3fQVyPo4QkcGpgpnPDnBe+lR31JKDOpF3hrgtgc= X-Received: by 2002:a25:4252:: with SMTP id p79mr24577079yba.229.1597701743469; Mon, 17 Aug 2020 15:02:23 -0700 (PDT) Date: Mon, 17 Aug 2020 15:02:09 -0700 In-Reply-To: <20200817220212.338670-1-ndesaulniers@google.com> Message-Id: <20200817220212.338670-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 1/4] Makefile: add -fno-builtin-stpcpy From: Nick Desaulniers To: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , " =?utf-8?b?RMOhdmlkIEJvbHZhbnNrw70=?= " , Eli Friedman , Nick Desaulniers , stable@vger.kernel.org, Sami Tolvanen Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 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 Suggested-by: Dávid Bolvanský Suggested-by: Kees Cook Signed-off-by: Nick Desaulniers Reviewed-by: Kees Cook --- 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 From patchwork Mon Aug 17 22:02:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 11719417 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66601109B for ; Mon, 17 Aug 2020 22:04:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4998E20738 for ; Mon, 17 Aug 2020 22:04:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SbD3KyAR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729624AbgHQWEi (ORCPT ); Mon, 17 Aug 2020 18:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729284AbgHQWC3 (ORCPT ); Mon, 17 Aug 2020 18:02:29 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36DAAC061347 for ; Mon, 17 Aug 2020 15:02:28 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id n32so10859863pgb.22 for ; Mon, 17 Aug 2020 15:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LSuJ265AIHX3+q/k1a/Z37Re9kn2OGu2g13JwIWu2AE=; b=SbD3KyARYSzP8T36XfR3PSHqanZP7aAf5JDZqJYGiBhLP4rKgTLGRPXAppDrg1sTl5 A9PvTf6cNxt3GdMtU0KSlh7GmwXcTGaesG0K0g3xTu8P8G7joqPf8pqpMrmBKfoEbjd6 PJZiF857IQv87kAQWEqVMLXO4K6nHk5cg7ima1rEYeAq7T29BawPJFtEEEoh/Txl8pWT TrKCydEAn6SB0ypdUtIwcrhW5JGeTybo2eNnMFkTEVjjLmLpnN6izcqwyzozEc5lZzCj z4Y3sjmLT2yMtfeZS2VtmD78guFvtoZ+47uKaDzT/rFKbG0PUt3gc85QKli8876L8iga 1+dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LSuJ265AIHX3+q/k1a/Z37Re9kn2OGu2g13JwIWu2AE=; b=JmWECM7BHDUgyTFVRrmRj9AHwB1NI0VFr+Nea8XGclw/1wv5xBfS6S7yDbKe7xgmpX HAe52POZq9q5UwSqNIXYlzMDdPCQtggk+Gyi287sq9XRmJvTDaKvqQDcHD/Bsq6VAV5K 4yrM1EMtVNhC6kYrJOR50uSOw9UG6Ut3Kd1stDFHy0NwBWOmIt55WW5EPVRZGtxmRixX +5PbxBzi4KJsVbhjxHy2ClczbiVgol+TYDIYurGjxc48BNc1CLJMlip0ZcYCaqwEgL2e pESuA+mtanUSusmmQOmeZtluEN3YgV2dW61t5yZk65eAQeomquA1b7QH2UD3sRRhMqNi zetw== X-Gm-Message-State: AOAM5316aJYvdtnBab6nLM/bMIGyDJ89YM/vlF50BVX7AQ4/TpBdXiDK v9VBSkQfnDvebZh6iglEU9UlsbTHCMn5/CfXM8Q= X-Google-Smtp-Source: ABdhPJz0bjSGZm+ZdrPGtRtCXBpejLmPe6KZV95C2FmKOvxUsvXkFXAWlKgIMYvfMsU+gy0mVusHMS/N02PzQC8v5VA= X-Received: by 2002:a62:86ca:: with SMTP id x193mr12601031pfd.152.1597701747572; Mon, 17 Aug 2020 15:02:27 -0700 (PDT) Date: Mon, 17 Aug 2020 15:02:10 -0700 In-Reply-To: <20200817220212.338670-1-ndesaulniers@google.com> Message-Id: <20200817220212.338670-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 2/4] Revert "lib/string.c: implement a basic bcmp" From: Nick Desaulniers To: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , " =?utf-8?b?RMOhdmlkIEJvbHZhbnNrw70=?= " , Eli Friedman , Nick Desaulniers Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This reverts commit 5f074f3e192f10c9fade898b9b3b8812e3d83342. Use `-fno-builtin-bcmp` instead. The issue with using `-fno-builtin-*` flags was that they were not retained during an LTO link with LLVM. This was fixed in clang-11 by https://reviews.llvm.org/D71193 (0508c994f0b14144041f2cfd3ba9f9a80f03de08), which is also the minimum supported version of clang for LTO. Signed-off-by: Nick Desaulniers Reviewed-by: Kees Cook --- Makefile | 1 + include/linux/string.h | 3 --- lib/string.c | 20 -------------------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 211a1b6f6478..722ff5864275 100644 --- a/Makefile +++ b/Makefile @@ -964,6 +964,7 @@ endif # to provide implementations of these routines, then prevent the compiler from # emitting calls to what will be undefined symbols. KBUILD_CFLAGS += -fno-builtin-stpcpy +KBUILD_CFLAGS += -fno-builtin-bcmp # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn diff --git a/include/linux/string.h b/include/linux/string.h index b1f3894a0a3e..f3bdb74bc230 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -155,9 +155,6 @@ extern void * memscan(void *,int,__kernel_size_t); #ifndef __HAVE_ARCH_MEMCMP extern int memcmp(const void *,const void *,__kernel_size_t); #endif -#ifndef __HAVE_ARCH_BCMP -extern int bcmp(const void *,const void *,__kernel_size_t); -#endif #ifndef __HAVE_ARCH_MEMCHR extern void * memchr(const void *,int,__kernel_size_t); #endif diff --git a/lib/string.c b/lib/string.c index 6012c385fb31..69328b8353e1 100644 --- a/lib/string.c +++ b/lib/string.c @@ -922,26 +922,6 @@ __visible int memcmp(const void *cs, const void *ct, size_t count) EXPORT_SYMBOL(memcmp); #endif -#ifndef __HAVE_ARCH_BCMP -/** - * bcmp - returns 0 if and only if the buffers have identical contents. - * @a: pointer to first buffer. - * @b: pointer to second buffer. - * @len: size of buffers. - * - * The sign or magnitude of a non-zero return value has no particular - * meaning, and architectures may implement their own more efficient bcmp(). So - * while this particular implementation is a simple (tail) call to memcmp, do - * not rely on anything but whether the return value is zero or non-zero. - */ -#undef bcmp -int bcmp(const void *a, const void *b, size_t len) -{ - return memcmp(a, b, len); -} -EXPORT_SYMBOL(bcmp); -#endif - #ifndef __HAVE_ARCH_MEMSCAN /** * memscan - Find a character in an area of memory. From patchwork Mon Aug 17 22:02:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 11719377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58FC2109B for ; Mon, 17 Aug 2020 22:03:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33FC320786 for ; Mon, 17 Aug 2020 22:03:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VGxOIYRq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729389AbgHQWC6 (ORCPT ); Mon, 17 Aug 2020 18:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729301AbgHQWCc (ORCPT ); Mon, 17 Aug 2020 18:02:32 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3016C061343 for ; Mon, 17 Aug 2020 15:02:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x6so15140094ybp.10 for ; Mon, 17 Aug 2020 15:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=9SBJtwgo4QVHI3Sdc2C7hxhI+hybE6P8MqvKEbw6VA0=; b=VGxOIYRqvHa4OmoZURsCdy57u/bUJl6KzXrNgmOYkyrfrvR66YapPh4X97oYZQWWRg PPSFP8ab88uJEB4dM5x690TZN4TeToNbmWek+tEXy/8FIxeHJogFlT3E+cY+vwQJJh+V UqzXvJ6LICQvDFw0d2Wfm5VbtDO+s2FYD4Z5rXsmF8BSsaOhwv8nwSBJYe5TuGUqZ28r eUqYly78IEZl2y2yTtKRIxrBG9WbrXpbJCxrKKp9G5eVg4dNrjD4kHGgxygmNlFo55ul 32YKIftLGlp4bO7YlOx051frMawUBgZZgnhziC63JGQbuH6MBwfbeUvcpyUofVzXzab8 HUPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9SBJtwgo4QVHI3Sdc2C7hxhI+hybE6P8MqvKEbw6VA0=; b=LfyRSlYwNRCb5J9JjYHLXwj4adx/L29HIf3mg2BN/DIW/8ixREEPBb+6C2mPM1qbGA fZjmvTJOBvSB0/+tDutb0wmQG3wT9kcYWdJKtfxHCxp00B/t0TAJjblXLw/GeEVT6vuC r4pz6g3y1IaTiornqVa1Z6qXZlDIEvrGeFF+AEKH4sBcpxy6bIFCRrFjGfO278mldFDq rKFh0jXLBMZALYycon8G43WkGjF931Nkhe5ieW6p6egnzJNQqbgT2LUzy6J6ZGv6yKxz KWfUZ/qigqPvWeEDEx5zlbsqgdTTQIr1/+442pTjiR6p+q2U9SKLs3D/Xcd0qSbD+VHV ix1Q== X-Gm-Message-State: AOAM5312njKcY72y33439PUOWoO5ShaQZws3EiwxJB4dUdYLEXSF2l4C 73mFUgaQsc8MT1y3IMvZVcj3MQ81/2jr6dwwfVs= X-Google-Smtp-Source: ABdhPJyJAr0txHHVKZqlGNMtvo97G00mjqcvpxwQOE5FwBgb1PBKiVkhfn3k+w3BBZIVVlLui27r6uHth2/gthlkOD8= X-Received: by 2002:a25:3f83:: with SMTP id m125mr22563936yba.324.1597701750925; Mon, 17 Aug 2020 15:02:30 -0700 (PDT) Date: Mon, 17 Aug 2020 15:02:11 -0700 In-Reply-To: <20200817220212.338670-1-ndesaulniers@google.com> Message-Id: <20200817220212.338670-4-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 3/4] x86/boot: use -fno-builtin-bcmp From: Nick Desaulniers To: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , " =?utf-8?b?RMOhdmlkIEJvbHZhbnNrw70=?= " , Eli Friedman , Nick Desaulniers Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We're reverting commit 5f074f3e192f ("lib/string.c: implement a basic bcmp") in favor of -fno-builtin-bcmp. Remove the additional definition here, too. arch/x86/purgatory/Makefile uses -ffreestanding, so there's no risk of this libcall optimization occurring for arch/x86/boot/purgatory.ro. arch/x86/boot/Makefile resets KBUILD_CFLAGS, so make sure to reset this flag that was set for the top level Makefile. Fixes: 4ce97317f41d ("x86/purgatory: Do not use __builtin_memcpy and __builtin_memset") Signed-off-by: Nick Desaulniers Reviewed-by: Kees Cook --- arch/x86/boot/Makefile | 1 + arch/x86/boot/string.c | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index fe605205b4ce..ef7f15bfceab 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile @@ -70,6 +70,7 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables +KBUILD_CFLAGS += -fno-builtin-bcmp GCOV_PROFILE := n UBSAN_SANITIZE := n diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index 8a3fff9128bb..23d91aa7691e 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c @@ -37,14 +37,6 @@ int memcmp(const void *s1, const void *s2, size_t len) return diff; } -/* - * Clang may lower `memcmp == 0` to `bcmp == 0`. - */ -int bcmp(const void *s1, const void *s2, size_t len) -{ - return memcmp(s1, s2, len); -} - int strcmp(const char *str1, const char *str2) { const unsigned char *s1 = (const unsigned char *)str1; From patchwork Mon Aug 17 22:02:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 11719345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A638D13B1 for ; Mon, 17 Aug 2020 22:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F2362078D for ; Mon, 17 Aug 2020 22:02:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gQoHfUpb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729331AbgHQWCl (ORCPT ); Mon, 17 Aug 2020 18:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729306AbgHQWCf (ORCPT ); Mon, 17 Aug 2020 18:02:35 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E225C061344 for ; Mon, 17 Aug 2020 15:02:34 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id y7so11855449qvj.11 for ; Mon, 17 Aug 2020 15:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kIk9FUx7DIlhGhFIt2N6cpuJCia592mQ/iQfMoiZ3iE=; b=gQoHfUpbLM0sDU/kmKlEItWnjMkZ07La/np9HovfFux6Z2VP9+/zZrQWA4ecIjJgvq dnD+gK0MB87V5MirFehxDF/9Y0qyw5jGSnVPfhphz46yfpH/a+RlENfRfPyt87lKvXNt 3M8YGTf9geBnYZq62BRsxzKcJtfiB7A2JPR7UVcm63uyarEjTgfrxkjaTulCAKeb73LZ exzQUda0T8aom4mtZLMJVL/LVK8eWeJNZoH1geb6HQxDryALTxFmCJwMm+oFzaxPCUpi A0f2OynWzgOjSsioBKP8o4nkCzdHdYSkPkC8fIcVqpZ5VTuRGrg4J4X3JxxkwMH7CMgJ uOEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kIk9FUx7DIlhGhFIt2N6cpuJCia592mQ/iQfMoiZ3iE=; b=NQJldEmnSQh0cm0LORObY3szeVblm80HlFlJl2nhW+STjMbD0TDiJcuGpZxliT7XLl mz+Fo5IQrOdyd/QYTmCVvi6rkhCrRzrMFifxGi7qswv9DWRhwcMPUCpbi3o/5Cg+qMgu Z2GR1OefbrNG42OzZVGQG7ivZmxYPaHtUqSGGXKyWCKdPSqUz+0RkOFgKV62ocj1mMkr SdJYynu5u3lfpm3EnNGK0T3vtJiyTViNHNwkB9Kli+kmYBdg/MgtmYXTLADMImiQvEMD XVgH/qOI3z+FT9CiiOWiueG7oRIhortC9LYV5Qerhcb/tgozuao4IiBVP8opKdEaUv2c bZJw== X-Gm-Message-State: AOAM533CK+4/unQyrX/PZdiQHT9bJ5X42xWO3dFgt2QpDmOGIFWe+SBZ GIzhwwKcdYMlHZ9dX3nlgRQTxCE1AHURjXp12Nw= X-Google-Smtp-Source: ABdhPJze4jPqkvcvZSWv8Q0KrJb4yDurztXHgzvX3/5K52RQR+v2CCftP6RNB8hQqPr5ZzSxOih+qN1vIkvEECe6SWQ= X-Received: by 2002:ad4:470f:: with SMTP id k15mr16321629qvz.216.1597701753768; Mon, 17 Aug 2020 15:02:33 -0700 (PDT) Date: Mon, 17 Aug 2020 15:02:12 -0700 In-Reply-To: <20200817220212.338670-1-ndesaulniers@google.com> Message-Id: <20200817220212.338670-5-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 4/4] x86: don't build CONFIG_X86_32 as -ffreestanding From: Nick Desaulniers To: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , " =?utf-8?b?RMOhdmlkIEJvbHZhbnNrw70=?= " , Eli Friedman , Nick Desaulniers Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org -ffreestanding typically inhibits "libcall optimizations" where calls to certain library functions can be replaced by the compiler in certain cases to calls to other library functions that may be more efficient. This can be problematic for embedded targets that don't provide full libc implementations. -ffreestanding inhibits all such optimizations, which is the safe choice, but generally we want the optimizations that are performed. The Linux kernel does implement a fair amount of libc routines. Instead of -ffreestanding (which makes more sense in smaller images like kexec's purgatory image), prefer -fno-builtin-* flags to disable the compiler from emitting calls to functions which may not be defined. If you see a linkage failure due to a missing symbol that's typically defined in a libc, and not explicitly called from the source code, then the compiler may have done such a transform. You can either implement such a function (ie. in lib/string.c) or disable the transform outright via -fno-builtin-* flag (where * is the name of the library routine, ie. -fno-builtin-bcmp). i386_defconfig build+boot tested with GCC and Clang. Removes a pretty old TODO from the codebase. Fixes: 6edfba1b33c7 ("x86_64: Don't define string functions to builtin") Suggested-by: Arvind Sankar Signed-off-by: Nick Desaulniers Reviewed-by: Kees Cook Reviewed-by: Fangrui Song --- arch/x86/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 4346ffb2e39f..2383a96cf4fd 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -80,9 +80,6 @@ ifeq ($(CONFIG_X86_32),y) # CPU-specific tuning. Anything which can be shared with UML should go here. include arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) - - # temporary until string.h is fixed - KBUILD_CFLAGS += -ffreestanding else BITS := 64 UTS_MACHINE := x86_64