diff options
| author | otto <> | 2023-06-04 06:58:33 +0000 |
|---|---|---|
| committer | otto <> | 2023-06-04 06:58:33 +0000 |
| commit | 2a8b47d0250685d7abc14fa96be74d04d0b8c8ec (patch) | |
| tree | 658d7037f67b98a6598726569c6933ca718927f6 /src/regress/lib/libc | |
| parent | 7819892ebb6ce6589ed0a5ef4e5079e4219f9df2 (diff) | |
| download | openbsd-2a8b47d0250685d7abc14fa96be74d04d0b8c8ec.tar.gz openbsd-2a8b47d0250685d7abc14fa96be74d04d0b8c8ec.tar.bz2 openbsd-2a8b47d0250685d7abc14fa96be74d04d0b8c8ec.zip | |
More thorough write-afetr-free checks.
On free, chunks (the pieces of a pages used for smaller allocations)
are junked and then validated after they leave the delayed free
list. So after free, a chunk always contains junk bytes. This means
that if we start with the right contents for a new page of chunks,
we can *validate* instead of *write* junk bytes when (re)-using a
chunk.
With this, we can detect write-after-free when a chunk is recycled,
not justy when a chunk is in the delayed free list. We do a little
bit more work on initial allocation of a page of chunks and when
re-using (as we validate now even on junk level 1).
Also: some extra consistency checks for recallocaray(3) and fixes
in error messages to make them more consistent, with man page bits.
Plus regress additions.
Diffstat (limited to 'src/regress/lib/libc')
| -rw-r--r-- | src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c index e0efb6ebf3..6040590a65 100644 --- a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c +++ b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc_errs.c,v 1.2 2023/05/09 19:07:37 otto Exp $ */ | 1 | /* $OpenBSD: malloc_errs.c,v 1.3 2023/06/04 06:58:33 otto Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net> |
| 4 | * | 4 | * |
| @@ -138,9 +138,7 @@ t8(void) | |||
| 138 | void | 138 | void |
| 139 | t9(void) | 139 | t9(void) |
| 140 | { | 140 | { |
| 141 | char *p; | 141 | char *p = malloc(100); |
| 142 | |||
| 143 | p = malloc(100); | ||
| 144 | p[100] = 0; | 142 | p[100] = 0; |
| 145 | free(p); | 143 | free(p); |
| 146 | } | 144 | } |
| @@ -191,7 +189,6 @@ t15(void) | |||
| 191 | void | 189 | void |
| 192 | t16(void) | 190 | t16(void) |
| 193 | { | 191 | { |
| 194 | abort(); /* not yet */ | ||
| 195 | char *p = recallocarray(NULL, 0, 16, 1); | 192 | char *p = recallocarray(NULL, 0, 16, 1); |
| 196 | char *q = recallocarray(p, 2, 3, 16); | 193 | char *q = recallocarray(p, 2, 3, 16); |
| 197 | } | 194 | } |
| @@ -208,11 +205,27 @@ t17(void) | |||
| 208 | void | 205 | void |
| 209 | t18(void) | 206 | t18(void) |
| 210 | { | 207 | { |
| 211 | abort(); /* not yet */ | ||
| 212 | char *p = recallocarray(NULL, 0, 1, getpagesize()); | 208 | char *p = recallocarray(NULL, 0, 1, getpagesize()); |
| 213 | char *q = recallocarray(p, 2, 3, getpagesize()); | 209 | char *q = recallocarray(p, 2, 3, getpagesize()); |
| 214 | } | 210 | } |
| 215 | 211 | ||
| 212 | /* recallocarray with wrong size, pages */ | ||
| 213 | void | ||
| 214 | t19(void) | ||
| 215 | { | ||
| 216 | char *p = recallocarray(NULL, 0, 1, 10 * getpagesize()); | ||
| 217 | char *q = recallocarray(p, 1, 2, 4 * getpagesize()); | ||
| 218 | } | ||
| 219 | |||
| 220 | /* canary check pages */ | ||
| 221 | void | ||
| 222 | t20(void) | ||
| 223 | { | ||
| 224 | char *p = malloc(2*getpagesize() - 100); | ||
| 225 | p[2*getpagesize() - 100] = 0; | ||
| 226 | free(p); | ||
| 227 | } | ||
| 228 | |||
| 216 | struct test { | 229 | struct test { |
| 217 | void (*test)(void); | 230 | void (*test)(void); |
| 218 | const char *flags; | 231 | const char *flags; |
| @@ -238,6 +251,8 @@ struct test tests[] = { | |||
| 238 | { t16, "" }, | 251 | { t16, "" }, |
| 239 | { t17, "C" }, | 252 | { t17, "C" }, |
| 240 | { t18, "" }, | 253 | { t18, "" }, |
| 254 | { t19, "" }, | ||
| 255 | { t20, "C" }, | ||
| 241 | }; | 256 | }; |
| 242 | 257 | ||
| 243 | int main(int argc, char *argv[]) | 258 | int main(int argc, char *argv[]) |
