public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug malloc/29283] New: assert when ptrace(PTRACE_POKEDATA) on allocated buffer
@ 2022-06-24  1:26 russkubik at gmail dot com
  2022-06-24  1:26 ` [Bug malloc/29283] " russkubik at gmail dot com
  2022-06-24  7:22 ` fweimer at redhat dot com
  0 siblings, 2 replies; 3+ messages in thread
From: russkubik at gmail dot com @ 2022-06-24  1:26 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29283

            Bug ID: 29283
           Summary: assert when ptrace(PTRACE_POKEDATA) on allocated
                    buffer
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: malloc
          Assignee: unassigned at sourceware dot org
          Reporter: russkubik at gmail dot com
  Target Milestone: ---

Created attachment 14165
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14165&action=edit
tracer.c

I am seeing an assert when a program that is set up to ptrace a child uses
ptrace(PTRACE_POKEDATA) to modify the contents of the child process' malloc
allocated buffer.

> tracee: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.

This only seems to occur if the buffer size that the tracee program requests
from malloc matches the usable size reported by malloc_usable_size.

Reproducer (x86-64 specific):

```
$ gcc -o tracee tracee.c
$ gcc -o tracer tracer.c
```

Locate the starting heap address for programs when address randomization is
disabled and provide that as an argument to the tracer program.

When requested size == malloc usable size, an assert:

```
$ BUFSIZ=72 ./tracer 0x5555555592a0 ./tracee
tracee: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) &&
old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse
(old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.

$ BUFSIZ=80 ./tracer 0x5555555592a0 ./tracee
buf: 0x5555555592a0
tracee: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) &&
old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse
(old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
```

When requested size != malloc usable size (ie. we have padding at the end), all
is well:

```
$ BUFSIZ=71 ./tracer 0x5555555592a0 ./tracee
buf: 0x5555555592a0
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA000000

$ BUFSIZ=73 ./tracer 0x5555555592a0 ./tracee
buf: 0x5555555592a0
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA00
```

This does not appear to be an issue with jemalloc (used as a sanity test):

```
$ BUFSIZ=72 LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so ./tracer
0x7ffff721e000 ./tracee
buf: 0x7ffff721e000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
```

Any insight appreciated, thx.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-24  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24  1:26 [Bug malloc/29283] New: assert when ptrace(PTRACE_POKEDATA) on allocated buffer russkubik at gmail dot com
2022-06-24  1:26 ` [Bug malloc/29283] " russkubik at gmail dot com
2022-06-24  7:22 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).