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=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=ham 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 60751C433E0 for ; Tue, 12 Jan 2021 14:34:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E35F523132 for ; Tue, 12 Jan 2021 14:34:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E35F523132 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 6FCEC6B0192; Tue, 12 Jan 2021 09:34:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ABC46B0194; Tue, 12 Jan 2021 09:34:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FF0C8D0090; Tue, 12 Jan 2021 09:34:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 361BA6B0192 for ; Tue, 12 Jan 2021 09:34:24 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EBF80180AD817 for ; Tue, 12 Jan 2021 14:34:23 +0000 (UTC) X-FDA: 77697368406.02.shade21_400b09727516 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id C930E10097AA1 for ; Tue, 12 Jan 2021 14:34:23 +0000 (UTC) X-HE-Tag: shade21_400b09727516 X-Filterd-Recvd-Size: 7221 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 14:34:23 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id c5so2720368wrp.6 for ; Tue, 12 Jan 2021 06:34:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=U744HxyOHZ4bYG3Cc/mr37WoBXh+B0nSwCGfLK9zJn0=; b=p7sCAvlUYMzziw08KT/qOtcyvICsjejqtIpqIExn+H4PwcgvGDwmg16FQlQ75sQuCD xBH4gE5KQye10UuMDSF2RgbVZIulq5JDyWzHKGHj260uD4/BAcMKaZh+HqEsPEtYjt7E U3coTjGgKjnE0BrpCvc5Py0MH9LJ2/RyQqA3OOWTIF/PyVmiFais/Its6G3UrNwYSnq+ JZU4hv4ikKdTh2+Mbj+cIsyhyUBRrEgL9tqvoyZvdoRJasaVXK3PacPRYYkpwCSYx4br ZYl6WqaJNYaCqtLmaclLMjiVfVdusosjDeERWjS8id9n3pvPWCz5aQPaV65r3pztPHLz 1NRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=U744HxyOHZ4bYG3Cc/mr37WoBXh+B0nSwCGfLK9zJn0=; b=tHboiaE6S0DLkfdkiL4ILDqptR8gCCQRoxCz8Rg20X56QN3s9HLZ5WstKbcNSHt+B6 33FztVBc+3syKwYNMjDBR617j5tBSK7xFuocEAFiPG0HgCqAx3xhXPYP6erELiN3U16U +XDlcDncZkuGbU/r+MCgitMhXEwMbyMg+HNA9WnrFsOQ+HRdlnZyeW4lcTQCK/Xs+IBY qjURPPcd0ZVNDChwytxKDTYNYGcdhuilhnszkiNV+wkD8m1Psyj8yPNE/zS9BXa6zTKY pXwPs4m39BcNAcKHapAlYjLVgLnoRKpfMMmVu6ZJk/UrOxILtqilR9D1OAL828G8KW/B ZhOA== X-Gm-Message-State: AOAM533JsZdIP7P1r5726RobB6FP3C0NLIGv8WUMA5IxwxTEp0TolYwa zKLW7wp37sfc5PHQmEbyFZyUhA== X-Google-Smtp-Source: ABdhPJzKuddLdUE2T+B3q5M1asSfQtHaNy4J4XGxxEqbDbNKrNxvoQKkAPi5eAkDeCrROmSsNM29dg== X-Received: by 2002:a5d:6204:: with SMTP id y4mr4678555wru.48.1610462061876; Tue, 12 Jan 2021 06:34:21 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) by smtp.gmail.com with ESMTPSA id u10sm4120446wmd.43.2021.01.12.06.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 06:34:20 -0800 (PST) Date: Tue, 12 Jan 2021 15:34:15 +0100 From: Marco Elver To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 11/11] kasan: add proper page allocator tests Message-ID: References: <15ca1976b26aa9edcec4a9d0f3b73f5b6536e5d0.1609871239.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15ca1976b26aa9edcec4a9d0f3b73f5b6536e5d0.1609871239.git.andreyknvl@google.com> User-Agent: Mutt/2.0.2 (2020-11-20) 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 Tue, Jan 05, 2021 at 07:27PM +0100, Andrey Konovalov wrote: > The currently existing page allocator tests rely on kmalloc fallback > with large sizes that is only present for SLUB. Add proper tests that > use alloc/free_pages(). > > Signed-off-by: Andrey Konovalov > Link: https://linux-review.googlesource.com/id/Ia173d5a1b215fe6b2548d814ef0f4433cf983570 Reviewed-by: Marco Elver > --- > lib/test_kasan.c | 54 +++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 49 insertions(+), 5 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 6261521e57ad..24798c034d05 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -128,6 +128,12 @@ static void kmalloc_node_oob_right(struct kunit *test) > kfree(ptr); > } > > +/* > + * These kmalloc_pagealloc_* tests try allocating a memory chunk that doesn't > + * fit into a slab cache and therefore is allocated via the page allocator > + * fallback. Since this kind of fallback is only implemented for SLUB, these > + * tests are limited to that allocator. > + */ > static void kmalloc_pagealloc_oob_right(struct kunit *test) > { > char *ptr; > @@ -138,14 +144,11 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) > return; > } > > - /* > - * Allocate a chunk that does not fit into a SLUB cache to trigger > - * the page allocator fallback. > - */ > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > > KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0); > + > kfree(ptr); > } > > @@ -161,8 +164,8 @@ static void kmalloc_pagealloc_uaf(struct kunit *test) > > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > - > kfree(ptr); > + > KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = 0); > } > > @@ -182,6 +185,45 @@ static void kmalloc_pagealloc_invalid_free(struct kunit *test) > KUNIT_EXPECT_KASAN_FAIL(test, kfree(ptr + 1)); > } > > +static void pagealloc_oob_right(struct kunit *test) > +{ > + char *ptr; > + struct page *pages; > + size_t order = 4; > + size_t size = (1UL << (PAGE_SHIFT + order)); > + > + /* > + * With generic KASAN page allocations have no redzones, thus > + * out-of-bounds detection is not guaranteed. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=210503. > + */ > + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC enabled"); > + return; > + } > + > + pages = alloc_pages(GFP_KERNEL, order); > + ptr = page_address(pages); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > + > + KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0); > + free_pages((unsigned long)ptr, order); > +} > + > +static void pagealloc_uaf(struct kunit *test) > +{ > + char *ptr; > + struct page *pages; > + size_t order = 4; > + > + pages = alloc_pages(GFP_KERNEL, order); > + ptr = page_address(pages); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > + free_pages((unsigned long)ptr, order); > + > + KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = 0); > +} > + > static void kmalloc_large_oob_right(struct kunit *test) > { > char *ptr; > @@ -933,6 +975,8 @@ static struct kunit_case kasan_kunit_test_cases[] = { > KUNIT_CASE(kmalloc_pagealloc_oob_right), > KUNIT_CASE(kmalloc_pagealloc_uaf), > KUNIT_CASE(kmalloc_pagealloc_invalid_free), > + KUNIT_CASE(pagealloc_oob_right), > + KUNIT_CASE(pagealloc_uaf), > KUNIT_CASE(kmalloc_large_oob_right), > KUNIT_CASE(kmalloc_oob_krealloc_more), > KUNIT_CASE(kmalloc_oob_krealloc_less), > -- > 2.29.2.729.g45daf8777d-goog >