From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 2CBBA3858C39 for ; Fri, 10 Sep 2021 11:01:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CBBA3858C39 Received: by mail-pg1-x52c.google.com with SMTP id g184so1459185pgc.6 for ; Fri, 10 Sep 2021 04:01:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=k1A8jPUs7gIFL61GpaEtKoA6H9ap0L7PnJhhQQXqBy4=; b=s14O627/E8y8YxpnOETE4yQueeKFLdvsjAQxr2HEDZudTAa97W2ZPGuszPoaBEHCa7 FNgm/ncUdmbGnvF9RaYebjBvj9kt486IekkSRjGpPez17+KK+yL323HXorC8pcB9BhPW nG5Q9Tq1+EcR4dT0diNE/jMS+IB0mcK2kc8dZ2DL+lHoLNCfeu4ui6BBXg+8LKappNb5 xcHkuTldNQ2HqUrTyVkp/xAvcostfnPcnu3fwax7KeLNKYMNVNUfCbkXXIfOJmM7wNMY JqHgJqx7531mk17KTsAVEKjtkrox+gtc81Ubmx2Dgy0nSjdmB5x0WyOEienmKKkgpKY9 Y9Pg== X-Gm-Message-State: AOAM530E+qQXfCdbAAZkfW5NOWIAdUJLtZuoJxrsiNA/v/k+0DmYqQcj Wd1f6g3dDizAnBFB+6EHZSo= X-Google-Smtp-Source: ABdhPJwaZQpTZlzQjeHmxrotf5siJyj9HHrgMYkhz8OhmT/ggg5MMVuhZ+PsaNGv2zMKY6PRq9wzUg== X-Received: by 2002:a63:9d0d:: with SMTP id i13mr6820651pgd.117.1631271698258; Fri, 10 Sep 2021 04:01:38 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id cl16sm4541546pjb.23.2021.09.10.04.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:01:18 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2E3391140069; Fri, 10 Sep 2021 20:31:06 +0930 (ACST) Date: Fri, 10 Sep 2021 20:31:06 +0930 From: Alan Modra To: "Maciej W. Rozycki" Cc: Chenghua Xu , binutils@sourceware.org Subject: Re: PR28306, segfault in _bfd_mips_elf_reloc_unshuffle Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3033.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2021 11:01:40 -0000 On Fri, Sep 10, 2021 at 11:50:04AM +0200, Maciej W. Rozycki wrote: > On Fri, 10 Sep 2021, Alan Modra wrote: > > > > I don't think there is any easy and safe way of doing that. Even > > > though there is a nice tidy array of NULL terminated arelent pointers, > > > the special_function doesn't see an arelent** but rather an arelent*. > > > > > > Hmm, how about replacing !relocatable above with > > > !(relocatable && !reloc_entry->howto->partial_inplace) ie. the > > > condition under which _bfd_mips_elf_generic_reloc writes section > > > contents? > > > > Testing revealed some fails > > mipsisa32r2el-elf +FAIL: MIPS reloc against local symbol overflow > > mipstx39-elf +FAIL: MIPS reloc against local symbol overflow > > > > The test in question puts a ".half" at the end of a section, with > > resultant R_MIPS_16, a 4 byte relocation, 2 bytes before the end of > > the section. I think the test should fail on these targets. With a > > very carefully crafted testcase it should be possible to cause a gas > > buffer overflow. > > Hmm, it looks to me like a bug in the implementation of the `.half' > pseudo-op (that it emits a 16-bit rather than a 32-bit data quantity with > R_MIPS_16 attached to the least significant halfword), but I'm not sure if > at this time of MIPS target's history it is safe to fix it. R_MIPS_16 is specified by the ABI to be the low 16-bits within a 32-bit word. That's a problem with .half as it is currently, since gas emits the R_MIPS_16 at the .half address if a reloc is needed. The result is that ld applies the relocation to the *next* halfword on big-endian mips targets. Effectively that means .half can only be used with constants. > I'll have to > chew it over a bit and I'll be travelling over the next couple of days > anyway, so I'll get back to this discussion after the weekend (including > the issue of `arelent*' vs `arelent**'). > > Maciej -- Alan Modra Australia Development Lab, IBM