From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 07F273857357; Fri, 24 Jun 2022 01:26:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07F273857357 From: "russkubik at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug malloc/29283] New: assert when ptrace(PTRACE_POKEDATA) on allocated buffer Date: Fri, 24 Jun 2022 01:26:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: malloc X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: russkubik at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 01:26:09 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29283 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=3D14165&action=3Ded= it 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 =3D=3D initial_top = (av) && old_size =3D=3D 0) || ((unsigned long) (old_size) >=3D MINSIZE && p= rev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) =3D=3D 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 =3D=3D malloc usable size, an assert: ``` $ BUFSIZ=3D72 ./tracer 0x5555555592a0 ./tracee tracee: malloc.c:2617: sysmalloc: Assertion `(old_top =3D=3D initial_top (a= v) && old_size =3D=3D 0) || ((unsigned long) (old_size) >=3D MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) =3D=3D 0)' failed. $ BUFSIZ=3D80 ./tracer 0x5555555592a0 ./tracee buf: 0x5555555592a0 tracee: malloc.c:2617: sysmalloc: Assertion `(old_top =3D=3D initial_top (a= v) && old_size =3D=3D 0) || ((unsigned long) (old_size) >=3D MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) =3D=3D 0)' failed. ``` When requested size !=3D malloc usable size (ie. we have padding at the end= ), all is well: ``` $ BUFSIZ=3D71 ./tracer 0x5555555592a0 ./tracee buf: 0x5555555592a0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA000000 $ BUFSIZ=3D73 ./tracer 0x5555555592a0 ./tracee buf: 0x5555555592a0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA00 ``` This does not appear to be an issue with jemalloc (used as a sanity test): ``` $ BUFSIZ=3D72 LD_PRELOAD=3D/usr/lib/x86_64-linux-gnu/libjemalloc.so ./tracer 0x7ffff721e000 ./tracee buf: 0x7ffff721e000 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ``` Any insight appreciated, thx. --=20 You are receiving this mail because: You are on the CC list for the bug.=