public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* strange segfault i386-dis.c:9815:28
@ 2023-03-17 10:41 Alan Modra
  2023-03-17 15:56 ` H.J. Lu
  2023-03-20  7:29 ` Jan Beulich
  0 siblings, 2 replies; 10+ messages in thread
From: Alan Modra @ 2023-03-17 10:41 UTC (permalink / raw)
  To: Jan Beulich, H.J. Lu; +Cc: binutils

Hi Jan, H.J.,
I'm seeing some really weird oss-fuzz reports of segfaults in
i386-dis.c.
https://oss-fuzz.com/testcase-detail/5870018505342976
https://oss-fuzz.com/testcase-detail/4651718416924672
https://oss-fuzz.com/testcase-detail/5452642448179200

I can't reproduce them locally, and don't have access to the binaries
to see exactly what is going on.  The problem may well turn out to be
a clang bug, but then there are these notes from the setjmp man page:

"Consequently, the values of automatic variables are unspecified after
a call to longjmp() if they meet all the following criteria:
  • they are local to the function that made the corresponding setjmp() call;
  • their values are changed between the calls to setjmp() and longjmp(); and
  • they are not declared as volatile."

Jan's commit 384e201e5aec made "ins" an auto var.  "priv" was already
an auto var.  It might be possible that one or more of the "ins" or
"priv" fields are living in non-volatile regs and thus have stale
values after the longjmp.  To cover that possibility, how about the
following patch?

	* i386-dis.c (print_insn): Access "ins" and "priv" via volatile
	pointers after second sigsetjmp return.

diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index a414e8c9b1e..9684dcda746 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -9808,12 +9808,17 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax)
       /* Getting here means we tried for data but didn't get it.  That
 	 means we have an incomplete instruction of some sort.  Just
 	 print the first byte as a prefix or a .byte pseudo-op.  */
-      if (ins.codep > priv.the_buffer)
+      volatile struct dis_private *ppriv = &priv;
+      volatile instr_info *pins = &ins;
+      if (pins->codep > ppriv->the_buffer)
 	{
 	  const char *name = NULL;
 
-	  if (ins.prefixes || ins.fwait_prefix >= 0 || (ins.rex & REX_OPCODE))
-	    name = prefix_name (&ins, priv.the_buffer[0], priv.orig_sizeflag);
+	  if (pins->prefixes
+	      || pins->fwait_prefix >= 0
+	      || (pins->rex & REX_OPCODE))
+	    name = prefix_name (&ins, ppriv->the_buffer[0],
+				ppriv->orig_sizeflag);
 	  if (name != NULL)
 	    i386_dis_printf (&ins, dis_style_mnemonic, "%s", name);
 	  else
@@ -9822,7 +9827,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax)
 	      i386_dis_printf (&ins, dis_style_assembler_directive,
 			       ".byte ");
 	      i386_dis_printf (&ins, dis_style_immediate, "0x%x",
-			       (unsigned int) priv.the_buffer[0]);
+			       (unsigned int) ppriv->the_buffer[0]);
 	    }
 
 	  return 1;

-- 
Alan Modra
Australia Development Lab, IBM

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 10:41 strange segfault i386-dis.c:9815:28 Alan Modra
2023-03-17 15:56 ` H.J. Lu
2023-03-17 17:09   ` Andreas Schwab
2023-03-19 22:44   ` Alan Modra
2023-03-20  7:29 ` Jan Beulich
2023-03-20  7:57   ` Alan Modra
2023-03-20 10:26     ` Alan Modra
2023-03-20 10:41       ` Jan Beulich
2023-03-23 12:59         ` Alan Modra
2023-04-04  7:03           ` Jan Beulich

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