From patchwork Mon Nov 20 17:44:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksei Vetrov X-Patchwork-Id: 80381 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62BEF3858413 for ; Mon, 20 Nov 2023 17:45:11 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by sourceware.org (Postfix) with ESMTPS id 108F43858D35 for ; Mon, 20 Nov 2023 17:45:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 108F43858D35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--vvvvvv.bounces.google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 108F43858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::449 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700502303; cv=none; b=BnOAyNCoA2RzfY+eSLaLGDaGjsuE3ZWOPBA7Ef04FVBir+B9DqQhkXC8//cdUbaA2NB/MCTbzCFRSoiW9pDLlLL+3b8y3j4oYDPxtBn7ew3ALgnzwnx3k93hKpl+Mu+vkWJl3xKAwFZGHCg02kEtO0X1KTWuWc/+VBt6/tGiBUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700502303; c=relaxed/simple; bh=b/ZGQdtzQ3oBIzoYyVoj2CEmW1lHUEXZ7wShQ8ax7sU=; h=DKIM-Signature:Date:Mime-Version:Message-ID:Subject:From:To; b=rnO+oSZZ7ZI3qHMWYXucrGRf5QJIkGfV/cKMrPqmbiscMk+PFEtOkJL4unTm9OPc2wn8CH1zbg3UTz4dwf2R935o2BvcTsl2KKnnmNwKIe3TYpgB9LVuMPu3a4FZaN2a8OStwfHSu6n2Ave/gYlRgpKDBM5OrKS3myms0L/hF0o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-332c50f4d98so760442f8f.1 for ; Mon, 20 Nov 2023 09:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700502300; x=1701107100; darn=sourceware.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=+p7wxlA+lE8ueAKrGjeqh66RVqGPKdZu98JGDoZZN1Y=; b=jRSiz+UxcpaRol1udQDkZAHx+poaEaGLzUJYWJHguM0/0y8uOEzPH1sNEPD0lsgIN+ 2Reji/jWn+efQBIb6W9/m5jrr/IIrUbLZjR49VQORoU+2LNkwn2792rWlOSIMduhuOVX +BIbJaBd1rUoo18UQA19DzwsOTQu1v/UJ+0hvcUBwUr9mgd/qi3NP0Lvg3ni2RSh0Az1 Co582k5ossc5VzMHujRsuq8+ZNl50eiPqxivbPxL+v5iAGVsOxlDBqvxb4boI783T1HZ i1XHFcQNlwFH4yTtkx1KpFQQ4vppO7wRTyCnaW0d+mAFd+/0C0ovXTOyHjGROWIzPaKC KcTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700502300; x=1701107100; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+p7wxlA+lE8ueAKrGjeqh66RVqGPKdZu98JGDoZZN1Y=; b=W3/DsIi9Qr5QEBBQ28g2z1ZqBVwPWZxL4H3LspS7tY7IvfnGeqDeoqGU040tH787Mo nAQTzBp+ZB+etoENVvP6Q/vAjrG4sLVzaBTBB5poYGwjcGQDLFre5mVqwBwgwqgF5TzR JdO0tkBn836gG20EbmnyuRPlRHZRjZJcsOUnKJIlnbaOd9mbK4xHvegHDPGa32rDnwgK JdjFsHotBNHcQERxniOODup5K5RoaeXkstldexwLGWP/30rit7XPOUBhUjkXJpGxUpsh W6b4pWKzC4na6GKMyBon4mUATIEizPholoB/VLfaF32p8f6yIAie2L/ybKbO0Vyqfkek 9KaQ== X-Gm-Message-State: AOJu0YzvYtFa4IZ/plQH8HXpNxo4P8W77XscFapyH0JxF/OG76sbvTbz Zlx1rfm4R3g9sbkv7/e1wgBH8U+NE/6IXs/s7Gm9CMKO6m/W/OMRN603kdio5aDxEW4RCK1d44/ CiA5vTvga3/twvRaxKXCC3HPrjqE/6uGbJcCeXXGmZJPaVjHZiDXOM1KZbkJ0o4XdmzJL1+Y= X-Google-Smtp-Source: AGHT+IHey4tMaeXiJFe27AQJMhg9yM8A3rIiwno0QPl0yMfnGFVXzFoJ7zIt9XPYTNNhL+k6dLV0xa7keRw= X-Received: from vvvvvv-dev.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:472]) (user=vvvvvv job=sendgmr) by 2002:adf:f5ce:0:b0:323:299e:fb87 with SMTP id k14-20020adff5ce000000b00323299efb87mr92792wrp.5.1700502300565; Mon, 20 Nov 2023 09:45:00 -0800 (PST) Date: Mon, 20 Nov 2023 17:44:47 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231120174448.1834594-1-vvvvvv@google.com> Subject: [PATCH v2 1/2] libdwfl: handle duplicate ELFs when reporting archives From: Aleksei Vetrov To: elfutils-devel@sourceware.org Cc: kernel-team@android.com, maennich@google.com, vvvvvv@google.com X-Spam-Status: No, score=-19.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org When archive is processed in process_archive (libdwfl/offline.c), it creates an Elf object for each archive member. Then in process_archive_member it calls process_file to create a Dwfl_Module through __libdwfl_report_elf. The ownership of the Elf object is expected to be: * either transfered to the Dwfl_Module, if __libdwfl_report_elf returns not NULL; * or handled at the end of process_archive_member by calling elf_end. Moreover, Elf object is expected to be alive, if __libdwfl_report_elf returns not NULL, because at the end of process_archive_member it advances to the next member through the elf_next call. The problem happens when __libdwfl_report_elf encounters Elf with the same name and content as it seen before. In that case dwfl_report_module will reuse existing Dwfl_Module object. This leads to a codepath that calls elf_end on the Elf object, while returning not NULL, breaking the elf_next call to the next member. The fix is to destroy m->main.elf instead and put the new Elf object in the already existing Dwfl_Module. * libdwfl/dwfl_report_elf.c (__libdwfl_report_elf): Replace Elf in the Dwfl_Module in case of duplicate modules to prolong its lifetime for subsequent processing. Signed-off-by: Aleksei Vetrov --- libdwfl/dwfl_report_elf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c index 581f4079..a76d3681 100644 --- a/libdwfl/dwfl_report_elf.c +++ b/libdwfl/dwfl_report_elf.c @@ -276,10 +276,11 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name, } else { - elf_end (elf); if (m->main_bias != bias || m->main.vaddr != vaddr || m->main.address_sync != address_sync) goto overlap; + elf_end (m->main.elf); + m->main.elf = elf; } } return m;