From patchwork Tue Aug 11 05:39:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 11708585 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADF151392 for ; Tue, 11 Aug 2020 05:39:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75B8220678 for ; Tue, 11 Aug 2020 05:39:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FV8uMO3a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75B8220678 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 33B726B000A; Tue, 11 Aug 2020 01:39:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C6C36B000C; Tue, 11 Aug 2020 01:39:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16A006B000D; Tue, 11 Aug 2020 01:39:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id EB0DE6B000A for ; Tue, 11 Aug 2020 01:39:45 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id ABAD340C6 for ; Tue, 11 Aug 2020 05:39:45 +0000 (UTC) X-FDA: 77137185930.03.rat74_000cb4c26fe0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 7E38C28A4E8 for ; Tue, 11 Aug 2020 05:39:45 +0000 (UTC) X-Spam-Summary: 1,0,0,bf16ad72caea020f,d41d8cd98f00b204,3ic8yxwgkcecmj4rmpx5pxxpun.lxvurw36-vvt4jlt.x0p@flex--davidgow.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1434:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2564:2682:2685:2693:2859:2892:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3355:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4250:4321:4385:4605:5007:6117:6119:6261:6653:6737:7576:7875:7903:8660:9025:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12683:12895:13148:13230:14181:14394:14659:14721:21080:21433:21444:21451:21627:21740:21796:21939:30012:30034:30036:30046:30054:30056:30075,0,RBL:209.85.160.201:@flex--davidgow.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfrmkzb5g31ifdtjijx8gcdwrbdocmthhr9sierd154pknsdnkbwc gy7re9gj X-HE-Tag: rat74_000cb4c26fe0 X-Filterd-Recvd-Size: 6681 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Aug 2020 05:39:44 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id q7so9124489qtd.1 for ; Mon, 10 Aug 2020 22:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=45vX/OukMjmRJbYoiR0tKiPizR257EeVnpqPnjVNEcE=; b=FV8uMO3aqhjqWbi2Tgu6Hf+4cQsDPp+CXiCl3C9oF+52ljsX5mX09Vas3qnKIU8GXK Za5pTaNn7UuRaTl83zJJLC3gdnWAcvDb7og/+aXXsugtYaswwIMKVMMU4v75yer9K7Hc U3UhMilmfY0yw4B9sm+1SL8QTpVXT+IuuWJFX2XEjGAmRz35A6wGp2CjZrnCxwN1BA/0 acTIiPOu9EPlnGxJuFa7hvuKdHATL1QCcXC/t41vf5GsUw6ZPMP0bwHXftyoynnUO0Eq F1EnwJSRefMzr4xasqLztPF6XK21ka4oP3/bbSYVJpcEEAjpaCWnxEGYDaAP+JF3GIiT QL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=45vX/OukMjmRJbYoiR0tKiPizR257EeVnpqPnjVNEcE=; b=COHTBgJ64HgvFo8M2FnA88Kesj+fQ/YVzSiTU1XY3im+sTeWLcEIYapvec5taquDaH mQQRTU0vxF3vWeE0S98Os7GfDrdpGRCROTumBkngrDnVdPNBFhRfFip2QZmjNbFjRkzb 0GZiLaN/ret7Lj+1lWWTSEs3wGev7Y1p2E02K3eIQ0m4qOjvfQ2uCKW9JwwjlGBS/W1I MFKgYq+VKtZ7cJCOBhHH34ixfGXZmnyHpKY25jdUCYqW4cimmaTmVj1ErfTGPS33F0bR hw5jKYlfVdF1p07N9nx5Y15Rsjv2FC3Bdld9dkuDPleiro9R3HhJ2A8dtVoa7elkgk8P ACMg== X-Gm-Message-State: AOAM5307D9/deqcJ6OKDBbfO8BCfBygzoGfcPUWHU4SP3LptjTUBemrk NKOhCo9NLcy6fG438vYLn/Vzl0ZTCtTCHA== X-Google-Smtp-Source: ABdhPJyX6cDzJ29PKias/qfWiHzlxz/CIIlnG39utN5Ohs9jzVf+HpAsJZW9sC7eGOZYJzaiFiHffLfuxlk31A== X-Received: by 2002:a0c:fdeb:: with SMTP id m11mr32366961qvu.103.1597124384218; Mon, 10 Aug 2020 22:39:44 -0700 (PDT) Date: Mon, 10 Aug 2020 22:39:14 -0700 In-Reply-To: <20200811053914.652710-1-davidgow@google.com> Message-Id: <20200811053914.652710-6-davidgow@google.com> Mime-Version: 1.0 References: <20200811053914.652710-1-davidgow@google.com> X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [PATCH v12 5/6] KASAN: Testing Documentation From: David Gow To: trishalfonso@google.com, brendanhiggins@google.com, aryabinin@virtuozzo.com, dvyukov@google.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, andreyknvl@google.com, shuah@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, David Gow X-Rspamd-Queue-Id: 7E38C28A4E8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Patricia Alfonso Include documentation on how to test KASAN using CONFIG_TEST_KASAN_KUNIT and CONFIG_TEST_KASAN_MODULE. Signed-off-by: Patricia Alfonso Signed-off-by: David Gow Reviewed-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Acked-by: Brendan Higgins Tested-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 38fd5681fade..42991e40cbe1 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -281,3 +281,73 @@ unmapped. This will require changes in arch-specific code. This allows ``VMAP_STACK`` support on x86, and can simplify support of architectures that do not have a fixed module region. + +CONFIG_KASAN_KUNIT_TEST & CONFIG_TEST_KASAN_MODULE +-------------------------------------------------- + +``CONFIG_KASAN_KUNIT_TEST`` utilizes the KUnit Test Framework for testing. +This means each test focuses on a small unit of functionality and +there are a few ways these tests can be run. + +Each test will print the KASAN report if an error is detected and then +print the number of the test and the status of the test: + +pass:: + + ok 28 - kmalloc_double_kzfree +or, if kmalloc failed:: + + # kmalloc_large_oob_right: ASSERTION FAILED at lib/test_kasan.c:163 + Expected ptr is not null, but is + not ok 4 - kmalloc_large_oob_right +or, if a KASAN report was expected, but not found:: + + # kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:629 + Expected kasan_data->report_expected == kasan_data->report_found, but + kasan_data->report_expected == 1 + kasan_data->report_found == 0 + not ok 28 - kmalloc_double_kzfree + +All test statuses are tracked as they run and an overall status will +be printed at the end:: + + ok 1 - kasan_kunit_test + +or:: + + not ok 1 - kasan_kunit_test + +(1) Loadable Module +~~~~~~~~~~~~~~~~~~~~ + +With ``CONFIG_KUNIT`` enabled, ``CONFIG_KASAN_KUNIT_TEST`` can be built as +a loadable module and run on any architecture that supports KASAN +using something like insmod or modprobe. + +(2) Built-In +~~~~~~~~~~~~~ + +With ``CONFIG_KUNIT`` built-in, ``CONFIG_KASAN_KUNIT_TEST`` can be built-in +on any architecure that supports KASAN. These and any other KUnit +tests enabled will run and print the results at boot as a late-init +call. + +(3) Using kunit_tool +~~~~~~~~~~~~~~~~~~~~~ + +With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, we can also +use kunit_tool to see the results of these along with other KUnit +tests in a more readable way. This will not print the KASAN reports +of tests that passed. Use `KUnit documentation `_ for more up-to-date +information on kunit_tool. + +.. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html + +``CONFIG_TEST_KASAN_MODULE`` is a set of KASAN tests that could not be +converted to KUnit. These tests can be run only as a module with +``CONFIG_TEST_KASAN_MODULE`` built as a loadable module and +``CONFIG_KASAN`` built-in. The type of error expected and the +function being run is printed before the expression expected to give +an error. Then the error is printed, if found, and that test +should be interpretted to pass only if the error was the one expected +by the test.