From: Steven Rostedt <rostedt@goodmis.org>
To: Ian Rogers <irogers@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v1] tracing: Avoid possible signed 64-bit truncation
Date: Tue, 9 Dec 2025 21:31:35 -0500 [thread overview]
Message-ID: <20251209213135.13eb68f4@fedora> (raw)
In-Reply-To: <20251209224024.2322124-1-irogers@google.com>
On Tue, 9 Dec 2025 14:40:24 -0800
Ian Rogers <irogers@google.com> wrote:
> 64-bit truncation to 32-bit can result in the sign of the truncated
> value changing. The cmp_mod_entry is used in bsearch and so the
> truncation could result in an invalid search order. This would only
> happen were the addresses more than 2GB apart and so unlikely, but
> let's fix the potentially broken compare anyway.
I'm fine with fixing this but I believe if the addresses are more than
2GB apart there could be other issues elsewhere ;-)
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> kernel/trace/trace.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index d1e527cf2aae..e6a80cbe9326 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -6057,8 +6057,10 @@ static int cmp_mod_entry(const void *key, const void *pivot)
>
> if (addr >= ent[0].mod_addr && addr < ent[1].mod_addr)
> return 0;
> + else if (addr > ent->mod_addr)
> + return 1;
> else
> - return addr - ent->mod_addr;
> + return -1;
Could we still keep this down to a single if check?
if (addr < ent->mod_addr)
return -1;
return addr >= ent[1].mod_addr;
-- Steve
> }
>
> /**
prev parent reply other threads:[~2025-12-10 2:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 22:40 [PATCH v1] tracing: Avoid possible signed 64-bit truncation Ian Rogers
2025-12-10 2:31 ` Steven Rostedt [this message]
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=20251209213135.13eb68f4@fedora \
--to=rostedt@goodmis.org \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).