From patchwork Fri Jan 19 17:58:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10175829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC8DF601E7 for ; Fri, 19 Jan 2018 17:58:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B57AA2873B for ; Fri, 19 Jan 2018 17:58:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A83EA2876B; Fri, 19 Jan 2018 17:58:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D57F2873B for ; Fri, 19 Jan 2018 17:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756005AbeASR6R (ORCPT ); Fri, 19 Jan 2018 12:58:17 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:43948 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755899AbeASR6Q (ORCPT ); Fri, 19 Jan 2018 12:58:16 -0500 Received: by mail-wm0-f65.google.com with SMTP id g1so5002304wmg.2 for ; Fri, 19 Jan 2018 09:58:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bnM3yqwfcyMCRhruHs/zLXwLj7jyBFs+46xDqRtGR6I=; b=IhPhqsvyYWBwzmEa02XBUi7kw3ING3iCwI/sgi0BawomfKZpoX6hEZ6pkmPbZiQqes telrQbdNMHW18vxwuPE6eyZ3rACnxKxWW3ZZ+58/aYkQmswSty6SZkGlPdtZ5N86DeT6 WydfZ1AOSxpUBsf7Kpguq6I1zL1PwGBs61DMVfMmP6jxAjPNrk5iAC8MCFrZEqUdd0Jd 1XL5RQOxUj7ZQRLGlBu+77Lnwqbl/mgTFUvVKtGXrHIxbjN3vOVoKuVmIOQl4nonL5iq 0y4GUoSf9p4CiWKT6BQiuc7/CTWI30hpoxSR37JNJcpk1V3OUEeMxs1kfgrctXE5YrD6 pTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bnM3yqwfcyMCRhruHs/zLXwLj7jyBFs+46xDqRtGR6I=; b=nzl2kleyldr9GU3uUC39zYJH1VKYrP5jkHh54hCLDSD3UVn86VAdPK9Ei/EG5JvPSy knD5Y695I3gFOgMQgTqmA6iaXUZRtFwmUEwFAdRwlVcDqPvbrq/T41mTuHGKc8ndN7wW Q0I/IXZc4WrSZls+OxkXIXchedb2QLQTrxLd7x3qUy5s6pwmpG89GlJXpDgEMkbM4Mvy L/f9SJ1ntpU3ETgXyh4cYvWrrXY7CCVfcqXgmqKWKDaB4FE4KMcM5ypbj/c1CpjAe069 Ov0f6/3ZVGbQUbq/A1RemTLIfobkqt2e3vllJhCxCsMH16Ds4+/HnNs0VaUarfJvHSpY SDEQ== X-Gm-Message-State: AKwxytd6EsZT8/AJsUfxArtL2UEyfDo7adwdSw0mDPT+f1N+D/Ic3x4z Oaoa+0FXOjdfAg8JtmCcyr5tfA== X-Google-Smtp-Source: AH8x227eWeifPKkXctX10hut1507ONEY+zQuosDyF+Ua/5/ewcpdS8z2W6/U6NCHCSK1Ch+f392I9g== X-Received: by 10.28.70.196 with SMTP id t187mr486585wma.129.1516384695319; Fri, 19 Jan 2018 09:58:15 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:fd05:7817:e369:bc8d]) by smtp.gmail.com with ESMTPSA id i47sm10379697wrf.26.2018.01.19.09.58.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 09:58:14 -0800 (PST) Received: by andreyknvl0.muc.corp.google.com (Postfix, from userid 206546) id 78354180C67; Fri, 19 Jan 2018 18:58:13 +0100 (CET) From: Andrey Konovalov To: Masahiro Yamada , Michal Marek , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Cc: Kostya Serebryany , Evgeniy Stepanov , Nick Desaulniers , Stephen Hines , Pirama Arumuga Nainar , Manoj Gupta , Greg Hackmann , Andrew Morton , Andrey Konovalov Subject: [PATCH v2] kasan: don't emit builtin calls when sanitization is off Date: Fri, 19 Jan 2018 18:58:12 +0100 Message-Id: <8ffecfffe04088c52c42b92739c2bd8a0bcb3f5e.1516384594.git.andreyknvl@google.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With KASAN enabled the kernel has two different memset() functions, one with KASAN checks (memset) and one without (__memset). KASAN uses some macro tricks to use the proper version where required. For example memset() calls in mm/slub.c are without KASAN checks, since they operate on poisoned slab object metadata. The issue is that clang emits memset() calls even when there is no memset() in the source code. They get linked with improper memset() implementation and the kernel fails to boot due to a huge amount of KASAN reports during early boot stages. The solution is to add -fno-builtin flag for files with KASAN_SANITIZE := n marker. Signed-off-by: Andrey Konovalov Acked-by: Nick Desaulniers --- Changed in v2: - dropped cc-option for -fno-builtin Makefile | 3 ++- scripts/Makefile.kasan | 3 +++ scripts/Makefile.lib | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bf5b8cbb9469..d45e31b293d0 100644 --- a/Makefile +++ b/Makefile @@ -432,7 +432,8 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS -export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN +export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index dbbd4382f15a..3fb382c69ff6 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -39,4 +39,7 @@ else endif CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) + +CFLAGS_KASAN_NOSANITIZE := -fno-builtin + endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1ca4dcd2d500..015aa9dbad86 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -121,7 +121,7 @@ endif ifeq ($(CONFIG_KASAN),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ - $(CFLAGS_KASAN)) + $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif ifeq ($(CONFIG_UBSAN),y)