tracing: Avoid possible signed 64-bit truncation
PATCH 1/1 tracing: Avoid possible signed 64-bit truncation
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.
--- kernel/trace/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace.c +3 -1
@@ -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 ; }/**
Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
Steven Rostedt
maintainerQuoted 5 lines · On Tue, 9 Dec 2025 14:40:24 -0800 Ian Rogers <[email protected]> wrote:
64-bit truncation to 32-bit can result in the sign of the truncated value changing. The
cmp_mod_entryis 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 ;-)
Quoted 11 lines
Signed-off-by Ian Rogers <[email protected]>--- kernel/trace/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/trace/trace.c +0
-0
kernel/trace/trace.c static int cmp_mod_entry(const void *key, const void *pivot) · line 6063
Quoted 8 lines
kernel/trace/trace.c +3
-1@@ -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
Quoted 3 lines
kernel/trace/trace.c +0
-0}/**
Steven Rostedt
maintainerQuoted 20 lines · On Tue, 9 Dec 2025 21:31:35 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 9 lines
--- kernel/trace/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/trace/trace.c +0
-0kernel/trace/trace.c static int cmp_mod_entry(const void *key, const void *pivot) · line 6063
Quoted 8 lines
kernel/trace/trace.c +3
-1@@ -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?
Quoted 4 lines
if (addr < ent->mod_addr) return -1; return addr >= ent[1].mod_addr;
Care to send a v2?
-- Steve
Quoted 24 lines · Steven Rostedt
Quoted 20 lines · On Tue, 9 Dec 2025 21:31:35 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 9 lines
--- kernel/trace/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/trace/trace.c +0
-0kernel/trace/trace.c static int cmp_mod_entry(const void *key, const void *pivot) · line 6063
Quoted 8 lines
kernel/trace/trace.c +3
-1@@ -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?
Quoted 6 lines
Quoted 4 lines
if (addr < ent->mod_addr) return -1; return addr >= ent[1].mod_addr;Care to send a v2?
Will do, sorry for the delay.
Ian
Quoted 1 line
-- Steve