From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 937606B0005 for ; Sat, 24 Mar 2018 04:29:53 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id v21so1788460wmh.9 for ; Sat, 24 Mar 2018 01:29:53 -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 o138sor2901692wmg.36.2018.03.24.01.29.52 for (Google Transport Security); Sat, 24 Mar 2018 01:29:52 -0700 (PDT) Date: Sat, 24 Mar 2018 09:29:47 +0100 From: Ingo Molnar Subject: Re: [RFC PATCH v2 11/15] khwasan, mm: perform untagged pointers comparison in krealloc Message-ID: <20180324082947.3isostkpsjraefqt@gmail.com> References: <6eb08c160ae23eb890bd937ddf8346ba211df09f.1521828274.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6eb08c160ae23eb890bd937ddf8346ba211df09f.1521828274.git.andreyknvl@google.com> 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" , Stephen Boyd , Thomas Gleixner , Paul Lawrence , Greg Kroah-Hartman , David Woodhouse , Sandipan Das , Kees Cook , Herbert Xu , Geert Uytterhoeven , Josh Poimboeuf , Arnd Bergmann , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org, Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Kees Cook , Jann Horn , Mark Brand * 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? Thanks, Ingo