Skip to content

Commit 00f13e2

Browse files
captain5050rostedt
authored andcommitted
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. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://patch.msgid.link/20260108002625.333331-1-irogers@google.com Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 90f9f5d commit 00f13e2

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

kernel/trace/trace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6115,10 +6115,10 @@ static int cmp_mod_entry(const void *key, const void *pivot)
61156115
unsigned long addr = (unsigned long)key;
61166116
const struct trace_mod_entry *ent = pivot;
61176117

6118-
if (addr >= ent[0].mod_addr && addr < ent[1].mod_addr)
6119-
return 0;
6120-
else
6121-
return addr - ent->mod_addr;
6118+
if (addr < ent[0].mod_addr)
6119+
return -1;
6120+
6121+
return addr >= ent[1].mod_addr;
61226122
}
61236123

61246124
/**

0 commit comments

Comments
 (0)