All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maíra Canal" <mairacanal@riseup.net>
To: David Gow <davidgow@google.com>
Cc: "Guilherme G . Piccoli" <gpiccoli@igalia.com>,
	Kees Cook <keescook@chromium.org>,
	Sebastian Reichel <sre@kernel.org>,
	John Ogness <john.ogness@linutronix.de>,
	Joe Fradley <joefradley@google.com>,
	Daniel Latypov <dlatypov@google.com>,
	kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jonathan Corbet <corbet@lwn.net>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Aaron Tomlin <atomlin@redhat.com>,
	linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
	Michal Marek <michal.lkml@markovi.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	linux-kbuild@vger.kernel.org,
	Brendan Higgins <brendanhiggins@google.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: Re: [PATCH v4 3/4] kunit: Taint the kernel when KUnit tests are run
Date: Fri, 1 Jul 2022 08:55:07 -0300	[thread overview]
Message-ID: <f361c4b7-12b8-0513-2025-4ed8025a67d1@riseup.net> (raw)
In-Reply-To: <20220701084744.3002019-3-davidgow@google.com>

On 7/1/22 05:47, 'David Gow' via KUnit Development wrote:
> 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 <mcgrof@kernel.org>
> Tested-by: Daniel Latypov <dlatypov@google.com>
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
> Signed-off-by: David Gow <davidgow@google.com>
> ---

Tested with DRM KUnit tests on x86_64.

Tested-By: Maíra Canal <mairacanal@riseup.net>

Best Regards
- Maíra Canal

> 
> 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 <kunit/test-bug.h>
>  #include <linux/kernel.h>
>  #include <linux/moduleparam.h>
> +#include <linux/panic.h>
>  #include <linux/sched/debug.h>
>  #include <linux/sched.h>
>  
> @@ -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) {

  reply	other threads:[~2022-07-01 11:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01  8:47 [PATCH v4 1/4] panic: Taint kernel if tests are run David Gow
2022-07-01  8:47 ` [PATCH v4 2/4] module: panic: Taint the kernel when selftest modules load David Gow
2022-07-01  8:55   ` Greg KH
2022-07-01  9:27     ` David Gow
2022-07-01 22:30   ` Luis Chamberlain
2022-07-02  2:48     ` David Gow
2022-07-02  2:48       ` David Gow
2022-07-01  8:47 ` [PATCH v4 3/4] kunit: Taint the kernel when KUnit tests are run David Gow
2022-07-01 11:55   ` Maíra Canal [this message]
2022-07-01  8:47 ` [PATCH v4 4/4] selftest: Taint kernel when test module loaded David Gow
2022-07-01 17:16   ` kernel test robot
2022-07-01 17:37   ` kernel test robot
2022-07-01 22:33   ` Luis Chamberlain
2022-07-02  4:06     ` David Gow
2022-07-02  5:15       ` David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f361c4b7-12b8-0513-2025-4ed8025a67d1@riseup.net \
    --to=mairacanal@riseup.net \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=atomlin@redhat.com \
    --cc=brendanhiggins@google.com \
    --cc=corbet@lwn.net \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=gpiccoli@igalia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joefradley@google.com \
    --cc=john.ogness@linutronix.de \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=ndesaulniers@google.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.