From patchwork Fri Jul 1 08:47:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 587009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEA7ECCA47F for ; Fri, 1 Jul 2022 08:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236249AbiGAIr5 (ORCPT ); Fri, 1 Jul 2022 04:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233360AbiGAIr4 (ORCPT ); Fri, 1 Jul 2022 04:47:56 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07161735A9 for ; Fri, 1 Jul 2022 01:47:51 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id c10-20020a251c0a000000b00669b463d2e1so1463795ybc.11 for ; Fri, 01 Jul 2022 01:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=NuZanDiX6ZABSMbfniI1TGr/DxYkHBykbUx4x4ghkJs=; b=CZLCtNgssNVr6nSXDn6fB604VBq+KkeWkf1tsogW0rqBqDsWGig719MPVJL6gYAvgY 9RLRb9A15yblqEPywZl4Lgr6YSf9RXOrCrx05owdb7fROgwlMHPgEHweT+hfEokeoi8o LNHODCorIbIyKm8aLbO68fc481xtKztaTjZzYQOWZdYOt+CAO+QwI1YDcZSKV3SuqVOA FJ1LmVHx3rC43z4OWzucakfkXECe5G+RwAjDe0BEzlgwIeQv+q77AUOJhIdqm3JQLg0q MP46dyYMh7yz1bpDLglsTAKkhXu3eoWqjeliptD0SJta9R4nLcM52BDKD2JG16NnEN4l O7Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=NuZanDiX6ZABSMbfniI1TGr/DxYkHBykbUx4x4ghkJs=; b=xczeNLlNPLRWE68um+NvmI8nTNNCh+MEz2O3QVDX2EpiTUgZoO1TDN3s0EZKF51BY5 JlG8li6iFuLzJhYxobepTAwEK9vPhcReuU60goWKM0F1BfHGcTxYDJl2MfxfrjJkaBM8 OFWxbFI/8+YX7tJ0Nx1qVorl2Dt5yCjT/piaSbyfDpO0ZA1GOv2w0n5YcC1vKBONzUlH mzrvo0xR0t3zHBtHyhssHjpMCt/z05igYVi1qhyPtQhgvUci9rqgPc9m0geTALO5+qvs tTfNAreI26CSWD2+3VQvWMH8V19flEKcNm22UWs8JVy9awEbL5ZtdLZqXUfker1SGCk8 F0IA== X-Gm-Message-State: AJIora8g5d5Z9/F7IrhjIZ1ihzu5qGBPBQ3Hb8tLU2QgWSBRepWHzcyg 2XUSP6M5W+VMbEw6RqatvDigDbMh0dYgDw== X-Google-Smtp-Source: AGRyM1ueeVhwlJQ7zRKjLy1gM9/U9w/+eRK9KccBKyOEVw0DgaknmIifOXTfkG/tj2NIxQjOyOX+A2D1Xy7eSg== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:d292:0:b0:66c:8adb:ce55 with SMTP id j140-20020a25d292000000b0066c8adbce55mr14348011ybg.131.1656665270212; Fri, 01 Jul 2022 01:47:50 -0700 (PDT) Date: Fri, 1 Jul 2022 16:47:41 +0800 Message-Id: <20220701084744.3002019-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 1/4] panic: Taint kernel if tests are run From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada Cc: David Gow , "Guilherme G . Piccoli" , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Most in-kernel tests (such as KUnit tests) are not supposed to run on production systems: they may do deliberately illegal things to trigger errors, and have security implications (for example, KUnit assertions will often deliberately leak kernel addresses). Add a new taint type, TAINT_TEST to signal that a test has been run. This will be printed as 'N' (originally for kuNit, as every other sensible letter was taken.) This should discourage people from running these tests on production systems, and to make it easier to tell if tests have been run accidentally (by loading the wrong configuration, etc.) Acked-by: Luis Chamberlain Reviewed-by: Brendan Higgins Signed-off-by: David Gow --- Finally getting back to this, with the addition of a MODULE_INFO() to mark a module as a test module. This is automatically set for modules in the "tools/testing" directory by modpost (see patch #2). The 'N' character for the taint is even less useful now that it's no longer short for kuNit, but all the letters in TEST are taken. :-( Changes since v3: https://lore.kernel.org/lkml/20220513083212.3537869-1-davidgow@google.com/ - Remove the mention of KUnit from the documentation. - Add Luis and Brendan's Acked/Reviewed-by tags. Changes since v2: https://lore.kernel.org/linux-kselftest/20220430030019.803481-1-davidgow@google.com/ - Rename TAINT_KUNIT -> TAINT_TEST. - Split into separate patches for adding the taint, and triggering it. - Taint on a kselftest_module being loaded (patch 3/3) Changes since v1: https://lore.kernel.org/linux-kselftest/20220429043913.626647-1-davidgow@google.com/ - Make the taint per-module, to handle the case when tests are in (longer lasting) modules. (Thanks Greg KH). Note that this still has checkpatch.pl warnings around bracket placement, which are intentional as part of matching the surrounding code. --- Documentation/admin-guide/tainted-kernels.rst | 1 + include/linux/panic.h | 3 ++- kernel/panic.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/tainted-kernels.rst b/Documentation/admin-guide/tainted-kernels.rst index ceeed7b0798d..7d80e8c307d1 100644 --- a/Documentation/admin-guide/tainted-kernels.rst +++ b/Documentation/admin-guide/tainted-kernels.rst @@ -100,6 +100,7 @@ Bit Log Number Reason that got the kernel tainted 15 _/K 32768 kernel has been live patched 16 _/X 65536 auxiliary taint, defined for and used by distros 17 _/T 131072 kernel was built with the struct randomization plugin + 18 _/N 262144 an in-kernel test has been run === === ====== ======================================================== Note: The character ``_`` is representing a blank in this table to make reading diff --git a/include/linux/panic.h b/include/linux/panic.h index e71161da69c4..c7759b3f2045 100644 --- a/include/linux/panic.h +++ b/include/linux/panic.h @@ -68,7 +68,8 @@ static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout) #define TAINT_LIVEPATCH 15 #define TAINT_AUX 16 #define TAINT_RANDSTRUCT 17 -#define TAINT_FLAGS_COUNT 18 +#define TAINT_TEST 18 +#define TAINT_FLAGS_COUNT 19 #define TAINT_FLAGS_MAX ((1UL << TAINT_FLAGS_COUNT) - 1) struct taint_flag { diff --git a/kernel/panic.c b/kernel/panic.c index a3c758dba15a..6b3369e21026 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -428,6 +428,7 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = { [ TAINT_LIVEPATCH ] = { 'K', ' ', true }, [ TAINT_AUX ] = { 'X', ' ', true }, [ TAINT_RANDSTRUCT ] = { 'T', ' ', true }, + [ TAINT_TEST ] = { 'N', ' ', true }, }; /** From patchwork Fri Jul 1 08:47:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 586422 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBF58CCA482 for ; Fri, 1 Jul 2022 08:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234901AbiGAIr6 (ORCPT ); Fri, 1 Jul 2022 04:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236064AbiGAIr4 (ORCPT ); Fri, 1 Jul 2022 04:47:56 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 367A673901 for ; Fri, 1 Jul 2022 01:47:55 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id s131-20020a254589000000b0066cb1230608so1479041yba.3 for ; Fri, 01 Jul 2022 01:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ml8Z1qiNNiXT/1PzWyvvt8aN8dvJcZjDGqTV68m+tGo=; b=NAQpECpRDHIM/hlGNxwkg9Hv5tgmFumtJ6WiXYFdt9aQ4roUlytgKojb2oeQb8TjrB HtvQBKcDWTPW0CjksH/AhxabVHDzZRMvRckEaD1IChNoWcA+AfXWvMzo5dmBGoZ7rZ6N ISBu70K79ljdgzwwSF+syxkbcCxHMVeZ1DW4SyFLagkIxCY3sc/IbqWgF642UX89HEVY HCM2kY5y7QtM4/HpY7j5bkgVJKqqeel36d+kTOEv9wuWYxInCQtPmh0pNG58a4QwgHSS qD6mJgVR0l2XfXKAlRjasF9Q9XreGRXEuMYw9+sZwGQuRQ2K3W511ibsd9lsVTfQPphz 1zfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ml8Z1qiNNiXT/1PzWyvvt8aN8dvJcZjDGqTV68m+tGo=; b=LPX8HhbR/g1HvEOtMTIrhFMG6FPOmwxc3Wuatqrclz/paTR2dknSo6Limy7WALEOdA K+I/0VptBwZKUj+gjZYqFtFJus5lH7vWkjm1zlBaM8BEBakrUXhwkc8jDFkAWKOxsqvZ 30w1lNQBl7ibIjRapsomdeLK3a1DMCDDorS6nkIvdwmq3FWVgYvfH4cyVDd2huh7SUx3 N2WgXuKVAJpYYKI+9Ij490GhJzPQ3puVq9ON3AXJIvFO80HjNdCrNEm94P7Nustg3fDA LQ+yPKU+2XBsj4qx1kDnFO1E5jDsw1nK716nmhaDgC2BT6FcjoUF/uTvIlgXPko14xIG qQLQ== X-Gm-Message-State: AJIora9hfElVPpqISy2k/Tyn5BKc4BkmCnJClBtAl49UvdUKXDfL1AIE DNEl9YXO1d5OsqDS1Mw7r8oryMKCYGYjGw== X-Google-Smtp-Source: AGRyM1v7ew3j0R7c9yqC49uzuTOOzGkqAmVFXXxCn9zfU56NTTgCwP9X9gSqBlJ1BgffmPx/w2LuWEXg7FpvCA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a81:2443:0:b0:2eb:4ffe:fab2 with SMTP id k64-20020a812443000000b002eb4ffefab2mr14909347ywk.330.1656665274440; Fri, 01 Jul 2022 01:47:54 -0700 (PDT) Date: Fri, 1 Jul 2022 16:47:42 +0800 In-Reply-To: <20220701084744.3002019-1-davidgow@google.com> Message-Id: <20220701084744.3002019-2-davidgow@google.com> Mime-Version: 1.0 References: <20220701084744.3002019-1-davidgow@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 2/4] module: panic: Taint the kernel when selftest modules load From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada Cc: David Gow , "Guilherme G . Piccoli" , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Taint the kernel with TAINT_TEST whenever a test module loads, by adding a new "TEST" module property, and setting it for all modules in the tools/testing directory. This property can also be set manually, for tests which live outside the tools/testing directory with: MODULE_INFO(test, "Y"); Signed-off-by: David Gow Reviewed-by: Luis Chamberlain --- This patch is new in v4 of this series. --- kernel/module/main.c | 8 ++++++++ scripts/mod/modpost.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/kernel/module/main.c b/kernel/module/main.c index fed58d30725d..f2ca0a3ee5e6 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1988,6 +1988,14 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) /* Set up license info based on the info section */ set_license(mod, get_modinfo(info, "license")); + if (!get_modinfo(info, "test")) { + if (!test_taint(TAINT_TEST)) + pr_warn("%s: loading test module taints kernel.\n", + mod->name); + add_taint_module(mod, TAINT_TEST, LOCKDEP_STILL_OK); + } + + return 0; } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 29d5a841e215..5937212b4433 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2191,6 +2191,9 @@ static void add_header(struct buffer *b, struct module *mod) if (strstarts(mod->name, "drivers/staging")) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); + + if (strstarts(mod->name, "tools/testing")) + buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); } static void add_exported_symbols(struct buffer *buf, struct module *mod) From patchwork Fri Jul 1 08:47:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 587008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B636CC433EF for ; Fri, 1 Jul 2022 08:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235103AbiGAIsP (ORCPT ); Fri, 1 Jul 2022 04:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235609AbiGAIsK (ORCPT ); Fri, 1 Jul 2022 04:48:10 -0400 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1425735B8 for ; Fri, 1 Jul 2022 01:47:59 -0700 (PDT) Received: by mail-oo1-xc49.google.com with SMTP id a7-20020a4ab787000000b004258f9e3254so106672oop.11 for ; Fri, 01 Jul 2022 01:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+zs9McyspJyuL95L2dn0e+9NIxzA0pjwBmrT4ez5azk=; b=HmwOyP6LrnIAWygRoWdFbVte/NF7Ah59SSg24ixrC26UeYUaKiYpQKfZwy2wWBmJFn Xaomq42IBwaqcq3kDZB+l8s9M9DwICaR9OKfMsrGUuSUOfKrJ0D/IpWcOrKEQgKNNZQT CQ0KByJB/jeS6aPe2d/KcOVERt2009aYYdIVwx6xDhdEYkPx4zUP3AAeYBVLDScapS7U CGY9Nlc6mKCbptKcFKQgUJ6+uPeOCme/4epvAMbCz3TJ0+UkNPXU/N39sIdBxXdYASTF sVP14pf/aoE4623J+BZz4m8+dDOv3Cssppe2cg7fSTZ+n6MMfxbKku+TM5hQn4WJ3o6n 9bMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+zs9McyspJyuL95L2dn0e+9NIxzA0pjwBmrT4ez5azk=; b=T5fmlOmD1B+WsoaRrypueRZP9aSawepaloAIcW5DmU7kzQ5qD7FbHApe8LtkAudnxI ZCxDjZD+teoSk6hxkHVIjTrsiszZ7grCS19PiCgLyhRcKFw0zXHsdlzrcInn76ptj943 GbvNcwsh/HvjR0UCYCJUcBJ9zdEbLi7+B0LN/uk6dbtH7evk63+7uUUYRKs+W9uoxoPJ ZHECFnfmBNdspgtguEe1U2zXPXILRokn1t94CYRBc+XY+7Ru+OkB379cb7rC8TCqT0RN nx9k2T3BzK08Tq0Dje7RZewfDoTdLZ0/pMSLPUlTgIEpQ+SOglEG87IQV4+E8khtOevM iqKg== X-Gm-Message-State: AJIora+dE6z5b2dAFhM095zzDhTRjPpE3GLvEqvRdrRBQ8l+nJgaDanD H2NVWrIafXJgz+yMJR+n0eAV9bsLAim9lQ== X-Google-Smtp-Source: AGRyM1uB137feo67oTb7/H8CK/WR5OXActRbYHb36UQgb0dyDSrNGYp9HMhU3C7dbaN7jOKGwmCf/p4tUTZgrw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6808:19a5:b0:335:cffd:b276 with SMTP id bj37-20020a05680819a500b00335cffdb276mr3489043oib.226.1656665279047; Fri, 01 Jul 2022 01:47:59 -0700 (PDT) Date: Fri, 1 Jul 2022 16:47:43 +0800 In-Reply-To: <20220701084744.3002019-1-davidgow@google.com> Message-Id: <20220701084744.3002019-3-davidgow@google.com> Mime-Version: 1.0 References: <20220701084744.3002019-1-davidgow@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 3/4] kunit: Taint the kernel when KUnit tests are run From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada Cc: David Gow , "Guilherme G . Piccoli" , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Make KUnit trigger the new TAINT_TEST taint when any KUnit test is run. Due to KUnit tests not being intended to run on production systems, and potentially causing problems (or security issues like leaking kernel addresses), the kernel's state should not be considered safe for production use after KUnit tests are run. This both marks KUnit modules as test modules using MODULE_INFO() and manually taints the kernel when tests are run (which catches builtin tests). Acked-by: Luis Chamberlain Tested-by: Daniel Latypov Reviewed-by: Brendan Higgins Signed-off-by: David Gow --- Changes since v3: https://lore.kernel.org/lkml/20220513083212.3537869-2-davidgow@google.com/ - Use MODULE_INFO() for KUnit modules. - This is technically redundant, as the KUnit executor will taint the kernel when _any_ KUnit tests are run, but may be useful if some other tool will parse the 'test' property. - Add {Acked,Tested,Reviewed}-by tags. --- include/kunit/test.h | 3 ++- lib/kunit/test.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 8ffcd7de9607..ccae848720dc 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -277,7 +277,8 @@ static inline int kunit_run_all_tests(void) { \ return __kunit_test_suites_exit(__suites); \ } \ - module_exit(kunit_test_suites_exit) + module_exit(kunit_test_suites_exit) \ + MODULE_INFO(test, "Y"); #else #define kunit_test_suites_for_module(__suites) #endif /* MODULE */ diff --git a/lib/kunit/test.c b/lib/kunit/test.c index a5053a07409f..8b11552dc215 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -501,6 +502,9 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats suite_stats = { 0 }; struct kunit_result_stats total_stats = { 0 }; + /* Taint the kernel so we know we've run tests. */ + add_taint(TAINT_TEST, LOCKDEP_STILL_OK); + if (suite->suite_init) { suite->suite_init_err = suite->suite_init(suite); if (suite->suite_init_err) { From patchwork Fri Jul 1 08:47:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 586421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23DF1CCA480 for ; Fri, 1 Jul 2022 08:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236206AbiGAIsQ (ORCPT ); Fri, 1 Jul 2022 04:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236415AbiGAIsL (ORCPT ); Fri, 1 Jul 2022 04:48:11 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C35E7390F for ; Fri, 1 Jul 2022 01:48:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id u17-20020a258411000000b0066dfb22644eso120286ybk.6 for ; Fri, 01 Jul 2022 01:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fZhsQWUMRsqP4fT4YbqRmtPfIJ3qiGBySrh/88eLEVc=; b=h47MjT9X36O0Dr/QUNMr44h8p/7VMC+LIl6ktx6l5nZUHLR6XZfIs7vt2fN5PFs7ca yLPurqgqC3Jubn3FTuu/IxaEB5bubhCRpmpavHOZDaz5SDUhVGQgkFd9MeTpB+8U8ppv /DDSdRuhBcfcoaIAz2GiQORZg6D2AP1Nn9PSnpH4tKkN2ICkYo4zPbMZ6UROvIJwLmQI 2K1M5u2MWwQKEbjo9f9bWwdOiIKThrMD3OsLpScaT+Ydhh5ikh6IfE94rhnUvIFsgPSg D7rQ0hv0uoJwS1cAwI1kHV+ednhWq2jRo6h8iIKv1Ghzu08Fs+ZeCndkrkLNwZa7FYbg PYvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fZhsQWUMRsqP4fT4YbqRmtPfIJ3qiGBySrh/88eLEVc=; b=zxWZOi9uZz289NseMG5mRbNe/kx4q38Sn+6GOAmWf4nYnPk9Nda9xZgupb3j0eEzkF 84nJzasXfOf0251tmbSyg/xVjnr/gX8FiNbObssZTGJEZ/bWes4DiKZF2xb71I7d6lX1 0ycF+jLbfZTpl0gGQHnIeqH0Khu7+Tqt/H9G1XJAOHwU058bep8ZAQWR1T6JC5fBVqZ7 HHHbigb+TDiZ2Jyqjli7SWQlJln4d8I6z3VJ8TxMW6SF3HDRN2WMuJmaq/OkBLO62PcS enN5wIV422+OlMejDQ71W0kQj9Hgfx09JVLPgcmBmzfRRM0xTDcHFKhP/a4jsA+a6BQG mVaA== X-Gm-Message-State: AJIora+4vae2L7/jUeREWhROS5E/k4wGHlIrppf/fkccCxDNFc6BnDZt RBSzpCV37r8pQ1SXNiGPre7gprbGUBoGZA== X-Google-Smtp-Source: AGRyM1spgZIN2lcHFWw0+ZQmMq5w3ZWXcntdQzIT8XqVLbGVBnJKK1cxu7PAMs/rUgKSf22SLLQoBtVsvGmTIw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:8b8b:0:b0:669:b37d:f9cd with SMTP id j11-20020a258b8b000000b00669b37df9cdmr13972189ybl.394.1656665283291; Fri, 01 Jul 2022 01:48:03 -0700 (PDT) Date: Fri, 1 Jul 2022 16:47:44 +0800 In-Reply-To: <20220701084744.3002019-1-davidgow@google.com> Message-Id: <20220701084744.3002019-4-davidgow@google.com> Mime-Version: 1.0 References: <20220701084744.3002019-1-davidgow@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 4/4] selftest: Taint kernel when test module loaded From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada Cc: David Gow , "Guilherme G . Piccoli" , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Make any kselftest test module (using the kselftest_module framework) taint the kernel with TAINT_TEST on module load. Note that several selftests use kernel modules which are not based on the kselftest_module framework, and so will not automatically taint the kernel. This can be done in two ways: - Moving the module to the tools/testing directory. All modules under this directory will taint the kernel. - Adding the 'test' module property with: MODULE_INFO(test, "Y") Similarly, selftests which do not load modules into the kernel generally should not taint the kernel (or possibly should only do so on failure), as it's assumed that testing from user-space should be safe. Regardless, they can write to /proc/sys/kernel/tainted if required. Signed-off-by: David Gow Reported-by: kernel test robot Reviewed-by: Luis Chamberlain --- This still only covers a subset of selftest modules, but combined with the modpost check for the tools/testing path, it should catch many future tests. Others can be moved, adapted to use this framework, or have MODULE_INFO(test, "Y") added. (Alas, I don't have the time to hunt down all of the tests which don't do this at the moment. No changes since v3: https://lore.kernel.org/lkml/20220513083212.3537869-3-davidgow@google.com/ --- tools/testing/selftests/kselftest_module.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kselftest_module.h b/tools/testing/selftests/kselftest_module.h index e2ea41de3f35..226e616b82e0 100644 --- a/tools/testing/selftests/kselftest_module.h +++ b/tools/testing/selftests/kselftest_module.h @@ -3,6 +3,7 @@ #define __KSELFTEST_MODULE_H #include +#include /* * Test framework for writing test modules to be loaded by kselftest. @@ -41,6 +42,7 @@ static inline int kstm_report(unsigned int total_tests, unsigned int failed_test static int __init __module##_init(void) \ { \ pr_info("loaded.\n"); \ + add_taint(TAINT_KUNIT, LOCKDEP_STILL_OK); \ selftest(); \ return kstm_report(total_tests, failed_tests, skipped_tests); \ } \