public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] i386: Check invalid (%dx) usage
Date: Fri, 11 Nov 2022 08:55:47 +0100	[thread overview]
Message-ID: <443cb5bb-880b-5999-1fb5-b2507cb79cd2@suse.com> (raw)
In-Reply-To: <CAMe9rOr=t0Z9FZHJ4s-NvCw3FR5HQ2E1eRgPmsjb8nSLcw8HKQ@mail.gmail.com>

On 10.11.2022 18:22, H.J. Lu wrote:
> On Wed, Nov 9, 2022 at 11:21 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 09.11.2022 21:24, H.J. Lu wrote:
>>> On Tue, Nov 8, 2022 at 11:21 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>
>>>> On 08.11.2022 22:06, H.J. Lu wrote:
>>>>> On Mon, Nov 7, 2022 at 11:34 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>>> On 07.11.2022 20:58, H.J. Lu wrote:
>>>>>>> On Mon, Nov 7, 2022 at 3:44 AM Jan Beulich <jbeulich@suse.com> wrote:
>>>>>>>> x86: restrict use of (%dx)
>>>>>>>>
>>>>>>>> PR gas/29751
>>>>>>>> The AT&T mode special case operand (%dx) is valid to use only with
>>>>>>>> instructions nominally expecting %dx to specify an I/O port address.
>>>>>>>> Prefix the respective checking with an opcode check. Keep that as
>>>>>>>> simple as possible by recognizing that opcodes 0x64 and 0x66 (which
>>>>>>>
>>>>>>> Since current_templates doesn't point to the matched instruction,
>>>>>>> checking current_templates looks like abuse.  I don't think error
>>>>>>> messages should be a concern here.
>>>>>>
>>>>>> We use current_templates in similar ways in quite a number of places,
>>>>>> when match_templates() hasn't run yet.
>>>>>
>>>>> Since the first template isn't the selected one, your check allows
>>>>> the invalid opcodes.
>>>>
>>>> I guess I don't understand, but I guess I'll also give up. Which
>>>
>>> Your proposed change does
>>>
>>> current_templates->start->base_opcode | 0x8a) == 0xee
>>>
>>> to allow opcode 0xe4 and (%dx) is allowed for non-I/O opcodes.
>>
>> 0xe4 is very much an I/O opcode, merely one not allowing for (%dx).
> 
> But it also matches other opcodes.

Let's enumerate them all:

0x64	gs: prefix
0x66	data prefix
0x6c	ins
0x6e	outs
0xe4	in
0xe6	out
0xec	in
0xee	out

As said in the description: "opcodes 0x64 and 0x66 (which wrongly also
match the check) encode prefixes, which hence - even if used standalone -
don't take any operands, so match_template() will fail there for other
reasons."

Jan

      reply	other threads:[~2022-11-11  7:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 20:55 H.J. Lu
2022-11-07  9:55 ` Jan Beulich
2022-11-07 11:44   ` Jan Beulich
2022-11-07 19:58     ` H.J. Lu
2022-11-08  7:34       ` Jan Beulich
2022-11-08 21:06         ` H.J. Lu
2022-11-09  7:21           ` Jan Beulich
2022-11-09 20:24             ` H.J. Lu
2022-11-10  7:21               ` Jan Beulich
2022-11-10 17:22                 ` H.J. Lu
2022-11-11  7:55                   ` Jan Beulich [this message]

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=443cb5bb-880b-5999-1fb5-b2507cb79cd2@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.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).