* [PATCH] kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED
@ 2019-02-14 0:25 Andrey Konovalov
2019-02-14 0:27 ` Andrey Konovalov
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Konovalov @ 2019-02-14 0:25 UTC (permalink / raw)
To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Catalin Marinas, Christoph Lameter, Pekka Enberg, David Rientjes,
Joonsoo Kim, Andrew Morton, kasan-dev, linux-mm, linux-kernel
Cc: Qian Cai, Vincenzo Frascino, Kostya Serebryany, Evgeniy Stepanov,
Andrey Konovalov
When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged.
Normally, this doesn't cause any issues, as both set_freepointer()
and get_freepointer() are called with a pointer with the same tag.
However, there are some issues with CONFIG_SLUB_DEBUG code. For
example, when __free_slub() iterates over objects in a cache, it
passes untagged pointers to check_object(). check_object() in turns
calls get_freepointer() with an untagged pointer, which causes the
freepointer to be restored incorrectly.
Add kasan_reset_tag to freelist_ptr(). Also add a detailed comment.
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
mm/slub.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 80da3a40b74d..c80e6699357c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -249,7 +249,18 @@ static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr,
unsigned long ptr_addr)
{
#ifdef CONFIG_SLAB_FREELIST_HARDENED
- return (void *)((unsigned long)ptr ^ s->random ^ ptr_addr);
+ /*
+ * When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged.
+ * Normally, this doesn't cause any issues, as both set_freepointer()
+ * and get_freepointer() are called with a pointer with the same tag.
+ * However, there are some issues with CONFIG_SLUB_DEBUG code. For
+ * example, when __free_slub() iterates over objects in a cache, it
+ * passes untagged pointers to check_object(). check_object() in turns
+ * calls get_freepointer() with an untagged pointer, which causes the
+ * freepointer to be restored incorrectly.
+ */
+ return (void *)((unsigned long)ptr ^ s->random ^
+ (unsigned long)kasan_reset_tag((void *)ptr_addr));
#else
return ptr;
#endif
--
2.20.1.791.gb4d0f1c61a-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED
2019-02-14 0:25 [PATCH] kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED Andrey Konovalov
@ 2019-02-14 0:27 ` Andrey Konovalov
2019-02-14 1:56 ` Qian Cai
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Konovalov @ 2019-02-14 0:27 UTC (permalink / raw)
To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Catalin Marinas, Christoph Lameter, Pekka Enberg, David Rientjes,
Joonsoo Kim, Andrew Morton, kasan-dev,
Linux Memory Management List, LKML
Cc: Qian Cai, Vincenzo Frascino, Kostya Serebryany, Evgeniy Stepanov
On Thu, Feb 14, 2019 at 1:25 AM Andrey Konovalov <andreyknvl@google.com> wrote:
>
> When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged.
> Normally, this doesn't cause any issues, as both set_freepointer()
> and get_freepointer() are called with a pointer with the same tag.
> However, there are some issues with CONFIG_SLUB_DEBUG code. For
> example, when __free_slub() iterates over objects in a cache, it
> passes untagged pointers to check_object(). check_object() in turns
> calls get_freepointer() with an untagged pointer, which causes the
> freepointer to be restored incorrectly.
>
> Add kasan_reset_tag to freelist_ptr(). Also add a detailed comment.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reported-by: Qian Cai <cai@lca.pw>
> ---
> mm/slub.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 80da3a40b74d..c80e6699357c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -249,7 +249,18 @@ static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr,
> unsigned long ptr_addr)
> {
> #ifdef CONFIG_SLAB_FREELIST_HARDENED
> - return (void *)((unsigned long)ptr ^ s->random ^ ptr_addr);
> + /*
> + * When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged.
> + * Normally, this doesn't cause any issues, as both set_freepointer()
> + * and get_freepointer() are called with a pointer with the same tag.
> + * However, there are some issues with CONFIG_SLUB_DEBUG code. For
> + * example, when __free_slub() iterates over objects in a cache, it
> + * passes untagged pointers to check_object(). check_object() in turns
> + * calls get_freepointer() with an untagged pointer, which causes the
> + * freepointer to be restored incorrectly.
> + */
> + return (void *)((unsigned long)ptr ^ s->random ^
> + (unsigned long)kasan_reset_tag((void *)ptr_addr));
> #else
> return ptr;
> #endif
> --
> 2.20.1.791.gb4d0f1c61a-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED
2019-02-14 0:27 ` Andrey Konovalov
@ 2019-02-14 1:56 ` Qian Cai
0 siblings, 0 replies; 3+ messages in thread
From: Qian Cai @ 2019-02-14 1:56 UTC (permalink / raw)
To: Andrey Konovalov, Andrey Ryabinin, Alexander Potapenko,
Dmitry Vyukov, Catalin Marinas, Christoph Lameter, Pekka Enberg,
David Rientjes, Joonsoo Kim, Andrew Morton, kasan-dev,
Linux Memory Management List, LKML
Cc: Vincenzo Frascino, Kostya Serebryany, Evgeniy Stepanov
On 2/13/19 7:27 PM, Andrey Konovalov wrote:
> On Thu, Feb 14, 2019 at 1:25 AM Andrey Konovalov <andreyknvl@google.com> wrote:
>>
>> When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged.
>> Normally, this doesn't cause any issues, as both set_freepointer()
>> and get_freepointer() are called with a pointer with the same tag.
>> However, there are some issues with CONFIG_SLUB_DEBUG code. For
>> example, when __free_slub() iterates over objects in a cache, it
>> passes untagged pointers to check_object(). check_object() in turns
>> calls get_freepointer() with an untagged pointer, which causes the
>> freepointer to be restored incorrectly.
>>
>> Add kasan_reset_tag to freelist_ptr(). Also add a detailed comment.
>>
>> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>
> Reported-by: Qian Cai <cai@lca.pw>
Tested-by: Qian Cai <cai@lca.pw>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-02-14 1:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 0:25 [PATCH] kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED Andrey Konovalov
2019-02-14 0:27 ` Andrey Konovalov
2019-02-14 1:56 ` Qian Cai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox