Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3628140rwb; Sun, 25 Sep 2022 09:41:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hfrINKUMuvYIT76uFAjgLK7/o3KTakOejjb+8JtpS0IbaZ0WkOMfhO4AVzAd4QuKvuFpb X-Received: by 2002:a05:6402:1394:b0:456:97cd:e9d4 with SMTP id b20-20020a056402139400b0045697cde9d4mr13207788edv.174.1664124107850; Sun, 25 Sep 2022 09:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664124107; cv=none; d=google.com; s=arc-20160816; b=SoKF8Fx+jApHm3CsxSw4RqUFPv9x+QjjeGxuppL0egVX7JqSa/0/b771E/BGPs9oda qt6R6KiroNAOjrFXkgOtvYxOxl7BHrYeKMIb3PNTq4u+DKMq0hFKyEp8jpz65h2nPu6L Ulr2XTMXjpWg5t8Ry3DQZTXyrqiDq8NHx7Zlbk8EjO+EtROyYRI3bI5oBEIWt1c6JbE6 LOazdV08h7PJ91nNVm6qeuFKTPIozlZI1i5lSw8ia9dlmtaWE2uDY3d85fHu+VUA38h2 9J6+2YAPmAEwDlz/u5FLu//3n8dm8Ck8WYXR7WpaL+ohA/OkyD+rsnUC/pVXUWbJVuaX ZOkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=C77rGCAYqGdTYQ5Hat6z7HfUcuu3QTxI69RZhcgUIhM=; b=yUzA44JnTxxMcJnga5PUgYk96UFPlSdGO5Wqa52fz8vtch8rb90rbFBEoqekxAgqcv dVpANz2f3UyBKM0czD/ZV40QwApHdAxP5KboqKQvRnuBKrk2xxy16Iuwnq5SI9nE8biE bUShmDdVJwYDGM9YLbF6ukMmcgceR6my1fRM4AbNAqBN70Bl7aQnEoWeLtzXgJ8qT0yv 0Z0S5syPT2WEyNCNnVku8ns2c52VdoK3r5Nn+pb4/YiBFGlAHlamIMRzpI3rSBW2ukvd WdUsEo0ujYNi9tA9xznIaHWoiKzZYp4JvN67qa4luFH71pUbdH+jmSprd8cnqcwif/09 O0Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ARNgIAQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a17090699c400b007707a47c3d5si14146837ejn.944.2022.09.25.09.41.18; Sun, 25 Sep 2022 09:41:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ARNgIAQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232846AbiIYQbv (ORCPT + 99 others); Sun, 25 Sep 2022 12:31:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbiIYQbt (ORCPT ); Sun, 25 Sep 2022 12:31:49 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD40229CBF for ; Sun, 25 Sep 2022 09:31:48 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id s13so3061929qvq.10 for ; Sun, 25 Sep 2022 09:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=C77rGCAYqGdTYQ5Hat6z7HfUcuu3QTxI69RZhcgUIhM=; b=ARNgIAQgcmdEtZOEexNNmGTo6Z9hsC3jci8S3O3+hey4a9RZsz3JkKVf+xclu8qRBe SQFORAr9hfCEyo+ZnGbD0dcJnnb38ai3BTpsv98wqNG5QYC4J8/pM0tegoZkeCv9DQyO QjP768mKhlw/fy6EQ1iSVh/6t1thIPSr3E1H96PLQ96JaihyJu/r15rK0qjEpoYoID2h dAjEZhhoobRodaqreGvoP7UEhHRstXMbD1MhrqzDruOhMZ8Yh8cr357KG+0ud0irD9pp 2n6TKfAhTMRe89Kf80nzRGVXZmc0ly85uTuVnCcCk4laF1isEnAfhj2/3R0jGPBkZb3T PQ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=C77rGCAYqGdTYQ5Hat6z7HfUcuu3QTxI69RZhcgUIhM=; b=GCYyQE7z5BXTJ51VtkgSUnLeC0DCmMXCBYU/Gwe50pV13G5e0xGEsvNk/Yt7xGvnSG Jo9pgLaACbw6cy5xRy3sXsLUGa/2yhsZGKV0jVTivJ/aNOdzPq75z4ejMZf3pi92PNdN royej3yjNuqW8XYHvlx0hAknODoI817K8d6dO6E2rUQigGryPR0vMnO7/HVjlUmZnpRE 1dtaYqgQMTAOPSE3t8ckAFprT0p+jq6RjIptMCWjbDGggWIGyhoedBEpWjRmHyAlBBLv XHB9QCypTHXAsVxZRVSOOLEFkd4CXIsZ91xx9jkcpnYMdtBLv5XpHaCfmpxjDJyaOEgZ hdtw== X-Gm-Message-State: ACrzQf3spUDGEbxjzQVW7chBF2dG9zn+oQajp742gtBCoX/J9nEYHaeV 411piAQ8bGv6Nf22wDc0OO5noc3BYz6ZJe1N1/E= X-Received: by 2002:ad4:5be2:0:b0:4ad:791c:8724 with SMTP id k2-20020ad45be2000000b004ad791c8724mr14396644qvc.56.1664123507765; Sun, 25 Sep 2022 09:31:47 -0700 (PDT) MIME-Version: 1.0 References: <20220913065423.520159-1-feng.tang@intel.com> <20220913065423.520159-4-feng.tang@intel.com> In-Reply-To: From: Andrey Konovalov Date: Sun, 25 Sep 2022 18:31:37 +0200 Message-ID: Subject: Re: [PATCH v6 3/4] mm: kasan: Add free_meta size info in struct kasan_cache To: Feng Tang Cc: Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Dmitry Vyukov , Jonathan Corbet , "Hansen, Dave" , Linux Memory Management List , LKML , kasan-dev , "Sang, Oliver" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 25, 2022 at 1:27 PM Feng Tang wrote: > > > [1] https://lore.kernel.org/linux-mm/c7b316d30d90e5947eb8280f4dc78856a49298cf.1662411799.git.andreyknvl@google.com/ > > I noticed this has been merged to -mm tree's 'mm-everything' branch, > so following is the patch againt that. Thanks! > > One thing I'm not very sure is, to check 'in-object' kasan's meta > size, I didn't check 'alloc_meta_offset', as from the code reading > the alloc_meta is never put inside slab object data area. Yes, this is correct. > Thanks, > Feng > > ---8<--- > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index d811b3d7d2a1..96c9d56e5510 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -302,7 +302,7 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {} > > #ifdef CONFIG_KASAN_GENERIC > > -size_t kasan_metadata_size(struct kmem_cache *cache); > +size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); > slab_flags_t kasan_never_merge(void); > void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, > slab_flags_t *flags); > @@ -315,7 +315,8 @@ void kasan_record_aux_stack_noalloc(void *ptr); > #else /* CONFIG_KASAN_GENERIC */ > > /* Tag-based KASAN modes do not use per-object metadata. */ > -static inline size_t kasan_metadata_size(struct kmem_cache *cache) > +static inline size_t kasan_metadata_size(struct kmem_cache *cache, > + bool in_object) > { > return 0; > } > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index d8b5590f9484..5a806f9b9466 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -450,15 +450,22 @@ void kasan_init_object_meta(struct kmem_cache *cache, const void *object) > __memset(alloc_meta, 0, sizeof(*alloc_meta)); > } > > -size_t kasan_metadata_size(struct kmem_cache *cache) > +size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object) > { > + struct kasan_cache *info = &cache->kasan_info ; > + > if (!kasan_requires_meta()) > return 0; > - return (cache->kasan_info.alloc_meta_offset ? > - sizeof(struct kasan_alloc_meta) : 0) + > - ((cache->kasan_info.free_meta_offset && > - cache->kasan_info.free_meta_offset != KASAN_NO_FREE_META) ? > - sizeof(struct kasan_free_meta) : 0); > + > + if (in_object) > + return (info->free_meta_offset ? > + 0 : sizeof(struct kasan_free_meta)); > + else > + return (info->alloc_meta_offset ? > + sizeof(struct kasan_alloc_meta) : 0) + > + ((info->free_meta_offset && > + info->free_meta_offset != KASAN_NO_FREE_META) ? > + sizeof(struct kasan_free_meta) : 0); > } > > static void __kasan_record_aux_stack(void *addr, bool can_alloc) > diff --git a/mm/slub.c b/mm/slub.c > index ce8310e131b3..a75c21a0da8b 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -887,7 +887,7 @@ static void print_trailer(struct kmem_cache *s, struct slab *slab, u8 *p) > if (s->flags & SLAB_STORE_USER) > off += 2 * sizeof(struct track); > > - off += kasan_metadata_size(s); > + off += kasan_metadata_size(s, false); > > if (off != size_from_object(s)) > /* Beginning of the filler is the free pointer */ > @@ -1042,7 +1042,7 @@ static int check_pad_bytes(struct kmem_cache *s, struct slab *slab, u8 *p) > /* We also have user information there */ > off += 2 * sizeof(struct track); > > - off += kasan_metadata_size(s); > + off += kasan_metadata_size(s, false); > > if (size_from_object(s) == off) > return 1; Reviewed-by: Andrey Konovalov Thanks!