Skip to contentSkip to conversation

mm/slub.c: add a naive detection of double free or corruption

PATCH In review [email protected] 1 participant 2 messages Sep 6, 2017 – Sep 7, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

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

Cc Kees Cook <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc David Rientjes <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Paul E McKenney <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Tycho Andersen <[email protected]>

---

 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
diff -puN mm/slub.c~mm-slubc-add-a-naive-detection-of-double-free-or-corruption mm/slub.c
@@ -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

author maintainer
#3 lore raw
Quoted 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/9

I'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?