2023-10-06 15:19:30

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH 0/5] kasan: assorted fixes and improvements

From: Andrey Konovalov <[email protected]>

Andrey Konovalov (5):
arm64, kasan: update comment in kasan_init
kasan: unify printk prefixes
kasan: use unchecked __memset internally
kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment
Documentation: *san: drop "the" from article titles

Documentation/dev-tools/kasan.rst | 7 +++++--
Documentation/dev-tools/kcsan.rst | 4 ++--
Documentation/dev-tools/kmsan.rst | 6 +++---
arch/arm64/mm/kasan_init.c | 6 +++++-
mm/kasan/kasan_test.c | 11 ++++++-----
mm/kasan/kasan_test_module.c | 2 +-
mm/kasan/quarantine.c | 4 +++-
mm/kasan/report.c | 4 ++--
mm/kasan/report_generic.c | 6 +++---
mm/kasan/shadow.c | 2 +-
10 files changed, 31 insertions(+), 21 deletions(-)

--
2.25.1


2023-10-06 15:19:33

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH 2/5] kasan: unify printk prefixes

From: Andrey Konovalov <[email protected]>

Unify prefixes for printk messages in mm/kasan/.

Signed-off-by: Andrey Konovalov <[email protected]>
---
mm/kasan/kasan_test.c | 2 +-
mm/kasan/kasan_test_module.c | 2 +-
mm/kasan/quarantine.c | 4 +++-
mm/kasan/report_generic.c | 6 +++---
4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c
index b61cc6a42541..c707d6c6e019 100644
--- a/mm/kasan/kasan_test.c
+++ b/mm/kasan/kasan_test.c
@@ -5,7 +5,7 @@
* Author: Andrey Ryabinin <[email protected]>
*/

-#define pr_fmt(fmt) "kasan_test: " fmt
+#define pr_fmt(fmt) "kasan: test: " fmt

#include <kunit/test.h>
#include <linux/bitops.h>
diff --git a/mm/kasan/kasan_test_module.c b/mm/kasan/kasan_test_module.c
index 7be7bed456ef..8b7b3ea2c74e 100644
--- a/mm/kasan/kasan_test_module.c
+++ b/mm/kasan/kasan_test_module.c
@@ -5,7 +5,7 @@
* Author: Andrey Ryabinin <[email protected]>
*/

-#define pr_fmt(fmt) "kasan test: %s " fmt, __func__
+#define pr_fmt(fmt) "kasan: test: " fmt

#include <linux/mman.h>
#include <linux/module.h>
diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index 152dca73f398..ca4529156735 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -8,6 +8,8 @@
* Based on code by Dmitry Chernenkov.
*/

+#define pr_fmt(fmt) "kasan: " fmt
+
#include <linux/gfp.h>
#include <linux/hash.h>
#include <linux/kernel.h>
@@ -414,7 +416,7 @@ static int __init kasan_cpu_quarantine_init(void)
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/kasan:online",
kasan_cpu_online, kasan_cpu_offline);
if (ret < 0)
- pr_err("kasan cpu quarantine register failed [%d]\n", ret);
+ pr_err("cpu quarantine register failed [%d]\n", ret);
return ret;
}
late_initcall(kasan_cpu_quarantine_init);
diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c
index 51a1e8a8877f..99cbcd73cff7 100644
--- a/mm/kasan/report_generic.c
+++ b/mm/kasan/report_generic.c
@@ -220,7 +220,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
const size_t tok_len = sep - *frame_descr;

if (tok_len + 1 > max_tok_len) {
- pr_err("KASAN internal error: frame description too long: %s\n",
+ pr_err("internal error: frame description too long: %s\n",
*frame_descr);
return false;
}
@@ -233,7 +233,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
*frame_descr = sep + 1;

if (value != NULL && kstrtoul(token, 10, value)) {
- pr_err("KASAN internal error: not a valid number: %s\n", token);
+ pr_err("internal error: not a valid number: %s\n", token);
return false;
}

@@ -323,7 +323,7 @@ static bool __must_check get_address_stack_frame_info(const void *addr,

frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE);
if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) {
- pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n",
+ pr_err("internal error: frame has invalid marker: %lu\n",
frame[0]);
return false;
}
--
2.25.1

