kasan: assorted fixes and improvements
Subsystems (7)
cover 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(-)
Signature · 1 line
2.25.1
PATCH 1/5 arm64, kasan: update comment in kasan_init
From: Andrey Konovalov <[email protected]>
Update the comment in kasan_init to also mention the Hardware Tag-Based KASAN mode.
--- arch/arm64/mm/kasan_init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm64/mm/kasan_init.c +5 -1
@@ -300,7 +300,11 @@ void __init kasan_init(void)kasan_init_shadow ();kasan_init_depth ();#if defined(CONFIG_KASAN_GENERIC ) -/* CONFIG_KASAN_SW_TAGS also requires kasan_init_sw_tags(). */ +/* +* Generic KASAN is now fully initialized. +* Software and Hardware Tag-Based modes still require +* kasan_init_sw_tags() and kasan_init_hw_tags() correspondingly. +*/ pr_info ("KernelAddressSanitizer initialized (generic)\n" );#endif }
Signature · 1 line
2.25.1
PATCH 2/5 kasan: unify printk prefixes
In reply to [email protected]From: Andrey Konovalov <[email protected]>
Unify prefixes for printk messages in mm/kasan/.
--- 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(-)
mm/kasan/kasan_test.c +1 -1
@@ -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>
mm/kasan/kasan_test_module.c +1 -1
@@ -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>
mm/kasan/quarantine.c +3 -1
@@ -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);
mm/kasan/report_generic.c +3 -3
@@ -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; }
Signature · 1 line
2.25.1
Re: [PATCH 2/5] kasan: unify printk prefixes
Quoted 6 lines · 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]>
Quoted 89 lines
--- 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(-)mm/kasan/kasan_test.c +1
-1@@ -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> mm/kasan/kasan_test_module.c +1
-1@@ -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> mm/kasan/quarantine.c +3
-1@@ -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);mm/kasan/report_generic.c +3
-4@@ -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
PATCH 3/5 kasan: use unchecked __memset internally
In reply to [email protected]From: Andrey Konovalov <[email protected]>
KASAN code is supposed to use the unchecked __memset implementation when accessing its metadata.
Change uses of memset to __memset in mm/kasan/.
--- mm/kasan/report.c | 4 ++-- mm/kasan/shadow.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
mm/kasan/report.c +2 -2
@@ -538,7 +538,7 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_tystart_report (&flags, true); -memset (&info,0 ,sizeof (info)); +__memset (&info,0 ,sizeof (info)); info.type = type; info.access_addr = ptr; info.access_size =0 ;
@@ -576,7 +576,7 @@ bool kasan_report(const void *addr, size_t size, bool is_write,start_report (&irq_flags, true); -memset (&info,0 ,sizeof (info)); +__memset (&info,0 ,sizeof (info)); info.type =KASAN_REPORT_ACCESS ; info.access_addr = addr; info.access_size = size;
mm/kasan/shadow.c +1 -1
@@ -324,7 +324,7 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,if (!page)return -ENOMEM ; -memset ((void *)page,KASAN_VMALLOC_INVALID ,PAGE_SIZE ); +__memset ((void *)page,KASAN_VMALLOC_INVALID ,PAGE_SIZE ); pte =pfn_pte (PFN_DOWN (__pa (page)),PAGE_KERNEL );spin_lock (&init_mm.page_table_lock);
Signature · 1 line
2.25.1
Re: [PATCH 3/5] kasan: use unchecked __memset internally
Quoted 9 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
KASAN code is supposed to use the unchecked
__memsetimplementation when accessing its metadata.Change uses of memset to
__memsetinmm/kasan/.Signed-off-by Andrey Konovalov <[email protected]>
Do we need a "Fixes" tag?
Quoted 43 lines
--- mm/kasan/report.c | 4 ++-- mm/kasan/shadow.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)mm/kasan/report.c +2
-2@@ -538,7 +538,7 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_tystart_report (&flags, true); -memset (&info,0 ,sizeof (info)); +__memset (&info,0 ,sizeof (info)); info.type = type; info.access_addr = ptr; info.access_size =0 ;@@ -576,7 +576,7 @@ bool kasan_report(const void *addr, size_t size, bool is_write,start_report (&irq_flags, true); -memset (&info,0 ,sizeof (info)); +__memset (&info,0 ,sizeof (info)); info.type =KASAN_REPORT_ACCESS ; info.access_addr = addr; info.access_size = size;mm/kasan/shadow.c +1
-2@@ -324,7 +324,7 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,if (!page)return -ENOMEM ; -memset ((void *)page,KASAN_VMALLOC_INVALID ,PAGE_SIZE ); +__memset ((void *)page,KASAN_VMALLOC_INVALID ,PAGE_SIZE ); pte =pfn_pte (PFN_DOWN (__pa (page)),PAGE_KERNEL );spin_lock (&init_mm.page_table_lock); --2.25.1
Andrey Konovalov
reviewerRe: [PATCH 3/5] kasan: use unchecked __memset internally
Quoted 5 lines · Marco Elver
Quoted 3 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
Quoted 8 lines
Quoted 6 lines
KASAN code is supposed to use the unchecked
__memsetimplementation when accessing its metadata.Change uses of memset to
__memsetinmm/kasan/.Signed-off-by Andrey Konovalov <[email protected]>Do we need a "Fixes" tag?
Good idea, let's add them:
shadow memory")
Quoted 1 line
Reviewed-by Marco Elver <[email protected]>
Thanks!
PATCH 4/5 kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment
In reply to [email protected]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.
--- mm/kasan/kasan_test.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
mm/kasan/kasan_test.c +5 -4
@@ -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
Signature · 1 line
2.25.1
Re: [PATCH 4/5] kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment
Quoted 11 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
Update the comment for
KUNIT_EXPECT_KASAN_FAILto describe the parameters this macro accepts.Also drop the mention of the "
kasan_status" KUnit resource, as it no longer exists.
"Closes" isn't a valid tag? Reported-by + Link should be enough to attribute.
Quoted 1 line
Signed-off-by Andrey Konovalov <[email protected]>
Quoted 27 lines
--- mm/kasan/kasan_test.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)mm/kasan/kasan_test.c +5
-5@@ -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
Andrey Konovalov
reviewerRe: [PATCH 4/5] kasan: fix and update KUNIT_EXPECT_KASAN_FAIL comment
Quoted 8 lines · Marco Elver
Quoted 6 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
Update the comment for
KUNIT_EXPECT_KASAN_FAILto describe the parameters this macro accepts.
Quoted 7 lines
Quoted 5 lines
Also drop the mention of the "
kasan_status" KUnit resource, as it no longer exists."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.)
Quoted 3 lines
Quoted 1 line
Signed-off-by Andrey Konovalov <[email protected]>Reviewed-by Marco Elver <[email protected]>
Thanks!
PATCH 5/5 Documentation: *san: drop "the" from article titles
In reply to [email protected]From: Andrey Konovalov <[email protected]>
Drop "the" from the titles of documentation articles for KASAN, KCSAN, and KMSAN, as it is redundant.
Also add SPDX-License-Identifier for kasan.rst.
--- Documentation/dev-tools/kasan.rst | 7 +++++-- Documentation/dev-tools/kcsan.rst | 4 ++-- Documentation/dev-tools/kmsan.rst | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-)
Documentation/dev-tools/kasan.rst +5 -2
@@ -1,5 +1,8 @@ -The Kernel Address Sanitizer (KASAN) -==================================== +.. SPDX-License-Identifier: GPL-2.0 +.. Copyright (C) 2023, Google LLC. + +Kernel Address Sanitizer (KASAN) +================================ Overview --------
Documentation/dev-tools/kcsan.rst +2 -2
@@ -1,8 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0 .. Copyright (C) 2019, Google LLC. -The Kernel Concurrency Sanitizer (KCSAN) -======================================== +Kernel Concurrency Sanitizer (KCSAN) +==================================== The Kernel Concurrency Sanitizer (KCSAN) is a dynamic race detector, which relies on compile-time instrumentation, and uses a watchpoint-based sampling
Documentation/dev-tools/kmsan.rst +3 -3
@@ -1,9 +1,9 @@ .. SPDX-License-Identifier: GPL-2.0 .. Copyright (C) 2022, Google LLC. -=================================== -The Kernel Memory Sanitizer (KMSAN) -=================================== +=============================== +Kernel Memory Sanitizer (KMSAN) +=============================== KMSAN is a dynamic error detector aimed at finding uses of uninitialized values. It is based on compiler instrumentation, and is quite similar to the
Signature · 1 line
2.25.1
Re: [PATCH 5/5] Documentation: *san: drop "the" from article titles
Quoted 6 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
Drop "the" from the titles of documentation articles for KASAN, KCSAN, and KMSAN, as it is redundant.
Quoted 7 lines
Also add SPDX-License-Identifier for
kasan.rst.Signed-off-by Andrey Konovalov <[email protected]>--- Documentation/dev-tools/kasan.rst | 7 +++++-- Documentation/dev-tools/kcsan.rst | 4 ++-- Documentation/dev-tools/kmsan.rst | 6 +++---
UBSan also has it: https://docs.kernel.org/dev-tools/ubsan.html
Quoted 52 lines
3 files changed, 10 insertions(+), 7 deletions(-)Documentation/dev-tools/kasan.rst +5
-2@@ -1,5 +1,8 @@ -The Kernel Address Sanitizer (KASAN) -==================================== +.. SPDX-License-Identifier: GPL-2.0 +.. Copyright (C) 2023, Google LLC. + +Kernel Address Sanitizer (KASAN) +================================ Overview --------Documentation/dev-tools/kcsan.rst +2
-2@@ -1,8 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0 .. Copyright (C) 2019, Google LLC. -The Kernel Concurrency Sanitizer (KCSAN) -======================================== +Kernel Concurrency Sanitizer (KCSAN) +==================================== The Kernel Concurrency Sanitizer (KCSAN) is a dynamic race detector, which relies on compile-time instrumentation, and uses a watchpoint-based samplingDocumentation/dev-tools/kmsan.rst +3
-4@@ -1,9 +1,9 @@ .. SPDX-License-Identifier: GPL-2.0 .. Copyright (C) 2022, Google LLC. -=================================== -The Kernel Memory Sanitizer (KMSAN) -=================================== +=============================== +Kernel Memory Sanitizer (KMSAN) +=============================== KMSAN is a dynamic error detector aimed at finding uses of uninitialized values. It is based on compiler instrumentation, and is quite similar to the --2.25.1
Andrey Konovalov
reviewerRe: [PATCH 5/5] Documentation: *san: drop "the" from article titles
Quoted 10 lines · Marco Elver
Quoted 8 lines · On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
From: Andrey Konovalov <[email protected]>
Drop "the" from the titles of documentation articles for KASAN, KCSAN, and KMSAN, as it is redundant.
Also add SPDX-License-Identifier for
kasan.rst.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Andrey Konovalov <[email protected]>--- Documentation/dev-tools/kasan.rst | 7 +++++-- Documentation/dev-tools/kcsan.rst | 4 ++-- Documentation/dev-tools/kmsan.rst | 6 +++---UBSan also has it: https://docs.kernel.org/dev-tools/ubsan.html
Ah, right, forgot that one. I'll send a fix up next week.
(Once again I wonder if we should rename UBSAN to KUBSAN. :)
Quoted 1 line
Reviewed-by Marco Elver <[email protected]>
Thanks!