All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: syzbot+53cf317e7803e4ef2f33@syzkaller.appspotmail.com,
	syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
	jgg@ziepe.ca, linux-kernel@vger.kernel.org,
	linux-rdma@vger.kernel.org
Subject: Re: [syzbot] [rdma?] kernel BUG in ib_device_get_by_index
Date: Mon, 2 Mar 2026 21:17:05 +0200	[thread overview]
Message-ID: <20260302191705.GR12611@unreal> (raw)
In-Reply-To: <14d97798-6cfa-4c2a-b1ab-391e4b823b1d@I-love.SAKURA.ne.jp>

On Sat, Feb 28, 2026 at 02:07:46PM +0900, Tetsuo Handa wrote:
> Hmm, this assertion was wrong because ib_device_get_by_index()
> might be called before enable_device_and_get() is called.
> 
> #syz invalid

I think this is a valid syzkaller report. As you correctly noted, the device
was inserted into the xarray database in assign_name(), but its refcount was
only set later in enable_device_and_get().

The proper fix can be something like that:

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index c7b227e2e657..5fc2604ec482 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -321,7 +321,7 @@ struct ib_device *ib_device_get_by_index(const struct net *net, u32 index)

        down_read(&devices_rwsem);
        device = xa_load(&devices, index);
-       if (device) {
+       if (device && xa_get_mark(&devices, index, DEVICE_REGISTERED)) {
                if (!rdma_dev_access_netns(device, net)) {
                        device = NULL;
                        goto out;

Thanks

  reply	other threads:[~2026-03-02 19:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28  4:38 [syzbot] [rdma?] kernel BUG in ib_device_get_by_index syzbot
2026-02-28  5:07 ` Tetsuo Handa
2026-03-02 19:17   ` Leon Romanovsky [this message]
2026-03-03 13:38     ` Tetsuo Handa
2026-03-04 14:22       ` Leon Romanovsky

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=20260302191705.GR12611@unreal \
    --to=leon@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=syzbot+53cf317e7803e4ef2f33@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.