public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bfd: Munmap readonly memory after bfd_free_cached_info
@ 2024-04-05  1:05 H.J. Lu
  2024-04-05  1:35 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2024-04-05  1:05 UTC (permalink / raw)
  To: binutils; +Cc: amodra

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.
---
 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);
 }
-- 
2.44.0


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

* Re: [PATCH] bfd: Munmap readonly memory after bfd_free_cached_info
  2024-04-05  1:05 [PATCH] bfd: Munmap readonly memory after bfd_free_cached_info H.J. Lu
@ 2024-04-05  1:35 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-04-05  1:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Thu, Apr 04, 2024 at 06:05:57PM -0700, H.J. Lu wrote:
> 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.

OK.

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2024-04-05  1:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05  1:05 [PATCH] bfd: Munmap readonly memory after bfd_free_cached_info H.J. Lu
2024-04-05  1:35 ` Alan Modra

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).