diff options
author | otto <> | 2023-06-04 06:58:33 +0000 |
---|---|---|
committer | otto <> | 2023-06-04 06:58:33 +0000 |
commit | 359dbb8e7485c66a6707470ce9d5af0ddbbff9f8 (patch) | |
tree | 658d7037f67b98a6598726569c6933ca718927f6 /src/lib/libc/stdlib/malloc.3 | |
parent | 2cbf6fb83a2b98d0b6ffbb161bcc85c81e5f2b59 (diff) | |
download | openbsd-359dbb8e7485c66a6707470ce9d5af0ddbbff9f8.tar.gz openbsd-359dbb8e7485c66a6707470ce9d5af0ddbbff9f8.tar.bz2 openbsd-359dbb8e7485c66a6707470ce9d5af0ddbbff9f8.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/lib/libc/stdlib/malloc.3')
-rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 4957591eef..d893626051 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
@@ -30,9 +30,9 @@ | |||
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.132 2023/04/17 05:45:06 jmc Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.133 2023/06/04 06:58:33 otto Exp $ |
34 | .\" | 34 | .\" |
35 | .Dd $Mdocdate: April 17 2023 $ | 35 | .Dd $Mdocdate: June 4 2023 $ |
36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
37 | .Os | 37 | .Os |
38 | .Sh NAME | 38 | .Sh NAME |
@@ -314,7 +314,7 @@ Increase the junk level by one if it is smaller than 2. | |||
314 | Decrease the junk level by one if it is larger than 0. | 314 | Decrease the junk level by one if it is larger than 0. |
315 | Junking writes some junk bytes into the area allocated. | 315 | Junking writes some junk bytes into the area allocated. |
316 | Junk is bytes of 0xdb when allocating; | 316 | Junk is bytes of 0xdb when allocating; |
317 | freed chunks are filled with 0xdf. | 317 | freed allocations are filled with 0xdf. |
318 | By default the junk level is 1: after free, | 318 | By default the junk level is 1: after free, |
319 | small chunks are completely junked; | 319 | small chunks are completely junked; |
320 | for pages the first part is junked. | 320 | for pages the first part is junked. |
@@ -628,22 +628,24 @@ An attempt to | |||
628 | .Fn free | 628 | .Fn free |
629 | or | 629 | or |
630 | reallocate an unallocated pointer was made. | 630 | reallocate an unallocated pointer was made. |
631 | .It Dq chunk is already free | 631 | .It Dq double free |
632 | There was an attempt to free a chunk that had already been freed. | 632 | There was an attempt to free an allocation that had already been freed. |
633 | .It Dq write after free | 633 | .It Dq write after free |
634 | A chunk has been modified after it was freed. | 634 | An allocation has been modified after it was freed. |
635 | .It Dq modified chunk-pointer | 635 | .It Dq modified chunk-pointer |
636 | The pointer passed to | 636 | The pointer passed to |
637 | .Fn free | 637 | .Fn free |
638 | or a reallocation function has been modified. | 638 | or a reallocation function has been modified. |
639 | .It Dq chunk canary corrupted address offset@length | 639 | .It Dq canary corrupted address offset@length |
640 | A byte after the requested size has been overwritten, | 640 | A byte after the requested size has been overwritten, |
641 | indicating a heap overflow. | 641 | indicating a heap overflow. |
642 | The offset at which corruption was detected is printed before the @, | 642 | The offset at which corruption was detected is printed before the @, |
643 | and the requested length of the allocation after the @. | 643 | and the requested length of the allocation after the @. |
644 | .It Dq recorded old size oldsize != size | 644 | .It Dq recorded size oldsize inconsistent with size |
645 | .Fn recallocarray | 645 | .Fn recallocarray |
646 | has detected that the given old size does not equal the recorded size in its | 646 | or |
647 | .Fn freezero | ||
648 | has detected that the given old size does not match the recorded size in its | ||
647 | meta data. | 649 | meta data. |
648 | Enabling option | 650 | Enabling option |
649 | .Cm C | 651 | .Cm C |