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.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 4E8AFC4347E for ; Mon, 21 Sep 2020 17:49:53 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E085E216C4 for ; Mon, 21 Sep 2020 17:49:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UX5KcoXn"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="T4oPJpc3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E085E216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:Reply-To:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0xEryA+J7kTWTGtwwFMjOD5p5SIPVy6cC7RCt2NkBHI=; b=UX5KcoXnbbgfGKqkg9GBrICusN 80j9YZfvwHdVl40KSNPP/J5PK/YXMcMUmZi6t2trCckadlfydkVMp5sSoNoVaVBWReMYSRfuLSy1a z0nna0j4wTg957ryjgSVBxzh76QqIbAf0HxS+LdxET0/oZx+6z7TYfYLCiiW152ZAzyuZnKVIxn4A ChqNjaUgI3DEN0GjVyrHcV/Qhj1M5QS8qnjNsWGUM+3GcSZpAbxdEBOh+fVOn+bPOsIngQ6n2L93V 9AbLbh7gMHTQ1oYz/9OZmDTf8Xm/5b557rXDMHYnmpBwiCycBMT7Yw8v9AGlgBc28uudbniiWHCmF ady70bbg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKPvU-0004Rh-JR; Mon, 21 Sep 2020 17:48:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKPvR-0004Pp-9H for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 17:48:30 +0000 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 Subject: Re: [PATCH v3 10/10] kfence: add test suite Message-ID: <20200921174827.GG29330@paulmck-ThinkPad-P72> References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_134829_469388_50B28A04 X-CRM114-Status: GOOD ( 31.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: paulmck@kernel.org Cc: Mark Rutland , Hillf Danton , "open list:DOCUMENTATION" , Peter Zijlstra , Catalin Marinas , Dave Hansen , Linux Memory Management List , Eric Dumazet , Alexander Potapenko , "H. Peter Anvin" , Christoph Lameter , Will Deacon , SeongJae Park , Jonathan Corbet , the arch/x86 maintainers , kasan-dev , Ingo Molnar , Vlastimil Babka , David Rientjes , Andrey Ryabinin , Kees Cook , Jann Horn , Andrey Konovalov , Borislav Petkov , Andy Lutomirski , Jonathan Cameron , Thomas Gleixner , Andrew Morton , Dmitry Vyukov , Linux ARM , Greg Kroah-Hartman , LKML , Pekka Enberg , Joonsoo Kim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel