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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 66967C4361C for ; Mon, 21 Sep 2020 17:37:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16854216C4 for ; Mon, 21 Sep 2020 17:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pamzCqMF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727512AbgIURh0 (ORCPT ); Mon, 21 Sep 2020 13:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbgIURhZ (ORCPT ); Mon, 21 Sep 2020 13:37:25 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84100C061755 for ; Mon, 21 Sep 2020 10:37:25 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id c13so17871532oiy.6 for ; Mon, 21 Sep 2020 10:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=pamzCqMFvLxyB5CpBGbPG7bal5m7ItNuXjTj8pGae/ftLVAUC9Bg/FS/A8URLMlfMZ v2hnX2ZiM5g+TmrpgLFmX5dspappl51u7l1LCJ/npH4P7y2d8PWGiHoeKFxbKCCmzYAA oq+Dfknz4oBZh1CSWxrSzt7fevC4E+ZUEYf9W75Itjt2/Bb3W1dOloFHulv6qpuJ77Iv 6pGCKmLfRlit/7xrESXwIqWaLEtuLil1p1IxWo78xjv2ztZVlx3nK1W+gbUI3Djje/uH Rfey8oUk8KDSI3TO5wkqPrR52MyHKkNTF30i8jxkCbC8d2rE7iPyHVDjYQIvHPalvuch JiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=ptJEmH/PPHkjl6f1BBevf00e8DAQfy6p6NWyHyJ2PRlaAl++oozsd4zbrTrEvQJZlj haXyQZaGB4/3PCNZRRdYq0bA79JOCSyzYb/SnY1U3JlHROxZv/LfoS35zyZVL82OZsl2 mZkJzgM5vi06uPleoq6kAZI+QKClZ3tFTeEr0cKzfKVLhPaEDsErUyvHHqN1GiZIJ3XT qxd5kL9PSa85A73avhV/b3q1hiNKR3WBdrQkt1wogTOvsqflAz/aKawBZOZRE5MQM2et 0Av3z7panXs0PglPzA2NYJV3y0cmA3pzuZ/nPYI0iUnNlZyOuglete5XmgUr4o+HLHHT Xm/w== X-Gm-Message-State: AOAM531evEH32SWpQqZyGc6gM5m3mHd7vk1N0tH58/IfSTYo1kQjPYwq /ZzVHwy0weFh3Qq3SZTutWuoHL3cK5sa2Vptf4Q5bQ== X-Google-Smtp-Source: ABdhPJy20vPuOn/xg/yLOqvqr+k3gT/RowlyliM3IYwweuAlnymXHBeynnmaqK/ExV2lh0t/6GAyPWsl92e/++ZSr1U= X-Received: by 2002:aca:5158:: with SMTP id f85mr303275oib.121.1600709844512; Mon, 21 Sep 2020 10:37:24 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> In-Reply-To: <20200921171325.GE29330@paulmck-ThinkPad-P72> From: Marco Elver Date: Mon, 21 Sep 2020 19:37:13 +0200 Message-ID: Subject: Re: [PATCH v3 10/10] kfence: add test suite To: "Paul E. McKenney" 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > + 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 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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 42FCDC43639 for ; Mon, 21 Sep 2020 17:37:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AB4E9235F9 for ; Mon, 21 Sep 2020 17:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pamzCqMF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB4E9235F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C09DA90009C; Mon, 21 Sep 2020 13:37:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B932A90008B; Mon, 21 Sep 2020 13:37:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E53190009C; Mon, 21 Sep 2020 13:37:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 824EC90008B for ; Mon, 21 Sep 2020 13:37:26 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4125C2478 for ; Mon, 21 Sep 2020 17:37:26 +0000 (UTC) X-FDA: 77287775292.23.ray06_190cf6627146 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 1E70E37604 for ; Mon, 21 Sep 2020 17:37:26 +0000 (UTC) X-HE-Tag: ray06_190cf6627146 X-Filterd-Recvd-Size: 6109 Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 17:37:25 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id a3so17909435oib.4 for ; Mon, 21 Sep 2020 10:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=pamzCqMFvLxyB5CpBGbPG7bal5m7ItNuXjTj8pGae/ftLVAUC9Bg/FS/A8URLMlfMZ v2hnX2ZiM5g+TmrpgLFmX5dspappl51u7l1LCJ/npH4P7y2d8PWGiHoeKFxbKCCmzYAA oq+Dfknz4oBZh1CSWxrSzt7fevC4E+ZUEYf9W75Itjt2/Bb3W1dOloFHulv6qpuJ77Iv 6pGCKmLfRlit/7xrESXwIqWaLEtuLil1p1IxWo78xjv2ztZVlx3nK1W+gbUI3Djje/uH Rfey8oUk8KDSI3TO5wkqPrR52MyHKkNTF30i8jxkCbC8d2rE7iPyHVDjYQIvHPalvuch JiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=lEi4MzutG3+vbh0iMcr2cRAcCnu8+euWj52HUJFg7zNqbNAHZy8jpi9fEpow81RGb7 Cs7sJK5TwmHq4JQLuNoFKdxq9iTLrajGVGIQj+u2YSWpsV/obTaOzBh03rGM8zyKVPTb w9kErRB53MNaAuYBy8lnLaF5hu5Ds+E/NHjeqf/nPcx+dt9tPhWU396mStqrcy6REsN0 8ylrtJ+dMScA1ix82DxQyHa5BeYPxQRu3hIC0KYWJ4uzVUWob1IvAdvGVDNrVRPmxzPo X6jJsJjHvoy/BvvkkIxK6vSevhqBl1z57tHlVZ4ZvYkW0IDMZgYH+YAysbGcEunvk243 Ynvw== X-Gm-Message-State: AOAM533kisEaz+KZbSf8hGksdu6oggRN5KDWT+/ctbIiFsLnFZUbSOCI Xqeko3NzRLN3fBQ9ItRGY6B3C83x8ljNpgOJ83V65w== X-Google-Smtp-Source: ABdhPJy20vPuOn/xg/yLOqvqr+k3gT/RowlyliM3IYwweuAlnymXHBeynnmaqK/ExV2lh0t/6GAyPWsl92e/++ZSr1U= X-Received: by 2002:aca:5158:: with SMTP id f85mr303275oib.121.1600709844512; Mon, 21 Sep 2020 10:37:24 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> In-Reply-To: <20200921171325.GE29330@paulmck-ThinkPad-P72> From: Marco Elver Date: Mon, 21 Sep 2020 19:37:13 +0200 Message-ID: Subject: Re: [PATCH v3 10/10] kfence: add test suite To: "Paul E. McKenney" 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 Content-Type: text/plain; charset="UTF-8" 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, 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. > > + 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 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=-8.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 7A6E2C4347E for ; Mon, 21 Sep 2020 17:38:51 +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 0F2CD20BED for ; Mon, 21 Sep 2020 17:38:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="igd0Jrcu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pamzCqMF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F2CD20BED Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ugVSMQkYJ7Ytv2kSujUJ6WK7tFHAz1TpWMfnoQsVW9s=; b=igd0JrcuRkJwdcy0vlS/T2LTM 1lawSjdku1NZs87ksvDm3BudNksQuaZBkcgISS00isntkkAruD64hNC6JTEgpjyh2p1O0mvY+RILq EPgqh8KwfFytZCpCQ18QvLeVcp0orkoEQa5DDHp/DFbVaRIY5oHXAuWwlNsNiViijLOuNIVDkVQZU sYBWAwm6ekz9g3yWtpJM/dlTzfEDyPceYI6nD9PgcXSUBa7AQt5Ryl3MUvgzaz4aGqyPKrAtKcU/N Xhh/tzwT5zrEhoENbmHCAMLqWqPa/qDQ2WFUwJDNMEauy99U863rEe7PUNsL1m8Qj1uDXELCOgOYu JcuDvFbsA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKPko-0002T4-HB; Mon, 21 Sep 2020 17:37:30 +0000 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKPkl-0002RB-9A for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 17:37:28 +0000 Received: by mail-oi1-x242.google.com with SMTP id u126so17839839oif.13 for ; Mon, 21 Sep 2020 10:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=pamzCqMFvLxyB5CpBGbPG7bal5m7ItNuXjTj8pGae/ftLVAUC9Bg/FS/A8URLMlfMZ v2hnX2ZiM5g+TmrpgLFmX5dspappl51u7l1LCJ/npH4P7y2d8PWGiHoeKFxbKCCmzYAA oq+Dfknz4oBZh1CSWxrSzt7fevC4E+ZUEYf9W75Itjt2/Bb3W1dOloFHulv6qpuJ77Iv 6pGCKmLfRlit/7xrESXwIqWaLEtuLil1p1IxWo78xjv2ztZVlx3nK1W+gbUI3Djje/uH Rfey8oUk8KDSI3TO5wkqPrR52MyHKkNTF30i8jxkCbC8d2rE7iPyHVDjYQIvHPalvuch JiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=SrlH7TKJM7edTpxE3Fc0Nahn94gqo8hyybVMN2TCtBMQTOUKpH8FseSx6aScwx138Y S57SxY3FrxFcmf5uGgYJUhAz1UWHsMjTXlPQL2ohOYAUOYO8GoVYpD2ScobwTJj2nMMK KlMtb/SoGAOMU/mmouYLHeK8zk3UdM/ytwwFVSTNvYWNLP55SyniJtO/eAlHfiEilwVp G40gLyjkPciVZYm/iLIagj69TUNgUrvHx7gMG5v5BlF4j7sYpv0dB2faeITSoZJOw5mq UmjPyARK7fiiQobBmOfZFoCLdoiMyfPRSLRTwx0YiQqT0mJwy7qBNxVFzloGROFsDAVy Kd6Q== X-Gm-Message-State: AOAM533k2qiGFF8pQUVsSPfL3PzxG2YTUCexcth3D2mUGBynxEWPcLrs jFVaS/hgADA8cbNSf5vQizfqSW6oGgwN+iFN2Mzh8Q== X-Google-Smtp-Source: ABdhPJy20vPuOn/xg/yLOqvqr+k3gT/RowlyliM3IYwweuAlnymXHBeynnmaqK/ExV2lh0t/6GAyPWsl92e/++ZSr1U= X-Received: by 2002:aca:5158:: with SMTP id f85mr303275oib.121.1600709844512; Mon, 21 Sep 2020 10:37:24 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> In-Reply-To: <20200921171325.GE29330@paulmck-ThinkPad-P72> From: Marco Elver Date: Mon, 21 Sep 2020 19:37:13 +0200 Message-ID: Subject: Re: [PATCH v3 10/10] kfence: add test suite To: "Paul E. McKenney" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_133727_378822_044C7C56 X-CRM114-Status: GOOD ( 25.12 ) 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: , 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, 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. > > + 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