Received: by 10.223.185.116 with SMTP id b49csp23408wrg; Thu, 15 Feb 2018 15:46:42 -0800 (PST) X-Google-Smtp-Source: AH8x224z4X3jiFtGN38tLCsW6HVYvLLH+pFugAAb4ShV9WZEbM+0aHdbRfEjgV5HphXSZKry0oXf X-Received: by 2002:a17:902:7509:: with SMTP id i9-v6mr3918782pll.220.1518738402339; Thu, 15 Feb 2018 15:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518738402; cv=none; d=google.com; s=arc-20160816; b=q1p42ILl69G5PDn3LJcESOC1N5Y+VWMw0yXHh2u03bBLXEmr8tTJIbWqas40JCg5ss oWP2BgtOZBAt0cX0tA6YDBZV/3GBnmtIFNSaPvDLFJq8N6QG+sfwyhMtFxpStr3a4j1M pwR5l1NDG23EsQsbMOrw/9cKKmjfx+URxAcBEKsZvg/fBYEqFJgmfFO8E56K9MPZmXEY WxX2pmW3OH2y4MpiJEbdhFno/Wz0ooghrF5Hlwjddls1NVCzeMU5hdcSNc98RqYAOqbW pN7cUbcq2OOUw9+tWdMf2EiXFSyZW4L3UfAvbmEe2eqEkLzIS16Z/oSP8+QlITzcL++C jAzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=giGQmluoN/YkEMMrM88drCdCXqKbA4loyYtXV8UpETg=; b=MxIK12QyPbflpRqzuDQN9SdMT1kNZh1gRjr9ibA79RSBwSJui/NfWcOQPvX3BVt/A9 EWxBpL5++lmGcpJXWBE4E0qkNwXmOAIlihxyOZbf0Kyy2YgDxw54HtfT+nDgw+Xx8/Vn prv/oUUXqgoOJCztADBNuXr29lPlUBLKXdjzQt2cUzObq+/IMLMNwav0se9ZoXz72ew5 Jgr5OlG0HRvXAxiWwtBHJODOEFfkyUKbNTA8WOm9mPNw6OjUqANGrNpW/q9LcjxmnxS7 fWLPTscwhPIdCc7AHz5WPkpFn5XRz48Rn3qJpZl2L0/3pn9n/zrR80/C93Ud4tdHjaGU s13Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si209438plk.313.2018.02.15.15.46.27; Thu, 15 Feb 2018 15:46:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422870AbeBOPgT (ORCPT + 99 others); Thu, 15 Feb 2018 10:36:19 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:57806 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422839AbeBOPgP (ORCPT ); Thu, 15 Feb 2018 10:36:15 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 50E16115A; Thu, 15 Feb 2018 15:36:14 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Konovalov , Nick Desaulniers , Masahiro Yamada , Michal Marek , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 147/195] kasan: dont emit builtin calls when sanitization is off Date: Thu, 15 Feb 2018 16:17:18 +0100 Message-Id: <20180215151713.198514640@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrey Konovalov commit 0e410e158e5baa1300bdf678cea4f4e0cf9d8b94 upstream. 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. Link: http://lkml.kernel.org/r/8ffecfffe04088c52c42b92739c2bd8a0bcb3f5e.1516384594.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Acked-by: Nick Desaulniers Cc: Masahiro Yamada Cc: Michal Marek Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Dmitry Vyukov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- Makefile | 3 ++- scripts/Makefile.kasan | 3 +++ scripts/Makefile.lib | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) --- a/Makefile +++ b/Makefile @@ -416,7 +416,8 @@ export MAKE AWK GENKSYMS INSTALLKERNEL P 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 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -31,4 +31,7 @@ else endif CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) + +CFLAGS_KASAN_NOSANITIZE := -fno-builtin + endif --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -128,7 +128,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)