Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/core: always drop device refcount in ib_del_sub_device_and_put()

Since nldev_deldev() (introduced by commit 060c642b2ab8 ("RDMA/nldev: Add
support to add/delete a sub IB device through netlink") grabs a reference
using ib_device_get_by_index() before calling ib_del_sub_device_and_put(),
we need to drop that reference before returning -EOPNOTSUPP error.

Reported-by: syzbot+881d65229ca4f9ae8c84@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=881d65229ca4f9ae8c84
Fixes: bca51197620a ("RDMA/core: Support IB sub device with type "SMI"")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Link: https://patch.msgid.link/80749a85-cbe2-460c-8451-42516013f9fa@I-love.SAKURA.ne.jp
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

Tetsuo Handa and committed by
Leon Romanovsky
fa3c411d de41cbc6

+3 -1
+3 -1
drivers/infiniband/core/device.c
··· 2881 2881 { 2882 2882 struct ib_device *parent = sub->parent; 2883 2883 2884 - if (!parent) 2884 + if (!parent) { 2885 + ib_device_put(sub); 2885 2886 return -EOPNOTSUPP; 2887 + } 2886 2888 2887 2889 mutex_lock(&parent->subdev_lock); 2888 2890 list_del(&sub->subdev_list);