From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f200.google.com (mail-wr0-f200.google.com [209.85.128.200]) by kanga.kvack.org (Postfix) with ESMTP id A29BD6B000D for ; Tue, 27 Mar 2018 16:01:57 -0400 (EDT) Received: by mail-wr0-f200.google.com with SMTP id e15so41821wrj.14 for ; Tue, 27 Mar 2018 13:01:57 -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 l2sor744092wmh.8.2018.03.27.13.01.55 for (Google Transport Security); Tue, 27 Mar 2018 13:01:55 -0700 (PDT) Date: Tue, 27 Mar 2018 22:01:50 +0200 From: Ingo Molnar Subject: Re: [RFC PATCH v2 11/15] khwasan, mm: perform untagged pointers comparison in krealloc Message-ID: <20180327200150.cadizr7wsfjnfta7@gmail.com> References: <6eb08c160ae23eb890bd937ddf8346ba211df09f.1521828274.git.andreyknvl@google.com> <20180324082947.3isostkpsjraefqt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org List-ID: To: Andrey Konovalov Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Christoffer Dall , Marc Zyngier , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Mark Rutland , Ard Biesheuvel , Yury Norov , Nick Desaulniers , Suzuki K Poulose , Kristina Martsenko , Punit Agrawal , Dave Martin , Michael Weiser , James Morse , Julien Thierry , Steve Capper , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Paul Lawrence , Greg Kroah-Hartman , David Woodhouse , Sandipan Das , Kees Cook , Herbert Xu , Geert Uytterhoeven , Josh Poimboeuf , Arnd Bergmann , kasan-dev , linux-doc@vger.kernel.org, LKML , Linux ARM , kvmarm@lists.cs.columbia.edu, 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 * Andrey Konovalov wrote: > On Sat, Mar 24, 2018 at 9:29 AM, Ingo Molnar wrote: > > > > * Andrey Konovalov wrote: > > > >> The krealloc function checks where the same buffer was reused or a new one > >> allocated by comparing kernel pointers. KHWASAN changes memory tag on the > >> krealloc'ed chunk of memory and therefore also changes the pointer tag of > >> the returned pointer. Therefore we need to perform comparison on untagged > >> (with tags reset) pointers to check whether it's the same memory region or > >> not. > >> > >> Signed-off-by: Andrey Konovalov > >> --- > >> mm/slab_common.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/mm/slab_common.c b/mm/slab_common.c > >> index a33e61315ca6..5911f2194cf7 100644 > >> --- a/mm/slab_common.c > >> +++ b/mm/slab_common.c > >> @@ -1494,7 +1494,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) > >> } > >> > >> ret = __do_krealloc(p, new_size, flags); > >> - if (ret && p != ret) > >> + if (ret && khwasan_reset_tag(p) != khwasan_reset_tag(ret)) > >> kfree(p); > > > > Small nit: > > > > If 'reset' here means an all zeroes tag (upper byte) then khwasan_clear_tag() > > might be a slightly easier to read primitive? > > 'Reset' means to set the upper byte to the value that is native for > kernel pointers, and that is 0xFF. So it sets the tag to all ones, not > all zeroes. I can still rename it to khwasan_clear_tag(), if you think > that makes sense in this case as well. Ok, if it's not 0 then I agree that 'reset' is the better name. 'clear' would in fact be actively confusing. Thanks, Ingo