From: H.J. Lu <hjl@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] bfd: Munmap readonly memory after bfd_free_cached_info
Date: Fri, 5 Apr 2024 01:53:28 +0000 (GMT) [thread overview]
Message-ID: <20240405015328.1DF1C3858C32@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=37eac4810b66f165ed5bb837ac36c0eb9baba727
commit 37eac4810b66f165ed5bb837ac36c0eb9baba727
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Thu Apr 4 18:05:57 2024 -0700
bfd: Munmap readonly memory after bfd_free_cached_info
Munmap readonly memory after bfd_free_cached_info which may use munmapped
readonly memory.
PR ld/31608
* opncls.c (_bfd_delete_bfd): Munmap readonly memory after
bfd_free_cached_info.
Diff:
---
bfd/opncls.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 5efec37175e..2f8a3a6c919 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -172,16 +172,6 @@ _bfd_delete_bfd (bfd *abfd)
munmap (elf_section_data (sec)->contents_addr,
elf_section_data (sec)->contents_size);
}
-
- struct bfd_mmapped *mmapped, *next;
- for (mmapped = abfd->mmapped; mmapped != NULL; mmapped = next)
- {
- struct bfd_mmapped_entry *entries = mmapped->entries;
- next = mmapped->next;
- for (unsigned int i = 0; i < mmapped->next_entry; i++)
- munmap (entries[i].addr, entries[i].size);
- munmap (mmapped, _bfd_pagesize);
- }
#endif
/* Give the target _bfd_free_cached_info a chance to free memory. */
@@ -197,6 +187,18 @@ _bfd_delete_bfd (bfd *abfd)
else
free ((char *) bfd_get_filename (abfd));
+#ifdef USE_MMAP
+ struct bfd_mmapped *mmapped, *next;
+ for (mmapped = abfd->mmapped; mmapped != NULL; mmapped = next)
+ {
+ struct bfd_mmapped_entry *entries = mmapped->entries;
+ next = mmapped->next;
+ for (unsigned int i = 0; i < mmapped->next_entry; i++)
+ munmap (entries[i].addr, entries[i].size);
+ munmap (mmapped, _bfd_pagesize);
+ }
+#endif
+
free (abfd->arelt_data);
free (abfd);
}
reply other threads:[~2024-04-05 1:53 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=20240405015328.1DF1C3858C32@sourceware.org \
--to=hjl@sourceware.org \
--cc=binutils-cvs@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: link
Be 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).