From: Collin Funk <collin.funk1@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Chun-Tse Shao <ctshao@google.com>,
Blake Jones <blakejones@google.com>,
James Clark <james.clark@linaro.org>,
Jan Polensky <japo@linux.ibm.com>,
Howard Chu <howardchu95@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Nam Cao <namcao@linutronix.de>, Li Huafei <lihuafei1@huawei.com>,
"Steinar H. Gunderson" <sesse@google.com>,
Athira Rajeev <atrajeev@linux.ibm.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/5] perf disasm: Avoid undefined behavior in incrementing NULL
Date: Thu, 21 Aug 2025 15:39:18 -0700 [thread overview]
Message-ID: <87h5y09u5l.fsf@gmail.com> (raw)
In-Reply-To: <20250821163820.1132977-2-irogers@google.com>
Ian Rogers <irogers@google.com> writes:
> Incrementing NULL is undefined behavior and triggers ubsan during the
> perf annotate test. Split a compound statement over two lines to avoid
> this.
>
> Fixes: 98f69a573c66 ("perf annotate: Split out util/disasm.c")
> Signed-off-by: Ian Rogers <irogers@google.com>
> Acked-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/disasm.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> index b1e4919d016f..e257bd918c89 100644
> --- a/tools/perf/util/disasm.c
> +++ b/tools/perf/util/disasm.c
> @@ -390,13 +390,16 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
> * skip over possible up to 2 operands to get to address, e.g.:
> * tbnz w0, #26, ffff0000083cd190 <security_file_permission+0xd0>
> */
> - if (c++ != NULL) {
> + if (c != NULL) {
> + c++;
> ops->target.addr = strtoull(c, NULL, 16);
> if (!ops->target.addr) {
> c = strchr(c, ',');
> c = validate_comma(c, ops);
> - if (c++ != NULL)
> + if (c != NULL) {
> + c++;
> ops->target.addr = strtoull(c, NULL, 16);
> + }
> }
> } else {
> ops->target.addr = strtoull(ops->raw, NULL, 16);
It is undefined behavior, but works correctly with GCC and Clang. In
Gnulib, we allow it and suggest using -fno-sanitize=pointer-overflow
instead [1].
But I can understand that is not every projects preference. Therefore,
this change looks good to me.
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
Collin
[1] https://www.gnu.org/software/gnulib/manual/html_node/Unsupported-Platforms.html
next prev parent reply other threads:[~2025-08-21 22:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 16:38 [PATCH v2 0/5] Various fixes around undefined behavior Ian Rogers
2025-08-21 16:38 ` [PATCH v2 1/5] perf disasm: Avoid undefined behavior in incrementing NULL Ian Rogers
2025-08-21 22:39 ` Collin Funk [this message]
2025-08-21 16:38 ` [PATCH v2 2/5] perf test trace_btf_enum: Skip if permissions are insufficient Ian Rogers
2025-08-21 16:38 ` [PATCH v2 3/5] perf evsel: Avoid container_of on a NULL leader Ian Rogers
2025-08-21 16:38 ` [PATCH v2 4/5] perf test shell lock_contention: Extra debug diagnostics Ian Rogers
2025-08-21 16:38 ` [PATCH v2 5/5] libperf event: Ensure tracing data is multiple of 8 sized Ian Rogers
2025-08-26 8:38 ` [PATCH v2 0/5] Various fixes around undefined behavior James Clark
2025-09-02 19:34 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h5y09u5l.fsf@gmail.com \
--to=collin.funk1@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atrajeev@linux.ibm.com \
--cc=blakejones@google.com \
--cc=ctshao@google.com \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=japo@linux.ibm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namcao@linutronix.de \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sesse@google.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox