mm/slub.c: add a naive detection of double free or corruption
Subsystems (2)
[email protected]
maintainerPATCH 15/119 mm/slub.c: add a naive detection of double free or corruption
From: Alexander Popov <[email protected]>
Subject: mm/slub.c: add a naive detection of double free or corruption
Add an assertion similar to "fasttop" check in GNU C Library allocator as a part of SLAB_FREELIST_HARDENED feature. An object added to a singly linked freelist should not point to itself. That helps to detect some double free errors (e.g. CVE-2017-2636) without slub_debug and KASAN.
---
mm/slub.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/slub.c renamed from mm/slub.c~mm-slubc-add-a-naive-detection-of-double-free-or-corruption +4 -0
@@ -290,6 +290,10 @@ static inline void set_freepointer(struc {unsigned long freeptr_addr = (unsigned long )object + s->offset; +#ifdef CONFIG_SLAB_FREELIST_HARDENED +BUG_ON (object == fp);/* naive detection of double free or corruption */ +#endif + *(void **)freeptr_addr =freelist_ptr (s, fp, freeptr_addr); }
_
A message that is not in the archive (sent off-list or not yet received): CA+55aFzmpViw5CJdCXC7f0TdsFYQAdbJt77bfn4t6oXq_=W9xw@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CAGXu5jLHyo3MZt2b7HSA-vpzn1qojUOU4AGo=eoBuyz6X9dzLw@mail.gmail.com
Andrew Morton
maintainerQuoted 14 lines · On Wed, 6 Sep 2017 17:25:21 -0700 Kees Cook <[email protected]> wrote:
Quoted 12 lines · Linus Torvalds
This _may_ be one of the few acceptable uses of
BUG_ON(), but I still question it.It's quite possibly going to bring the machine down, with no messages going to the logs, and nothing to say what happened.
That's not good for debugging, but it's not good for security either.
Are you really sure you don't want to just replace it with a
if (WARN_ON_ONCE(..)) return;
Quoted 8 lines
Quoted 3 lines
instead?
Killing a machine really isn't a great thing to do.
I asked after this as well, but it didn't really get addressed:
http://www.openwall.com/lists/kernel-hardening/2017/07/19/9I'd be fine with this being
WARN_ON_ONCE().
Well... if the kernel warns then proceeds with known pointer crazies, it isn't really "hardened". It's just "kernel with extra debug checks". Yes the log splat is useful, but not very satisfying if someone has already made off with all your customers' credit card numbers?