From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id D3B2E3858432 for ; Mon, 7 Nov 2022 19:59:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3B2E3858432 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x630.google.com with SMTP id q9so33227801ejd.0 for ; Mon, 07 Nov 2022 11:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=W5mQGN+p0vdRLRQkCftqvLMUitUrhN+MXwQRu2UM9j0=; b=O8qj6o0Z2EEx+3FpuJZ8X1PXgEMLOjOVJgSADcbYrwf9PjZ0jFrrNyIo5wnnBrq/lO VXbdXY8GggxcEmFd0OoJLiM04SUJQS7FXMnLnRouuMFLFg3F5Q/RlghDh7Mk1fgU0N9h ASMcnLAO9ziqK/lF7uh/JUEU1/CXdTWTHpEO+LIC+T3a6LGGHRooGyM1bnlkfjmH2NG4 FwEjnR8KdiGq6y8WxBrFF1dpohMmdC/mla8Cl/PEnxGyI+5k3+ZGJDI2E+GP5eilay3m WpiaSZyZQo7qaEtrvsDEfxJq2FAuwkbNKwCcKrmcZgBsbeRQhsDF0rEiTPhonhAEajn7 niNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W5mQGN+p0vdRLRQkCftqvLMUitUrhN+MXwQRu2UM9j0=; b=kQAELXLHa38/vYyFgFm8REkIPh3VmBIj5OwhcbPHGmgi70CeJXWEkfgKocEz9S3Ydx VB2PJ7iD7BsK3vxZhneyNQqX2iJsC0xv3dImpBo8y0ngFKiajExCLNQeAYkH2IXoYLFQ VIladFbsD5rN9I/BUE1XFvA6i8ABK6ggN+OS8nPzRVmMg5zrs34YPWZrQsG27454Ih3k YiqGyUNRTtqhtKmG4hrIcoNOxGfrg0TOwUoyEKpG12j5oa6q75hsE/SpKDfSXksr8E5x mqd5PL6IVC9Pi7+VKi6uOL6bsLn8HQhg2cRgLO5STm3FD4or46r9fO8TERNsZ+cM5dJf HcVQ== X-Gm-Message-State: ACrzQf2xGoTegEmmvi9yO2TECIKAsyudpaMt0oHlT39aRlphBfegebL1 JwPZ3GutOVEbRC2dxrJ+TsEKHAJPBmC83mNCH1Gcc/AHBys= X-Google-Smtp-Source: AMsMyM6V3FgEhIkQ/er7O9qI9dOe0ipxX0+J19lEq0JCnxBRevSDjgOrY0WZjDBh2ECj2oJcrRVD0oI/yndWOWxtE5A= X-Received: by 2002:a17:906:dc8f:b0:7a5:8160:1995 with SMTP id cs15-20020a170906dc8f00b007a581601995mr49531765ejc.500.1667851157490; Mon, 07 Nov 2022 11:59:17 -0800 (PST) MIME-Version: 1.0 References: <20221104205547.3728827-1-hjl.tools@gmail.com> <781ed098-079c-212e-7e46-a375c27f5486@suse.com> <73b15165-8615-282a-560f-30049b1963a1@suse.com> In-Reply-To: <73b15165-8615-282a-560f-30049b1963a1@suse.com> From: "H.J. Lu" Date: Mon, 7 Nov 2022 11:58:38 -0800 Message-ID: Subject: Re: [PATCH] i386: Check invalid (%dx) usage To: Jan Beulich Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3017.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Nov 7, 2022 at 3:44 AM Jan Beulich wrote: > > On 07.11.2022 10:55, Jan Beulich via Binutils wrote: > > On 04.11.2022 21:55, H.J. Lu via Binutils wrote: > >> (%dx) isn't a valid memory address in any modes. It is used as a special > >> memory operand for input/output port address in AT&T syntax and should > >> only be used with input/output instructions. Update i386_att_operand to > >> set i.input_output_operand to true for (%dx) and issue an error if (%dx) > >> is used with non-input/output instructions. > > > > Hmm, this shouldn't require a new flag I would hope. We did properly reject > > bad uses up to 2.31 ("operand type mismatch"). Whatever was broken there > > would need correcting instead, imo. A possible candidate looks to be > > 2fb5be8dac9d ("x86: drop {,reg16_}inoutportreg variables"), albeit perhaps > > combined with later changes - in 2.33 behavior changed again. > > What about the change below, perhaps combined with your testsuite adjustments > (albeit I'd like to point out that "incl" isn't the best choice, as %dx is Since incl is misassembled, it is a good test. > invalid with that anyway; "incw" would be better)? That way we'll uniformly > get "`(%dx)' is not a valid base/index expression" for bad uses of (%dx), > matching any other uses of wrong addressing forms. > > Jan > > 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. > 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. > > While there also complete the transformation from memory to register I prefer to keep it ASIS since the lack of the transformation helped catch this error. > operand: The lack thereof was responsible for SEGV when (%dx) was > (wrongly) used with certain insns. > > --- a/gas/config/tc-i386.c > +++ b/gas/config/tc-i386.c > @@ -11884,7 +11884,9 @@ i386_att_operand (char *operand_string) > } > > /* Special case for (%dx) while doing input/output op. */ > - if (i.base_reg > + if ((current_templates->start->base_opcode | 0x8a) == 0xee > + && current_templates->start->opcode_modifier.opcodespace == SPACE_BASE > + && i.base_reg > && i.base_reg->reg_type.bitfield.instance == RegD > && i.base_reg->reg_type.bitfield.word > && i.index_reg == 0 > @@ -11893,6 +11895,8 @@ i386_att_operand (char *operand_string) > && !operand_type_check (i.types[this_operand], disp)) > { > i.types[this_operand] = i.base_reg->reg_type; > + i.op[this_operand].regs = i.base_reg; > + i.reg_operands++; > return 1; > } > > > -- H.J.