From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71550 invoked by alias); 13 Oct 2017 15:09:48 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 71538 invoked by uid 89); 13 Oct 2017 15:09:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=H*Ad:U*jistone, HTo:U*jistone, our X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Oct 2017 15:09:46 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 52AB3302BAA6; Fri, 13 Oct 2017 17:09:44 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 1173047FE13F; Fri, 13 Oct 2017 17:09:44 +0200 (CEST) Message-ID: <1507907383.339.42.camel@klomp.org> Subject: Re: failed reading "Smallest x86 ELF Hello World" From: Mark Wielaard To: Josh Stone , elfutils-devel@sourceware.org Date: Fri, 13 Oct 2017 15:09:00 -0000 In-Reply-To: <1507143353.9961.25.camel@klomp.org> References: <2c4070fd-23b1-1758-b8be-342bfe852cb6@redhat.com> <1507143353.9961.25.camel@klomp.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution 3.22.6 (3.22.6-10.el7) Mime-Version: 1.0 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2017-q4/txt/msg00019.txt.bz2 On Wed, 2017-10-04 at 20:55 +0200, Mark Wielaard wrote: > The first issue is indeed that almost anything that goes wrong when > setting up the initial Elf handle ends up being described as > ELF_E_INVALID_FILE. Which is not always the correct error code. So I > introduced ELF_E_INVALID_ELF which indicates it is bad ELF data being > encountered and not just the inability to read the data from the file > descriptor. Also in a couple of cases we didn't explicitly set the > libelf errno to indicate what really went wrong. I made sure we > always > do now. >=20 > =C2=A0 libelf: Add ELF_E_INVALID_ELF error value. > > [...] > > But while auditing this code it is clear we go out of our way to get > the section (count) making sure we don't touch any bad data. If there > is a change we might read anything bad from the (mmapped) file then > we > explicitly set the elf->state.elf[64|32].scns.cnt to zero. Which is > respected throughout libelf whenever we try to touch section headers. > Except... during the initial read we double check e_shoff is sane and > error out early. Even though the code right below it explicitly > doesn't > use it when scncnt is zero. So we can fix this sanity check. >=20 > =C2=A0 libelf: Don't error out when sanity checking e_shoff if scncnt is > zero. I pushed both these commits to master now. Cheers, Mark