2023-10-06 15:19:12

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH 3/5] kasan: use unchecked __memset internally

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/.

Signed-off-by: Andrey Konovalov <[email protected]>
---
mm/kasan/report.c | 4 ++--
mm/kasan/shadow.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index ca4b6ff080a6..12557ffee90b 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -538,7 +538,7 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_ty

start_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;
diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
index dd772f9d0f08..d687f09a7ae3 100644
--- a/mm/kasan/shadow.c
+++ b/mm/kasan/shadow.c
@@ -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


2023-10-09 08:46:47

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH 3/5] kasan: use unchecked __memset internally

On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
>
> 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/.
>
> Signed-off-by: Andrey Konovalov <[email protected]>

Do we need a "Fixes" tag?

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

> ---
> mm/kasan/report.c | 4 ++--
> mm/kasan/shadow.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index ca4b6ff080a6..12557ffee90b 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -538,7 +538,7 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_ty
>
> start_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;
> diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
> index dd772f9d0f08..d687f09a7ae3 100644
> --- a/mm/kasan/shadow.c
> +++ b/mm/kasan/shadow.c
> @@ -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
>

2023-10-09 19:52:09

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH 3/5] kasan: use unchecked __memset internally

On Mon, Oct 9, 2023 at 10:46 AM Marco Elver <[email protected]> wrote:
>
> On Fri, 6 Oct 2023 at 17:18, <[email protected]> wrote:
> >
> > 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/.
> >
> > Signed-off-by: Andrey Konovalov <[email protected]>
>
> Do we need a "Fixes" tag?

Good idea, let's add them:

Fixes: 59e6e098d1c1 ("kasan: introduce kasan_complete_mode_report_info")
Fixes: 3c5c3cfb9ef4 ("kasan: support backing vmalloc space with real
shadow memory")

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

Thanks!