diff options
| author | tedu <> | 2005-06-07 04:42:42 +0000 |
|---|---|---|
| committer | tedu <> | 2005-06-07 04:42:42 +0000 |
| commit | 65ac8e1aa6c8de74722ab9326131aca3acef08db (patch) | |
| tree | 49280eea02373789fcd096dc440929b57b806a2f /src/lib/libc | |
| parent | 4128e973a85b96d70a30e67b8c644cd546701184 (diff) | |
| download | openbsd-65ac8e1aa6c8de74722ab9326131aca3acef08db.tar.gz openbsd-65ac8e1aa6c8de74722ab9326131aca3acef08db.tar.bz2 openbsd-65ac8e1aa6c8de74722ab9326131aca3acef08db.zip | |
adding pointer protection to 'G' was too heavyweight. Since malloc guard
should be generally usable, split this out into option 'P'. ok deraadt
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 9 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index df62e7d3a5..2b0f5632a9 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
| 32 | .\" | 32 | .\" |
| 33 | .\" $OpenBSD: malloc.3,v 1.38 2005/05/24 16:48:35 tedu Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.39 2005/06/07 04:42:42 tedu Exp $ |
| 34 | .\" | 34 | .\" |
| 35 | .Dd August 27, 1996 | 35 | .Dd August 27, 1996 |
| 36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
| @@ -204,8 +204,6 @@ Enable guard pages and chunk randomization. | |||
| 204 | Each page size or larger allocation is followed by a guard page that will | 204 | Each page size or larger allocation is followed by a guard page that will |
| 205 | cause a segmentation fault upon any access. | 205 | cause a segmentation fault upon any access. |
| 206 | Smaller than page size chunks are returned in a random order. | 206 | Smaller than page size chunks are returned in a random order. |
| 207 | Pointer sized allocations are aligned to the end of a page to catch | ||
| 208 | sizeof(ptr) errors where sizeof(*ptr) is meant. | ||
| 209 | .Pp | 207 | .Pp |
| 210 | .It Cm H | 208 | .It Cm H |
| 211 | .Dq Hint . | 209 | .Dq Hint . |
| @@ -223,6 +221,11 @@ Currently junk is bytes of 0xd0; this is pronounced | |||
| 223 | Do not output warning messages when encountering possible corruption | 221 | Do not output warning messages when encountering possible corruption |
| 224 | or bad pointers. | 222 | or bad pointers. |
| 225 | .Pp | 223 | .Pp |
| 224 | .It Cm P | ||
| 225 | .Dq Pointer Protection . | ||
| 226 | Pointer sized allocations are aligned to the end of a page to catch | ||
| 227 | sizeof(ptr) errors where sizeof(*ptr) is meant. | ||
| 228 | .Pp | ||
| 226 | .It Cm R | 229 | .It Cm R |
| 227 | .Dq realloc . | 230 | .Dq realloc . |
| 228 | Always reallocate when | 231 | Always reallocate when |
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 9f7ceba080..e3405df39a 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #if defined(LIBC_SCCS) && !defined(lint) | 10 | #if defined(LIBC_SCCS) && !defined(lint) |
| 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.73 2005/05/24 16:39:05 tedu Exp $"; | 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.74 2005/06/07 04:42:42 tedu Exp $"; |
| 12 | #endif /* LIBC_SCCS and not lint */ | 12 | #endif /* LIBC_SCCS and not lint */ |
| 13 | 13 | ||
| 14 | /* | 14 | /* |
| @@ -211,6 +211,8 @@ static int malloc_freeprot; | |||
| 211 | 211 | ||
| 212 | /* use guard pages after allocations? */ | 212 | /* use guard pages after allocations? */ |
| 213 | static int malloc_guard = 0; | 213 | static int malloc_guard = 0; |
| 214 | /* align pointers to end of page? */ | ||
| 215 | static int malloc_ptrguard; | ||
| 214 | 216 | ||
| 215 | #if defined(__FreeBSD__) || (defined(__OpenBSD__) && defined(MADV_FREE)) | 217 | #if defined(__FreeBSD__) || (defined(__OpenBSD__) && defined(MADV_FREE)) |
| 216 | /* pass the kernel a hint on free pages ? */ | 218 | /* pass the kernel a hint on free pages ? */ |
| @@ -612,6 +614,8 @@ malloc_init(void) | |||
| 612 | case 'J': malloc_junk = 1; break; | 614 | case 'J': malloc_junk = 1; break; |
| 613 | case 'n': malloc_silent = 0; break; | 615 | case 'n': malloc_silent = 0; break; |
| 614 | case 'N': malloc_silent = 1; break; | 616 | case 'N': malloc_silent = 1; break; |
| 617 | case 'p': malloc_ptrguard = 0; break; | ||
| 618 | case 'P': malloc_ptrguard = 1; break; | ||
| 615 | case 'r': malloc_realloc = 0; break; | 619 | case 'r': malloc_realloc = 0; break; |
| 616 | case 'R': malloc_realloc = 1; break; | 620 | case 'R': malloc_realloc = 1; break; |
| 617 | #ifdef __FreeBSD__ | 621 | #ifdef __FreeBSD__ |
| @@ -1082,7 +1086,7 @@ imalloc(size_t size) | |||
| 1082 | if (suicide) | 1086 | if (suicide) |
| 1083 | abort(); | 1087 | abort(); |
| 1084 | 1088 | ||
| 1085 | if (malloc_guard && size == PTR_SIZE) { | 1089 | if (malloc_ptrguard && size == PTR_SIZE) { |
| 1086 | ptralloc = 1; | 1090 | ptralloc = 1; |
| 1087 | size = malloc_pagesize; | 1091 | size = malloc_pagesize; |
| 1088 | } | 1092 | } |
| @@ -1128,7 +1132,7 @@ irealloc(void *ptr, size_t size) | |||
| 1128 | return (NULL); | 1132 | return (NULL); |
| 1129 | } | 1133 | } |
| 1130 | 1134 | ||
| 1131 | if (malloc_guard && PTR_ALIGNED(ptr)) { | 1135 | if (malloc_ptrguard && PTR_ALIGNED(ptr)) { |
| 1132 | if (size <= PTR_SIZE) | 1136 | if (size <= PTR_SIZE) |
| 1133 | return (ptr); | 1137 | return (ptr); |
| 1134 | else { | 1138 | else { |
| @@ -1602,7 +1606,7 @@ ifree(void *ptr) | |||
| 1602 | if (suicide) | 1606 | if (suicide) |
| 1603 | return; | 1607 | return; |
| 1604 | 1608 | ||
| 1605 | if (malloc_guard && PTR_ALIGNED(ptr)) | 1609 | if (malloc_ptrguard && PTR_ALIGNED(ptr)) |
| 1606 | ptr = (char *)ptr - PTR_GAP; | 1610 | ptr = (char *)ptr - PTR_GAP; |
| 1607 | 1611 | ||
| 1608 | index = ptr2index(ptr); | 1612 | index = ptr2index(ptr); |
