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: 247886 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp3007137ilo; Mon, 17 Aug 2020 15:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRhpedP6LtaFiyO6jLSXl/qGH2yh2iodOtkrQmgYNDKISGb43Fus1Rqa4GNY8g7Xv4bqG/ X-Received: by 2002:a05:6402:339:: with SMTP id q25mr16285400edw.268.1597701897721; Mon, 17 Aug 2020 15:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701897; cv=none; d=google.com; s=arc-20160816; b=mWj5WlAs0nqQOYPH7wAD8H1YuIwryHtMwkH7CCuSEAHT943aX2dXLeE0xtnvDhuasM Zb2nbCDAo1lyAkebTH/aSpf7JvKrdZFhV9+bEjmrjm1U7usjnwKWlMdg+KnBWjoUE5hu AhYr5UAVgFYESmuRZEDOO3ivWF14E0vWYF/QzAFTwqfm2mghWMr3eT1FzhV0fIE4Iwf+ g5yPwh3toUs71s9W2lzyrXS8kc3/oIsTuFqzJ9CK8LV7PjrHFKHgw87VYnyVVQkpdlat Rk16IrOvNobVYB15Xkd3Dj8/psVm7LAKASRHR+MO93opAfzCKsgMiUVGK6mE1XlylhHn zmWg== 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:from :subject:references:mime-version:message-id:in-reply-to:date :dkim-signature; bh=UpYGtC8VuPYbMUYzVChohylhl5f+DwA/jtv3WLbpTdU=; b=zajbMuKe6WOaU5STWOnRetXPqIBIbNGpEVXhnrNimNs1lcYjv8Yx/0KoFglGRgV9NA MUoJtkYYDOR89Z8+FZxR2PJehYwcNUitmSaDLCXY10Oc+0ZBgzGSVX3HMkmGZf5NeFex tIc9Mis9/umxyaoAULIgTx0B6pAUVSVKmlIptgj70/8osxMpiqkKy8JVlkQbPs0/ooEk BdfAr1wOC6rKscFcLf7eokRyoObYwC1tCVupO1yx5SDSy0TJYxeHyTOsot8FHdKj2B/O 1Ni9nYxwV+JRcYjH3D+vkvWngvJGt414LfsCW56hsa5AC2/l0Ml5H9Na0dBRC7jdL4qX tBCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LiE9k63v; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i16si12166465edr.196.2020.08.17.15.04.57; Mon, 17 Aug 2020 15:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@google.com header.s=20161025 header.b=LiE9k63v; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729661AbgHQWEi (ORCPT + 15 others); Mon, 17 Aug 2020 18:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729279AbgHQWCY (ORCPT ); Mon, 17 Aug 2020 18:02:24 -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 64B5DC061344 for ; Mon, 17 Aug 2020 15:02:24 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e196so19906275ybh.6 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=rMKVMfppkt46seVZATE7BSsOHxViwLAceCaNLvkXT+GXyj0aw+b3JWpxpUhwQwdyO9 osBimLsUepZTANH8dC+cjLT3J4VbLHqpnFl8qPJATFbDjj4FcoBMHpFDOf/BQpYl79ZP E3Xw4Afqdtn2tXFbY3bbjA+1P58IMoi+c/Rh+Ko365/kar5ocnwi3QTOlycZl9lvrp58 Bzvh4p1oBekcRkNeVlW2kqvZCwyQHYWBsWHnoC4w04/tqD35RJAYy7E1CtIIL90EIu9T x4s8gHTsSKiyl/7og2cgTpoDSLuSi9EAY8My37tgdAATWDOX3hZmqgRw72plkjLbb31O oAVg== X-Gm-Message-State: AOAM53130u5cZg45ScDWepobg3c2RCvXCUuNBzThb8V7NCZllDnBj4ZY 3P9IZlhH5JT8W/b+qA7Uzd+SWIbJlai2SAEiNqo= 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?q?D=C3=A1vid=20Bolvansk=C3=BD?=" , Eli Friedman , Nick Desaulniers , stable@vger.kernel.org, Sami Tolvanen Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.28.0.220.ged08abb693-goog Reviewed-by: Kees Cook 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