Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp126530qtg; Thu, 6 Apr 2023 14:34:54 -0700 (PDT) X-Google-Smtp-Source: AKy350Zm/v/Uda8NAWFGVkxxxUubU+dFb0uQ7HRd4PqEqRaIhf548i3P9Ltqji2hJxwXGWp4Ie2C X-Received: by 2002:a17:90a:764f:b0:234:b03:5a70 with SMTP id s15-20020a17090a764f00b002340b035a70mr12054751pjl.35.1680816894154; Thu, 06 Apr 2023 14:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816894; cv=none; d=google.com; s=arc-20160816; b=xd6FDGtYjIq+oROnI+F6iSZ/jyhN9NXPJCpPoBBT+v3ypbSWXQsrTMkwglF3JiQy9S lsWKodKRYqAwRgEJAhrJXnFyVjLJ5fYXrhOzk28et799PGZ24ndo04hlkoTnSXY0AuLH RDnItmqzP4g+5c9ucG3DTmn+PPZk20/lkUiub2gDv2z/bqtcoWmpZvAafbfYow1llWOw nAjIO+GeayY/WTiU8AIhEE2E55bivXQ9ro0U4nUCBxcqN/B1TjM8+T1bZwX1PYJrtbrR vAxKUISbRv533+ORQv2lmxbESzYnCcJmw4LO4SlHVZ2VCeX1kQS/nU06ADLiRJ8zeQP3 Vm6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=IObMk8A+yB7kzQzd06qcvUQD4B00Pzu5PtnbgiCc0Qc=; b=xFSOaYjnew+AkZ7IDuEa7IDuPRYMiTTRcltF/NQXYnGp/IJnr/RjhhzSDR8KRgK3b3 dRvsl6dA0gQNtMXmsvI9cxlqYw8WdamoHWU/SBo1OlWVqBJbBika3gqTrB1VNCQmwE6I 6TUUuXFcFSvFfdgJkDDU3mHh5/u5lFNi3+6InY0pfWpjeMnScBE/b8+d9PhHWaGLb3U6 g4AbJEkc9HmibvaviYMzqT5fHhknNYaGeYZczSef4DL+2NCSj9eR6MsoA2ikSQQw15m5 3+VRuZafE1k/aBF8bgDli3htVQQfdeMdXEC11mIqKNf7FkULIRQWtC9f+eySAuoIFJNb K9gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rfBYLWlu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t5-20020a17090a3e4500b002307345bf7bsi4780760pjm.23.2023.04.06.14.34.42; Thu, 06 Apr 2023 14:34:54 -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=@google.com header.s=20210112 header.b=rfBYLWlu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbjDFVdY (ORCPT + 99 others); Thu, 6 Apr 2023 17:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231316AbjDFVdW (ORCPT ); Thu, 6 Apr 2023 17:33:22 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D0BC8A6E for ; Thu, 6 Apr 2023 14:33:19 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-3e390e23f83so528031cf.1 for ; Thu, 06 Apr 2023 14:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680816798; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IObMk8A+yB7kzQzd06qcvUQD4B00Pzu5PtnbgiCc0Qc=; b=rfBYLWluQ0/Pd7dFpjwZXmRk6uGk/xeFl3oqLaePqw0xeERch2oiY4AxHT9EJaZ+Jc O2rdydCfeZvAvtDwiWqxVd3/d/p0jeE4MPlQfO1ys6QZYNdkjk0BoGwyaiXbuLfrzOpw hVz0mhcXBPMnkBJyP/9ttJOIr7Mq0Xa3/ladg15pyMqEcH14NjzwzXsgPW7giOlNLX3H n+lVKYjoIidbNWXSHuRgz/yB8zRV60SnGZaT2P2Jc7NJ/lvAbVwxwTihErJQddtq4Mwu in+uqz8l9G9gPh72cka0drTL5o7FJC9HEME2XPBvqESwcdMnMdvOTqYzlaUpeUfZUzUV ecDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680816798; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IObMk8A+yB7kzQzd06qcvUQD4B00Pzu5PtnbgiCc0Qc=; b=jzjUNx47D8JT3c5510fs0+TuKLG5mVverwL/9lArcJR5jZ9ngvfdLA4Zqt9gVqpFcG QZ6dpujwRuetqwP+ZQCyadcOEXRjk/nB5h+r1vOq4yq5pVLk2bU1QH1H9kHPtSxQfQnb QDV6nagH6Pb17E3LPtH4Ushc0vicPapt2MvsXm1bcvGMvrrlwX1AIrFIsJzciig/pimH 7lYO8wDh0bvpGsPjUYRmHlXv0KzIg+zAncdBcVaUX169v+kz1MQGjtCAni+S3ZLqVLKG y6+Kku1iWQTDow4xKrZRLD2HKcriaFAxOLlBC8pRVG/5QNYKgmLmGxsFIsWTlt1cluh6 P+OQ== X-Gm-Message-State: AAQBX9cnqR4tJ/4pH9HZeo0j97AhRstcuJxPJozf3dlkBZBsYxFyRUs4 msd5WjknstRMjPrNnRWEcXZcFZL9fYjWNjCJDdSl5A== X-Received: by 2002:ac8:5bd2:0:b0:3bd:17d6:e04c with SMTP id b18-20020ac85bd2000000b003bd17d6e04cmr138867qtb.2.1680816798405; Thu, 06 Apr 2023 14:33:18 -0700 (PDT) MIME-Version: 1.0 References: <20230406065224.2553640-1-irogers@google.com> <20230406065224.2553640-2-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Thu, 6 Apr 2023 14:33:07 -0700 Message-ID: Subject: Re: [PATCH v3 2/2] perf pmu: Fix a few potential fd leaks To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 On Thu, Apr 6, 2023 at 2:09=E2=80=AFPM Arnaldo Carvalho de Melo wrote: > > 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? Jiri's one was in the code I modified, whereas these were from Namhyung's previous openat change. It is the same issue, I'm agnostic on whether it needs a tag or not. Thanks, Ian > - 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 lis= t_head *head) > > continue; > > > > fd =3D openat(dirfd, name, O_RDONLY); > > + if (fd =3D=3D -1) { > > + pr_debug("Cannot open %s\n", name); > > + continue; > > + } > > file =3D 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 =3D openat(caps_fd, name, O_RDONLY); > > + if (fd =3D=3D -1) > > + continue; > > file =3D 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