Received: by 10.223.185.116 with SMTP id b49csp334635wrg; Thu, 15 Feb 2018 23:05:09 -0800 (PST) X-Google-Smtp-Source: AH8x227iVKLVj5UycIrL7xlVspeJ4l8MbeQ/8ZCgAsnM9i4pPAUVog0cCyszg7e4WFPenAiEpMI6 X-Received: by 10.99.175.76 with SMTP id s12mr4413125pgo.240.1518764709796; Thu, 15 Feb 2018 23:05:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518764709; cv=none; d=google.com; s=arc-20160816; b=qd8ZRyTiJxtMrn3tgZw7PlngumMUJBDdE4A4rrPQELhJgMJ0rswP7h0uV5FBugF/2R qURFxdv1x+OekR19aO7qjkuP5HiODSQIxh3HhRHZ8pb9gbxjXlxnCr1xdSyrTD8eDGK0 G8kd/2pKgbrskhQ7WoIybTlDCN1uR41hC+2DhDwSXUeI2jvC+aPhOVetYKcT1OAGbHUc Y2n30xQEdmdhZuHRTgRGGoEybyx4kchD1TBxYz5qutMnVpl2wbR3Lc9vbyKRfOPjk5Lw tzwo/KoFIsTAIaO0bL24eQQkRtzP6rcWW0xcrnxtOBJLcWzJzepDFXF8jHw7bG9khtCD CLsA== 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=3052UsBYMhPEoUl2uelHgyrcWfzB0DMGwcDA1ca2YLk=; b=FVY0885aD1Cwf2ewWgFrumIRIF9sYeJZ++/607L0QxStTtJC3LLhJopsxkNLW+z0mR QiOH7Ljvk/t1izare7d0w3J6QT/lFCFRbTCMs198XvEjNqA9Q0tK/NOsj9S1m7UGhJFF QqXgEd4iwu78f8yDNQlLiBfUgv+DnxXUqWTuTi8FNevUKC3VxmYkZIotKaTKuBNqyydJ OHRdQjvQptTvpTZH9VD3/VVwpIfIZgYVaJY3+xNyfopmhQnyadFa1MDXR2tkxariG14U Ccz1yvVPSPUcQSjcY81PI8tzgRET+rLUC45AvgtLZghelDtQYZd9OXYGZtjx9ZhDHg/U jvtw== 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 68si1075075pfx.60.2018.02.15.23.04.43; Thu, 15 Feb 2018 23:05:09 -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 S1424608AbeBOQKe (ORCPT + 99 others); Thu, 15 Feb 2018 11:10:34 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34930 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424461AbeBOPpX (ORCPT ); Thu, 15 Feb 2018 10:45:23 -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 CDFD411C5; Thu, 15 Feb 2018 15:45:22 +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.15 148/202] kasan: dont emit builtin calls when sanitization is off Date: Thu, 15 Feb 2018 16:17:28 +0100 Message-Id: <20180215151720.750037629@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-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 @@ -432,7 +432,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 @@ -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)