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, INCLUDES_PATCH,MAILING_LIST_MULTI,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 AEC0EC4363A for ; Fri, 30 Oct 2020 10:50:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 151E7221EB for ; Fri, 30 Oct 2020 10:50:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mCyFqjN1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 151E7221EB 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 37CD56B005C; Fri, 30 Oct 2020 06:50:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32BDD6B005D; Fri, 30 Oct 2020 06:50:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21DF06B0062; Fri, 30 Oct 2020 06:50:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id E47A56B005C for ; Fri, 30 Oct 2020 06:50:46 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 857C9180AD80F for ; Fri, 30 Oct 2020 10:50:46 +0000 (UTC) X-FDA: 77428273692.24.story58_1c0be7927295 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 6B6651A4A0 for ; Fri, 30 Oct 2020 10:50:46 +0000 (UTC) X-HE-Tag: story58_1c0be7927295 X-Filterd-Recvd-Size: 6886 Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 10:50:45 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id w191so6253873oif.2 for ; Fri, 30 Oct 2020 03:50:45 -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=hvuWYo7Yuy4+Xoosva2YfT/B6vDa7o+k5TcZrFjzw2I=; b=mCyFqjN1bQQC8Hvkpi7xW/3dnxa3ThGOZg+0wqlUrAHvvhX8m/ncxpq7Pyp/dRRs3g 4WEWXc3YTkQEmBo4hMY8pxvX5o+Gv/Ie9TXg7vKqqMwjs5D7KvUPpTYMZtWdx8246Vkw J6HR1GHDIFM02CVcqc8Kk+Y6oFzxFgYqMnr0GfrzLUtvoripkAXvu1boXzKL84jaqzZ0 JLMFVm206/J5PjBOhMmilJ6+hEiScGTLGEKl7zMM1R9M2vfhOCCinAqTix2sr1UDctvr 8/O6shRzAPdYkLPxVflRgSxCAY0CYhUvm76k9hSxcnPW4WCKFajDZSAKGSGrz5NSjsJN Ywlw== 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=hvuWYo7Yuy4+Xoosva2YfT/B6vDa7o+k5TcZrFjzw2I=; b=klesxixdD1zAHTgVuuQVmR/7asQbVkJTh1jVMN1RQYZj0/UnHEOVCYYdf79S1KUy0j 9DMTEVSFyVAw2KKHWUEL7HpWsHGEYZXejrJh8M6Sv6I8CoW/DgEXpWh/MCws7o1j7Mv5 In2BIGsX+WQ5t28Pcub1LVeUtqPJIWUJRsIfQIzac5lwFqiMLv0iy8yRg8rye2Twsk5x +5DvfoSYKmE85le57HY90eORYoGSqe81Krq9yxXrD5x9UUHaju0Fq7lfdvsrrW25NZ1B VD+h6XjmP7c8ahlBQxVfko09QBDacuFInoQyCcsTMsSkrMTfMX/tZ6ehgw5pRwhEh2EZ x8FA== X-Gm-Message-State: AOAM5312LlRB/pz84R75yc9pwgT2yp32m7DFKtsTGwv6eX2w2K8yPPUg mKA+lVYwhBz9HDxnbt7x6+neruPq9kY7QVrnTfyemQ== X-Google-Smtp-Source: ABdhPJw9y4ECaTHMdQAHz0FiGUzAKJL50sOGurP0au+ieUbVtdZIpyIHjQtwwPIJDX0B/6q9TBKmmH52j9NmaIeqdOQ= X-Received: by 2002:aca:4f55:: with SMTP id d82mr1138528oib.172.1604055045058; Fri, 30 Oct 2020 03:50:45 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-9-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 30 Oct 2020 11:50:32 +0100 Message-ID: Subject: Re: [PATCH v6 8/9] kfence: add test suite To: Jann Horn Cc: Andrew Morton , Alexander Potapenko , "H . Peter Anvin" , "Paul E . McKenney" , 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 , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , =?UTF-8?Q?J=C3=B6rn_Engel?= , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , kernel list , kasan-dev , Linux ARM , Linux-MM 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 Fri, 30 Oct 2020 at 03:50, Jann Horn wrote: > > On Thu, Oct 29, 2020 at 2:17 PM 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. > [...] > > diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c > [...] > > +static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocation_policy policy) > > +{ > > + void *alloc; > > + unsigned long timeout, resched_after; > [...] > > + /* > > + * 100x the sample interval should be more than enough to ensure we get > > + * a KFENCE allocation eventually. > > + */ > > + timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL); > > + /* > > + * Especially for non-preemption kernels, ensure the allocation-gate > > + * timer has time to catch up. > > + */ > > + resched_after = jiffies + msecs_to_jiffies(CONFIG_KFENCE_SAMPLE_INTERVAL); > > + do { > [...] > > + if (time_after(jiffies, resched_after)) > > + cond_resched(); > > You probably meant to recalculate resched_after after the call to > cond_resched()? This is intentional. After @resched_after is reached, every failed allocation attempt will result in a cond_resched(), because we know the sample interval has elapsed and KFENCE should have kicked in. So we just want to ensure the delayed work gets to run as soon as possible, and just keep yielding. Added a clarifying comment. > > + } while (time_before(jiffies, timeout)); > > + > > + KUNIT_ASSERT_TRUE_MSG(test, false, "failed to allocate from KFENCE"); > > + return NULL; /* Unreachable. */ > > +} > [...] > > +/* > > + * KFENCE is unable to detect an OOB if the allocation's alignment requirements > > + * leave a gap between the object and the guard page. Specifically, an > > + * allocation of e.g. 73 bytes is aligned on 8 and 128 bytes for SLUB or SLAB > > + * respectively. Therefore it is impossible for the allocated object to adhere > > + * to either of the page boundaries. > > Should this be "to the left page boundary" instead of "to either of > the page boundaries"? Thanks for spotting. I think it's "Therefore it is impossible for the allocated object to contiguously line up with the right guard page." > > + * However, we test that an access to memory beyond the gap result in KFENCE > > *results > > > > > + * detecting an OOB access. > > + */ > > +static void test_kmalloc_aligned_oob_read(struct kunit *test) Thanks, will address these for v7.