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