From nobody Mon Oct 6 06:46:45 2025 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) (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 598A62EBDC7 for ; Thu, 24 Jul 2025 16:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374810; cv=none; b=R7hJypg8E4nWYz3rKfpC3OFJZpUnD6+KlO3Ugyc7rYz0SkX8z550mQYsyGJYXtufaGIPG2+85OgGcczVmAU5GY6aZ8wqUKd0dWeb/u/kHpJ6hdvPh80FhCMMG+ce3uU0yUwpwYwk8r3ZjjX0l0j41XGzSq5Bs+3BINM+T6/SOiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753374810; c=relaxed/simple; bh=jWmhHDZHMj/3vn0T7Yg57/66qyMX0GILKf6742UzDIc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=eZqgUk+l50IHbDdITLKbgbJyfCzoLpbgV+DGL1gxTFabcrSwKvZL6GblmqaLdO00M6KvAkaO8AFyJFGJu5dWeZszTO3cYxcPdqinDgPheJ47tPt8CEuv+ts2XFAAifnQRI9XTo4cUA6tCbyGwnjq0E2r9aU37r1Y+Z0XcokzixE= 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=fVilWEzi; arc=none smtp.client-ip=209.85.210.74 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="fVilWEzi" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-73e542afa9dso1531006a34.1 for ; Thu, 24 Jul 2025 09:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753374807; x=1753979607; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=k8rjfFzd/+TAfQBkNwQcdwCN90rmJcS2goaVAmuWKh4=; b=fVilWEzisKewcIKQ/VuE2GrYq9psuDo2oh9HyLZBQTd5LpWOPtth/D2aVt/+pO5Lil 4b7d2w4t2sawZ1rnqJSvEd7Fvt3vELwTdEbYz61DH/I6Pz7zIXcuGIeIsUtudHJfHJKr 6bblw3HAPLifH/rNQWOoAUerLV2L4LpdulUUoy4Cok1tjix7tddGtIvVIuDoWAAaxmmZ R6+RRKkFxt5iOqINr+rqK0rs7Mn/DeIUlPui+xS0ZftOiLPSqwP66yDpHotYEOIaHR1T JTRAJOm2Bgt5RWVTqncPXSKdjGfoyDFLYZUKJmruLI0pY2B2YM/lR2gc9rOsjS7AMkBk d49w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753374807; x=1753979607; h=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=k8rjfFzd/+TAfQBkNwQcdwCN90rmJcS2goaVAmuWKh4=; b=CO0QGAHJIbofDUDCrj5ncVlIBsKEVFDBmAqUrE5gQFhUIAuf4DfjrPSv40INwm7+1o uHH14MXflS8ckZH2lrk0O7ii9I+bspE42Raq8JEK9dycmW87DPl8rW0zvDrWBToyyBkc +AdRS78xSACcAPBcwLf42835dqZPidCakYPlWjRr+i3IH0hmfyV5F9cfD9kPQemvP9xF kJSZBlp1YPkkrbM3tts/ryvIgFRgUIVslzbI6KTkjvMF/JKsa0SJvKIzBxB9gQpVXT7M hqURBCS0ZvQBDmBG0sP1V/D2HtGtUK8LupT8Tny7NIWb0yvlgLMXbEoP0e2GJl2UFStb Cwvg== X-Forwarded-Encrypted: i=1; AJvYcCXVONoP31AJJ4qpzRnI0UzMQsmCQASGNEOgtrR2wfR53BHlgI9qCacVM6S1hypKUY3MYiNZFeL9tVKmWS0=@vger.kernel.org X-Gm-Message-State: AOJu0YzbymLWtimXqw/AVKIGAcTzrdvYfzL2KGVKR6kbmLfPgqDNyFek k7nUUBiHyS8yxPbJwAdezLuPJMBAkWOSrTQVyhxEGI/TTJTDZQP+sw704Fe1bLRAvz8kF0Z8S+k wscSQS81n/Q== X-Google-Smtp-Source: AGHT+IGeB/DLDZyaNVsHJ4AdldqG7OAmJC6adn7cWB80Ve9eLfKQAPhnQItfzN+IISZ5vKzoha8DgZyIV7TB X-Received: from oabti11.prod.google.com ([2002:a05:6871:890b:b0:2c8:7806:5ad0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:270e:b0:735:b9db:5939 with SMTP id 46e09a7af769-74088ab9e84mr6005118a34.10.1753374807417; Thu, 24 Jul 2025 09:33:27 -0700 (PDT) Date: Thu, 24 Jul 2025 09:32:45 -0700 In-Reply-To: <20250724163302.596743-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: <20250724163302.596743-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250724163302.596743-6-irogers@google.com> Subject: [PATCH v6 05/22] perf build-id: Ensure struct build_id is empty before use From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , "Masami Hiramatsu (Google)" , Ravi Bangoria , Charlie Jenkins , Colin Ian King , Andi Kleen , Dmitry Vyukov , Graham Woodward , Ilkka Koskinen , Zhongqiu Han , Yicong Yang , Athira Rajeev , Kajol Jain , Li Huafei , "Steinar H. Gunderson" , Stephen Brennan , Chun-Tse Shao , Yujie Liu , "Dr. David Alan Gilbert" , Levi Yun , Howard Chu , Weilin Wang , Thomas Falcon , Matt Fleming , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Zixian Cai , Steve Clevenger , Ben Gainey , Chaitanya S Prakash , Martin Liska , "=?UTF-8?q?Martin=20Li=C5=A1ka?=" , Song Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a build ID is read then not all code paths may ensure it is empty before use. Initialize the build_id to be zero-ed unless there is clear initialization such as a call to build_id__init. Signed-off-by: Ian Rogers --- tools/perf/bench/inject-buildid.c | 2 +- tools/perf/builtin-buildid-cache.c | 8 ++++---- tools/perf/tests/pe-file-parsing.c | 2 +- tools/perf/tests/sdt.c | 2 +- tools/perf/util/build-id.c | 6 +++--- tools/perf/util/debuginfo.c | 2 +- tools/perf/util/probe-event.c | 3 ++- tools/perf/util/probe-finder.c | 3 ++- tools/perf/util/symbol-minimal.c | 2 +- tools/perf/util/symbol.c | 5 +++-- tools/perf/util/synthetic-events.c | 2 +- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-bu= ildid.c index f55c07e4be94..aad572a78d7f 100644 --- a/tools/perf/bench/inject-buildid.c +++ b/tools/perf/bench/inject-buildid.c @@ -80,7 +80,7 @@ static int add_dso(const char *fpath, const struct stat *= sb __maybe_unused, int typeflag, struct FTW *ftwbuf __maybe_unused) { struct bench_dso *dso =3D &dsos[nr_dsos]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; =20 if (typeflag =3D=3D FTW_D || typeflag =3D=3D FTW_SL) return 0; diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index 3f7739b21148..e936a34b7d37 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -175,7 +175,7 @@ static int build_id_cache__add_kcore(const char *filena= me, bool force) static int build_id_cache__add_file(const char *filename, struct nsinfo *n= si) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int err; struct nscookie nsc; =20 @@ -198,7 +198,7 @@ static int build_id_cache__add_file(const char *filenam= e, struct nsinfo *nsi) static int build_id_cache__remove_file(const char *filename, struct nsinfo= *nsi) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nscookie nsc; =20 int err; @@ -275,7 +275,7 @@ static int build_id_cache__purge_all(void) static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_u= nused) { char filename[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; =20 if (!dso__build_id_filename(dso, filename, sizeof(filename), false)) return true; @@ -303,7 +303,7 @@ static int build_id_cache__fprintf_missing(struct perf_= session *session, FILE *f static int build_id_cache__update_file(const char *filename, struct nsinfo= *nsi) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nscookie nsc; =20 int err; diff --git a/tools/perf/tests/pe-file-parsing.c b/tools/perf/tests/pe-file-= parsing.c index fff58b220c07..30c7da79e109 100644 --- a/tools/perf/tests/pe-file-parsing.c +++ b/tools/perf/tests/pe-file-parsing.c @@ -24,7 +24,7 @@ static int run_dir(const char *d) { char filename[PATH_MAX]; char debugfile[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; char debuglink[PATH_MAX]; char expect_build_id[] =3D { 0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22, diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c index 919712899251..de4c7916b40d 100644 --- a/tools/perf/tests/sdt.c +++ b/tools/perf/tests/sdt.c @@ -28,7 +28,7 @@ static int target_function(void) static int build_id_cache__add_file(const char *filename) { char sbuild_id[SBUILD_ID_SIZE]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int err; =20 err =3D filename__read_build_id(filename, &bid); diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 3386fa8e1e7e..1abd5a670665 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -95,7 +95,7 @@ int build_id__snprintf(const struct build_id *build_id, c= har *bf, size_t bf_size int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t= sbuild_id_size) { char notes[PATH_MAX]; - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 if (!root_dir) @@ -112,7 +112,7 @@ int sysfs__snprintf_build_id(const char *root_dir, char= *sbuild_id, size_t sbuil =20 int filename__snprintf_build_id(const char *pathname, char *sbuild_id, siz= e_t sbuild_id_size) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 ret =3D filename__read_build_id(pathname, &bid); @@ -849,7 +849,7 @@ static int filename__read_build_id_ns(const char *filen= ame, =20 static bool dso__build_id_mismatch(struct dso *dso, const char *name) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; bool ret =3D false; =20 mutex_lock(dso__lock(dso)); diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c index b5deea7cbdf2..a44c70f93156 100644 --- a/tools/perf/util/debuginfo.c +++ b/tools/perf/util/debuginfo.c @@ -103,7 +103,7 @@ struct debuginfo *debuginfo__new(const char *path) char buf[PATH_MAX], nil =3D '\0'; struct dso *dso; struct debuginfo *dinfo =3D NULL; - struct build_id bid; + struct build_id bid =3D { .size =3D 0}; =20 /* Try to open distro debuginfo files */ dso =3D dso__new(path); diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index cb777b878a48..e11c1be5c6d5 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1063,7 +1063,6 @@ static int sprint_line_description(char *sbuf, size_t= size, struct line_range *l static int __show_line_range(struct line_range *lr, const char *module, bool user) { - struct build_id bid; int l =3D 1; struct int_node *ln; struct debuginfo *dinfo; @@ -1088,6 +1087,8 @@ static int __show_line_range(struct line_range *lr, c= onst char *module, ret =3D -ENOENT; } if (dinfo->build_id) { + struct build_id bid; + build_id__init(&bid, dinfo->build_id, BUILD_ID_SIZE); build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); } diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index b74f6fe24bb6..5ffd97ee4898 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -848,7 +848,6 @@ static int probe_point_lazy_walker(const char *fname, i= nt lineno, /* Find probe points from lazy pattern */ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *p= f) { - struct build_id bid; char sbuild_id[SBUILD_ID_SIZE] =3D ""; int ret =3D 0; char *fpath; @@ -858,6 +857,8 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, str= uct probe_finder *pf) =20 comp_dir =3D cu_get_comp_dir(&pf->cu_die); if (pf->dbg->build_id) { + struct build_id bid; + build_id__init(&bid, pf->dbg->build_id, BUILD_ID_SIZE); build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id)); } diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index c73fe2e09fe9..7201494c5c20 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -317,7 +317,7 @@ int dso__load_sym(struct dso *dso, struct map *map __ma= ybe_unused, struct symsrc *runtime_ss __maybe_unused, int kmodule __maybe_unused) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; int ret; =20 ret =3D fd__is_64_bit(ss->fd); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 573c65da9fe0..e816e4220d33 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1813,7 +1813,6 @@ int dso__load(struct dso *dso, struct map *map) struct symsrc *syms_ss =3D NULL, *runtime_ss =3D NULL; bool kmod; bool perfmap; - struct build_id bid; struct nscookie nsc; char newmapname[PATH_MAX]; const char *map_path =3D dso__long_name(dso); @@ -1874,6 +1873,8 @@ int dso__load(struct dso *dso, struct map *map) */ if (!dso__has_build_id(dso) && is_regular_file(dso__long_name(dso))) { + struct build_id bid =3D { .size =3D 0, }; + __symbol__join_symfs(name, PATH_MAX, dso__long_name(dso)); if (filename__read_build_id(name, &bid) > 0) dso__set_build_id(dso, &bid); @@ -2122,7 +2123,7 @@ static bool filename__readable(const char *file) =20 static char *dso__find_kallsyms(struct dso *dso, struct map *map) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; char sbuild_id[SBUILD_ID_SIZE]; bool is_host =3D false; char path[PATH_MAX]; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 68bb7c5fe1b1..b7ebee95536f 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -368,7 +368,7 @@ static void perf_record_mmap2__read_build_id(struct per= f_record_mmap2 *event, struct machine *machine, bool is_kernel) { - struct build_id bid; + struct build_id bid =3D { .size =3D 0, }; struct nsinfo *nsi; struct nscookie nc; struct dso *dso =3D NULL; --=20 2.50.0.727.gbf7dc18ff4-goog