From patchwork Fri Jan 19 14:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10175473 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 B4A1F601E7 for ; Fri, 19 Jan 2018 14:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7B892837D for ; Fri, 19 Jan 2018 14:54:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA2842865F; Fri, 19 Jan 2018 14:54:12 +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 463812837D for ; Fri, 19 Jan 2018 14:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755473AbeASOyL (ORCPT ); Fri, 19 Jan 2018 09:54:11 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:42918 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754951AbeASOyK (ORCPT ); Fri, 19 Jan 2018 09:54:10 -0500 Received: by mail-wm0-f66.google.com with SMTP id b141so3963605wme.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=LGXEdSTForV4DHqGwmGX0AynQYmyhKkiy5D7qWoIbxrPAsEWCZSXuCwZVxCJ7jyiY7 YVkmMXLng15MtIsrmQg47Fn73U0iGq2MIlmVEAEs6JSoOk7eORN8EwB8iBpn5rSGtf8f tsnfkPrDMaYUE9MA23auGd2fHMJQMFTfL5DLETz2pzF5HJXqPb5u4rnN3vFTTlMk7vdw rewlbQ19xxRE15EFpLhITQLET96tPqZNSE800k0GRDzMxdDFK2BIZTiB4zvORZqAUh/d qTdUDag7fI7hVCPqFjM7GCh2x62ZNWgfbL+mhZmfg22Wxx5WfWaDvQvnGpygEootc1ok GBnA== X-Gm-Message-State: AKwxyteQ8w1IDf9l6Psql1OBwa39bAabK+fRpmPU2V083lJvpnH/GjdR AGE64dc+3IE0WyfMjHrFR1Q5qg== X-Google-Smtp-Source: ACJfBosDTc5+SSopnVZuCCv2t8bX+lBGn/sSDQHqDX2iF6Nd+G8DMNWdfJJlNYE4XYt9vQM9CsQK7g== 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-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 --- 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)