Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp117857qtg; Thu, 6 Apr 2023 14:14:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bpnYEG/EKXEWFubOQXwzv3CXDx0kFoNcHpZhHYO8Q/zvK7bqzyQuCpQnony5AuIF7miuS0 X-Received: by 2002:a17:907:2136:b0:885:fee4:69ee with SMTP id qo22-20020a170907213600b00885fee469eemr255946ejb.59.1680815644462; Thu, 06 Apr 2023 14:14:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815644; cv=none; d=google.com; s=arc-20160816; b=ufWoKDQWDlgUs0lk8EFDiHuxaYBOnyLdKGJO7tGmoejP8cS8QRFtazb4EZJoMmjqy5 5Znr47WpjvGBoQdXXNH6AzeiK8P9VMVYCSJQ4p34nEMOEQahhyGZfnu2ABWjMIlBNrNR uWJVJKsGlFVNtsv0zE0NmTR6wXJhSGNjrT8KVhifSB8KCLLX46kU88kqIHw+z8WuFmT4 r7BSw2rm5TzyfqO/MyxNxjnHhwpxgkWMEzq8975CCYyHb3XSlRx1g6KDrc+lRdWSrOSx cOolmiYWtYIU92F3cxZjAbuY67axqb6yDP05rTIpD8k8HaFX4RqzVA0VSbr3Cajz3nAk AYFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RFSpG5wpEZPim+qwDg57IRshLb3yXVGY2D+dWC0cNiw=; b=n/7IY/z8nYkGwl9temWsVfFzJ0EVaEvNVGdX9xCxxFxJ4nO/Si35yAJkKveXkp1xyO +4renk+Ys1ZL3x29U2XYb+Qlw7VxTHM0RpHhMiyTP8cRuMfo+K+yUWUfEZWScZ+8kaq9 EV0LtKAFiO9uXBlCabZi4QOQj+pyheOS6TjEKERNkc9OPywxOofCF2eS9JkH551qcDOB 2NiR6+QR/e4GDIkd1pWS3xE0988hJ1WY4JA7JtNN25hm9lAOc14Biqt7iVHs1DUakuyZ AAQ3W3e8qBeYfdOBQNIWU3hpfenhNa6SjNCm0UkXjocvv4txxYg4rnvpARrEeBhXC87v Spfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N75fWbfk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a17090669c200b00937a2b0691asi1802499ejs.298.2023.04.06.14.13.39; Thu, 06 Apr 2023 14:14:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N75fWbfk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239478AbjDFVJk (ORCPT + 99 others); Thu, 6 Apr 2023 17:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238341AbjDFVJe (ORCPT ); Thu, 6 Apr 2023 17:09:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E2DA277; Thu, 6 Apr 2023 14:09:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E7AC8646B6; Thu, 6 Apr 2023 21:09:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D06C433EF; Thu, 6 Apr 2023 21:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680815372; bh=V73X3zvMa9mX4eCZmR/vnJEvOTmLrZEgknm1JtpSEVs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N75fWbfkjf2gsk/xhd1aFBCHQuVhOAIpqMmBceeHsPiKJoWyfqBAUEmm49JSsazJ+ u8z6pMW+oGkVtWRjhKyKKzWC/ex+NIRvJRBEUcGdZwurMaTcodHvs2Pr9yk4I9YG5C LkwzdIeVQ2VEB+KgXHVe64J2IwdZvZiZWYLYdAfEakD3lzI0zdKGJSXIYLC6GmEorV iGFcNlaEHEGATO5iRF7ghyW/CrhH1CsNbznnhES4c5MM7xFHta61N54+LJsm11Ld/4 iIbfSZw5djNdFr8GSjgiycIa4MXvQKCNv1iVJR3gmDHvlEf5uXJyu/ucTpQTgI/77K tn2n9yfEV/8uw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 748954052D; Thu, 6 Apr 2023 18:09:29 -0300 (-03) Date: Thu, 6 Apr 2023 18:09:29 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers , Jiri Olsa Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Namhyung Kim , Adrian Hunter , James Clark , Suzuki Poulouse , Sean Christopherson , Ravi Bangoria , Rob Herring , Leo Yan , German Gomez , Jing Zhang , Gaosheng Cui , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] perf pmu: Fix a few potential fd leaks Message-ID: References: <20230406065224.2553640-1-irogers@google.com> <20230406065224.2553640-2-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230406065224.2553640-2-irogers@google.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Apr 05, 2023 at 11:52:24PM -0700, Ian Rogers escreveu: > Ensure fd is closed on error paths. Was this reported by Jiri? - Arnaldo > Signed-off-by: Ian Rogers > --- > tools/perf/util/pmu.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 96ef317bac41..9eedbfc9e863 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -494,9 +494,13 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head) > continue; > > fd = openat(dirfd, name, O_RDONLY); > + if (fd == -1) { > + pr_debug("Cannot open %s\n", name); > + continue; > + } > file = fdopen(fd, "r"); > if (!file) { > - pr_debug("Cannot open %s\n", name); > + close(fd); > continue; > } > > @@ -1882,9 +1886,13 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) > continue; > > fd = openat(caps_fd, name, O_RDONLY); > + if (fd == -1) > + continue; > file = fdopen(fd, "r"); > - if (!file) > + if (!file) { > + close(fd); > continue; > + } > > if (!fgets(value, sizeof(value), file) || > (perf_pmu__new_caps(&pmu->caps, name, value) < 0)) { > -- > 2.40.0.348.gf938b09366-goog > -- - Arnaldo