Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp169968pxf; Wed, 17 Mar 2021 02:10:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygCEke4mNylE2lO+Ikf+K6uWHG1534okF6RLkPF4z0dVe9W4aeWBNkcTAKqdi0NQrxSL9/ X-Received: by 2002:a17:906:7384:: with SMTP id f4mr34391513ejl.196.1615972251581; Wed, 17 Mar 2021 02:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615972251; cv=none; d=google.com; s=arc-20160816; b=m+WS/wKGymrvqciQyLoXpWIA/sJCfGJrtNXiLi+gLQ/+IY5KoZs14cgXeiCDxBCkhT DaZ//LBdzKx61r8hIgMDkPMdlDwGU7CNtf97ofXDDO+XGFSoQ40U3/PXBS+ywUQ+0yNN l0rt2Ef5CKYat7O72GE55hqZ4kZhUt7HnB0nLangeDd2ETk+57DzfIo0jr7jM5kvHsgn OXoIxjolqz0xS+ZywfEf2+T1U4GrVc3U42gY2br1AmnoFHLTGSwFeI2LpAQ1ybO24qpv nsPWispwQQFyqgOHzUKk7yr29RFhWxwLKQp4NBPyNY2vpTkQ1l5o5p0QQAq9ISZLKSTQ T2FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=7U07xh2zqleGRz70hYQcPUf+qvh2lpP8dVJ/nDnhvmY=; b=KYpjhQU/VgIOVqhriGzDrOAm9w3u9qg3OluLB8DbZN63K1vZPiz+1SB9kOrTtweXEC yfY+gZe2O/XA/rpmbpuBNkLC/2qyqWcS+YarMOpTUWv5kYV/Ru1J00J0pDuT+sdZpQvk +6qHCE3Efv5AS/inzauckdRBkLQcxlfLg8iFCxwqzsASC1xpFmMdl7e6mbvAEwI0eNIX LZ2MiVA6tAg/nwt0pOpCJEWimtMwno+o0FZzqG9m6zWvpRTS8xwIbrxJwOTF4sLx1/7J 4KMm2hcflChgOab+//NxFgqcqY3BYL9G7EDbw2P3v2NHiwIB54ZEaCxqnwSADiadiuq2 82OA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si8500355edo.368.2021.03.17.02.10.28; Wed, 17 Mar 2021 02:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbhCQJH2 (ORCPT + 99 others); Wed, 17 Mar 2021 05:07:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:40796 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbhCQJHN (ORCPT ); Wed, 17 Mar 2021 05:07:13 -0400 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >