From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot0-f199.google.com (mail-ot0-f199.google.com [74.125.82.199]) by kanga.kvack.org (Postfix) with ESMTP id C2B786B0003 for ; Mon, 5 Mar 2018 09:39:35 -0500 (EST) Received: by mail-ot0-f199.google.com with SMTP id a32so9818984otj.5 for ; Mon, 05 Mar 2018 06:39:35 -0800 (PST) Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 7si2723112otm.390.2018.03.05.06.39.34 for ; Mon, 05 Mar 2018 06:39:34 -0800 (PST) Date: Mon, 5 Mar 2018 14:39:23 +0000 From: Mark Rutland Subject: Re: [RFC PATCH 08/14] khwasan: perform untagged pointers comparison in krealloc Message-ID: <20180305143923.oefjqjiulaedax3y@lakrids.cambridge.arm.com> References: 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 , Theodore Ts'o , Jan Kara , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Ard Biesheuvel , Yury Norov , Nick Desaulniers , Marc Zyngier , Bob Picco , Suzuki K Poulose , Kristina Martsenko , Punit Agrawal , Dave Martin , James Morse , Julien Thierry , Michael Weiser , Steve Capper , Ingo Molnar , Thomas Gleixner , Sandipan Das , Paul Lawrence , David Woodhouse , Kees Cook , 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, linux-ext4@vger.kernel.org, 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 On Fri, Mar 02, 2018 at 08:44:27PM +0100, 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. > --- > 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..7c829cbda1a5 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((void *)p) != khwasan_reset_tag(ret)) Why doesn't khwasan_reset_tag() take a const void *, like khwasan_set_tag() does? That way, this cast wouldn't be necessary. Thanks, Mark. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org