From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id oDOyC5gxXGdKQAAAqHPOHw:P1 (envelope-from ) for ; Fri, 13 Dec 2024 13:07:36 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id oDOyC5gxXGdKQAAAqHPOHw (envelope-from ) for ; Fri, 13 Dec 2024 14:07:36 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b="tt/fSOLL"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734095255; a=rsa-sha256; cv=none; b=UceGaPXLeLDq92hiXgw+5DsiGDCGbIyo724Kn7/vyMbAGqX9JU4mn6luHxZeiQGfhuQ37q KxOKQEWrAm/8Ywh5vFYLwFcqPUADu7Zkg7R3Eu9NkWIb6Nny9tsds34JCvtYLSzV1UJdVT veDPrhw1fq/l5Z0YY5K1C/iJ34U9XNvHI/3g/+lz06a2iYbdeh8fQJSgYphSs7Rzsmg25J RSFS19I+ujbNkshxfyu0CqpNLvHwc/Bz5iH4vCOgVl6wMvkMOHqrb5H64TrooH6DgPTgvx u3H5lwP9FvMRg8h3d5gIR+qkgo0zGw4P/EtJ6c6DEfirs9DyhOferF0B3QJ7ZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b="tt/fSOLL"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734095255; h=from:from:sender:sender: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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=UThB9x6rPpQxW6078xDntT/9MmvXNamOcqG8ZgY3Tbg=; b=dggoJPPBJW4d5eWjZDWU7GsX+mE+yxOdp8TP7gr0zWh/Txk3i605NO0hmEKAaDiGJGqPr3 1a9YOxvc5yuWBEvJEpkBRd8baPaRPWiwRxiTH9pY/V/f0OTGZ7PLivZ31Yyaeyo/q5yR02 vLP7hb9DkLrz9zZL6cNPDUg6EGt7ZEwjumAJRmlam23eSaafl/qXTrqi5p8Ost6PJ/axvp 3X3vHCfmdrNQqxB48jNNJTdwVyfY351XgJDbXA7IW3JYP6x0GZvijjddl5ydpeXzeqb6HC 1wPbRoBmLU9EQWoirKGjvhNz3ltUhbjiC6JXkGV86xISlozg3ayCbqhwZATguw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BDFB87CAF8 for ; Fri, 13 Dec 2024 14:07:35 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tM5Nx-00013y-Mo; Fri, 13 Dec 2024 08:07:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tM5Nn-0000uJ-Mf for guix-patches@gnu.org; Fri, 13 Dec 2024 08:07:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tM5Nn-0004Rp-45 for guix-patches@gnu.org; Fri, 13 Dec 2024 08:07:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=UThB9x6rPpQxW6078xDntT/9MmvXNamOcqG8ZgY3Tbg=; b=tt/fSOLLYNm63vS+WphwwJPEO6LV8U8h8hnEm23TskOSU9g/ZOohUzM6DmCVHZ6Va89KTuCT6/u5GxtNFVXpit5A/4doIQv9dSoH6AGRUPdUQoxREBUXHNRLXmGFZlIEGpp/4GkDocr652tQuTeuyr9+urIzxggXwmoaJYtXy673ZHhpK7ErI+NKiOaYGp7pd9yEzc+XLubCLFvtY/xrikmBFtyrJGtnxMX41uErRVRNZIrt2FV+Vcg2p+UgRhjBPV6QvJc6LdtIHf3TbZmK2/X8ju6L3399JeeBPL7kXfwmNsJzrZ8UNEeJnusDYGLGYsR938MQj/xu3F3izF7ngQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tM5Nm-0005Wt-I8 for guix-patches@gnu.org; Fri, 13 Dec 2024 08:07:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74669] [PATCH v3] gnu: elfutils: Fix cross-compilation. References: <814be590b438138df7b35507a0fd266b319da388.1733228331.git.zhengjunjie@iscas.ac.cn> In-Reply-To: <814be590b438138df7b35507a0fd266b319da388.1733228331.git.zhengjunjie@iscas.ac.cn> Resent-From: Zheng Junjie Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 13 Dec 2024 13:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74669 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74669@debbugs.gnu.org Received: via spool by 74669-submit@debbugs.gnu.org id=B74669.173409518821199 (code B ref 74669); Fri, 13 Dec 2024 13:07:02 +0000 Received: (at 74669) by debbugs.gnu.org; 13 Dec 2024 13:06:28 +0000 Received: from localhost ([127.0.0.1]:42056 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM5NC-0005Vn-KW for submit@debbugs.gnu.org; Fri, 13 Dec 2024 08:06:28 -0500 Received: from smtp21.cstnet.cn ([159.226.251.21]:56624 helo=cstnet.cn) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM5N5-0005VM-TF for 74669@debbugs.gnu.org; Fri, 13 Dec 2024 08:06:24 -0500 Received: from m.tailaa68d.ts.net (unknown [107.174.64.25]) by APP-01 (Coremail) with SMTP id qwCowAAXHNA2MVxnfSeTAQ--.8797S2; Fri, 13 Dec 2024 21:06:02 +0800 (CST) From: Zheng Junjie Date: Fri, 13 Dec 2024 21:05:53 +0800 Message-ID: <1f088473ff01e785e8a8b3414f831dc6b1fe6841.1734095153.git.zhengjunjie@iscas.ac.cn> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowAAXHNA2MVxnfSeTAQ--.8797S2 X-Coremail-Antispam: 1UD129KBjvJXoW3uFyUWF18GFyrtr15Wr18AFb_yoWDAr4rpa y3Ar1Yq3yfJFs3Jan3ZF1Ikw1rG3s7AFWY9ry3G3W0yF4YqF13JrWftryrCayUWryku3yr uwsYqa4fuF95WaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyIb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1j6r15MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUgVHqDUUUU X-Originating-IP: [107.174.64.25] X-CM-SenderInfo: x2kh0wxmxqyx3h6l2u1dvotugofq/ X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: BDFB87CAF8 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -5.40 X-Spam-Score: -5.40 X-TUID: 6qVANApHYXHz * gnu/packages/elf.scm (elfutils): Fix cross-compilation [arguments]: When cross-compilation, apply patch. <#:phases>: Use G-expressions. * gnu/packages/patches/elfutils-libdwfl-string-overflow.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. Change-Id: Ia1ab9c09124a140608bda34bf62f0ae80eb44f9b --- gnu/local.mk | 1 + gnu/packages/elf.scm | 94 +++++++------- .../elfutils-libdwfl-string-overflow.patch | 116 ++++++++++++++++++ 3 files changed, 169 insertions(+), 42 deletions(-) create mode 100644 gnu/packages/patches/elfutils-libdwfl-string-overflow.patch diff --git a/gnu/local.mk b/gnu/local.mk index 39b142af5a..67d0085b71 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1177,6 +1177,7 @@ dist_patch_DATA = \ %D%/packages/patches/eigen-fix-strict-aliasing-bug.patch \ %D%/packages/patches/einstein-build.patch \ %D%/packages/patches/elfutils-tests-ptrace.patch \ + %D%/packages/patches/elfutils-libdwfl-string-overflow.patch \ %D%/packages/patches/elixir-path-length.patch \ %D%/packages/patches/elm-ghc9.2.patch \ %D%/packages/patches/elm-offline-package-registry.patch \ diff --git a/gnu/packages/elf.scm b/gnu/packages/elf.scm index 81a753a483..8f036ab221 100644 --- a/gnu/packages/elf.scm +++ b/gnu/packages/elf.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2021 Leo Le Bouter ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2023, 2024 Janneke Nieuwenhuizen +;;; Copyright © 2024 Zheng Junjie <873216071@qq.com> ;;; ;;; This file is part of GNU Guix. ;;; @@ -99,48 +100,57 @@ (define-public elfutils '()) #:phases - (modify-phases %standard-phases - ;; No reason has been found for this test to reliably fail on aarch64-linux. - (add-after 'unpack 'disable-failing-aarch64-tests - (lambda _ - (substitute* "tests/Makefile.in" - (("run-backtrace-native.sh") "")) - #t)) - ,@(if (target-riscv64?) - `((add-after 'unpack 'disable-failing-riscv64-test - (lambda _ - (substitute* "tests/Makefile.in" - ;; dwfl_thread_getframes: No DWARF information found - (("run-backtrace-dwarf.sh") "") - ;; These tests have several errors: - ;; unknown program header entry type 0x70000003 - ;; '.riscv.attributes' has unsupported type 1879048195 - (("run-reverse-sections-self.sh") "") - (("run-strip-strmerge.sh") "") - (("run-elflint-self.sh") ""))))) - '()) - ,@(if (system-hurd?) - `((add-after 'unpack 'skip-tests - (lambda _ - (substitute* '("tests/elfstrtab.c" - "tests/emptyfile.c") - (("elf_version \\(EV_CURRENT\\);" all) - "exit (77);")) - (substitute* '("tests/run-all-dwarf-ranges.sh" - "tests/run-allfcts-multi.sh" - "tests/run-attr-integrate-skel.sh" - "tests/run-bug1-test.sh" - "tests/run-copyadd-sections.sh" - "tests/run-deleted.sh" - "tests/run-get-units-split.sh" - "tests/run-native-test.sh" - "tests/run-readelf-loc.sh" - "tests/run-readelf-ranges.sh" - "tests/run-unit-info.sh" - "tests/run-varlocs.sh") - (("^#!.*" all) - (string-append all "exit 77;\n")))))) - '())))) + ,#~(modify-phases %standard-phases + ;; No reason has been found for this test to reliably fail on aarch64-linux. + (add-after 'unpack 'disable-failing-aarch64-tests + (lambda _ + (substitute* "tests/Makefile.in" + (("run-backtrace-native.sh") "")) + #t)) + #$@(if (target-riscv64?) + #~((add-after 'unpack 'disable-failing-riscv64-test + (lambda _ + (substitute* "tests/Makefile.in" + ;; dwfl_thread_getframes: No DWARF information found + (("run-backtrace-dwarf.sh") "") + ;; These tests have several errors: + ;; unknown program header entry type 0x70000003 + ;; '.riscv.attributes' has unsupported type 1879048195 + (("run-reverse-sections-self.sh") "") + (("run-strip-strmerge.sh") "") + (("run-elflint-self.sh") ""))))) + #~()) + #$@(if (system-hurd?) + #~((add-after 'unpack 'skip-tests + (lambda _ + (substitute* '("tests/elfstrtab.c" + "tests/emptyfile.c") + (("elf_version \\(EV_CURRENT\\);" all) + "exit (77);")) + (substitute* '("tests/run-all-dwarf-ranges.sh" + "tests/run-allfcts-multi.sh" + "tests/run-attr-integrate-skel.sh" + "tests/run-bug1-test.sh" + "tests/run-copyadd-sections.sh" + "tests/run-deleted.sh" + "tests/run-get-units-split.sh" + "tests/run-native-test.sh" + "tests/run-readelf-loc.sh" + "tests/run-readelf-ranges.sh" + "tests/run-unit-info.sh" + "tests/run-varlocs.sh") + (("^#!.*" all) + (string-append all "exit 77;\n")))))) + #~()) + #$@(if (%current-target-system) + #~((add-after 'unpack 'patch + (lambda* (#:key native-inputs #:allow-other-keys) + (invoke + "patch" "-p1" "--force" "-i" + #$(local-file + (search-patch + "elfutils-libdwfl-string-overflow.patch")))))) + #~())))) (native-inputs (list m4)) (inputs (list xz zlib)) diff --git a/gnu/packages/patches/elfutils-libdwfl-string-overflow.patch b/gnu/packages/patches/elfutils-libdwfl-string-overflow.patch new file mode 100644 index 0000000000..e9d51359c4 --- /dev/null +++ b/gnu/packages/patches/elfutils-libdwfl-string-overflow.patch @@ -0,0 +1,116 @@ +from https://sourceware.org/cgit/elfutils/patch/?id=0873ae782d14e672e8344775e76b7fca0a8b41bf + +Adjust the changelog so it can be applied on elfutils 0.187. + +From 0873ae782d14e672e8344775e76b7fca0a8b41bf Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Thu, 28 Jul 2022 15:31:12 +0200 +Subject: libdwfl: Rewrite reading of ar_size in elf_begin_rand +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +With GCC 12.1.1, glibc 2.35, -fsanitize=undefined and +-D_FORTIFY_SOURCE=3 we get the following error message: + +In file included from /usr/include/ar.h:22, + from ../libelf/libelfP.h:33, + from core-file.c:31: +In function ‘pread’, + inlined from ‘pread_retry’ at ../lib/system.h:188:21, + inlined from ‘elf_begin_rand’ at core-file.c:86:16, + inlined from ‘core_file_read_eagerly’ at core-file.c:205:15: +/usr/include/bits/unistd.h:74:10: error: ‘__pread_alias’ writing 58 or more bytes into a region of size 10 overflows the destination [-Werror=stringop-overflow=] + 74 | return __glibc_fortify (pread, __nbytes, sizeof (char), + | ^~~~~~~~~~~~~~~ +/usr/include/ar.h: In function ‘core_file_read_eagerly’: +/usr/include/ar.h:41:10: note: destination object ‘ar_size’ of size 10 + 41 | char ar_size[10]; /* File size, in ASCII decimal. */ + | ^~~~~~~ +/usr/include/bits/unistd.h:50:16: note: in a call to function ‘__pread_alias’ declared with attribute ‘access (write_only, 2, 3)’ + 50 | extern ssize_t __REDIRECT (__pread_alias, + | ^~~~~~~~~~ +cc1: all warnings being treated as errors + +The warning disappears when dropping either -fsanitize=undefined +or when using -D_FORTIFY_SOURCE=2. It looks like a false positive. +But I haven't figured out how/why it happens. + +The code is a little tricky to proof correct though. The ar_size +field is a not-zero terminated string ASCII decimal, right-padded +with spaces. Which is then converted with strtoll. Relying on the +fact that the struct ar_hdr is zero initialized, so there will be +a zero byte after the ar_size field. + +Rewrite the code to just use a zero byte terminated char array. +Which is much easier to reason about. As a bonus the error disappears. + +Signed-off-by: Mark Wielaard +--- + libdwfl/ChangeLog | 5 +++++ + libdwfl/core-file.c | 26 ++++++++++++++++---------- + 2 files changed, 21 insertions(+), 10 deletions(-) + +diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog +index 75c53948d..acdaa0138 100644 +--- a/libdwfl/ChangeLog ++++ b/libdwfl/ChangeLog +@@ -1,0 +1,5 @@ ++2022-07-28 Mark Wielaard ++ ++ * core-file.c (elf_begin_rand): Replace struct ar_hdr h with ++ a char ar_size[AR_SIZE_CHARS + 1] array to read size. ++ +2022-04-22 Mark Wielaard + + * debuginfod-client.c (init_control): New static pthread_once_t. +diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c +index cefc3db0f..4418ef338 100644 +--- a/libdwfl/core-file.c ++++ b/libdwfl/core-file.c +@@ -75,26 +75,32 @@ elf_begin_rand (Elf *parent, off_t offset, off_t size, off_t *next) + from the archive header to override SIZE. */ + if (parent->kind == ELF_K_AR) + { +- struct ar_hdr h = { .ar_size = "" }; +- +- if (unlikely (parent->maximum_size - offset < sizeof h)) ++ /* File size, in ASCII decimal, right-padded with ASCII spaces. ++ Max 10 characters. Not zero terminated. So make this ar_size ++ array one larger and explicitly zero terminate it. As needed ++ for strtoll. */ ++ #define AR_SIZE_CHARS 10 ++ char ar_size[AR_SIZE_CHARS + 1]; ++ ar_size[AR_SIZE_CHARS] = '\0'; ++ ++ if (unlikely (parent->maximum_size - offset < sizeof (struct ar_hdr))) + return fail (ELF_E_RANGE); + + if (parent->map_address != NULL) +- memcpy (h.ar_size, parent->map_address + parent->start_offset + offset, +- sizeof h.ar_size); ++ memcpy (ar_size, parent->map_address + parent->start_offset + offset, ++ AR_SIZE_CHARS); + else if (unlikely (pread_retry (parent->fildes, +- h.ar_size, sizeof (h.ar_size), ++ ar_size, AR_SIZE_CHARS, + parent->start_offset + offset + + offsetof (struct ar_hdr, ar_size)) +- != sizeof (h.ar_size))) ++ != AR_SIZE_CHARS)) + return fail (ELF_E_READ_ERROR); + +- offset += sizeof h; ++ offset += sizeof (struct ar_hdr); + + char *endp; +- size = strtoll (h.ar_size, &endp, 10); +- if (unlikely (endp == h.ar_size) ++ size = strtoll (ar_size, &endp, 10); ++ if (unlikely (endp == ar_size) + || unlikely ((off_t) parent->maximum_size - offset < size)) + return fail (ELF_E_INVALID_ARCHIVE); + } +-- +cgit + base-commit: 0787a180b3ca64d3958438920ca1b58a2a27fba4 -- 2.46.0