public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* More ecoff sanity checks
@ 2023-02-15  6:06 Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2023-02-15  6:06 UTC (permalink / raw)
  To: binutils

Change FIX so that unused pointers that escape the UPDATE_RAW_END
sanity checks won't result in overflows.  Also sanity check the local
sym fdr isymBase and csym values.

	* ecoff.c (_bfd_ecoff_slurp_symbolic_info): Define FIX to set
	pointers into swapped internal data to NULL if count is zero.
	Sanity check local sym fdr_ptr->isymBase and fdr_ptr->csym.

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 7498766dd3f..1bea7005fee 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -579,25 +579,24 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
   ecoff_data (abfd)->raw_syments = raw;
 
   /* Get pointers for the numeric offsets in the HDRR structure.  */
-#define FIX(off1, off2, type)				\
-  if (internal_symhdr->off1 == 0)			\
-    debug->off2 = NULL;					\
-  else							\
-    debug->off2 = (type) ((char *) raw			\
-			  + (internal_symhdr->off1	\
-			     - raw_base))
-
-  FIX (cbLineOffset, line, unsigned char *);
-  FIX (cbDnOffset, external_dnr, void *);
-  FIX (cbPdOffset, external_pdr, void *);
-  FIX (cbSymOffset, external_sym, void *);
-  FIX (cbOptOffset, external_opt, void *);
-  FIX (cbAuxOffset, external_aux, union aux_ext *);
-  FIX (cbSsOffset, ss, char *);
-  FIX (cbSsExtOffset, ssext, char *);
-  FIX (cbFdOffset, external_fdr, void *);
-  FIX (cbRfdOffset, external_rfd, void *);
-  FIX (cbExtOffset, external_ext, void *);
+#define FIX(start, count, ptr, type) \
+  if (internal_symhdr->start == 0 || internal_symhdr->count == 0)	\
+    debug->ptr = NULL;							\
+  else									\
+    debug->ptr = (type) ((char *) raw					\
+			 + (internal_symhdr->start - raw_base))
+
+  FIX (cbLineOffset, cbLine, line, unsigned char *);
+  FIX (cbDnOffset, idnMax, external_dnr, void *);
+  FIX (cbPdOffset, ipdMax, external_pdr, void *);
+  FIX (cbSymOffset, isymMax, external_sym, void *);
+  FIX (cbOptOffset, ioptMax, external_opt, void *);
+  FIX (cbAuxOffset, iauxMax, external_aux, union aux_ext *);
+  FIX (cbSsOffset, issMax, ss, char *);
+  FIX (cbSsExtOffset, issExtMax, ssext, char *);
+  FIX (cbFdOffset, ifdMax, external_fdr, void *);
+  FIX (cbRfdOffset, crfd, external_rfd, void *);
+  FIX (cbExtOffset, iextMax, external_ext, void *);
 #undef FIX
 
   /* I don't want to always swap all the data, because it will just
@@ -932,7 +931,13 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
     {
       char *lraw_src;
       char *lraw_end;
+      HDRR *symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
 
+      if (fdr_ptr->isymBase < 0
+	  || fdr_ptr->isymBase > symhdr->isymMax
+	  || fdr_ptr->csym <= 0
+	  || fdr_ptr->csym > symhdr->isymMax - fdr_ptr->isymBase)
+	continue;
       lraw_src = ((char *) ecoff_data (abfd)->debug_info.external_sym
 		  + fdr_ptr->isymBase * external_sym_size);
       lraw_end = lraw_src + fdr_ptr->csym * external_sym_size;
@@ -944,7 +949,6 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
 
 	  (*swap_sym_in) (abfd, (void *) lraw_src, &internal_sym);
 
-	  HDRR *symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
 	  if (internal_sym.iss >= symhdr->issMax
 	      || internal_sym.iss < 0)
 	    {

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: More ecoff sanity checks
  2023-06-02  0:01 Alan Modra
@ 2023-06-03  8:04 ` Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2023-06-03  8:04 UTC (permalink / raw)
  To: binutils

Yet another fuzzer fix.

	* ecoff.c (ecoff_slurp_symbolic_header <FIX>): Zero counts when
	associated pointer is zero.
	(_bfd_ecoff_slurp_symbolic_info): Remove now unnecessary check.

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index f2930569f21..c4c2e530be0 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -468,6 +468,23 @@ ecoff_slurp_symbolic_header (bfd *abfd)
       goto error_return;
     }
 
+#define FIX(start, count) \
+  if (internal_symhdr->start == 0)	\
+    internal_symhdr->count = 0;
+
+  FIX (cbLineOffset, cbLine);
+  FIX (cbDnOffset, idnMax);
+  FIX (cbPdOffset, ipdMax);
+  FIX (cbSymOffset, isymMax);
+  FIX (cbOptOffset, ioptMax);
+  FIX (cbAuxOffset, iauxMax);
+  FIX (cbSsOffset, issMax);
+  FIX (cbSsExtOffset, issExtMax);
+  FIX (cbFdOffset, ifdMax);
+  FIX (cbRfdOffset, crfd);
+  FIX (cbExtOffset, iextMax);
+#undef FIX
+
   /* Now we can get the correct number of symbols.  */
   abfd->symcount = internal_symhdr->isymMax + internal_symhdr->iextMax;
 
@@ -580,7 +597,7 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
 
   /* Get pointers for the numeric offsets in the HDRR structure.  */
 #define FIX(start, count, ptr, type) \
-  if (internal_symhdr->start == 0 || internal_symhdr->count == 0)	\
+  if (internal_symhdr->count == 0)					\
     debug->ptr = NULL;							\
   else									\
     debug->ptr = (type) ((char *) raw					\

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: More ecoff sanity checks
@ 2023-06-02  0:01 Alan Modra
  2023-06-03  8:04 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2023-06-02  0:01 UTC (permalink / raw)
  To: binutils

Another fix for fuzzed object files, exhibiting as a segfault in
nm.c filter_symbols when accessing a symbol name.

	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Sanity check
	fdr_ptr->issBase, and tighten sym.iss check.

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 676b8d84017..f2930569f21 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -942,7 +942,9 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
       if (fdr_ptr->isymBase < 0
 	  || fdr_ptr->isymBase > symhdr->isymMax
 	  || fdr_ptr->csym <= 0
-	  || fdr_ptr->csym > symhdr->isymMax - fdr_ptr->isymBase)
+	  || fdr_ptr->csym > symhdr->isymMax - fdr_ptr->isymBase
+	  || fdr_ptr->issBase < 0
+	  || fdr_ptr->issBase > symhdr->issMax)
 	continue;
       lraw_src = ((char *) ecoff_data (abfd)->debug_info.external_sym
 		  + fdr_ptr->isymBase * external_sym_size);
@@ -955,7 +957,7 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
 
 	  (*swap_sym_in) (abfd, (void *) lraw_src, &internal_sym);
 
-	  if (internal_sym.iss >= symhdr->issMax
+	  if (internal_sym.iss >= symhdr->issMax - fdr_ptr->issBase
 	      || internal_sym.iss < 0)
 	    {
 	      bfd_set_error (bfd_error_bad_value);

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2023-06-03  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15  6:06 More ecoff sanity checks Alan Modra
2023-06-02  0:01 Alan Modra
2023-06-03  8:04 ` 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).