From patchwork Tue Aug 11 05:39:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 11708569 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 12C0B722 for ; Tue, 11 Aug 2020 05:39:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BEA1C20678 for ; Tue, 11 Aug 2020 05:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BrmmSX27" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEA1C20678 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 B4FF86B0003; Tue, 11 Aug 2020 01:39:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ADB106B0005; Tue, 11 Aug 2020 01:39:36 -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 9560F6B0006; Tue, 11 Aug 2020 01:39:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 78A096B0003 for ; Tue, 11 Aug 2020 01:39:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E04F68248D51 for ; Tue, 11 Aug 2020 05:39:35 +0000 (UTC) X-FDA: 77137185510.29.scene91_530b6b826fe0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id BE8E518086CD8 for ; Tue, 11 Aug 2020 05:39:35 +0000 (UTC) X-Spam-Summary: 50,0,0,82a07e63060329f0,d41d8cd98f00b204,3fi8yxwgkcd0czuhcfnvfnnfkd.bnlkhmtw-lljuzbj.nqf@flex--davidgow.bounces.google.com,,RULES_HIT:2:41:69:152:355:379:541:800:967:968:973:981:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:1801:1981:2194:2198:2199:2200:2393:2525:2560:2568:2629:2682:2685:2689:2693:2859:2895:2899:2902:2914:2924:2926:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4049:4120:4250:4321:4605:5007:6119:6261:6653:6690:6691:6737:7875:7904:8660:8784:9025:9969:10004:11026:11473:11657:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12683:12698:12737:12895:12986:13148:13153:13228:13230:14096:14097:14394:14659:21063:21080:21220:21347:21365:21433:21444:21451:21627:21749:21788:21796:21811:21939:21990:30029:30030:30036:30054:30056:30069:30070,0,RBL:209.85.219.201:@flex--davidgow.bounces .google. X-HE-Tag: scene91_530b6b826fe0 X-Filterd-Recvd-Size: 9312 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Aug 2020 05:39:35 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id k11so15544731ybp.1 for ; Mon, 10 Aug 2020 22:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=eI3dpvpZLLpmJ9nqCDi7T91G61DRoZz1t5zO7N7HKA8=; b=BrmmSX27ZRi82o7xEzX2l5M/sJN6sMvF5eCXUYLzJ0vt6z/eZSp8FiktjvhFRHGg3a xN1efG2MozbLRkMpoPfW0LtCCXCTgYehg18sKbiZIypQlBi06akHrSp8zuEwCAzDL0hM wTfHxdWS/psRpaNOKLJiviTtXwBv9EIcQbChOz6Dai+cfTM9+AAdFQaikiAxIRuGBx2r I+HqIeg9nX0eU0rDDlrmPZXIFdKnrg66YeGtl1MlnDaCwIArVV6+dTQyPEnDGOVUdlWC r5Ogv5mGen0CEDU6/h46gy5hAAC3H+WLg/KVNNd3i3+J/7rc/K0Z4q5z590roifWPDOy Vp8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=eI3dpvpZLLpmJ9nqCDi7T91G61DRoZz1t5zO7N7HKA8=; b=AtNZKzT8C3DIxyQ4h5gdaTduTl1YYy3oNGbd8db4x0mBY2uTWntIaxy50LnnbJqbOP IDHYV0yPti1F1qDkLMfB4eDYUVDmvsrJy90pelSJK3UqHPq7WBe8RbyEAA51erBf+RWd BaOD5n8GjCwSK+xJpKXyL1q60o3QmkhHVwz4m+FyM7qngZSYeKV0mcp6CydbXmNwFcYg dCzBPJl5J/qZ80ydvSSW+NmD5UnUxn9qr4vCJ4sREZAtNJo5218SVDCWHOh9IXXvS7eZ 3uEjUZxIJ4zsaHaLA9PybJWYdmUt82Aes6NC91uttNet2XYQAykq7gTK03Z2oY2FvHSV JHgg== X-Gm-Message-State: AOAM533RwaDYxIxO1EU+RzMtcImuRu1Gggd5N0f7ZaNnCTM9uERz0fvo 7bh2bL/+aO/eWHYMyWOMtbsce9zULxzNlg== X-Google-Smtp-Source: ABdhPJxZFZ0NcbWXJxUbFG2ezYdT7p63Z4lATrGjue8Q0YNqAuGMcw2vz1LPFixU8ZifT2aWSpQa4CR39vDMXw== X-Received: by 2002:a25:de48:: with SMTP id v69mr15076735ybg.191.1597124374426; Mon, 10 Aug 2020 22:39:34 -0700 (PDT) Date: Mon, 10 Aug 2020 22:39:09 -0700 Message-Id: <20200811053914.652710-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [PATCH v12 0/6] KASAN-KUnit Integration 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: David Gow , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org X-Rspamd-Queue-Id: BE8E518086CD8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: This patchset contains everything needed to integrate KASAN and KUnit. KUnit will be able to: (1) Fail tests when an unexpected KASAN error occurs (2) Pass tests when an expected KASAN error occurs Convert KASAN tests to KUnit with the exception of copy_user_test because KUnit is unable to test those. Add documentation on how to run the KASAN tests with KUnit and what to expect when running these tests. This patchset depends on: - "kunit: extend kunit resources API" [1] - This is included in the KUnit 5.9-rci pull request[8] Sorry for spamming you all with all these revisions. I'd _really_ like to get this into 5.9 if possible: we also have some other changes which depend on some things here. Changes from v11: - Rebased on top of latest -next (20200810) - Fixed a redundant memchr() call in kasan_memchr() - Added Andrey's "Tested-by" to everything. Changes from v10: - Fixed some whitespace issues in patch 2. - Split out the renaming of the KUnit test suite into a separate patch. Changes from v9: - Rebased on top of linux-next (20200731) + kselftest/kunit and [7] - Note that the kasan_rcu_uaf test has not been ported to KUnit, and remains in test_kasan_module. This is because: (a) KUnit's expect failure will not check if the RCU stacktraces show. (b) KUnit is unable to link the failure to the test, as it occurs in an RCU callback. Changes from v8: - Rebased on top of kselftest/kunit - (Which, with this patchset, should rebase cleanly on 5.8-rc7) - Renamed the KUnit test suite, config name to patch the proposed naming guidelines for KUnit tests[6] Changes from v7: - Rebased on top of kselftest/kunit - Rebased on top of v4 of the kunit resources API[1] - Rebased on top of v4 of the FORTIFY_SOURCE fix[2,3,4] - Updated the Kconfig entry to support KUNIT_ALL_TESTS Changes from v6: - Rebased on top of kselftest/kunit - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE incompatibilites [2] - Removed a redundant report_enabled() check. - Fixed some places with out of date Kconfig names in the documentation. Changes from v5: - Split out the panic_on_warn changes to a separate patch. - Fix documentation to fewer to the new Kconfig names. - Fix some changes which were in the wrong patch. - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1) Changes from v4: - KASAN no longer will panic on errors if both panic_on_warn and kasan_multishot are enabled. - As a result, the KASAN tests will no-longer disable panic_on_warn. - This also means panic_on_warn no-longer needs to be exported. - The use of temporary "kasan_data" variables has been cleaned up somewhat. - A potential refcount/resource leak should multiple KASAN errors appear during an assertion was fixed. - Some wording changes to the KASAN test Kconfig entries. Changes from v3: - KUNIT_SET_KASAN_DATA and KUNIT_DO_EXPECT_KASAN_FAIL have been combined and included in KUNIT_DO_EXPECT_KASAN_FAIL() instead. - Reordered logic in kasan_update_kunit_status() in report.c to be easier to read. - Added comment to not use the name "kasan_data" for any kunit tests outside of KUNIT_EXPECT_KASAN_FAIL(). Changes since v2: - Due to Alan's changes in [1], KUnit can be built as a module. - The name of the tests that could not be run with KUnit has been changed to be more generic: test_kasan_module. - Documentation on how to run the new KASAN tests and what to expect when running them has been added. - Some variables and functions are now static. - Now save/restore panic_on_warn in a similar way to kasan_multi_shot and renamed the init/exit functions to be more generic to accommodate. - Due to [4] in kasan_strings, kasan_memchr, and kasan_memcmp will fail if CONFIG_AMD_MEM_ENCRYPT is enabled so return early and print message explaining this circumstance. - Changed preprocessor checks to C checks where applicable. Changes since v1: - Make use of Alan Maguire's suggestion to use his patch that allows static resources for integration instead of adding a new attribute to the kunit struct - All KUNIT_EXPECT_KASAN_FAIL statements are local to each test - The definition of KUNIT_EXPECT_KASAN_FAIL is local to the test_kasan.c file since it seems this is the only place this will be used. - Integration relies on KUnit being builtin - copy_user_test has been separated into its own file since KUnit is unable to test these. This can be run as a module just as before, using CONFIG_TEST_KASAN_USER - The addition to the current task has been separated into its own patch as this is a significant enough change to be on its own. [1] https://lore.kernel.org/linux-kselftest/CAFd5g46Uu_5TG89uOm0Dj5CMq+11cwjBnsd-k_CVy6bQUeU4Jw@mail.gmail.com/T/#t [2] https://lore.kernel.org/linux-mm/20200424145521.8203-1-dja@axtens.net/ [3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=adb72ae1915db28f934e9e02c18bfcea2f3ed3b7 [4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=47227d27e2fcb01a9e8f5958d8997cf47a820afc [5] https://bugzilla.kernel.org/show_bug.cgi?id=206337 [6] https://lore.kernel.org/linux-kselftest/20200620054944.167330-1-davidgow@google.com/ [7] https://lkml.org/lkml/2020/7/31/571 [8] https://lore.kernel.org/linux-kselftest/8d43e88e-1356-cd63-9152-209b81b16746@linuxfoundation.org/T/#u David Gow (2): kasan: test: Make KASAN KUnit test comply with naming guidelines mm: kasan: Do not panic if both panic_on_warn and kasan_multishot set Patricia Alfonso (4): Add KUnit Struct to Current Task KUnit: KASAN Integration KASAN: Port KASAN Tests to KUnit KASAN: Testing Documentation Documentation/dev-tools/kasan.rst | 70 +++ include/kunit/test.h | 5 + include/linux/kasan.h | 6 + include/linux/sched.h | 4 + lib/Kconfig.kasan | 22 +- lib/Makefile | 7 +- lib/kasan_kunit.c | 769 +++++++++++++++++++++++++ lib/kunit/test.c | 13 +- lib/test_kasan.c | 903 ------------------------------ lib/test_kasan_module.c | 111 ++++ mm/kasan/report.c | 34 +- 11 files changed, 1027 insertions(+), 917 deletions(-) create mode 100644 lib/kasan_kunit.c delete mode 100644 lib/test_kasan.c create mode 100644 lib/test_kasan_module.c