From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 053503855014 for ; Wed, 7 Jul 2021 20:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 053503855014 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=immunant.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=immunant.com Received: by mail-pf1-x42c.google.com with SMTP id f20so3320846pfa.1 for ; Wed, 07 Jul 2021 13:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=immunant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5kFjenXgTdDUsbYURYUZvZAS8p2c7NUu8+icUqXpz8I=; b=2Mq//gSrTKFH+FKrMdoHDDmeiZsynVj5C7Uu70bPkrwV4MdSqxTuQL/l0VyILiriIk ifv7wWD0Se1Wj3OCVQxtLkI2tpmNdD2rXOp7SzZJFxkuR5Rq5gr0ktwoeRM5qvwr2vwa VVYYhmhMny5Tu3zNFQ+IZmzUpM5B1ZRjoB+L67hfGcxB1Rb+o7CE6oXwCLCE8aNW9UrW 0PcdYXeEsB/sOKO+clD5msHbSteWS9TBLn8JiUk2AW3S0bZ1PiouBzDryk6+yS7olqaZ fveCokVz6+O3vHANqz7x+gnh6Lgy/ZiQtvESSUioTC5m5E7+9CvdCeOMARSTDOlicwTv zRig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5kFjenXgTdDUsbYURYUZvZAS8p2c7NUu8+icUqXpz8I=; b=lhcMyPu1rFCm6UnQCq6SjGB2mveAe41V304/H1T1gKH+4Z7CY1ZiAzqVx84HWswwnH rCirhRTF2RrTT1YmshY+Ydn1ZXMWi5GwDOIquuE/BIQGl4pQHgcLJeGzRNC4n+eyjILZ NWsSWgPJtpzpGXs5uvtqLCfOmzEivi7gLNrfW3oRJgWwKiICF0Siv4n+aQA7nXGUIJYD FsoA2OCx6EyAhIvDs2mhmkfRIgSwpVm06u63TvFrdXCEmhO84Rdcmay/789QrR5YncCt YFCAV0Pc8V3Eoyhdj87n9dI67pnKIzTepkWs6HdqgKlcm3FMBlIcs5M+YTWEXOHf/bUG bJrw== X-Gm-Message-State: AOAM533jTx1f3X8yKaSm3kEn4flBaCHeBPoo0PnNwON8Cy8BAtjK14y2 GuPi8jq440jS5VupHp1pkvkRM65kgYSMmdSB61u4iKzx1RE= X-Google-Smtp-Source: ABdhPJwMeGJpoDe2N7QHrrQyriwaB+hI6tBxZlXB8jolQEMeYpfFT5RqYJKzN/9F1ZBWF2yd5ja/YuLGiRG6LEviwQ4= X-Received: by 2002:a65:6412:: with SMTP id a18mr27320152pgv.445.1625689452042; Wed, 07 Jul 2021 13:24:12 -0700 (PDT) MIME-Version: 1.0 References: <20210629012653.2375942-1-ah@immunant.com> <9d78443192899df450e3f1128b7692c55e3e6bf6.camel@klomp.org> In-Reply-To: <9d78443192899df450e3f1128b7692c55e3e6bf6.camel@klomp.org> From: Andrei Homescu Date: Wed, 7 Jul 2021 13:24:01 -0700 Message-ID: Subject: Re: [PATCH] libelf: Fix unaligned d_off offsets for input sections with large alignments To: Mark Wielaard Cc: elfutils-devel@sourceware.org X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jul 2021 20:24:14 -0000 Hi, On Wed, Jul 7, 2021 at 5:02 AM Mark Wielaard wrote: > Hi Andrei, > > On Mon, 2021-06-28 at 18:26 -0700, Andrei Homescu wrote: > > The mkl_memory_patched.o object inside the libmkl_core.a library from > > the Intel Math Kernel Library version 2018.2.199 has this section > > with an alignment of 4096 and offset of 0xb68: > > [ 2] .data PROGBITS 0000000000000000 000b68 011000 00 WA 0 0 4096 > > > > Reading this file with libelf and trying to write it back to disk > triggers > > the following sequence of events: > > 1) code in elf_getdata.c clamps d_align for this section's data buffer > > to the section's offset > > 2) code in elf32_updatenull.c checks if the alignment is a power of two > > and incorrectly returns an error > > > > This commit fixes this corner case by increasing the alignment to the > > next power of two after the clamping, so the check passes. > > > > A test that reproduces this bug using strip is also included. > > Thanks for this perfect patch, including and excellent explanation of > the issue and a testcase. I have only a minor suggestion: > > > --- /dev/null > > +++ b/tests/run-strip-largealign.sh > > @@ -0,0 +1,34 @@ > > +#! /bin/sh > > +# Copyright (C) 2011 TODO. > > Should we make this Copyright (C) 2021 Andrei Homescu > or Copyright (C) 2021 Immunant, Inc. > Sorry about that, I intended to resolve that TODO myself and then missed it. I wrote this patch on behalf of someone else, so the copyright line should be: Copyright (C) 2021 Runsafe Security, Inc. > > +# This file is part of elfutils. > > +# > > +# This file is free software; you can redistribute it and/or modify > > +# it under the terms of the GNU General Public License as published > > by > > +# the Free Software Foundation; either version 3 of the License, or > > +# (at your option) any later version. > > +# > > +# elfutils is distributed in the hope that it will be useful, but > > +# WITHOUT ANY WARRANTY; without even the implied warranty of > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > +# GNU General Public License for more details. > > +# > > +# You should have received a copy of the GNU General Public License > > +# along with this program. If not, see < > > http://www.gnu.org/licenses/>. > > +# > > + > > +. $srcdir/test-subr.sh > > + > > +# = testfile-largealign.S = > > +# section .data > > +# align 4096 > > +# dd 0x12345678 > > +# > > +# nasm -f elf64 -o testfile-largealign.o testfile-largealign.S > > + > > +infile=testfile-largealign.o > > +outfile=$infile.stripped > > + > > +testfiles $infile > > +tempfiles $outfile > > + > > +testrun ${abs_top_builddir}/src/strip -o $outfile $infile > > The testcase already fails before the patch and succeeds after, but it > would be nice to double check the output with elflint just in case. > Shall we add: > > testrun ${abs_top_builddir}/src/elflint --gnu $outfile > Sounds good, no objection from me. Should I submit an updated version of the patch, or can you add this on your end? Andrei