From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f197.google.com (mail-io0-f197.google.com [209.85.223.197]) by kanga.kvack.org (Postfix) with ESMTP id B2E726B0003 for ; Fri, 25 May 2018 08:43:28 -0400 (EDT) Received: by mail-io0-f197.google.com with SMTP id o194-v6so4182976iod.21 for ; Fri, 25 May 2018 05:43:28 -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 b6-v6sor2283060iog.149.2018.05.25.05.43.26 for (Google Transport Security); Fri, 25 May 2018 05:43:26 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <5dddd7d6f18927de291e7b09e1ff45190dd6d361.1525798754.git.andreyknvl@google.com> From: Andrey Konovalov Date: Fri, 25 May 2018 14:43:22 +0200 Message-ID: Subject: Re: [PATCH v1 13/16] khwasan: add hooks implementation 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 Tue, May 15, 2018 at 3:13 PM, Andrey Ryabinin wrote: > > Using variable to store untagged_object pointer, instead of tagging/untagging back and forth would make the > code easier to follow. > static bool inline shadow_ivalid(u8 tag, s8 shadow_byte) > { > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) > return shadow_byte < 0 || shadow_byte >= KASAN_SHADOW_SCALE_SIZE; > else > return tag != (u8)shadow_byte; > } > > > static bool __kasan_slab_free(struct kmem_cache *cache, void *object, > > ... > if (shadow_invalid(tag, shadow_byte)) { > kasan_report_invalid_free(object, ip); > return true; > } > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 7cd4a4e8c3be..f11d6059fc06 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -404,12 +404,9 @@ void *kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size, > redzone_end = round_up((unsigned long)object + cache->object_size, > KASAN_SHADOW_SCALE_SIZE); > > -#ifdef CONFIG_KASAN_GENERIC > - kasan_unpoison_shadow(object, size); > -#else > tag = random_tag(); > - kasan_poison_shadow(object, redzone_start - (unsigned long)object, tag); > -#endif > + kasan_unpoison_shadow(set_tag(object, tag), size); > + > kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, > KASAN_KMALLOC_REDZONE); > kasan_kmalloc_large() should be left untouched. It works correctly as is in both cases. > ptr comes from page allocator already already tagged at this point. Will fix all in v2, thanks!