summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
authorotto <>2023-06-04 06:58:33 +0000
committerotto <>2023-06-04 06:58:33 +0000
commit359dbb8e7485c66a6707470ce9d5af0ddbbff9f8 (patch)
tree658d7037f67b98a6598726569c6933ca718927f6 /src/lib/libc/stdlib/malloc.3
parent2cbf6fb83a2b98d0b6ffbb161bcc85c81e5f2b59 (diff)
downloadopenbsd-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.320
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.
314Decrease the junk level by one if it is larger than 0. 314Decrease the junk level by one if it is larger than 0.
315Junking writes some junk bytes into the area allocated. 315Junking writes some junk bytes into the area allocated.
316Junk is bytes of 0xdb when allocating; 316Junk is bytes of 0xdb when allocating;
317freed chunks are filled with 0xdf. 317freed allocations are filled with 0xdf.
318By default the junk level is 1: after free, 318By default the junk level is 1: after free,
319small chunks are completely junked; 319small chunks are completely junked;
320for pages the first part is junked. 320for pages the first part is junked.
@@ -628,22 +628,24 @@ An attempt to
628.Fn free 628.Fn free
629or 629or
630reallocate an unallocated pointer was made. 630reallocate an unallocated pointer was made.
631.It Dq chunk is already free 631.It Dq double free
632There was an attempt to free a chunk that had already been freed. 632There was an attempt to free an allocation that had already been freed.
633.It Dq write after free 633.It Dq write after free
634A chunk has been modified after it was freed. 634An allocation has been modified after it was freed.
635.It Dq modified chunk-pointer 635.It Dq modified chunk-pointer
636The pointer passed to 636The pointer passed to
637.Fn free 637.Fn free
638or a reallocation function has been modified. 638or a reallocation function has been modified.
639.It Dq chunk canary corrupted address offset@length 639.It Dq canary corrupted address offset@length
640A byte after the requested size has been overwritten, 640A byte after the requested size has been overwritten,
641indicating a heap overflow. 641indicating a heap overflow.
642The offset at which corruption was detected is printed before the @, 642The offset at which corruption was detected is printed before the @,
643and the requested length of the allocation after the @. 643and 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
646has detected that the given old size does not equal the recorded size in its 646or
647.Fn freezero
648has detected that the given old size does not match the recorded size in its
647meta data. 649meta data.
648Enabling option 650Enabling option
649.Cm C 651.Cm C