mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "lyican53@gmail.com" <lyican53@gmail.com>
Cc: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
	"idryomov@gmail.com" <idryomov@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Xiubo Li <xiubli@redhat.com>
Subject: RE: [PATCH] ceph: Fix potential undefined behavior in crush_ln() with GCC 11.1.0
Date: Fri, 19 Sep 2025 18:51:19 +0000	[thread overview]
Message-ID: <d6ccd709466d1460baf6e9b0bcec212007172622.camel@ibm.com> (raw)
In-Reply-To: <C8E92D42-0336-45DD-A415-EA8588DE731D@gmail.com>

On Fri, 2025-09-19 at 10:34 +0800, 陈华昭(Lyican) wrote:
> > 2025年9月19日 02:07,Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> 写道:
> > 

<skipped>

> 
> Hi Slava,
> 
> Thank you for reviewing my patch. I apologize for the issues in my original submission.
> 
> You are absolutely right about the patch application failure. The main problem was that I failed to properly specify the Linux kernel version and commit hash I was working with in my original submission. I am indeed working on commit f83ec76bf285bea5727f478a68b894f5543ca76e (Linux 6.17-rc6), which matches exactly what you mentioned.
> 
> I've now regenerated the patch using git format-patch based on the correct commit. I've also refined the fix by simplifying the zero-value check to make it more concise while maintaining the same safety guarantees. Please find the updated patch below and kindly review it again:
> 
> ---
> 
> From 2465d99797764ad45d7315f0a4a0fe0f5e7113a1 Mon Sep 17 00:00:00 2001
> From: Huazhao Chen <lyican53@gmail.com>
> Date: Fri, 19 Sep 2025 09:34:14 +0800
> Subject: [PATCH] ceph: Fix potential undefined behavior in crush_ln() with GCC
> 11.1.0
> 
> When x & 0x1FFFF equals zero, __builtin_clz() is called with a zero
> argument, which results in undefined behavior. This can happen during
> ceph's consistent hashing calculations and may lead to incorrect
> placement group mappings.
> 
> Fix by storing the masked value in a variable and checking if it's
> non-zero before calling __builtin_clz(). If the masked value is zero,
> use the expected result of 16 directly.
> 
> Signed-off-by: Huazhao Chen <lyican53@gmail.com>
> ---
> net/ceph/crush/mapper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ceph/crush/mapper.c b/net/ceph/crush/mapper.c
> index 3a5bd1cd1..000f7a633 100644
> --- a/net/ceph/crush/mapper.c
> +++ b/net/ceph/crush/mapper.c
> @@ -262,7 +262,7 @@ static __u64 crush_ln(unsigned int xin)
>   * do it in one step instead of iteratively
>   */
>  if (!(x & 0x18000)) {
> - int bits = __builtin_clz(x & 0x1FFFF) - 16;
> + int bits = (x & 0x1FFFF) ? __builtin_clz(x & 0x1FFFF) - 16 : 16;
>  x <<= bits;
>  iexpon = 15 - bits;
>  }

I still have the same issue with the new patch. Your patch is trying to modify
the line 262. However, we have comments on this line [1]:

260	/*
261	 * figure out number of bits we need to shift and
262	 * do it in one step instead of iteratively
263	 */
264	if (!(x & 0x18000)) {
265		int bits = __builtin_clz(x & 0x1FFFF) - 16;
266		x <<= bits;
267		iexpon = 15 - bits;
268	}

Thanks,
Slava.

[1]
https://elixir.bootlin.com/linux/v6.17-rc6/source/net/ceph/crush/mapper.c#L262

  reply	other threads:[~2025-09-19 18:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  1:50 陈华昭(Lyican)
2025-09-18  2:09 ` Viacheslav Dubeyko
2025-09-18 18:07 ` Viacheslav Dubeyko
2025-09-19  2:34   ` 陈华昭(Lyican)
2025-09-19 18:51     ` Viacheslav Dubeyko [this message]
2025-09-20 12:06       ` 陈华昭(Lyican)
2025-09-22 17:19         ` Viacheslav Dubeyko
2025-09-24  1:27           ` 陈华昭(Lyican)
2025-09-26 23:42 陈华昭

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=d6ccd709466d1460baf6e9b0bcec212007172622.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyican53@gmail.com \
    --cc=xiubli@redhat.com \
    /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

all inboxes | Powered by JetHome®