Linux Trace Kernel
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tracing: Avoid possible signed 64-bit truncation
Date: Thu, 8 Jan 2026 11:35:10 +0900	[thread overview]
Message-ID: <20260108113510.5f0716c539f2ab416fd39ec9@kernel.org> (raw)
In-Reply-To: <20260108002625.333331-1-irogers@google.com>

On Wed,  7 Jan 2026 16:26:25 -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.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> Reduce the number of checks as suggested-by Steven Rostedt
> <rostedt@goodmis.org>.
> v1: https://lore.kernel.org/lkml/20251209224024.2322124-1-irogers@google.com/

Look good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks!

> ---
>  kernel/trace/trace.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 6f2148df14d9..5e2d597b4377 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -6109,10 +6109,10 @@ static int cmp_mod_entry(const void *key, const void *pivot)
>  	unsigned long addr = (unsigned long)key;
>  	const struct trace_mod_entry *ent = pivot;
>  
> -	if (addr >= ent[0].mod_addr && addr < ent[1].mod_addr)
> -		return 0;
> -	else
> -		return addr - ent->mod_addr;
> +	if (addr < ent[0].mod_addr)
> +		return -1;
> +
> +	return addr >= ent[1].mod_addr;
>  }
>  
>  /**
> -- 
> 2.52.0.351.gbe84eed79e-goog
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2026-01-08  2:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  0:26 [PATCH v2] tracing: Avoid possible signed 64-bit truncation Ian Rogers
2026-01-08  2:35 ` Masami Hiramatsu [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=20260108113510.5f0716c539f2ab416fd39ec9@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.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