From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 337C231B803 for ; Mon, 4 May 2026 08:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882373; cv=none; b=d6gv12puNO2ISKTSGgDrJ8yrvEt26xtgBeEbm4UgbwDiFq6YybXluZOH2MQXAhVmkJf0t15NtV9Bhoe7LYFJjJr2MFDfCdxIdEpeiwVAyNe8KdU71VF5avQa8E7a8IWxXCuKRcyDoAALQcgKIT1wYW9ymynsanXO0p0CkUjnBYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882373; c=relaxed/simple; bh=86Fi8XgRbKLUoxAcrNtQ/NCYtxcmPhDpKOGB2wMyx9M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rbfOU4TtlEt9u3r4Pg26oroldlm8eq6TvRI7swk5tW+FmuVPl6C/vqGMVeHJq2v7mr/EE0/B84YrC3/ouM13+lLX7Pkk3HGgl2rH1DNrD99z11N/GPBZy7YE+/uTkl1TJq38ivGMqa3+cGMU+kohnotc1FL4ZWLThI0/4BUtwRk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MUZuLnAA; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MUZuLnAA" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bda35eab74so3219521eec.0 for ; Mon, 04 May 2026 01:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882370; x=1778487170; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ws2FlyxY3Py6KisW5mWMui419nDHfCw03Zt9ciWQIP4=; b=MUZuLnAAu/oOYxIZ1TQ/OUgzKDqIOirC+4mN1mJMyx6OQdWwYTPcHtyHWzfUYKlO15 78YWRDU5xyKye5g5BJhF+qG0pXCN/Yr5NgxFCGqgASBCZ5pF07IOmGQ7YpqcmF/QnQjb V5LrYmRboRJLDTFQGJmtTXGJ+S5ISndT1Z7QqjKXS7EjfXNZGToO4rbO06MHQcmW+wck NjLfWOKSYf3LMHNwf+VCwAXWa/SG7W9p10J3u7Xp7vJlQDA8Suk4WZd50SMLWF7lAqj6 +2xyDQuu6RpiiscBND9QhGd5DhcoolSpTt5p9GqyKBhhhkiHqWfOB0xsTUG1SNe4tA9J E4AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882370; x=1778487170; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ws2FlyxY3Py6KisW5mWMui419nDHfCw03Zt9ciWQIP4=; b=kvzpYhm1Wxp2YUCw9Nx3Ydg9jA/zqeowT+r6RS0ghx4CXyAz1iFk+ymVIRdSH4YxzV C/SAcPrHcGaabJx9kio/jFYVuolqSzuT6SpiWATbnCuKS3L5oIw8eanduLO6BarNRrF6 ZHvj25rBE2HdQiTPQRdswY0jsVGmo47RB9dbddmPtmUFX+9XCTCRlBgiOoJcQ90jVlCk HRHBokvOx/4708QZChAkN8JFl52f/gyElKRfruebjUzgLeq3HXSKPtntHdfJnf/IznQ+ UqpxF1Sm0cbjPWECAlkMrljfS8XldWn9WSVfAQHRZn4jeQHoXAmZ2ZGO1lnvcMrZ/POH 09uA== X-Forwarded-Encrypted: i=1; AFNElJ+yte8Bqb09N4TfkHHLOeF50ddaXVLFvjd1jTi7ddfj9zJh43MrcXg9HvpZ91Tirj5+eVA0DaYHlk3toHs=@vger.kernel.org X-Gm-Message-State: AOJu0YzaIIUmv0ZbTJLdd08E83/Vjs5VsBolImvkUKwomABYx+VSL5+d fX4NwlIKE2IPFoHc9ah6gliX6bzzSVJ+8pDSNNBqP/hj0qQx3MMnM2cT9ADsh6jTuq52c+s/Yus 5zX1FfEBLiQ== X-Received: from dlbps10.prod.google.com ([2002:a05:7023:88a:b0:12d:d43c:4120]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:68a9:b0:12c:aae:7b43 with SMTP id a92af1059eb24-12dece4285bmr6819531c88.24.1777882370014; Mon, 04 May 2026 01:12:50 -0700 (PDT) Date: Mon, 4 May 2026 01:12:27 -0700 In-Reply-To: <20260504081227.2203848-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-10-irogers@google.com> Subject: [PATCH v5 9/9] perf debuginfo: Fix libdw API contract violations From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Adrian Hunter , James Clark , Zecheng Li , Masami Hiramatsu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" Check return value of `dwfl_report_end` during offline initialization. Validate `dwfl_module_relocation_info` result before passing to `strcmp` to avoid potential segmentation faults. Additionally: - Fix a file descriptor leak in `debuginfo__init_offline_dwarf()` when `dwfl_report_offline()` or subsequent setup calls fail. Fixes: 6f1b6291cf73 ("perf tools: Add util/debuginfo.[ch] files") Assisted-by: Gemini-CLI:Google Gemini 3 Acked-by: Namhyung Kim Signed-off-by: Ian Rogers --- v5: - Added Acked-by tag. v4: - Fix file descriptor leaks in debuginfo init paths. --- tools/perf/util/debuginfo.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c index 0e35c13abd04..84a78b30ceac 100644 --- a/tools/perf/util/debuginfo.c +++ b/tools/perf/util/debuginfo.c @@ -42,6 +42,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, { GElf_Addr dummy; int fd; + bool fd_consumed = false; fd = open(path, O_RDONLY); if (fd < 0) @@ -55,6 +56,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, dbg->mod = dwfl_report_offline(dbg->dwfl, "", "", fd); if (!dbg->mod) goto error; + fd_consumed = true; dbg->dbg = dwfl_module_getdwarf(dbg->mod, &dbg->bias); if (!dbg->dbg) @@ -62,13 +64,14 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, dwfl_module_build_id(dbg->mod, &dbg->build_id, &dummy); - dwfl_report_end(dbg->dwfl, NULL, NULL); + if (dwfl_report_end(dbg->dwfl, NULL, NULL) != 0) + goto error; return 0; error: if (dbg->dwfl) dwfl_end(dbg->dwfl); - else + if (!fd_consumed) close(fd); memset(dbg, 0, sizeof(*dbg)); @@ -167,7 +170,7 @@ int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs, /* Search the relocation related .text section */ for (i = 0; i < n; i++) { p = dwfl_module_relocation_info(dbg->mod, i, &shndx); - if (strcmp(p, ".text") == 0) { + if (p && strcmp(p, ".text") == 0) { /* OK, get the section header */ scn = elf_getscn(elf, shndx); if (!scn) -- 2.54.0.545.g6539524ca2-goog