summaryrefslogtreecommitdiffstats
path: root/sys/vm/memguard.h
diff options
context:
space:
mode:
authorbmilekic <bmilekic@FreeBSD.org>2005-01-21 18:09:17 +0000
committerbmilekic <bmilekic@FreeBSD.org>2005-01-21 18:09:17 +0000
commitda7116f3aca878545c2d52ffca882ba388d0d89e (patch)
treee3ac68d91ce5b621ef858776db95b6901b4a7e6b /sys/vm/memguard.h
parent7dbaec2b97d80c5ce16b2d9f62681d30230940b8 (diff)
downloadFreeBSD-src-da7116f3aca878545c2d52ffca882ba388d0d89e.zip
FreeBSD-src-da7116f3aca878545c2d52ffca882ba388d0d89e.tar.gz
Bring in MemGuard, a very simple and small replacement allocator
designed to help detect tamper-after-free scenarios, a problem more and more common and likely with multithreaded kernels where race conditions are more prevalent. Currently MemGuard can only take over malloc()/realloc()/free() for particular (a) malloc type(s) and the code brought in with this change manually instruments it to take over M_SUBPROC allocations as an example. If you are planning to use it, for now you must: 1) Put "options DEBUG_MEMGUARD" in your kernel config. 2) Edit src/sys/kern/kern_malloc.c manually, look for "XXX CHANGEME" and replace the M_SUBPROC comparison with the appropriate malloc type (this might require additional but small/simple code modification if, say, the malloc type is declared out of scope). 3) Build and install your kernel. Tune vm.memguard_divisor boot-time tunable which is used to scale how much of kmem_map you want to allott for MemGuard's use. The default is 10, so kmem_size/10. ToDo: 1) Bring in a memguard(9) man page. 2) Better instrumentation (e.g., boot-time) of MemGuard taking over malloc types. 3) Teach UMA about MemGuard to allow MemGuard to override zone allocations too. 4) Improve MemGuard if necessary. This work is partly based on some old patches from Ian Dowse.
Diffstat (limited to 'sys/vm/memguard.h')
-rw-r--r--sys/vm/memguard.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/vm/memguard.h b/sys/vm/memguard.h
new file mode 100644
index 0000000..46f0460
--- /dev/null
+++ b/sys/vm/memguard.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2005,
+ * Bosko Milekic <bmilekic@freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+void memguard_init(vm_map_t parent_map, unsigned long size);
+void *memguard_alloc(unsigned long size, int flags);
+void memguard_free(void *addr);
OpenPOWER on IntegriCloud