From patchwork Wed Aug 5 04:29:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 11701279 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 4D1521392 for ; Wed, 5 Aug 2020 04:30:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20A9222D2C for ; Wed, 5 Aug 2020 04:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TBGXVFSW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20A9222D2C 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 AF6716B0024; Wed, 5 Aug 2020 00:29:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A54836B0025; Wed, 5 Aug 2020 00:29:58 -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 8CFE76B0026; Wed, 5 Aug 2020 00:29:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 6F56B6B0024 for ; Wed, 5 Aug 2020 00:29:58 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2C2FD181AEF1D for ; Wed, 5 Aug 2020 04:29:58 +0000 (UTC) X-FDA: 77115237276.30.part26_300a0b726fac Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id F2EE0180B3AA7 for ; Wed, 5 Aug 2020 04:29:57 +0000 (UTC) X-Spam-Summary: 1,0,0,20dd26b218007af6,d41d8cd98f00b204,3xduqxwgkcnc63ob69hp9hh9e7.5hfebgnq-ffdo35d.hk9@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.202:@flex--davidgow.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8wund3n9np3h7oez9cm4iqrrhcocmthhr9sierd154pknsd1jmrt ruz5h9gj X-HE-Tag: part26_300a0b726fac X-Filterd-Recvd-Size: 6634 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 5 Aug 2020 04:29:57 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id u17so28405518qtq.13 for ; Tue, 04 Aug 2020 21:29:57 -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=nr8mXyqoppq75z/FRAmv2PARhpMnaUiNjcYddLk+74Y=; b=TBGXVFSWKjIeEBqhvRaejVcq72l1gKFOpsaGCkZOAQJpdKTwqMp/DQXge1vJKAeR5/ ThVPPm/zNb2xLLpfeYEeQKNcqG1kCFRXvJwJiHpulAaJiB4j61TxQCMJFcOkOXgOLQ/Z a2+HD8lIq0X8NR4IZH3ThaMkZ5BmfQlKqHdr8xVOPWzrMhVpfzKN2qoCftelTjCce5AI cymRYGgP42zU7ZsJC3GMRNkOPIaQt/cJM7bc1TnycBnTatTc0ilWK9Nq2QCTMj/6Bb4/ FtEHlXvb7Mgo1q8joQCtFHwsHZ1OiGoQ78JdVDGjNgdnJ6t86ULnbwBakvPUfdTbNOMZ Ibtg== 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=nr8mXyqoppq75z/FRAmv2PARhpMnaUiNjcYddLk+74Y=; b=m/WEBuPhW26YAAQc9dJLAevdZUXUUOMsg+XzuXBAoI9BeupP2qE6UuHESRLeJwofq7 lzhhhoXgv8xOJcyKiLiii/0ZSkk+XdPr5oTs9o6+Pw47pcql4VMUcPxV8MpjQu5+Zkkq 7a+c0ow86pftk4Q6XNvEyGOKcyzBqjzNQFj2aOasGJGtL1L2wnM0fLFvK1d6BaHadjtX v9T03IlLLP8I1rchCC526Xej7zllGcY7gjv+gcHNSV4Vlimy1tDnO8nUAxNuZ+pXc14E Zl77bB3V83MYmCT/HLmvCKCb1CGjnoMseReUmatrJr+c32aDsgywrqG3nNh2zQxJDknU nr/g== X-Gm-Message-State: AOAM531BS/MICuem4ZEOiaau5Ahv2CMH7RhapbBTNbXiOVLYltn9vsUJ hpofelB7VzPKnXcDv79PaHMLp/g4seuUhQ== X-Google-Smtp-Source: ABdhPJyOD1VNp72JmjPWa6NqIFzpjMKCPktNfzHcJvlTS4cUwujsKARM51+jzJ3ICEGDcQvZK6HI7D4IA5H6KQ== X-Received: by 2002:ad4:4152:: with SMTP id z18mr1839378qvp.42.1596601796941; Tue, 04 Aug 2020 21:29:56 -0700 (PDT) Date: Tue, 4 Aug 2020 21:29:37 -0700 In-Reply-To: <20200805042938.2961494-1-davidgow@google.com> Message-Id: <20200805042938.2961494-6-davidgow@google.com> Mime-Version: 1.0 References: <20200805042938.2961494-1-davidgow@google.com> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [PATCH v11 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: F2EE0180B3AA7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 --- 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.