From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f199.google.com (mail-io0-f199.google.com [209.85.223.199]) by kanga.kvack.org (Postfix) with ESMTP id 9C2DE6B0006 for ; Tue, 22 May 2018 10:25:58 -0400 (EDT) Received: by mail-io0-f199.google.com with SMTP id f9-v6so15246536iob.14 for ; Tue, 22 May 2018 07:25:58 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f80-v6sor40142ita.15.2018.05.22.07.25.57 for (Google Transport Security); Tue, 22 May 2018 07:25:57 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <658f02bd-e647-52e6-87cf-5d91f8243b66@virtuozzo.com> References: <658f02bd-e647-52e6-87cf-5d91f8243b66@virtuozzo.com> From: Andrey Konovalov Date: Tue, 22 May 2018 16:25:54 +0200 Message-ID: Subject: Re: [PATCH v1 03/16] khwasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_HW Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Andrey Ryabinin Cc: 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 , linux-doc@vger.kernel.org, LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux Memory Management List , Linux Kbuild mailing list , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Kees Cook , Jann Horn , Mark Brand , Chintan Pandya On Mon, May 14, 2018 at 6:57 PM, Andrey Ryabinin wrote: > > > 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. Should I remove "call cc-option" to fix this? > > >> + >> +CFLAGS_KASAN_NOSANITIZE := -fno-builtin >> + > > Does it really has to declared twice? Will fix in v2.