public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29444] New: gmon memory corruption due wrong calculation of required buffer size
@ 2022-08-03 17:30 leo at yuriev dot ru
  2022-08-03 17:32 ` [Bug libc/29444] " leo at yuriev dot ru
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: leo at yuriev dot ru @ 2022-08-03 17:30 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 29444
           Summary: gmon memory corruption due wrong calculation of
                    required buffer size
           Product: glibc
           Version: 2.38
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: leo at yuriev dot ru
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

The `__monstartup()` allocates a buffer used to store all the data accumulated
by the monitor.

The size of this buffer depends on the size of the internal structures used and
the address range for which the monitor is activated, as well as on the maximum
density of call instuctions and/or callable functions that could be potentially
on a segment of executable code.

In particular a hash table of arcs is placed at the end of this buffer. The
size of this hash table is calculated in bytes as `p->fromssize = p->textsize /
HASHFRACTION`, but actually should be `p->fromssize = ROUNDUP(p->textsize /
HASHFRACTION, sizeof(*p->froms))`.

This results in writing beyond the end of the allocated buffer when an added
arc corresponds to a call near from the end of the monitored address range,
since `_mcount()` check the incoming caller address for monitored range but not
the intermediate result hash-like index that uses to write into the table.

It should be noted that when the results are output to `gmon.out`, the table is
read to the last element calculated from the allocated size in bytes, so the
arcs stored outside the buffer boundary did not fall into `gprof` for analysis.
Thus  this "feature" help me to found this bug during working with Bug 29438.

Another minor error seems a related typo in the calculation of `kcountsize`.

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

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

end of thread, other threads:[~2023-03-07  4:30 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 17:30 [Bug libc/29444] New: gmon memory corruption due wrong calculation of required buffer size leo at yuriev dot ru
2022-08-03 17:32 ` [Bug libc/29444] " leo at yuriev dot ru
2022-08-03 20:10 ` leo at yuriev dot ru
2022-12-16 19:56 ` pinskia at gcc dot gnu.org
2023-01-30 12:38 ` leo at yuriev dot ru
2023-01-30 16:24 ` adhemerval.zanella at linaro dot org
2023-02-04 12:12 ` leo at yuriev dot ru
2023-02-06 17:43 ` leo at yuriev dot ru
2023-02-06 19:29 ` leo at yuriev dot ru
2023-02-07  6:30 ` fweimer at redhat dot com
2023-02-07  8:40 ` ismail at i10z dot com
2023-02-07  8:41 ` fweimer at redhat dot com
2023-02-07  9:32 ` leo at yuriev dot ru
2023-02-07 15:00 ` siddhesh at sourceware dot org
2023-02-07 15:57 ` leo at yuriev dot ru
2023-02-07 16:01 ` siddhesh at sourceware dot org
2023-02-08 11:18 ` leo at yuriev dot ru
2023-02-08 11:51 ` siddhesh at sourceware dot org
2023-02-08 12:03 ` leo at yuriev dot ru
2023-02-08 13:00 ` siddhesh at sourceware dot org
2023-02-09 22:05 ` carnil at debian dot org
2023-02-09 22:27 ` siddhesh at sourceware dot org
2023-02-20 13:18 ` jamborm at gcc dot gnu.org
2023-02-23  7:36 ` leo at yuriev dot ru
2023-02-23 18:13 ` dj at redhat dot com
2023-03-04 10:44 ` linzhuorong at huawei dot com
2023-03-07  4:30 ` dj 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).