linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm] kasan: untag addresses for KFENCE
@ 2021-01-29 18:50 Andrey Konovalov
  2021-02-01 10:40 ` Marco Elver
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Konovalov @ 2021-01-29 18:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, Marco Elver,
	kasan-dev, linux-mm, linux-kernel, Andrey Konovalov

KFENCE annotations operate on untagged addresses.

Untag addresses in KASAN runtime where they might be tagged.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

---

This can be squashed into:

revert kasan-remove-kfence-leftovers
kfence, kasan: make KFENCE compatible with KASA

---
 mm/kasan/common.c |  2 +-
 mm/kasan/kasan.h  | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index a390fae9d64b..fe852f3cfa42 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -416,7 +416,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object,
 	if (unlikely(object == NULL))
 		return NULL;
 
-	if (is_kfence_address(object))
+	if (is_kfence_address(kasan_reset_tag(object)))
 		return (void *)object;
 
 	redzone_start = round_up((unsigned long)(object + size),
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 11c6e3650468..4fb8106f8e31 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -320,22 +320,28 @@ static inline u8 kasan_random_tag(void) { return 0; }
 
 static inline void kasan_poison(const void *address, size_t size, u8 value)
 {
+	address = kasan_reset_tag(address);
+
 	/* Skip KFENCE memory if called explicitly outside of sl*b. */
 	if (is_kfence_address(address))
 		return;
 
-	hw_set_mem_tag_range(kasan_reset_tag(address),
+	hw_set_mem_tag_range((void *)address,
 			round_up(size, KASAN_GRANULE_SIZE), value);
 }
 
 static inline void kasan_unpoison(const void *address, size_t size)
 {
+	u8 tag = get_tag(address);
+
+	address = kasan_reset_tag(address);
+
 	/* Skip KFENCE memory if called explicitly outside of sl*b. */
 	if (is_kfence_address(address))
 		return;
 
-	hw_set_mem_tag_range(kasan_reset_tag(address),
-			round_up(size, KASAN_GRANULE_SIZE), get_tag(address));
+	hw_set_mem_tag_range((void *)address,
+			round_up(size, KASAN_GRANULE_SIZE), tag);
 }
 
 static inline bool kasan_byte_accessible(const void *addr)
-- 
2.30.0.365.g02bc693789-goog



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH mm] kasan: untag addresses for KFENCE
  2021-01-29 18:50 [PATCH mm] kasan: untag addresses for KFENCE Andrey Konovalov
@ 2021-02-01 10:40 ` Marco Elver
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2021-02-01 10:40 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, Linux Memory Management List, LKML

On Fri, 29 Jan 2021 at 19:50, Andrey Konovalov <andreyknvl@google.com> wrote:
>
> KFENCE annotations operate on untagged addresses.
>
> Untag addresses in KASAN runtime where they might be tagged.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Reviewed-by: Marco Elver <elver@google.com>

Thank you!

> ---
>
> This can be squashed into:
>
> revert kasan-remove-kfence-leftovers
> kfence, kasan: make KFENCE compatible with KASA
>
> ---
>  mm/kasan/common.c |  2 +-
>  mm/kasan/kasan.h  | 12 +++++++++---
>  2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index a390fae9d64b..fe852f3cfa42 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -416,7 +416,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object,
>         if (unlikely(object == NULL))
>                 return NULL;
>
> -       if (is_kfence_address(object))
> +       if (is_kfence_address(kasan_reset_tag(object)))
>                 return (void *)object;
>
>         redzone_start = round_up((unsigned long)(object + size),
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index 11c6e3650468..4fb8106f8e31 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -320,22 +320,28 @@ static inline u8 kasan_random_tag(void) { return 0; }
>
>  static inline void kasan_poison(const void *address, size_t size, u8 value)
>  {
> +       address = kasan_reset_tag(address);
> +
>         /* Skip KFENCE memory if called explicitly outside of sl*b. */
>         if (is_kfence_address(address))
>                 return;
>
> -       hw_set_mem_tag_range(kasan_reset_tag(address),
> +       hw_set_mem_tag_range((void *)address,
>                         round_up(size, KASAN_GRANULE_SIZE), value);
>  }
>
>  static inline void kasan_unpoison(const void *address, size_t size)
>  {
> +       u8 tag = get_tag(address);
> +
> +       address = kasan_reset_tag(address);
> +
>         /* Skip KFENCE memory if called explicitly outside of sl*b. */
>         if (is_kfence_address(address))
>                 return;
>
> -       hw_set_mem_tag_range(kasan_reset_tag(address),
> -                       round_up(size, KASAN_GRANULE_SIZE), get_tag(address));
> +       hw_set_mem_tag_range((void *)address,
> +                       round_up(size, KASAN_GRANULE_SIZE), tag);
>  }
>
>  static inline bool kasan_byte_accessible(const void *addr)
> --
> 2.30.0.365.g02bc693789-goog
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-01 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 18:50 [PATCH mm] kasan: untag addresses for KFENCE Andrey Konovalov
2021-02-01 10:40 ` Marco Elver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).