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=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 416D2C4361C for ; Mon, 21 Sep 2020 17:48:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD87422262 for ; Mon, 21 Sep 2020 17:48:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="T4oPJpc3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD87422262 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2792790009F; Mon, 21 Sep 2020 13:48:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24D7390008B; Mon, 21 Sep 2020 13:48:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13EE390009F; Mon, 21 Sep 2020 13:48:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id EB81F90008B for ; Mon, 21 Sep 2020 13:48:29 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AB4A3180AD806 for ; Mon, 21 Sep 2020 17:48:29 +0000 (UTC) X-FDA: 77287803138.19.cake93_320209927147 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 80FCD1AD1A3 for ; Mon, 21 Sep 2020 17:48:29 +0000 (UTC) X-HE-Tag: cake93_320209927147 X-Filterd-Recvd-Size: 5666 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 17:48:28 +0000 (UTC) Received: from paulmck-ThinkPad-P72.home (unknown [50.45.173.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 316392193E; Mon, 21 Sep 2020 17:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600710508; bh=+LrtWrB/YrmXALBTyY0f60jzeqjafAoXq/e/i/AT3Dw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=T4oPJpc3zGBvo6gaEbUhE7CZH2GIgVqggZVoxF++8x5XjrT0k0xFuBvmIsrCTCYnI suHtgCs8P9zaNvOk+9hXZPb/z4sljpAQXhUuosoTYmSaJ8IIZAooG/3yCPuEgMIfyw 3I6gtpXwpyZhRq+GabN5WTDIqbSYrC3OseR72KBg= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id D2957352303A; Mon, 21 Sep 2020 10:48:27 -0700 (PDT) Date: Mon, 21 Sep 2020 10:48:27 -0700 From: "Paul E. McKenney" To: Marco Elver Cc: Andrew Morton , Alexander Potapenko , "H. Peter Anvin" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jann Horn , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , the arch/x86 maintainers , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux Memory Management List Subject: Re: [PATCH v3 10/10] kfence: add test suite Message-ID: <20200921174827.GG29330@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) 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 Mon, Sep 21, 2020 at 07:37:13PM +0200, Marco Elver wrote: > On Mon, 21 Sep 2020 at 19:13, Paul E. McKenney wrote: > > > > On Mon, Sep 21, 2020 at 03:26:11PM +0200, Marco Elver wrote: > > > Add KFENCE test suite, testing various error detection scenarios. Makes > > > use of KUnit for test organization. Since KFENCE's interface to obtain > > > error reports is via the console, the test verifies that KFENCE outputs > > > expected reports to the console. > > > > > > Reviewed-by: Dmitry Vyukov > > > Co-developed-by: Alexander Potapenko > > > Signed-off-by: Alexander Potapenko > > > Signed-off-by: Marco Elver > > > > [ . . . ] > > > > > +/* Test SLAB_TYPESAFE_BY_RCU works. */ > > > +static void test_memcache_typesafe_by_rcu(struct kunit *test) > > > +{ > > > + const size_t size = 32; > > > + struct expect_report expect = { > > > + .type = KFENCE_ERROR_UAF, > > > + .fn = test_memcache_typesafe_by_rcu, > > > + }; > > > + > > > + setup_test_cache(test, size, SLAB_TYPESAFE_BY_RCU, NULL); > > > + KUNIT_EXPECT_TRUE(test, test_cache); /* Want memcache. */ > > > + > > > + expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); > > > + *expect.addr = 42; > > > + > > > + rcu_read_lock(); > > > + test_free(expect.addr); > > > + KUNIT_EXPECT_EQ(test, *expect.addr, (char)42); > > > + rcu_read_unlock(); > > > > It won't happen very often, but memory really could be freed at this point, > > especially in CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels ... > > Ah, thanks for pointing it out. > > > > + /* No reports yet, memory should not have been freed on access. */ > > > + KUNIT_EXPECT_FALSE(test, report_available()); > > > > ... so the above statement needs to go before the rcu_read_unlock(). > > You mean the comment (and not the KUNIT_EXPECT_FALSE that no reports > were generated), correct? > > Admittedly, the whole comment is a bit imprecise, so I'll reword. I freely confess that I did not research exactly what might generate a report. But if this KUNIT_EXPECT_FALSE() was just verifying that the previous KUNIT_EXPECT_TRUE() did not trigger, then yes, the code is just fine as it is. Thanx, Paul > > > + rcu_barrier(); /* Wait for free to happen. */ > > > > But you are quite right that the memory is not -guaranteed- to be freed > > until we get here. > > Right, I'll update the comment. > > Thanks, > -- Marco