From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id E55E43858C39 for ; Fri, 10 Sep 2021 08:27:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E55E43858C39 Received: by mail-pg1-x536.google.com with SMTP id w7so1131054pgk.13 for ; Fri, 10 Sep 2021 01:27:19 -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=LBKrIPYIZtY4EHNg4uyW8LmzET/GEDVFiy/esvLMc4Y=; b=a1Im4HNMzPykODc2Z2ljc6983rqzA7xYjXazqwSPKYKUN/8NZzuDUbp3XHnfuQDKjs CXFKTBa5ZnyunX0aF3IY+Cu8m3GQsHCo+4LoZxMi9B0QjdmZ0NC/shRkUTxGZH9lhemk UUnoxBBJeCpIcjBIeGoxgAVkK8igJRM7hXrEOfPZek1tFo5d/82tHA/Q7wZcwKjO2z+s t+2OyeIuvP+1dioVHB2WeUnkT3Nr58YMdHrd2cINez3RlQ5ul0Kkfjg8tKdxBo+juXG/ mM0KJaZTr5d2V89nvhGdGxo+ckWKy7ADDdH1b+77x57yqHV8xRvozdHhi5Z5Rkyymdux kkpA== X-Gm-Message-State: AOAM531I+xO4Q3z4Iss+Za6zFlEUbLmhZMUVVtvVMOe1Zv5Ymwe4KRNd fq+SfsaOaZRq3vFC8J/kdtk= X-Google-Smtp-Source: ABdhPJzSgMg2Q67jD6Ib13g+yofWSmki5JbShSGmK1hjSE1+KYmSEPh7KJ4HIACjK/pRs+NFty26cA== X-Received: by 2002:a05:6a00:2405:b0:3e1:9f65:9703 with SMTP id z5-20020a056a00240500b003e19f659703mr7168075pfh.6.1631262438943; Fri, 10 Sep 2021 01:27:18 -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 j123sm4567594pgc.77.2021.09.10.01.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 01:27:16 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 7C6251140086; Fri, 10 Sep 2021 17:57:12 +0930 (ACST) Date: Fri, 10 Sep 2021 17:57:12 +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.1 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 08:27:21 -0000 On Thu, Sep 09, 2021 at 11:44:38PM +0930, Alan Modra wrote: > On Thu, Sep 09, 2021 at 11:51:48AM +0200, Maciej W. Rozycki wrote: > > On Wed, 8 Sep 2021, Alan Modra wrote: > > > + /* ld -r or gas. */ > > > relocatable = (output_bfd != NULL); > > > > > > - if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) > > > + /* We only use bfd_reloc_offset_in_range for final linking because > > > + mips object files may use relocations that seem to access beyond > > > + section limits. gas/testsuite/gas/mips/dla-reloc.s is an example > > > + that puts R_MIPS_SUB, a 64-bit relocation, on the last > > > + instruction in the section. If final linking that object file > > > + the R_MIPS_SUB won't be processed here since it applies to the > > > + addend for the next reloc rather than the section contents. */ > > > + if (!relocatable > > > + && !bfd_reloc_offset_in_range (reloc_entry->howto, abfd, > > > + input_section, reloc_entry->address)) > > > return bfd_reloc_outofrange; > > > > Would a correct check be feasible here? For a composed relocation only > > the final entry is applied to output, so could we instead check if there > > is a follow-up relocation? > > 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. -- Alan Modra Australia Development Lab, IBM