public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "milod2048 at gmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug malloc/29709] New: malloc: inappropriate allocation retry when exceeding sane request sizes Date: Thu, 20 Oct 2022 17:06:05 +0000 [thread overview] Message-ID: <bug-29709-131@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=29709 Bug ID: 29709 Summary: malloc: inappropriate allocation retry when exceeding sane request sizes Product: glibc Version: 2.36 Status: UNCONFIRMED Severity: minor Priority: P2 Component: malloc Assignee: unassigned at sourceware dot org Reporter: milod2048 at gmail dot com Target Milestone: --- version: master 10/17/2022 02:00 PM (MESZ) h/b/t: x86_64-pc-linux-gnu configure options: --prefix=$(pwd)/install/ --disable-experimental-malloc kernel: Linux cbox 5.19.14-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 5 21:31:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux gcc version: gcc version 12.2.1 20220819 (Red Hat 12.2.1-2) (GCC) ld version: GNU ld version 2.37-36.fc36 A rather minor issue, but consider following scenario: A multithreaded process is linked against a build of glibc without tcache support (--disable-experimental-malloc) and makes a request for an invalid amount of memory (i.e. greater than PTRDIFF_MAX) to __libc_malloc. This would result in a failure within _int_malloc due to the sanity checks implemented in checked_request2size (req > PTRDIFF_MAX) and _int_malloc would return NULL. This in turn leads to a second allocation attempt within __libc_malloc, but this time with a different arena, which does not make much sense. A retry with a different arena wont result in a successful allocation since previous failure was not caused by the arena but the invalid argument to __libc_malloc. And an invalid request will never be serviced by malloc, therefore we can skip the call to arena_get_retry plus the second allocation attempt. This behavior can also be found in the __libc_memalign function. Proposal: Differentiate between allocation failure due to actual memory shortage and allocation failure due to an invalid memory request. A second attempt should only be made if the request size is reasonable. This would prevent malloc from unnecessarily switching/creating arenas. I have already prepared a patch which should fix this minor issue. -- You are receiving this mail because: You are on the CC list for the bug.
reply other threads:[~2022-10-20 17:06 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-29709-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).