From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796347625; b=s+BIz73USagf6ZUnC03ZDKAmQcSXL7sKMQrvFokvf3FWKodkbQP83C4xBVhXviY1XNfy Ug9aHFhPjhusxPZsT0dKyqTuEJB9A7uSwIsLC7IEZ1lVJa3DVoR/vEz87gGafTLBghMK9 2L9hFD+Qf0bks3hnD8ctOtc7Jos7nhA4r9RVfu7KMzJ0ZK1MCOVv/v6sO2BmpmWo+aU4Z zA27HJyh1MKiJcX8i3wgyVFOjtD1OanpPyw2lDZz1oTG2hXVSVhyR0tKE/bhLy878XXIc 6z3gWDMizeon9WSGw+WMvx6QJgacIxim6IpAA5y9wM5C9Ov2BhJLp0WiUxp5OgnC20g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796347625; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=xQH2bs68ajFPt2woguJkDHP94Hz05vJpPdU4g9VudVE=; b=D1vUtxi8ewF/qo0id+BC2kos3FqVnIQXo+WC7LrxbQ4qOHMBmt1WrIi42jlVP5cLAjs8 /7Gx0FRf4A3PBof58YtXEitVl9A8cKxT7JnGpg3PrM4jkXU2tRAFuyjJq4aGaZce07Kxf E8IXvRrUQsDHuLgeEx2GC7L4bDdFG3FZNrbIqAYL2Zi3Dg6ffrZwhJZkOmS4lplPvF3+G RyD92/TMc+Z3x/x8OEPc0SfrQomVW32Pw15FGWWQjXb2rBBonBHqXywJonrgaqRQKkHnN HqIO8v7rVinuJq1O42MFHBqTge8HrBmna0YZNcXLk7vKSwouk4xv2CjXXVWbB6aDJ5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kfCJ4+RC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3EB606A322 for ; Fri, 4 Dec 2026 01:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kfCJ4+RC Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53D91F00897; Fri, 4 Dec 2026 01:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796347625; bh=xQH2bs68ajFPt2woguJkDHP94Hz05vJpPdU4g9VudVE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kfCJ4+RCdnme2qZlUALv61yb98yuqnyFshRQA5ia90v2EQ5kYyezpl8plsmIcPWkU OFTntLlhiVBgapgMckOXcdANZpGOuTi84INIQvhDOYZr7xM6WoDfELLqcFj8dc2I4q FdQerKVHsu2x84RFXomjeqUmYvxuwDDY2cmGYgf7pT79QZlqY66HMigDhXgvYMtaGd 8+0UCq7LBh5R4FuyogQpNF9EptRChDPMWo/ma44/gGJA85H81kuWDDtVCUKrc7n/1S i2xzseqflx5FZ9DDklaoV0ZM5+lw+bUI58Vt3fxHOLb8dwtiwmIXIAYL1wS9/9466B PdnKFdBt9c78w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 05/11] perf config: Add pmu-events.dir configuration option Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261204011029.1946921-6-irogers@google.com> References: <20261204011029.1946921-1-irogers@google.com> <20261204011029.1946921-6-irogers@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:27:04 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] perf pmu-layer: unexpanded tilde path in pmu_layers_add_user_dirs() - [Medium] perf pmu-layer: per-lookup openat and getdents64 storms in user_dir_layer_ops - [Medium] perf pmu-layer: unchecked cap doubling and file type in dir_read_fd() - [Low] perf pmu-layer: tilde overflow aborts init in pmu_layers_add_user_dirs() -- commit ef894413c604fbf05187e1f7bae3997e7d585869 Author: Ian Rogers perf config: Add pmu-events.dir configuration option This commit adds the pmu-events.dir configuration option to register colon-separated PMU overlay directories with leading ~/ expansion in the PMU layer stack. It activates user_dir_layer_ops, resets the layer stack in perf_config__exit() and perf_pmus__destroy(), and documents the option in perf-config.txt. > diff --git a/tools/perf/util/pmu-layer.c b/tools/perf/util/pmu-layer.c > index d4fb8c64f617a..7ab72c8adf9cc 100644 > --- a/tools/perf/util/pmu-layer.c > +++ b/tools/perf/util/pmu-layer.c [ ... ] > @@ -2079,7 +2080,7 @@ static int user_dir_load_metricgroup(const struct p= mu_layer *layer, > return ret < 0 ? ret : 0; > } > =20 > -static const struct pmu_layer_ops __maybe_unused user_dir_layer_ops =3D { > +static const struct pmu_layer_ops user_dir_layer_ops =3D { [Severity: Medium] Now that user_dir_layer_ops is active, can non-regular or oversized files in a pmu-events.dir overlay hang perf or corrupt the heap in dir_read_fd()? dir_read_file_at_mode() calls openat() with O_RDONLY and no O_NONBLOCK or fstat() S_ISREG check, and dir_read_fd() reads in an unbounded loop with an unchecked cap *=3D 2: tools/perf/util/pmu-layer.c:dir_read_fd() { ... for (;;) { if (len + 1 >=3D cap) { char *next; cap *=3D 2; next =3D realloc(buf, cap); if (!next) { free(buf); close(fd); return -ENOMEM; } buf =3D next; } n =3D read(fd, buf + len, cap - len - 1); ... } A symlink to /dev/zero in an overlay directory reads until OOM on 64-bit systems, and on 32-bit builds cap *=3D 2 wraps size_t: either passing 0 to realloc() (double free on glibc or out-of-bounds write on musl) or shrinking buf below len and overflowing the heap buffer on the next read(). A FIFO in the directory also blocks openat() indefinitely. Opening with O_NONBLOCK, rejecting non-regular files via fstat(), and enforcing a size limit in dir_read_fd() would prevent both failures. [ ... ] > @@ -2318,13 +2319,65 @@ void pmu_layers__exit(void) > pmu_layers_initialized =3D false; > } > =20 > +static int pmu_layers_add_user_dirs(const char *cfg) > +{ > + const char *p =3D cfg; > + > + if (!cfg || !cfg[0]) > + return 0; > + > + while (*p) { > + const char *colon =3D strchr(p, ':'); > + size_t seg_len =3D colon ? (size_t)(colon - p) : strlen(p); > + > + if (seg_len > 0 && seg_len < PATH_MAX) { > + char raw[PATH_MAX]; > + char expanded[PATH_MAX]; > + const char *use_path =3D raw; > + int ret; > + > + memcpy(raw, p, seg_len); > + raw[seg_len] =3D '\0'; > + > + if (raw[0] =3D=3D '~' && (raw[1] =3D=3D '\0' || raw[1] =3D=3D '/')) { > + const char *home =3D getenv("HOME"); > + > + if (home && home[0]) { > + int n =3D snprintf(expanded, sizeof(expanded), > + "%s%s", home, raw + 1); > + > + if (n < 0 || (size_t)n >=3D sizeof(expanded)) > + return -ENAMETOOLONG; [Severity: Low] Should an overlong tilde expansion skip this entry instead of returning -ENAMETOOLONG? pmu_layers_ensure_init() treats any error from pmu_layers_add_user_dirs() as fatal and tears down the stack before appending the built-in and sysfs layers, so every later event or metric lookup silently returns NULL. An unexpanded segment of length >=3D PATH_MAX is already skipped above; warning and skipping here would keep the lower layers working. > + use_path =3D expanded; > + } > + } [Severity: Medium] If HOME is unset or empty, does this register the unexpanded tilde path as a working-directory-relative overlay? When perf runs under cron or systemd with a system perfconfig entry such as ~/.perf-events/local:/opt/pmu-events, use_path stays as the literal "~/.perf-events/local" string. dir_for_each_scope() then passes it straight to open(), which resolves ./~/.perf-events/local against the current working directory and lets a ./~ tree in a shared directory like /tmp override system overlays, built-in tables, and sysfs. Skipping the segment when HOME is unset or empty would match how home_perfconfig() handles missing HOME. > + > + ret =3D pmu_layers_append(PMU_LAYER_USER_DIR, > + &user_dir_layer_ops, use_path); [Severity: Medium] Can registering uncached user_dir_layer_ops entries here cause severe openat() and getdents64() syscall amplification on routine perf invocations? pmu_layers_add_user_dirs() appends every configured path without checking if it exists or caching an open root fd. On each lookup, dir_for_each_scope() re-opens root_path and its cpus/ and sys/ scopes, and for every uncore PMU dir_for_each_pmu_subdir() runs dup() and a full io_dir__readdir() scan of each matched scope. Because bare event parsing in parse_events_multi_pmu_add() and metric lookup scan across all PMUs, systems with many uncore PMUs incur repeated directory scans per event. On sparse overlays, an absent event also triggers up to 45 openat() sidecar probes per matched PMU subdir per scope in user_dir_find_event_pmu_cb(), and pmu_layer__find_event() and pmu_layer__find_metric() do not cache negative results so repeated probes replay the full sequence. Skipping nonexistent roots and caching discovered scope/PMU directories (or negative lookups) would avoid this overhead. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204011029.1946= 921-1-irogers@google.com?part=3D5