1f8cd5f23SChristian Brueffer.\" Copyright (c) 2005 Christian Brueffer 2f8cd5f23SChristian Brueffer.\" All rights reserved. 3f8cd5f23SChristian Brueffer.\" 4f8cd5f23SChristian Brueffer.\" Redistribution and use in source and binary forms, with or without 5f8cd5f23SChristian Brueffer.\" modification, are permitted provided that the following conditions 6f8cd5f23SChristian Brueffer.\" are met: 7f8cd5f23SChristian Brueffer.\" 1. Redistributions of source code must retain the above copyright 8f8cd5f23SChristian Brueffer.\" notice, this list of conditions and the following disclaimer. 9f8cd5f23SChristian Brueffer.\" 2. Redistributions in binary form must reproduce the above copyright 10f8cd5f23SChristian Brueffer.\" notice, this list of conditions and the following disclaimer in the 11f8cd5f23SChristian Brueffer.\" documentation and/or other materials provided with the distribution. 12f8cd5f23SChristian Brueffer.\" 13f8cd5f23SChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14f8cd5f23SChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15f8cd5f23SChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16f8cd5f23SChristian Brueffer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17f8cd5f23SChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18f8cd5f23SChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19f8cd5f23SChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20f8cd5f23SChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21f8cd5f23SChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22f8cd5f23SChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23f8cd5f23SChristian Brueffer.\" SUCH DAMAGE. 24f8cd5f23SChristian Brueffer.\" 25f8cd5f23SChristian Brueffer.\" $FreeBSD$ 26f8cd5f23SChristian Brueffer.\" 27b88c6e87SChristian Brueffer.Dd January 31, 2006 28f8cd5f23SChristian Brueffer.Dt MEMGUARD 9 29f8cd5f23SChristian Brueffer.Os 30f8cd5f23SChristian Brueffer.Sh NAME 31f8cd5f23SChristian Brueffer.Nm MemGuard 32f8cd5f23SChristian Brueffer.Nd "memory allocator for debugging purposes" 33f8cd5f23SChristian Brueffer.Sh SYNOPSIS 34f8cd5f23SChristian Brueffer.Cd "options DEBUG_MEMGUARD" 35f8cd5f23SChristian Brueffer.Sh DESCRIPTION 36f8cd5f23SChristian Brueffer.Nm 37f8cd5f23SChristian Bruefferis a simple and small replacement memory allocator designed 38f8cd5f23SChristian Bruefferto help detect tamper-after-free scenarios. 39f8cd5f23SChristian BruefferThese problems are more and more common and likely with 40f8cd5f23SChristian Brueffermultithreaded kernels where race conditions are more prevalent. 41f8cd5f23SChristian Brueffer.Pp 42f8cd5f23SChristian BruefferCurrently, 43f8cd5f23SChristian Brueffer.Nm 44f8cd5f23SChristian Brueffercan only take over 45f8cd5f23SChristian Brueffer.Fn malloc , 46f8cd5f23SChristian Brueffer.Fn realloc 47f8cd5f23SChristian Bruefferand 48f8cd5f23SChristian Brueffer.Fn free 49f8cd5f23SChristian Bruefferfor a particular malloc type. 50f8cd5f23SChristian Brueffer.Sh EXAMPLES 5181ae4b8dSRuslan ErmilovTo use 5281ae4b8dSRuslan Ermilov.Nm 5381ae4b8dSRuslan Ermilovfor memory type compiled into the kernel, one has to add the 54104a3dc0SPawel Jakub Dawidekfollowing line to the 55104a3dc0SPawel Jakub Dawidek.Pa /boot/loader.conf : 56104a3dc0SPawel Jakub Dawidek.Bd -literal -offset indent 57104a3dc0SPawel Jakub Dawidekvm.memguard.desc=<memory_type> 58104a3dc0SPawel Jakub Dawidek.Ed 59104a3dc0SPawel Jakub Dawidek.Pp 6081ae4b8dSRuslan ErmilovWhere 6181ae4b8dSRuslan Ermilov.Ar memory_type 6281ae4b8dSRuslan Ermilovis a short description of memory type to monitor. 63b81709d1SPawel Jakub DawidekThe short description of memory type is the second argument to 64b81709d1SPawel Jakub Dawidek.Xr MALLOC_DEFINE 9 , 65b81709d1SPawel Jakub Dawidekso one has to find it in the kernel source. 66104a3dc0SPawel Jakub Dawidek.Pp 6781ae4b8dSRuslan ErmilovTo use 6881ae4b8dSRuslan Ermilov.Nm 6981ae4b8dSRuslan Ermilovfor memory type defined in a kernel module, one has to set 70104a3dc0SPawel Jakub Dawidek.Va vm.memguard.desc 71104a3dc0SPawel Jakub Dawidek.Xr sysctl 8 72104a3dc0SPawel Jakub Dawidekvariable before loading the module: 73104a3dc0SPawel Jakub Dawidek.Bd -literal -offset indent 74104a3dc0SPawel Jakub Dawideksysctl vm.memguard.desc=<memory_type> 75104a3dc0SPawel Jakub Dawidek.Ed 76104a3dc0SPawel Jakub Dawidek.Pp 77104a3dc0SPawel Jakub DawidekThe 78104a3dc0SPawel Jakub Dawidek.Va vm.memguard.divisor 79104a3dc0SPawel Jakub Dawidekboot-time tunable is used to scale how much of 80f8cd5f23SChristian Brueffer.Va kmem_map 81104a3dc0SPawel Jakub Dawidekone wants to allocate for 82f8cd5f23SChristian Brueffer.Nm . 83f8cd5f23SChristian BruefferThe default is 10, so 84f8cd5f23SChristian Brueffer.Va kmem_size Ns /10 85f8cd5f23SChristian Bruefferbytes will be used. 86f8cd5f23SChristian BruefferThe 87f8cd5f23SChristian Brueffer.Va kmem_size 88f8cd5f23SChristian Brueffervalue can be obtained via the 89f8cd5f23SChristian Brueffer.Va vm.kmem_size 90f8cd5f23SChristian Brueffer.Xr sysctl 8 91f8cd5f23SChristian Brueffervariable. 92f8cd5f23SChristian Brueffer.Sh SEE ALSO 93f8cd5f23SChristian Brueffer.Xr sysctl 8 , 94f8cd5f23SChristian Brueffer.Xr vmstat 8 , 95f8cd5f23SChristian Brueffer.Xr contigmalloc 9 , 96b88c6e87SChristian Brueffer.Xr malloc 9 , 97b88c6e87SChristian Brueffer.Xr redzone 9 98f8cd5f23SChristian Brueffer.Sh HISTORY 99f8cd5f23SChristian Brueffer.Nm 100f8cd5f23SChristian Bruefferfirst appeared in 101f8cd5f23SChristian Brueffer.Fx 6.0 . 102f8cd5f23SChristian Brueffer.Sh AUTHORS 103f8cd5f23SChristian Brueffer.An -nosplit 104f8cd5f23SChristian Brueffer.Nm 105f8cd5f23SChristian Bruefferwas written by 106f8cd5f23SChristian Brueffer.An Bosko Milekic Aq bmilekic@FreeBSD.org . 107f8cd5f23SChristian BruefferThis manual page was written by 108f8cd5f23SChristian Brueffer.An Christian Brueffer Aq brueffer@FreeBSD.org . 109f8cd5f23SChristian Brueffer.Sh BUGS 110f8cd5f23SChristian BruefferCurrently, it is not possible to override UMA 111f8cd5f23SChristian Brueffer.Xr zone 9 112f8cd5f23SChristian Bruefferallocations. 113