From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from poodle.tulip.relay.mailchannels.net (poodle.tulip.relay.mailchannels.net [23.83.218.249]) by sourceware.org (Postfix) with ESMTPS id 90DA23858297 for ; Fri, 29 Jul 2022 16:31:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 90DA23858297 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 37E7C4C22B3; Fri, 29 Jul 2022 16:31:13 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 390384C282D; Fri, 29 Jul 2022 16:31:12 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1659112272; a=rsa-sha256; cv=none; b=A8XchOa+2+YFz/1exOQ3W06V7YeiKkt2v45GzmiJOGLup1SfVJDU8YXl/iMw2DGum8Vjhm vT+gCi3jYrvHg3neJT9uX0S05AEjTFXYiElJUxxbYIz4LfKm10vRqA1XIIdwjHLpMcZLdG rEKM2y2DbuZbfEbMCkSKfI/6fliaaux0yrtrrZV9ti9bbTWgW++Lf3VIENfPfyfw6u1rE1 +MWXYkzILGBi2eABMBx1APyneCHarDKFY1ZWxcHlFdYqsgqNVlkT+PP4dIhbjPSCd7KSSj ek0cpq+xGK5+cdtJeLrwVa6b9J9nbAvm7WzBcUxg23A7Ziey2DFNi09pxwCT0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1659112272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rtQ/tGXoNGdbbx3jjXXCIDXxTeaEPXdGccNedRSXqbM=; b=5EYxdChbQk4/TYkGld925fkFZoL+3iAaiEQvf7urtZoavm9Db1wgBH5Rd6/L4vk6dLOUJX iibMIja1jvKys+gNtk6L3EmR4cFI90sGaXfcOBdPxZPSHiGmAmb8JdTu9XPoBtGXG4fsaH ia+oXAS2M7XEXGBlrAUFa2dqb3rO9QoQn80+vsDHhxKabYz1zhUqJGwfADShJPXr5RlyXb /Mbugfjtur42Mg4y5SUdJd0NQ99oK6fXZiNxj3aFk60ZwaaXFJbD1t28s/XDa+iGYlNDLf UVDqAvBwa/IZoKxg1WYWkn0GY9GqTBpBhRuaM2DIdkMOKFBUyAqs3xr0kPNLyQ== ARC-Authentication-Results: i=1; rspamd-5c5fdbc7b9-454lx; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Tasty-Abortive: 6ce8ca0177afef71_1659112272843_4106052243 X-MC-Loop-Signature: 1659112272842:2931747151 X-MC-Ingress-Time: 1659112272838 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.55.239 (trex/6.7.1); Fri, 29 Jul 2022 16:31:12 +0000 Received: from [192.168.2.151] (bras-base-bmtnon1328w-grc-12-174-91-14-188.dsl.bell.ca [174.91.14.188]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4LvY1C5ZJZz5y; Fri, 29 Jul 2022 09:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1659112272; bh=rtQ/tGXoNGdbbx3jjXXCIDXxTeaEPXdGccNedRSXqbM=; h=Date:Subject:From:To:Content-Type:Content-Transfer-Encoding; b=spOnPhIDCunCqfeFb79tSx7YObxIm15P7guNQ4mMfF7wKJzzah4frYKlQH+W3t9T3 v0wM9oF1i6cEGomIRbiarUIBoymTkW5pGnl/IDspPyehuNFAyifpxlHOuv08kqOoze nvMtBhxjT02DRvp1WlidPPeY9p4KgpntTPu9XGlR5nLfUrMHfmOf5Qk0pD7ilfGZ2p rDK3yHXqtUCNeSUn/PGIBJrzphpw0b3tXUkOfIuZjq/4f0dFOZiaDoJC3FLxWej9VB JJ2XPP9jmFj3/ALKFEujVffRTwbRALRr7+QNUDiQmm9fqBCS5QdU4VTlehbH6skJCH SBUw6SktJ72OA== Message-ID: <64196909-f1ae-3c54-5485-8e89f1dba9c8@gotplt.org> Date: Fri, 29 Jul 2022 12:31:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] libdwfl: Rewrite reading of ar_size in elf_begin_rand Content-Language: en-US From: Siddhesh Poyarekar To: Mark Wielaard , elfutils-devel@sourceware.org References: <20220728134844.8618-1-mark@klomp.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3031.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 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: Fri, 29 Jul 2022 16:31:18 -0000 On 2022-07-28 13:27, Siddhesh Poyarekar wrote: > Interesting, I'll take a closer look at this from the gcc context.  I > obviously don't have any strong opinions about the elfutils patch :) I reduced this to the below program and I see it warns with `-D_FORTIFY_SOURCE=3 -O2 -fsanitize=undefined` as well as `-D_FORTIFY_SOURCE=2 -O2 -fsanitize=undefined`. This is definitely a false positive on unreachable code; __pread_alias will never be called when nbytes is greater than object size. So I can confirm that this is harmless. Sid ~~~ typedef long ssize_t; typedef unsigned long size_t; typedef long off_t; struct ar_hdr { char ar_mode; char ar_size[10]; }; extern ssize_t __pread_chk (int fd, void *buf, size_t nbytes, off_t offset, size_t bufsize) __attribute__((__access__ (__write_only__, 2, 3))); extern ssize_t __pread_alias (int fd, void *buf, size_t nbytes, off_t offset) __attribute__((__access__ (__write_only__, 2, 3))); extern ssize_t __pread_chk_warn (int fd, void *buf, size_t nbytes, off_t offset, size_t bufsize); extern __inline __attribute__((__always_inline__)) __attribute__((__gnu_inline__)) ssize_t pread (int fd, void *buf, size_t nbytes, off_t offset) { size_t osz = __builtin_dynamic_object_size (buf, 0); if (__builtin_constant_p (osz) && osz == (size_t) -1) return __pread_alias (fd, buf, nbytes, offset); return (((__typeof (nbytes)) 0 < (__typeof (nbytes)) - 1 || (__builtin_constant_p (nbytes) && (nbytes) > 0)) && __builtin_constant_p (nbytes <= osz / 1) && nbytes <= osz / 1) ? __pread_alias (fd, buf, nbytes, offset) : __pread_chk (fd, buf, nbytes, offset, osz); } ssize_t pread_retry (int fd, off_t start_offset, off_t offset) { ssize_t recvd = 0; struct ar_hdr h = {.ar_size = {0} }; void *buf = h.ar_size; size_t len = sizeof (h.ar_size); off_t off = start_offset + offset + __builtin_offsetof (struct ar_hdr, ar_size); do { long int res; do { res = pread (fd, ((char *) buf) + recvd, len - recvd, off + recvd); } while (res == -1L); recvd += res; } while ((size_t) recvd < len); return recvd; }