public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
Cc: Jan Beulich <jbeulich@suse.com>, Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] opcodes/i386-dis.c is not thread-safe
Date: Wed, 5 Jan 2022 11:47:01 -0800	[thread overview]
Message-ID: <CAMe9rOofuBqNuWufwp0dumAAdPVvNCtZPHN+4rdL055jjPZecw@mail.gmail.com> (raw)
In-Reply-To: <3908cc3e-9df0-8413-b4c4-a125f783b670@oracle.com>

On Wed, Jan 5, 2022 at 11:19 AM Vladimir Mezentsev via Binutils
<binutils@sourceware.org> wrote:
>
>
>
> On 1/5/22 03:42, Jan Beulich wrote:
> > On 05.01.2022 08:07, Vladimir Mezentsev via Binutils wrote:
> >> From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
> >>
> >> We plan to use print_insn_i386_att, print_insn_i386_intel and
> >> print_insn_i386 in a multithreaded application.
> >> These functions are not thread safe due to the use of static variables.
> >>
> >> Tested on x86_64-pc-linux-gnu.
> >>
> >> opcodes/ChangeLog:
> >> 2022-01-04 Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
> >>
> >>      * opcodes/i386-dis.c: Make print_insn_i386_att, print_insn_i386_intel
> >>      and print_insn_i386 thread-safe
> > While I appreciate this step, I don't think the result is quite thread-
> > safe yet.
>
>   Why ?
>
>
> >   In particular the various abort() invocations aren't going to
> > play well with a multi-threaded consumer of the library. And we know
> > that there have been bugs in this area, i.e. where abort() would have
> > got triggered by certain invalid encodings;
>
> It is a real bug if we see abort() in one thread application.
>
> But in a multi-threaded application, the problem is very easy to reproduce.
> The problem is the shared variables are used in opcodes/i386-dis.c
> without synchronization.
> For example:
>
> % grep -n need_modrm i386-dis.c
> 2404:static unsigned char need_modrm; <<<<<< the static shared variable
> 2439:#define MODRM_CHECK  if (!need_modrm) abort () <<<<<< Can be
> abort() because need_modrm was reset for the other instruction.
> 9682:      need_modrm = twobyte_has_modrm[threebyte];         <<<<<<
> Settings for two byte instruction
> 9688:      need_modrm = onebyte_has_modrm[*codep];<<<<<< Settings for
> the other instruction
>
>
>
> -Vladimir
>
> >   I'm pretty certain we haven't
> > found (and eliminated) all of them just yet.
> >
> > Jan
> >

Hi, Vladimir,

Please check it in.

Thanks.

-- 
H.J.

  reply	other threads:[~2022-01-05 19:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  7:07 vladimir.mezentsev
2022-01-05 11:42 ` Jan Beulich
2022-01-05 15:53   ` H.J. Lu
2022-01-05 19:19   ` Vladimir Mezentsev
2022-01-05 19:47     ` H.J. Lu [this message]
2022-01-06 12:47     ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2021-12-20 23:04 vladimir.mezentsev
2022-01-04 17:38 ` Vladimir Mezentsev
2022-01-04 17:47   ` H.J. Lu
2022-01-05  6:54     ` Vladimir Mezentsev
2021-12-16 22:26 vladimir.mezentsev
2021-12-17  7:24 ` Jan Beulich
2021-12-17 23:23   ` Vladimir Mezentsev

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=CAMe9rOofuBqNuWufwp0dumAAdPVvNCtZPHN+4rdL055jjPZecw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=vladimir.mezentsev@oracle.com \
    /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).