From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74980C433DB for ; Wed, 17 Mar 2021 09:07:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B45B64EEC for ; Wed, 17 Mar 2021 09:07:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B45B64EEC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 828986B006E; Wed, 17 Mar 2021 05:07:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D92B6B0070; Wed, 17 Mar 2021 05:07:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0EC6B0071; Wed, 17 Mar 2021 05:07:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id 50CE46B006E for ; Wed, 17 Mar 2021 05:07:14 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0DFD6282B for ; Wed, 17 Mar 2021 09:07:14 +0000 (UTC) X-FDA: 77928787188.24.8BECA82 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf14.hostedemail.com (Postfix) with ESMTP id 75E75C0001EA for ; Wed, 17 Mar 2021 09:07:13 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 37607AC1E; Wed, 17 Mar 2021 09:07:12 +0000 (UTC) Received: from localhost (brahms [local]) by brahms (OpenSMTPD) with ESMTPA id 5b239ed0; Wed, 17 Mar 2021 09:08:27 +0000 (UTC) Date: Wed, 17 Mar 2021 09:08:26 +0000 From: Luis Henriques To: Marco Elver Cc: akpm@linux-foundation.org, glider@google.com, dvyukov@google.com, andreyknvl@google.com, jannh@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Catalin Marinas Subject: Re: [PATCH mm] kfence: make compatible with kmemleak Message-ID: References: <20210317084740.3099921-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210317084740.3099921-1-elver@google.com> X-Stat-Signature: y1ja9pe6qh9z6ebwd5tb39r4y1jh3hwn X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 75E75C0001EA Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1615972033-147181 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Mar 17, 2021 at 09:47:40AM +0100, Marco Elver wrote: > Because memblock allocations are registered with kmemleak, the KFENCE > pool was seen by kmemleak as one large object. Later allocations through > kfence_alloc() that were registered with kmemleak via > slab_post_alloc_hook() would then overlap and trigger a warning. > Therefore, once the pool is initialized, we can remove (free) it from > kmemleak again, since it should be treated as allocator-internal and be > seen as "free memory". > > The second problem is that kmemleak is passed the rounded size, and not > the originally requested size, which is also the size of KFENCE objects. > To avoid kmemleak scanning past the end of an object and trigger a > KFENCE out-of-bounds error, fix the size if it is a KFENCE object. > > For simplicity, to avoid a call to kfence_ksize() in > slab_post_alloc_hook() (and avoid new IS_ENABLED(CONFIG_DEBUG_KMEMLEAK) > guard), just call kfence_ksize() in mm/kmemleak.c:create_object(). > > Reported-by: Luis Henriques > Cc: Catalin Marinas > Signed-off-by: Marco Elver Tested-by: Luis Henriques > --- > mm/kfence/core.c | 9 +++++++++ > mm/kmemleak.c | 3 ++- > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index f7106f28443d..768dbd58170d 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -481,6 +482,14 @@ static bool __init kfence_init_pool(void) > addr += 2 * PAGE_SIZE; > } > > + /* > + * The pool is live and will never be deallocated from this point on. > + * Remove the pool object from the kmemleak object tree, as it would > + * otherwise overlap with allocations returned by kfence_alloc(), which > + * are registered with kmemleak through the slab post-alloc hook. > + */ > + kmemleak_free(__kfence_pool); > + > return true; > > err: > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index c0014d3b91c1..fe6e3ae8e8c6 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -97,6 +97,7 @@ > #include > > #include > +#include > #include > #include > > @@ -589,7 +590,7 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size, > atomic_set(&object->use_count, 1); > object->flags = OBJECT_ALLOCATED; > object->pointer = ptr; > - object->size = size; > + object->size = kfence_ksize((void *)ptr) ?: size; > object->excess_ref = 0; > object->min_count = min_count; > object->count = 0; /* white color initially */ > -- > 2.31.0.rc2.261.g7f71774620-goog >