From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 23A8E6B0008 for ; Mon, 14 May 2018 12:56:07 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id h32-v6so11732784pld.15 for ; Mon, 14 May 2018 09:56:07 -0700 (PDT) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00105.outbound.protection.outlook.com. [40.107.0.105]) by mx.google.com with ESMTPS id f8-v6si8161371pgr.139.2018.05.14.09.56.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 09:56:05 -0700 (PDT) Subject: Re: [PATCH v1 03/16] khwasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_HW References: From: Andrey Ryabinin Message-ID: <658f02bd-e647-52e6-87cf-5d91f8243b66@virtuozzo.com> Date: Mon, 14 May 2018 19:57:06 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Mark Rutland , Nick Desaulniers , Yury Norov , Marc Zyngier , Kristina Martsenko , Suzuki K Poulose , Punit Agrawal , Dave Martin , Ard Biesheuvel , James Morse , Michael Weiser , Julien Thierry , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Kees Cook , Sandipan Das , David Woodhouse , Paul Lawrence , Herbert Xu , Josh Poimboeuf , Geert Uytterhoeven , Tom Lendacky , Arnd Bergmann , Dan Williams , Michal Hocko , Jan Kara , Ross Zwisler , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Matthew Wilcox , "Kirill A . Shutemov" , Souptick Joarder , Hugh Dickins , Davidlohr Bueso , Greg Kroah-Hartman , Philippe Ombredanne , Kate Stewart , Laura Abbott , Boris Brezillon , Vlastimil Babka , Pintu Agarwal , Doug Berger , Anshuman Khandual , Mike Rapoport , Mel Gorman , Pavel Tatashin , Tetsuo Handa , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Kees Cook , Jann Horn , Mark Brand , Chintan Pandya On 05/08/2018 08:20 PM, Andrey Konovalov wrote: > diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan > index 69552a39951d..47023daf5606 100644 > --- a/scripts/Makefile.kasan > +++ b/scripts/Makefile.kasan > @@ -1,5 +1,5 @@ > # SPDX-License-Identifier: GPL-2.0 > -ifdef CONFIG_KASAN > +ifdef CONFIG_KASAN_GENERIC > ifdef CONFIG_KASAN_INLINE > call_threshold := 10000 > else > @@ -45,3 +45,28 @@ endif > CFLAGS_KASAN_NOSANITIZE := -fno-builtin > > endif > + > +ifdef CONFIG_KASAN_HW > + > +ifdef CONFIG_KASAN_INLINE > + instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) > +else > + instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1 > +endif > + > +CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-hwaddress > + > +ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) > + ifneq ($(CONFIG_COMPILE_TEST),y) > + $(warning Cannot use CONFIG_KASAN_HW: \ > + -fsanitize=hwaddress is not supported by compiler) > + endif > +else > + CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-hwaddress \ > + -mllvm -hwasan-instrument-stack=0 \ > + $(instrumentation_flags)) > +endif So this code does the following: 1) Warn if compiler doesn't support -fsanitize=kernel-hwaddress 2) Compile the kernel with all necessary set of the '-fsanitize=kernel-hwaddress -mllvm -hwasan-*' flags if compiler supports all of them. 3) Compile the kernel with empty CFLAGS_KASAN without a warning if compiler supports 'fsanitize=kernel-hwaddress', but doesn't support the rest '-mllvm -hwasan-*' flags. The last one is just nonsense. > + > +CFLAGS_KASAN_NOSANITIZE := -fno-builtin > + Does it really has to declared twice?