diff mbox series

[v2,14/14] kasan: don't run tests when KASAN is not enabled

Message ID 654bdeedde54e9e8d5d6250469966b0bdf288010.1610554432.git.andreyknvl@google.com (mailing list archive)
State New, archived
Headers show
Series kasan: HW_TAGS tests support and fixes | expand

Commit Message

Andrey Konovalov Jan. 13, 2021, 4:21 p.m. UTC
Don't run KASAN tests when it's disabled with kasan.mode=off to avoid
corrupting kernel memory.

Link: https://linux-review.googlesource.com/id/I6447af436a69a94bfc35477f6bf4e2122948355e
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 lib/test_kasan.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Marco Elver Jan. 13, 2021, 4:39 p.m. UTC | #1
On Wed, 13 Jan 2021 at 17:22, Andrey Konovalov <andreyknvl@google.com> wrote:
>
> Don't run KASAN tests when it's disabled with kasan.mode=off to avoid
> corrupting kernel memory.
>
> Link: https://linux-review.googlesource.com/id/I6447af436a69a94bfc35477f6bf4e2122948355e
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  lib/test_kasan.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index d9f9a93922d5..0c8279d9907e 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -47,6 +47,9 @@ static bool multishot;
>   */
>  static int kasan_test_init(struct kunit *test)
>  {
> +       if (!kasan_enabled())
> +               return -1;

This should WARN_ON() or pr_err(). Otherwise it's impossible to say
why the test couldn't initialize.

>         multishot = kasan_save_enable_multi_shot();
>         hw_set_tagging_report_once(false);
>         return 0;
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>
Andrey Konovalov Jan. 14, 2021, 3:32 p.m. UTC | #2
On Wed, Jan 13, 2021 at 5:39 PM Marco Elver <elver@google.com> wrote:
>
> On Wed, 13 Jan 2021 at 17:22, Andrey Konovalov <andreyknvl@google.com> wrote:
> >
> > Don't run KASAN tests when it's disabled with kasan.mode=off to avoid
> > corrupting kernel memory.
> >
> > Link: https://linux-review.googlesource.com/id/I6447af436a69a94bfc35477f6bf4e2122948355e
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> > ---
> >  lib/test_kasan.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> > index d9f9a93922d5..0c8279d9907e 100644
> > --- a/lib/test_kasan.c
> > +++ b/lib/test_kasan.c
> > @@ -47,6 +47,9 @@ static bool multishot;
> >   */
> >  static int kasan_test_init(struct kunit *test)
> >  {
> > +       if (!kasan_enabled())
> > +               return -1;
>
> This should WARN_ON() or pr_err(). Otherwise it's impossible to say
> why the test couldn't initialize.

Will do in v3, thanks!
diff mbox series

Patch

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index d9f9a93922d5..0c8279d9907e 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -47,6 +47,9 @@  static bool multishot;
  */
 static int kasan_test_init(struct kunit *test)
 {
+	if (!kasan_enabled())
+		return -1;
+
 	multishot = kasan_save_enable_multi_shot();
 	hw_set_tagging_report_once(false);
 	return 0;