2023-10-06 15:19:40

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH 4/5] kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment

From: Andrey Konovalov <[email protected]>

Update the comment for KUNIT_EXPECT_KASAN_FAIL to describe the parameters
this macro accepts.

Also drop the mention of the "kasan_status" KUnit resource, as it no
longer exists.

Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Andrey Konovalov <[email protected]>
---
mm/kasan/kasan_test.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c
index c707d6c6e019..2030c7ff7de9 100644
--- a/mm/kasan/kasan_test.c
+++ b/mm/kasan/kasan_test.c
@@ -91,10 +91,11 @@ static void kasan_test_exit(struct kunit *test)
}

/**
- * KUNIT_EXPECT_KASAN_FAIL() - check that the executed expression produces a
- * KASAN report; causes a test failure otherwise. This relies on a KUnit
- * resource named "kasan_status". Do not use this name for KUnit resources
- * outside of KASAN tests.
+ * KUNIT_EXPECT_KASAN_FAIL - check that the executed expression produces a
+ * KASAN report; causes a KUnit test failure otherwise.
+ *
+ * @test: Currently executing KUnit test.
+ * @expression: Expression that must produce a KASAN report.
*
* For hardware tag-based KASAN, when a synchronous tag fault happens, tag
* checking is auto-disabled. When this happens, this test handler reenables
--
2.25.1

2023-10-09 08:48:16

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH 4/5] kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment

On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
>
> From: Andrey Konovalov <[email protected]>
>
> Update the comment for KUNIT_EXPECT_KASAN_FAIL to describe the parameters
> this macro accepts.
>
> Also drop the mention of the "kasan_status" KUnit resource, as it no
> longer exists.
>
> Reported-by: kernel test robot <[email protected]>
> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

"Closes" isn't a valid tag? Reported-by + Link should be enough to attribute.

> Signed-off-by: Andrey Konovalov <[email protected]>

Reviewed-by: Marco Elver <[email protected]>

> ---
> mm/kasan/kasan_test.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c
> index c707d6c6e019..2030c7ff7de9 100644
> --- a/mm/kasan/kasan_test.c
> +++ b/mm/kasan/kasan_test.c
> @@ -91,10 +91,11 @@ static void kasan_test_exit(struct kunit *test)
> }
>
> /**
> - * KUNIT_EXPECT_KASAN_FAIL() - check that the executed expression produces a
> - * KASAN report; causes a test failure otherwise. This relies on a KUnit
> - * resource named "kasan_status". Do not use this name for KUnit resources
> - * outside of KASAN tests.
> + * KUNIT_EXPECT_KASAN_FAIL - check that the executed expression produces a
> + * KASAN report; causes a KUnit test failure otherwise.
> + *
> + * @test: Currently executing KUnit test.
> + * @expression: Expression that must produce a KASAN report.
> *
> * For hardware tag-based KASAN, when a synchronous tag fault happens, tag
> * checking is auto-disabled. When this happens, this test handler reenables
> --
> 2.25.1
>

2023-10-09 10:20:06

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH 2/5] kasan: unify printk prefixes

On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
>
> From: Andrey Konovalov <[email protected]>
>
> Unify prefixes for printk messages in mm/kasan/.
>
> Signed-off-by: Andrey Konovalov <[email protected]>

Reviewed-by: Marco Elver <[email protected]>

> ---
> mm/kasan/kasan_test.c | 2 +-
> mm/kasan/kasan_test_module.c | 2 +-
> mm/kasan/quarantine.c | 4 +++-
> mm/kasan/report_generic.c | 6 +++---
> 4 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c
> index b61cc6a42541..c707d6c6e019 100644
> --- a/mm/kasan/kasan_test.c
> +++ b/mm/kasan/kasan_test.c
> @@ -5,7 +5,7 @@
> * Author: Andrey Ryabinin <[email protected]>
> */
>
> -#define pr_fmt(fmt) "kasan_test: " fmt
> +#define pr_fmt(fmt) "kasan: test: " fmt
>
> #include <kunit/test.h>
> #include <linux/bitops.h>
> diff --git a/mm/kasan/kasan_test_module.c b/mm/kasan/kasan_test_module.c
> index 7be7bed456ef..8b7b3ea2c74e 100644
> --- a/mm/kasan/kasan_test_module.c
> +++ b/mm/kasan/kasan_test_module.c
> @@ -5,7 +5,7 @@
> * Author: Andrey Ryabinin <[email protected]>
> */
>
> -#define pr_fmt(fmt) "kasan test: %s " fmt, __func__
> +#define pr_fmt(fmt) "kasan: test: " fmt
>
> #include <linux/mman.h>
> #include <linux/module.h>
> diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
> index 152dca73f398..ca4529156735 100644
> --- a/mm/kasan/quarantine.c
> +++ b/mm/kasan/quarantine.c
> @@ -8,6 +8,8 @@
> * Based on code by Dmitry Chernenkov.
> */
>
> +#define pr_fmt(fmt) "kasan: " fmt
> +
> #include <linux/gfp.h>
> #include <linux/hash.h>
> #include <linux/kernel.h>
> @@ -414,7 +416,7 @@ static int __init kasan_cpu_quarantine_init(void)
> ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/kasan:online",
> kasan_cpu_online, kasan_cpu_offline);
> if (ret < 0)
> - pr_err("kasan cpu quarantine register failed [%d]\n", ret);
> + pr_err("cpu quarantine register failed [%d]\n", ret);
> return ret;
> }
> late_initcall(kasan_cpu_quarantine_init);
> diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c
> index 51a1e8a8877f..99cbcd73cff7 100644
> --- a/mm/kasan/report_generic.c
> +++ b/mm/kasan/report_generic.c
> @@ -220,7 +220,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
> const size_t tok_len = sep - *frame_descr;
>
> if (tok_len + 1 > max_tok_len) {
> - pr_err("KASAN internal error: frame description too long: %s\n",
> + pr_err("internal error: frame description too long: %s\n",
> *frame_descr);
> return false;
> }
> @@ -233,7 +233,7 @@ static bool __must_check tokenize_frame_descr(const char **frame_descr,
> *frame_descr = sep + 1;
>
> if (value != NULL && kstrtoul(token, 10, value)) {
> - pr_err("KASAN internal error: not a valid number: %s\n", token);
> + pr_err("internal error: not a valid number: %s\n", token);
> return false;
> }
>
> @@ -323,7 +323,7 @@ static bool __must_check get_address_stack_frame_info(const void *addr,
>
> frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE);
> if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) {
> - pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n",
> + pr_err("internal error: frame has invalid marker: %lu\n",
> frame[0]);
> return false;
> }
> --
> 2.25.1
>

2023-10-09 19:42:34

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH 4/5] kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment

On Mon, Oct 9, 2023 at 10:48 AM Marco Elver <[email protected]> wrote:
>
> On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
> >
> > From: Andrey Konovalov <[email protected]>
> >
> > Update the comment for KUNIT_EXPECT_KASAN_FAIL to describe the parameters
> > this macro accepts.
> >
> > Also drop the mention of the "kasan_status" KUnit resource, as it no
> > longer exists.
> >
> > Reported-by: kernel test robot <[email protected]>
> > Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> "Closes" isn't a valid tag? Reported-by + Link should be enough to attribute.

I believe it is: the robot asks to use it, see the link. (I think this
tag is also used by syzbot btw.)

> > Signed-off-by: Andrey Konovalov <[email protected]>
>
> Reviewed-by: Marco Elver <[email protected]>

Thanks!