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 3505CC43468 for ; Mon, 21 Sep 2020 17:13:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E88C42084C for ; Mon, 21 Sep 2020 17:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600708408; bh=nx2TaoLqWNqyr9nmT07RvYE1xPfejV7fHLR9RhvDxrs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:List-ID: From; b=jJHCPO4Xzu/Q3QvneRL0L/Y+mVdSCtP5coBifZVKowXC7ZTmIjzBgG2N7rBmiw7Lr 3Ijl9Uh85S/6krxKyWOS9WGUitRVJ1RL4D0kKcl3OZyQM2vJn62WFKqj3BgMBcapRr YKSgID1jWCD5hEyyuVA8KOle3NSChcQY4qv9KNBo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727858AbgIURN1 (ORCPT ); Mon, 21 Sep 2020 13:13:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:53628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbgIURN0 (ORCPT ); Mon, 21 Sep 2020 13:13:26 -0400 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 1305520758; Mon, 21 Sep 2020 17:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600708406; bh=nx2TaoLqWNqyr9nmT07RvYE1xPfejV7fHLR9RhvDxrs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=1ijNGgPZsuS/MdRNOo+9S8z8K8msXaiAAXasAViW7Pc1fvHVHsRMQmavi1F5KLtPh L9Re+/yGF1bX9rpvp3gODn97EevX4KNCT1dvqtucDsCJkeffjsyPXqu17zAkpdyhX1 W1lNBAILQoN644xeMWEGZaA7OWAQsGtAc0RFYifk= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id D2C8D352303A; Mon, 21 Sep 2020 10:13:25 -0700 (PDT) Date: Mon, 21 Sep 2020 10:13:25 -0700 From: "Paul E. McKenney" To: Marco Elver Cc: akpm@linux-foundation.org, glider@google.com, hpa@zytor.com, andreyknvl@google.com, aryabinin@virtuozzo.com, luto@kernel.org, bp@alien8.de, catalin.marinas@arm.com, cl@linux.com, dave.hansen@linux.intel.com, rientjes@google.com, dvyukov@google.com, edumazet@google.com, gregkh@linuxfoundation.org, hdanton@sina.com, mingo@redhat.com, jannh@google.com, Jonathan.Cameron@huawei.com, corbet@lwn.net, iamjoonsoo.kim@lge.com, keescook@chromium.org, mark.rutland@arm.com, penberg@kernel.org, peterz@infradead.org, sjpark@amazon.com, tglx@linutronix.de, vbabka@suse.cz, will@kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH v3 10/10] kfence: add test suite Message-ID: <20200921171325.GE29330@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921132611.1700350-11-elver@google.com> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ... > + /* 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(). > + 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. Thanx, Paul 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=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 5825DC43466 for ; Mon, 21 Sep 2020 17:14:50 +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 DEAC620758 for ; Mon, 21 Sep 2020 17:14:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sjgrI7so"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="1ijNGgPZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DEAC620758 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=e78GW8g1SVjeNcrJdi0yZttgvlHV3mk4JIXhA4c+h6g=; b=sjgrI7soAoXHXHbEyp+ADESZ35 +TAxL5Gd4bIYrt7pbHOfHsGrZuez7EBSjhb5RTgcDJrCZdGY9aMjS0CpyOxUrlQqCAs3gUYb2t5Qd seQw8Nsn3nh2tAAz3o5XKrFPaVr+8nhyl66FWcroUS5bTvb3wNcQCh7CVMPUBdiQDqYJzg4vh7N0T UwE01+vNn0o1uNA02f26uVu5DgKvEmtGvjWpwx8Yppg9tnx0DXZ/F1dBkO/fkbbwZFEkG8f02EfwR T4gBW42KAIDsJj6CaWEK6fb3N/TTM79Y6ksAgJ/Mnco80p62A9bAmFlfY2fLypFLVmKLHdZMVJqRq lCpzOhcw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKPNZ-0007Ys-UD; Mon, 21 Sep 2020 17:13:29 +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 1kKPNX-0007XZ-4y for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 17:13:28 +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 1305520758; Mon, 21 Sep 2020 17:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600708406; bh=nx2TaoLqWNqyr9nmT07RvYE1xPfejV7fHLR9RhvDxrs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=1ijNGgPZsuS/MdRNOo+9S8z8K8msXaiAAXasAViW7Pc1fvHVHsRMQmavi1F5KLtPh L9Re+/yGF1bX9rpvp3gODn97EevX4KNCT1dvqtucDsCJkeffjsyPXqu17zAkpdyhX1 W1lNBAILQoN644xeMWEGZaA7OWAQsGtAc0RFYifk= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id D2C8D352303A; Mon, 21 Sep 2020 10:13:25 -0700 (PDT) Date: Mon, 21 Sep 2020 10:13:25 -0700 From: "Paul E. McKenney" To: Marco Elver Subject: Re: [PATCH v3 10/10] kfence: add test suite Message-ID: <20200921171325.GE29330@paulmck-ThinkPad-P72> References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200921132611.1700350-11-elver@google.com> 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_131327_258603_A7A9C0D1 X-CRM114-Status: GOOD ( 18.22 ) 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@arm.com, hdanton@sina.com, linux-doc@vger.kernel.org, peterz@infradead.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, linux-mm@kvack.org, edumazet@google.com, glider@google.com, hpa@zytor.com, cl@linux.com, will@kernel.org, sjpark@amazon.com, corbet@lwn.net, x86@kernel.org, kasan-dev@googlegroups.com, mingo@redhat.com, vbabka@suse.cz, rientjes@google.com, aryabinin@virtuozzo.com, keescook@chromium.org, jannh@google.com, andreyknvl@google.com, bp@alien8.de, luto@kernel.org, Jonathan.Cameron@huawei.com, tglx@linutronix.de, akpm@linux-foundation.org, dvyukov@google.com, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, penberg@kernel.org, iamjoonsoo.kim@lge.com 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 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 ... > + /* 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(). > + 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. Thanx, Paul _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel