Received: by 10.223.176.46 with SMTP id f43csp1097787wra; Fri, 19 Jan 2018 06:55:03 -0800 (PST) X-Google-Smtp-Source: ACJfBos4EsaXYz7FzGYNpHjpHLE36TChgr0xbusmNxC35eMzX3Rrewk4SDxr3bXNcmMaB9X0hOTj X-Received: by 10.99.111.193 with SMTP id k184mr33962295pgc.378.1516373702986; Fri, 19 Jan 2018 06:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516373702; cv=none; d=google.com; s=arc-20160816; b=W6nXvmOcM/RFWVlPj6S9QngWXJOSmA3jSrusNjXbSUyLivLF4CmCPc1IEIBuYXFOwI l/pixmaA3hi7c4OdZEK8Fnx2oJFqbw02YRWgaX9I2k+3gZ6CJs+sEWiuJSp1WGRrfdCV lI72SV0RJS32vRS64oD+nsYfFD6wYC028zLvlJM3yX8dgaLxECgxyx3qXUnAmAJr04iR XiruLAe2afjlo16Lq5bHwsUlnD2sqDBa79A2wtYv/MzMaIxhJv/9T8dUWdua5BagytSI f8A62cHWB6Zmy+vyI2am+qjhJv9RPjVV/rcaSTTZwIu2D8V9DYdaR0Oji8KkRjeUXz4D anCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=wg0SH2y50adAYEp8R9zt7yxiQ2FBNnwxB04SutIiD4k=; b=tGICm7n3Ffisi/QCRrkKb9TYnGbLNjz0SULfmLVYQmqP76y1SL9RRAF/00BcRsMJaI JvxlBci5Q+q54nzz9fItp9KKpHKfVpe9EmIXERtbUcP9+JwIX1pD7lW+Y8szgZkDE7a3 KWkiP1zpymWExN7OEgPEOM6ydUfEigqnIwqJUSqi/kheXMGZHDZ2RVmZMRdEDqmZ4g3i BDbiuOepWWOf+R6eD/OE1f+HvjhqXH2yeWlXbKyX9KSctCaUKbOh4uATHLxhKqA+4jHq w22LdwH3FyDE9gPG1KjcRgk5nC2TUWK3b6dotzkgpaDTBSE/vg1l4IxathrnJk+ejwUe LphQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wKLFzTlw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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. [209.132.180.67]) by mx.google.com with ESMTP id d12si8434339pgt.606.2018.01.19.06.54.48; Fri, 19 Jan 2018 06:55:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wKLFzTlw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1755766AbeASOyR (ORCPT + 99 others); Fri, 19 Jan 2018 09:54:17 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42919 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754892AbeASOyK (ORCPT ); Fri, 19 Jan 2018 09:54:10 -0500 Received: by mail-wm0-f67.google.com with SMTP id b141so3963608wme.1 for ; Fri, 19 Jan 2018 06:54:10 -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=wg0SH2y50adAYEp8R9zt7yxiQ2FBNnwxB04SutIiD4k=; b=wKLFzTlwCZ9j+NJOI+cDpBMj1tnW0N8BZ4Vl8IkyEeTWMFMt5nWn5qrRfeP/Mjmybw 8e/g1yxsQPcIXnXCcxMWWpCX6M4iuAQaLUofcWgOpyUTBqoUUKPh7qp+2CTfaQmtPBIY PkLhExxruD5pQDHDY6zpJ/xDNoKHd6PKVaXc5v3Ojr6FVAwY3i3vewitAA4gHoWxkpJf TX5Z4tfXvsWWeXeBN40RecQwXrQpCB0JjJSAG4RO3EenNd5VAqip6zIGbIfDxuiBZLkE b76jQXn+LRYCAYCrrF/OjlkRC+3sxavJZI1FKFk677rM+1htd9a6zQftYr2MCV1FYqHk rP5w== 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=wg0SH2y50adAYEp8R9zt7yxiQ2FBNnwxB04SutIiD4k=; b=GcqXtFSMhvqCk858twuUUCSxHyBoaIWbVnyY4jqpBoJ48RcJJBO2ZlFiMtAGlUl1CU rEWNRTQo0xV5Svxs78cwmbj3RNPPdfRpTR8GDOotbkVr5pGMfFYxfkIjxSUnoWgDThvy s3P2DuCupu8yrVAhT3u0LPI0l0gUv9K66S9NA0h8DpnQ2D+//QAC4jZtqnGI5Wbz+kYX JfH2mRbWEDHsAZjgdglWgaE8YpqZGu9DzibTIuQqfl6DMRhPsca9VJ0dBW2bIzdLrxcv Z26SFQ3r+c0E6myrn+pVzKRiNvLKjFDARY4iSHrAlEwaIenjUXeTJFmXNEFM2gAL1jpk BEyw== X-Gm-Message-State: AKwxytdbDbs7aAXwvb5KrNx9dgTS8RSfq3Zq6c+L65CCCAr2VxeoHB5d MmuFip+epMAGD5oo7c2IZSDZ+A== X-Received: by 10.28.192.24 with SMTP id q24mr8707274wmf.149.1516373649212; Fri, 19 Jan 2018 06:54:09 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:fd05:7817:e369:bc8d]) by smtp.gmail.com with ESMTPSA id e132sm1624583wmd.40.2018.01.19.06.54.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 06:54:08 -0800 (PST) Received: by andreyknvl0.muc.corp.google.com (Postfix, from userid 206546) id 1568E1833C3; Fri, 19 Jan 2018 15:54:06 +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 , Andrey Konovalov Subject: [PATCH] kasan: don't emit builtin calls when sanitization is off Date: Fri, 19 Jan 2018 15:54:02 +0100 Message-Id: <7d2dddbb7e4d4522fcf8e57c7da072c1ac76e1b0.1516373316.git.andreyknvl@google.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- This patch should be applied on top of the v4 "kasan: support alloca, LLVM" patchset from Paul Lawrence. 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..db473309f136 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 := $(call cc-option, -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) -- 2.16.0.rc1.238.g530d649a79-goog