From patchwork Tue Sep 15 03:58:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 11775455 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 DAC1D92C for ; Tue, 15 Sep 2020 03:58:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8E3AA20738 for ; Tue, 15 Sep 2020 03:58:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="HPKahaLV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E3AA20738 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 38F22900011; Mon, 14 Sep 2020 23:58:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F29E8E0009; Mon, 14 Sep 2020 23:58:47 -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 0F442900011; Mon, 14 Sep 2020 23:58:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id E38B78E0009 for ; Mon, 14 Sep 2020 23:58:46 -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 A35E9181AEF1D for ; Tue, 15 Sep 2020 03:58:46 +0000 (UTC) X-FDA: 77263939452.30.pies03_090af732710e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 764CD180B3C83 for ; Tue, 15 Sep 2020 03:58:46 +0000 (UTC) X-Spam-Summary: 1,0,0,fb9686db02b87e8f,d41d8cd98f00b204,39ttgxwgkco4tqlytwemweewbu.secbydkn-ccalqsa.ehw@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;04y8kbu7cjpaewn3xmqisjfnypfwnyprze3s3gmcrd154pknsd7xd4r 7mk6dw9m X-HE-Tag: pies03_090af732710e X-Filterd-Recvd-Size: 6888 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 03:58:45 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id c5so1837471qtd.12 for ; Mon, 14 Sep 2020 20:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=uCglP5LX985FGF4m2PQOWOUblsVZfIf8g+EYcPDK67c=; b=HPKahaLV0BRynEGp6ZaODFkiwQm1KiRc4qKnG7F0a72KRtJLIW+kK9HpYePY+PelRW kqfvCu5DTIS8RLAsyz6LsWwQgIXFxbSIfKdVQqZBtt/kzQAuUjER20J4MM1AeRBjbe9N 1sjCzqqF0ugnAnz2WCZfARgqOotVf2e9fB6j9OicYUNrSV035CoRTjhwoJ48YTLd8nC6 taGtf0mqTakdfcWbUXx+q4JRFdl/cRzBjusPvSdNxI4i8lKIiyWedjAjB6NjVl/1MuEl ai4RGLJ46opkRsumeRA6bG1+fRtGQoHJ7G0N/G7QdhixURMVxgOl8tC2v9Be21dh8p/U Qs4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uCglP5LX985FGF4m2PQOWOUblsVZfIf8g+EYcPDK67c=; b=ZL79D7nzfmbyDQCwufCOOMsf2gt4qVU8vxJdoC1v17dAjvd4HhVS8l/qTWBKx5I6jR nMk+TBPI7lpKLBSPJ2LOH9HBYe7P49qGP4LZi9a5JWyBugw5n3wcGlvAaAOaqgsucU/S QGy8guo9my2qFAwyXL7ZpyRaaiQQncq2+Op6w7uqC0XUSY9Fl81QsRf2fdLKBVJDHYN6 m3WZGc+EtfIHRftsmc6RkooNnVmudr9JXA3XLZpN9U6KG/dncnGrIiwz7BYBWpWblPj+ AxLLIQUqktmvonKctrf7mYUHqF7tZhVN1XXhKz9dXUZ4AumBRYiXMsQJhZmiiF95V2jQ zOpQ== X-Gm-Message-State: AOAM533igRePW09U+3mJPZrra1TnjdkrjnYFMprC4QENhW45WZ1ydiT2 uNZG0sgmYQkriBh80sBSBuPkK8i+sWxhlg== X-Google-Smtp-Source: ABdhPJzwoiMnTkw6yQ4Uu2gGaOfIAl6aoYI/Wx2A+phY8mopGuZDP+JJBXzJsVOGJLcvnpOIpt/sx8ONxdq62Q== X-Received: from spirogrip.svl.corp.google.com ([2620:15c:2cb:201:42a8:f0ff:fe4d:3548]) (user=davidgow job=sendgmr) by 2002:a0c:f48e:: with SMTP id i14mr16532536qvm.9.1600142325247; Mon, 14 Sep 2020 20:58:45 -0700 (PDT) Date: Mon, 14 Sep 2020 20:58:27 -0700 In-Reply-To: <20200915035828.570483-1-davidgow@google.com> Message-Id: <20200915035828.570483-5-davidgow@google.com> Mime-Version: 1.0 References: <20200915035828.570483-1-davidgow@google.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v14 4/5] 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: 764CD180B3C83 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000792, 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..072ecdadba07 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 + +or:: + + not ok 1 - kasan + +(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. The module is called ``test_kasan``. + +(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.