From: npiggin@suse.de
From: Nick Piggin <npiggin@suse.de>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, glommer@redhat.com
Subject: [patch 7/7] mm: vmalloc make lazy unmapping configurable
Date: Tue, 11 Nov 2008 00:35:22 +1100 [thread overview]
Message-ID: <20081110133841.247282000@suse.de> (raw)
In-Reply-To: <20081110133515.011510000@suse.de>
[-- Attachment #1: mm-vmalloc-nolazy-debug.patch --]
[-- Type: text/plain, Size: 2117 bytes --]
Lazy unmapping in the vmalloc code has now opened the possibility for use
after free bugs to go undetected. We can catch those by forcing an unmap
and flush (which is going to be slow, but that's what happens).
Signed-off-by: Nick Piggin <npiggin@suse.de>
---
Index: linux-2.6/mm/vmalloc.c
===================================================================
--- linux-2.6.orig/mm/vmalloc.c
+++ linux-2.6/mm/vmalloc.c
@@ -434,6 +434,27 @@ static void unmap_vmap_area(struct vmap_
vunmap_page_range(va->va_start, va->va_end);
}
+static void vmap_debug_free_range(unsigned long start, unsigned long end)
+{
+ /*
+ * Unmap page tables and force a TLB flush immediately if
+ * CONFIG_DEBUG_PAGEALLOC is set. This catches use after free
+ * bugs similarly to those in linear kernel virtual address
+ * space after a page has been freed.
+ *
+ * All the lazy freeing logic is still retained, in order to
+ * minimise intrusiveness of this debugging feature.
+ *
+ * This is going to be *slow* (linear kernel virtual address
+ * debugging doesn't do a broadcast TLB flush so it is a lot
+ * faster).
+ */
+#ifdef CONFIG_DEBUG_PAGEALLOC
+ vunmap_page_range(start, end);
+ flush_tlb_kernel_range(start, end);
+#endif
+}
+
/*
* lazy_max_pages is the maximum amount of virtual address space we gather up
* before attempting to purge with a TLB flush.
@@ -896,6 +917,7 @@ void vm_unmap_ram(const void *mem, unsig
BUG_ON(addr & (PAGE_SIZE-1));
debug_check_no_locks_freed(mem, size);
+ vmap_debug_free_range(addr, addr+size);
if (likely(count <= VMAP_MAX_ALLOC))
vb_free(mem, size);
@@ -1110,6 +1132,8 @@ struct vm_struct *remove_vm_area(const v
if (va && va->flags & VM_VM_AREA) {
struct vm_struct *vm = va->private;
struct vm_struct *tmp, **p;
+
+ vmap_debug_free_range(va->va_start, va->va_end);
free_unmap_vmap_area(va);
vm->size -= PAGE_SIZE;
--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2008-11-10 13:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-10 13:35 [patch 0/7] vmalloc fixes and improvements #2 npiggin
2008-11-10 13:35 ` [patch 1/7] mm: vmalloc allocator off by one npiggin, Nick Piggin
2008-11-10 13:35 ` [patch 2/7] mm: vmalloc failure flush fix npiggin, Nick Piggin
2008-11-10 13:35 ` [patch 3/7] mm: vmalloc search restart fix npiggin, Glauber Costa
2008-11-10 13:35 ` [patch 4/7] mm: vmalloc tweak failure printk npiggin, Glauber Costa
2008-11-10 13:35 ` [patch 5/7] mm: vmalloc improve vmallocinfo npiggin, Glauber Costa
2008-11-10 13:35 ` [patch 6/7] mm: vmalloc use mutex for purge npiggin, Nick Piggin
2008-11-10 13:35 ` npiggin, Nick Piggin [this message]
2008-11-11 18:25 ` [patch 0/7] vmalloc fixes and improvements #2 Glauber Costa
2008-11-12 3:45 ` Nick Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081110133841.247282000@suse.de \
--to=npiggin@suse.de \
--cc=akpm@linux-foundation.org \
--cc=glommer@redhat.com \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox