Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3331651pxk; Mon, 21 Sep 2020 10:49:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvSl1aAyKHRDwoPP5seaDrJI5oYlYjRbDe4BBPC9IlPpVY+imq0oYyQZjne8eJ0XF5YlyN X-Received: by 2002:a17:906:eb11:: with SMTP id mb17mr590818ejb.255.1600710593147; Mon, 21 Sep 2020 10:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600710593; cv=none; d=google.com; s=arc-20160816; b=O+h4aW51NrmAbdX0mzBNjvQiusBDa6VtSV+IIgZAhO/C7H1+asgSwdEleZyz5xKXyF fHVp2xTpVZgU8zlFQNREddBIHRwcFPTtUqKs51xF4oulxWBr9oZhcTjaDVKXzj2e9rbv 6n1BlkwdBoHtxyncxDhE6I/8uP7FaFTg7yyRXFLUywhZlW1dGqRX4hNg8g0tph03L7cD TWCWKZtIrP+y+SZzd0+IBAf852OnuXD+QnmzXbeKwUjdpC0VmMbj3G8dnWCvQR5TZHzq upC61ANf7ZejZsxhk2VPO2pb43BiWMvEZywUC/Ls6O3SqdosMDbPKXKYqO1n40BnuWI+ Fcfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9gMCgUPuqmsDOVX4JdDkewhoINxdoNAYr1tEhpDlJvQ=; b=AKgySXuoHml1ZyrRLjrlKZJMQREiA9BY9eobCdG+s0OPxTdeEYeRhvwVO7cqknzTSn e8nXFz46L9BHhl3obmbwN5cuJOrZ05d38jbCsVie5/9CdP1BEoZsyoyEfRCie6ua3vwy j/8pleBr2HsSmMp6W9faThYXRVgRKyDqsoTBrinVlnA/U4//sDIShfss5AXzvao5xGfs LRc7dJcKfowCq9ViMAHHBHPbkU8eXINuPP59WrAJXU4/B+vFby8Hvjl2/AY5XAVj6nF/ wpP9IkYgA2qFsBkM/iIRjr3ec/9tKRkgVJ0o60A9I8XLirHUZhBOnBeyQ18h2rlV+HY8 PTbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T4oPJpc3; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df4si8170275edb.378.2020.09.21.10.49.29; Mon, 21 Sep 2020 10:49:53 -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=@kernel.org header.s=default header.b=T4oPJpc3; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbgIURs3 (ORCPT + 99 others); Mon, 21 Sep 2020 13:48:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:38376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbgIURs3 (ORCPT ); Mon, 21 Sep 2020 13:48:29 -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 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 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 Subject: Re: [PATCH v3 10/10] kfence: add test suite Message-ID: <20200921174827.GG29330@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-11-elver@google.com> <20200921171325.GE29330@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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