* [PATCH v1] tracing: Avoid possible signed 64-bit truncation
@ 2025-12-09 22:40 Ian Rogers
2025-12-10 2:31 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2025-12-09 22:40 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel
Cc: Ian Rogers
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.
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;
}
/**
--
2.52.0.223.gf5cc29aaa4-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] tracing: Avoid possible signed 64-bit truncation
2025-12-09 22:40 [PATCH v1] tracing: Avoid possible signed 64-bit truncation Ian Rogers
@ 2025-12-10 2:31 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2025-12-10 2:31 UTC (permalink / raw)
To: Ian Rogers
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel
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
> }
>
> /**
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-10 2:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 22:40 [PATCH v1] tracing: Avoid possible signed 64-bit truncation Ian Rogers
2025-12-10 2:31 ` Steven Rostedt
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).