* [PATCH][v4.19][v4.14] slub: improve bit diffusion for freelist ptr obfuscation
@ 2020-04-13 17:03 Kees Cook
2020-04-14 8:09 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2020-04-13 17:03 UTC (permalink / raw)
To: gregkh; +Cc: akpm, cl, iamjoonsoo.kim, penberg, rientjes, silvio.cesare,
stable
commit 1ad53d9fa3f6168ebcf48a50e08b170432da2257 upstream.
Under CONFIG_SLAB_FREELIST_HARDENED=y, the obfuscation was relatively weak
in that the ptr and ptr address were usually so close that the first XOR
would result in an almost entirely 0-byte value[1], leaving most of the
"secret" number ultimately being stored after the third XOR. A single
blind memory content exposure of the freelist was generally sufficient to
learn the secret.
Add a swab() call to mix bits a little more. This is a cheap way (1
cycle) to make attacks need more than a single exposure to learn the
secret (or to know _where_ the exposure is in memory).
kmalloc-32 freelist walk, before:
ptr ptr_addr stored value secret
ffff90c22e019020@ffff90c22e019000 is 86528eb656b3b5bd (86528eb656b3b59d)
ffff90c22e019040@ffff90c22e019020 is 86528eb656b3b5fd (86528eb656b3b59d)
ffff90c22e019060@ffff90c22e019040 is 86528eb656b3b5bd (86528eb656b3b59d)
ffff90c22e019080@ffff90c22e019060 is 86528eb656b3b57d (86528eb656b3b59d)
ffff90c22e0190a0@ffff90c22e019080 is 86528eb656b3b5bd (86528eb656b3b59d)
...
after:
ptr ptr_addr stored value secret
ffff9eed6e019020@ffff9eed6e019000 is 793d1135d52cda42 (86528eb656b3b59d)
ffff9eed6e019040@ffff9eed6e019020 is 593d1135d52cda22 (86528eb656b3b59d)
ffff9eed6e019060@ffff9eed6e019040 is 393d1135d52cda02 (86528eb656b3b59d)
ffff9eed6e019080@ffff9eed6e019060 is 193d1135d52cdae2 (86528eb656b3b59d)
ffff9eed6e0190a0@ffff9eed6e019080 is f93d1135d52cdac2 (86528eb656b3b59d)
[1] https://blog.infosectcbr.com.au/2020/03/weaknesses-in-linux-kernel-heap.html
Fixes: 2482ddec670f ("mm: add SLUB free list pointer obfuscation")
Reported-by: Silvio Cesare <silvio.cesare@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/202003051623.AF4F8CB@keescook
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[kees: Backport to v4.19 which doesn't call kasan_reset_untag()]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
This requires that commit d5767057c9a76a29f073dad66b7fa12a90e8c748 is
also cherry-picked into -stable.
---
mm/slub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 9b7b989273d4..d8116a43a287 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -249,7 +249,7 @@ 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);
+ return (void *)((unsigned long)ptr ^ s->random ^ swab(ptr_addr));
#else
return ptr;
#endif
--
2.20.1
--
Kees Cook
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][v4.19][v4.14] slub: improve bit diffusion for freelist ptr obfuscation
2020-04-13 17:03 [PATCH][v4.19][v4.14] slub: improve bit diffusion for freelist ptr obfuscation Kees Cook
@ 2020-04-14 8:09 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2020-04-14 8:09 UTC (permalink / raw)
To: Kees Cook
Cc: akpm, cl, iamjoonsoo.kim, penberg, rientjes, silvio.cesare,
stable
On Mon, Apr 13, 2020 at 10:03:23AM -0700, Kees Cook wrote:
> commit 1ad53d9fa3f6168ebcf48a50e08b170432da2257 upstream.
>
> Under CONFIG_SLAB_FREELIST_HARDENED=y, the obfuscation was relatively weak
> in that the ptr and ptr address were usually so close that the first XOR
> would result in an almost entirely 0-byte value[1], leaving most of the
> "secret" number ultimately being stored after the third XOR. A single
> blind memory content exposure of the freelist was generally sufficient to
> learn the secret.
>
> Add a swab() call to mix bits a little more. This is a cheap way (1
> cycle) to make attacks need more than a single exposure to learn the
> secret (or to know _where_ the exposure is in memory).
>
> kmalloc-32 freelist walk, before:
>
> ptr ptr_addr stored value secret
> ffff90c22e019020@ffff90c22e019000 is 86528eb656b3b5bd (86528eb656b3b59d)
> ffff90c22e019040@ffff90c22e019020 is 86528eb656b3b5fd (86528eb656b3b59d)
> ffff90c22e019060@ffff90c22e019040 is 86528eb656b3b5bd (86528eb656b3b59d)
> ffff90c22e019080@ffff90c22e019060 is 86528eb656b3b57d (86528eb656b3b59d)
> ffff90c22e0190a0@ffff90c22e019080 is 86528eb656b3b5bd (86528eb656b3b59d)
> ...
>
> after:
>
> ptr ptr_addr stored value secret
> ffff9eed6e019020@ffff9eed6e019000 is 793d1135d52cda42 (86528eb656b3b59d)
> ffff9eed6e019040@ffff9eed6e019020 is 593d1135d52cda22 (86528eb656b3b59d)
> ffff9eed6e019060@ffff9eed6e019040 is 393d1135d52cda02 (86528eb656b3b59d)
> ffff9eed6e019080@ffff9eed6e019060 is 193d1135d52cdae2 (86528eb656b3b59d)
> ffff9eed6e0190a0@ffff9eed6e019080 is f93d1135d52cdac2 (86528eb656b3b59d)
>
> [1] https://blog.infosectcbr.com.au/2020/03/weaknesses-in-linux-kernel-heap.html
>
> Fixes: 2482ddec670f ("mm: add SLUB free list pointer obfuscation")
> Reported-by: Silvio Cesare <silvio.cesare@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: <stable@vger.kernel.org>
> Link: http://lkml.kernel.org/r/202003051623.AF4F8CB@keescook
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> [kees: Backport to v4.19 which doesn't call kasan_reset_untag()]
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This requires that commit d5767057c9a76a29f073dad66b7fa12a90e8c748 is
> also cherry-picked into -stable.
> ---
> mm/slub.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 9b7b989273d4..d8116a43a287 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -249,7 +249,7 @@ 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);
> + return (void *)((unsigned long)ptr ^ s->random ^ swab(ptr_addr));
> #else
> return ptr;
> #endif
> --
> 2.20.1
>
>
> --
Now queued up, thanks.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-14 8:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-13 17:03 [PATCH][v4.19][v4.14] slub: improve bit diffusion for freelist ptr obfuscation Kees Cook
2020-04-14 8:09 ` Greg KH
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).