From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (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 15AB03D330C for ; Sun, 3 May 2026 17:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777828257; cv=none; b=nu6wUJ/mlBDgJXs/VxxE7sB2DdflacNTTBsSqxwJbYAM9qVc3w0puijW/fNLLcQqRPLhtVTRaMb6CxQRtrCMVdEqTorBXQUeE/0B0Jqa2gFJe6+GBH0TKcohPQ5DeOFi8irNhFZRDfpb/SLZdVZjCcymnSX8YaIw94/vzq9+RG0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777828257; c=relaxed/simple; bh=TVHo9dnFcw/tGdRrYrVbasoITISy+2trrO5Bo/2ExRE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=co/bztEQO42MUIW+rEnLpmGUA6QHWamvByXRVtfjW13zOeKix/K5Pftm4/qmXHXfDMW4haVzxdUJZlUZKx1hAueYiuElislegi6/YV/WPly8mqejyOfDy4ww/XKPWr+T9j8ohFSdYge6D7w+Gm+PJWnnfuw5nZ2Y5yTMVuSnNOI= 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=P9dKItcx; arc=none smtp.client-ip=74.125.82.202 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="P9dKItcx" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso5349148eec.0 for ; Sun, 03 May 2026 10:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777828255; x=1778433055; 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=N0tW0FxSBXoHGLy8UAyiIK3CDK7lkkw9WSavrtAU+9E=; b=P9dKItcxpVCMY5cMFHC0kQllnKMtIcU+8XCizQQjjJbcNKoIZRuCFU8KDlh/Vkt1Lm ZxBQh+s92fQVa3vS+8Ky1d2aaqcgAG2CLbcw8YHkh0+84FdtVQLklV7WPAmbKRX58leS W71cht323Y3W+2EiA//UTcCnSoRUX/ChSC2CBMA0rLKTC2GTdF0bGNMXCfHUA5xIFYXi do2UkOhyp6I8pNsugq4vfexkEMkKRv04wwhgW9JZ6tHWfODdXOheKa2WSLI562QJ/dEs qpWK1TETgv023IdxeOf+yVegl7Sfetps9EpbaNFWu7+R2SfehOTt4VgVb93IXkCIlQ8b JwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777828255; x=1778433055; 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=N0tW0FxSBXoHGLy8UAyiIK3CDK7lkkw9WSavrtAU+9E=; b=rszh2Ne6T1m4TyqSTm6yk22n+xzFWWzPbjy8F1MPOfEtySHGngXeHorydkj3FOrwEs 7RCZpguF2h8VZrQ6aL77soLJGTbPxi3hIVBIadT/S9WxAzE+s6Folj4bRc6C0ZPHq90i QQRugzPJe7dSJePOpDJ/UksP8ZqDSviryUmOoLQUny+H+Bmf2nYp2lhm3J0G1Ej1R4BR 2IlgIbCGE9kDygOjM8zWSViPrhcAEixHskWn+DnIQZzgQsRgPoX5rX9/j5ClOctGeikS JeJSoYsXLEqL3BsIbh9xlW1kB4lbO7sfX4rduy6aIOP4LplFJYAtTNcxO4BICjQbcEQD zdqQ== X-Forwarded-Encrypted: i=1; AFNElJ8V5mit/7nHzq7c74KMD7SLlpw1hHs3Z7TzoUBG+mODu7oDxlExdKHBnNFhIgOLTLN9+xEQtHrdxKAXLQk=@vger.kernel.org X-Gm-Message-State: AOJu0YxgbmURG2jZBGeI3GuDVfnxA7mfJf6d0giPXRUUm27WM16zb6uu kaaDi0A8DuLG73vyZ86UwjrMN8m0jnvskZDf19wCvVhXIsOY0cOUG8+Q2AtFAj/bilTSwv9840B /TM82XXcNJA== X-Received: from dlbuu10.prod.google.com ([2002:a05:7022:7e8a:b0:12c:87ba:191d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1a85:b0:127:380e:ff5a with SMTP id a92af1059eb24-12dfd7f994bmr3060618c88.17.1777828255093; Sun, 03 May 2026 10:10:55 -0700 (PDT) Date: Sun, 3 May 2026 10:10:32 -0700 In-Reply-To: <20260503171032.1559338-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: <20260503003552.1063540-1-irogers@google.com> <20260503171032.1559338-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503171032.1559338-7-irogers@google.com> Subject: [PATCH v4 6/6] 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 Signed-off-by: Ian Rogers --- 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