From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by sourceware.org (Postfix) with ESMTPS id 124F03858D1E for ; Mon, 19 Dec 2022 17:45:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 124F03858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.org Received: (Authenticated sender: dodji@seketeli.org) by mail.gandi.net (Postfix) with ESMTPSA id DB224C000A; Mon, 19 Dec 2022 17:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seketeli.org; s=gm1; t=1671471921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wp/MC9ZDF0g7wr6TkkNRK4uLUaiVrkp90WtoBWx9mMc=; b=WP05jD1jUnzkAieBtqtPqlMGE8/dfBQHkUyyGKmsnS3bTTWQdwz9ROZKEl0dlehv30NFf6 /Z1kiVJBAPz/ZQl0xE74NSNDAhMhF+uDLumsN1umoE+tzk7wDehMQKtaoU8VPbalxd37Iy 7fuN10CJ27IV2exK72Hb+8QPqXBbOisr4MF58yquGkw25QKr+Job1fBUjjVk13NVWA2QBK nEc/c6jYxLbaGtMzrFX0x6P/FL0yESVppay6Pn1ZDAXenzPcuKMTrmIN8zOk6ab9ahDYzt iukmGljE9rQdYKv7J0EK9MXXDUfA3xWYKfoKACOqmXnplGBx8LUHdI+XpLZEcA== Received: by localhost (Postfix, from userid 1000) id 1539CB5649; Mon, 19 Dec 2022 18:45:20 +0100 (CET) From: Dodji Seketeli To: Petr Pavlu via Libabigail Cc: Petr Pavlu Subject: Re: [PATCH] Fix de-initialization of elf::reader::priv Organization: Me, myself and I References: <20221218193340.30426-1-petr.pavlu@suse.com> X-Operating-System: CentOS Stream release 9 X-URL: http://www.seketeli.net/~dodji Date: Mon, 19 Dec 2022 18:45:20 +0100 In-Reply-To: <20221218193340.30426-1-petr.pavlu@suse.com> (Petr Pavlu via Libabigail's message of "Sun, 18 Dec 2022 20:33:40 +0100") Message-ID: <87bknze18v.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,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 List-Id: Hello Petr, Petr Pavlu via Libabigail a =C3=A9crit: > Add a destructor for elf::reader::priv which releases any allocated alt > DWARF data and fix the initialize() method to fully reset the object. > > The latter fixes a crash observed when handling multiple files. For > instance, when reading the Linux kernel tree, load_vmlinux_corpus() > processes vmlinux and all modules. Member dwarf_handle was never reset > after setting it for the first file which could later result in use of > invalid DWARF data in dwarf::reader::build_die_parent_maps(). > > * src/abg-elf-reader.cc (priv::~priv): Release alt debug > information. > (priv::initialize): Reset all members. > (priv::clear_alt_dwarf_debug_info_data): New helper function. > > Fixes: 7bd69830 ("Make Front Ends first class citizens") Thanks for the patch! I have just edited slightly to fix what I think is a related dormant issue in find_alt_dwarf_debug_info, which is that if the macro LIBDW_HAS_DWARF_GETALT is not defined, then find_alt_dwarf_debug_info doesn't return the proper file descriptor for the alternate DWARF debug info file. With this additional fix, clear_alt_dwarf_debug_info_data() will find (and clear) the expected alternate DWARF debuginfo file descriptor. The diff of my change is: diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index 4814a70e..c07f0655 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -225,10 +225,10 @@ find_alt_dwarf_debug_info(Dwfl_Module *elf_module, // If we reach this point it means we have found the path to the // alternate debuginfo file and it's in alt_file_path. So let's // open it and read it. - int fd =3D open(alt_file_path.c_str(), O_RDONLY); - if (fd =3D=3D -1) + alt_fd =3D open(alt_file_path.c_str(), O_RDONLY); + if (alt_fd =3D=3D -1) return result; - result =3D dwarf_begin(fd, DWARF_C_READ); + result =3D dwarf_begin(alt_fd, DWARF_C_READ); #ifdef LIBDW_HAS_DWARF_GETALT Dwarf_Addr bias =3D 0; Please find below the patch that I am applying to the master branch. Thanks! Cheers, >From 241c7fc7c1fb3b258815c800311f6d83869de87b Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Sun, 18 Dec 2022 20:33:40 +0100 Subject: [PATCH] Fix de-initialization of elf::reader::priv This fixes 7bd69830 ("Make Front Ends first class citizens"). Add a destructor for elf::reader::priv which releases any allocated alt DWARF data and fix the initialize() method to fully reset the object. The latter fixes a crash observed when handling multiple files. For instance, when reading the Linux kernel tree, load_vmlinux_corpus() processes vmlinux and all modules. Member dwarf_handle was never reset after setting it for the first file which could later result in use of invalid DWARF data in dwarf::reader::build_die_parent_maps(). * src/abg-elf-reader.cc (priv::~priv): Release alt debug information. (priv::initialize): Reset all members. (priv::clear_alt_dwarf_debug_info_data): New helper function. Signed-off-by: Petr Pavlu Signed-off-by: Dodji Seketeli --- src/abg-elf-reader.cc | 44 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index 3b1b5803..c07f0655 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -225,10 +225,10 @@ find_alt_dwarf_debug_info(Dwfl_Module *elf_module, // If we reach this point it means we have found the path to the // alternate debuginfo file and it's in alt_file_path. So let's // open it and read it. - int fd =3D open(alt_file_path.c_str(), O_RDONLY); - if (fd =3D=3D -1) + alt_fd =3D open(alt_file_path.c_str(), O_RDONLY); + if (alt_fd =3D=3D -1) return result; - result =3D dwarf_begin(fd, DWARF_C_READ); + result =3D dwarf_begin(alt_fd, DWARF_C_READ); =20 #ifdef LIBDW_HAS_DWARF_GETALT Dwarf_Addr bias =3D 0; @@ -281,6 +281,11 @@ struct reader::priv initialize(debug_info_roots); } =20 + ~priv() + { + clear_alt_dwarf_debug_info_data(); + } + /// Reset the private data of @elf elf::reader. /// /// @param debug_info_roots the vector of new directories where to @@ -288,11 +293,23 @@ struct reader::priv void initialize(const vector& debug_info_roots) { - debug_info_root_paths =3D debug_info_roots; + clear_alt_dwarf_debug_info_data(); + + elf_handle =3D nullptr; + symtab_section =3D nullptr; + elf_architecture.clear(); + dt_needed.clear(); symt.reset(); + debug_info_root_paths =3D debug_info_roots; + offline_callbacks =3D {}; dwfl_handle.reset(); elf_module =3D nullptr; - elf_handle =3D nullptr; + dwarf_handle =3D nullptr; + alt_dwarf_handle =3D nullptr; + alt_dwarf_path.clear(); + alt_dwarf_fd =3D 0; + ctf_section =3D nullptr; + alt_ctf_section =3D nullptr; } =20 /// Setup the necessary plumbing to open the ELF file and find all @@ -348,6 +365,23 @@ struct reader::priv return result; } =20 + /// Clear the resources related to the alternate DWARF data. + void + clear_alt_dwarf_debug_info_data() + { + if (alt_dwarf_fd) + { + if (alt_dwarf_handle) + { + dwarf_end(alt_dwarf_handle); + alt_dwarf_handle =3D nullptr; + } + close(alt_dwarf_fd); + alt_dwarf_fd =3D 0; + } + alt_dwarf_path.clear(); + } + /// Locate the DWARF debug info in the ELF file. /// /// This also knows how to locate split debug info. --=20 2.31.1 --=20 Dodji