From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by kanga.kvack.org (Postfix) with ESMTP id F14AB8E0001 for ; Tue, 18 Sep 2018 11:45:33 -0400 (EDT) Received: by mail-io1-f70.google.com with SMTP id m13-v6so2635714ioq.9 for ; Tue, 18 Sep 2018 08:45:33 -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 v7-v6sor6026499itv.63.2018.09.18.08.45.32 for (Google Transport Security); Tue, 18 Sep 2018 08:45:32 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <6cd298a90d02068969713f2fd440eae21227467b.1535462971.git.andreyknvl@google.com> From: Dmitry Vyukov Date: Tue, 18 Sep 2018 17:45:11 +0200 Message-ID: Subject: Re: [PATCH v6 07/18] khwasan: add tag related helper functions Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Andrey Konovalov Cc: Andrey Ryabinin , Alexander Potapenko , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev , "open list:DOCUMENTATION" , LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux-MM , "open list:KERNEL BUILD + fi..." , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan On Mon, Sep 17, 2018 at 8:59 PM, Andrey Konovalov wrote: > On Wed, Sep 12, 2018 at 6:21 PM, Dmitry Vyukov wrote: >> On Wed, Aug 29, 2018 at 1:35 PM, Andrey Konovalov wrote: > >>> +void *khwasan_preset_slub_tag(struct kmem_cache *cache, const void *addr) >> >> Can't we do this in the existing kasan_init_slab_obj() hook? It looks >> like it should do exactly this -- allow any one-time initialization >> for objects. We could extend it to accept index and return a new >> pointer. >> If that does not work for some reason, I would try to at least unify >> the hook for slab/slub, e.g. pass idx=-1 from slub and then use >> random_tag(). >> It also seems that we do preset tag for slab multiple times (from >> slab_get_obj()). Using kasan_init_slab_obj() should resolve this too >> (hopefully we don't call it multiple times). > > The issue is that SLAB stores freelist as an array of indexes instead > of using an actual linked list like SLUB. So you can't store the tag > in the pointer while the object is in the freelist, since there's no > pointer. And, technically, we don't preset tags for SLAB, we just use > the id as the tag every time a pointer is used, so perhaps we should > rename the callback. As to unifying the callbacks, sure, we can do > that. As per offline discussion: potentially we can use kasan_init_slab_obj() if we add tag in kmalloc hook by using obj_to_idx().