Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1164181pxx; Fri, 30 Oct 2020 03:52:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIk478kTUQ7YUaBYosWbVVqws8ljBPZr8tSgj52Vdp1uFZZxXGn7hagyq0bIThkhBriSTN X-Received: by 2002:a17:906:415a:: with SMTP id l26mr1732039ejk.442.1604055150475; Fri, 30 Oct 2020 03:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604055150; cv=none; d=google.com; s=arc-20160816; b=aZ4bFcChg/1k+4fO7zzOzVW38G9X7SB9HHsxcSbmrzE46kTFx0PLjrRCT4+z4mOEF8 zmkFT244tUOURK6abcwqGvQVp0OihALMmz4Z1flHrM7nfojTJVEH4IAAcsoOt3EpHBI8 Z5L4RK4dz68C2CbPE4E8GdW6kWR2wmIrLeyRT3BMKXTptJ6NPhipp1qEXjbyNjSFvnrp +7iK3nq6uqMHlvhWNskWf78q3ooRAgMo0FJeG4QpsKkzQieludNna8R4SzBIUsDLVLmu Hjco57fdV4OqY7UjmZt8o897HRO9+GUoRR3DJZ8/UtABg4GnFioYZ2sMF8k7F1hCp0I/ CxrA== 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=hvuWYo7Yuy4+Xoosva2YfT/B6vDa7o+k5TcZrFjzw2I=; b=C5ipVhj3rSoOIeVoz+QlRnVHrL93eKS0clZKosN5w+Ppf82aC40s2oQnbSxM7Lk8aw hUoz2aOgT4tBoKYq5m5ZPuE9hoYRj8ziuH2pfN+wzdQt3B2KFL1UonGLnSGLE0VnooOH QB9yGmp5OepDVrnBVisA+pT/AwYREfRKVANzJmKOlw4DfpE8gF/+1487nPiy28JxfHgh 7vxisk1EjO3XlxGUvVxDTw2WvuXaXxvxWNUCPLhId5kDbnMrV8+/2EtOkv9aLKTUuvIe A7Gcd4VDr7oBBAtfFlsKNKYp5PpjNUiINCq+quc0vIwBySuHhxP0uZkctDP9BpMAhvMu B/PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mCyFqjN1; 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 cy1si3970278edb.13.2020.10.30.03.52.07; Fri, 30 Oct 2020 03:52:30 -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=mCyFqjN1; 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 S1726297AbgJ3Kuq (ORCPT + 99 others); Fri, 30 Oct 2020 06:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ3Kuq (ORCPT ); Fri, 30 Oct 2020 06:50:46 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDD4C0613D2 for ; Fri, 30 Oct 2020 03:50:45 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id d9so225899oib.3 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=iodq8p4jt7QUgOghu0a3DWxtvHwrbVYDGUbuYrNEjl4yVP7+VeZaELq2BegvMx+GpL er+nZBjJlyzbAjgZAoX/wOpn1QV877oHOG2xm8gSIH8Xo3B48UXbmP8Pt/zoW/u+3bNa DxsPtKjtMWXFtPGakJ7Re8Nu8PXcAM/FUyXX5qnjx+05gm0qGJ7BU64pJoyqZTHrUxj1 TiU+LoBaXH3rQTmL3aQgh6rc4hC95tpJ7aBZ1z2ZEj+mqNurCek5BUfnNhR7TsGw9Nld YRO6eGTCaXl1smyi6CV7xfDBv4BExCewKWm6nbqXooP2GUipbuA9Td9o1rD5lyrs2Ma2 m/AQ== X-Gm-Message-State: AOAM530zh9Ujr3xsdTluQyDGjpgjFE7b2Fpq2PlUKjwv2coxdOady6Pk +sLdfGPNLdp0tlU6TguHtlFgVMSA2E0zN4QHqFt0mg== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.