Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3326062pxk; Mon, 21 Sep 2020 10:41:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+dCMo5HwYgDp796xOuIN9Jvq49nAvSEoey7EkDSGQ7qa98fnIBfDL2wA4ZaMYZvM82ChV X-Received: by 2002:a17:906:1690:: with SMTP id s16mr613380ejd.122.1600710060736; Mon, 21 Sep 2020 10:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600710060; cv=none; d=google.com; s=arc-20160816; b=OyCVMxowuFFhc7ruyCQ65tqwHsRbSQ4hzykB7WRZJt0VTvtXmbo5ug4i0mRL0T0jHh 6AvjNc+frSc1BA7M+Q5FgChj5b4C970xd//VytJ1972K70WjJXNUGHeUBPI/gmJx/dof +/MX6Su69GFrEvM0P9ZE+ETGJSFsCb2LPU21PBXib3hGPkPl/ZjU0dgzFb1Ovrxf5E/8 RCJ+WD5wtxHEyuTtzG0e6m8JJ53ZQM1W8l/Yyg8W3UincWbsINHjwF9dD+rsMKH7GlMg VJCo45VHGGCUiqWEBoNg0xU0GEXpaMFrCc6YCHKhDwnunVjPqeyI35qul45QMnZjuXPJ yBsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SSZ5KD0dn5jNkyMg9eCMzr2gsc7k3aZ4lV6MBn/HzxM=; b=qdbQYZ6cE/Xs5XTJt0UUgy631sU4BXDzE4r5NlshfKxZC1StQbLmpgSSzkdXzPXh3V 0BLCllzK7DBqRkxp9QBYgV34FAxaY3ulhw2FJtttRBAv/AiXQlVCtuHJziEk8jtXhLmM pdTQKFOnhGY6pxbf+9L/WekecXuKP45iFJFTBzY/5bmLV36MBVq/nm3Yi5Lypn9tmCMP Qa0rZeqXkMbe6h/dtlFk6CwkZSCpNWK/IDM/UcSchK6hEJ7eOwbN2AimmkeSgM1zGY3R urKHwXyFer07vHr2otPVSd7pe5eZfL6Ng61l+yy5kroTjfvavzDA4qRXDND/VCW2VI4D zexw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pamzCqMF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si9230873edq.397.2020.09.21.10.40.36; Mon, 21 Sep 2020 10:41:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pamzCqMF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbgIURh0 (ORCPT + 99 others); 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-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