linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>,
	linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
	syzbot+8fcbb77276d43cc8b693@syzkaller.appspotmail.com
Subject: Re: [PATCH rdma-rc] RDMA/cma: Clear all multicast request fields
Date: Thu, 6 Jan 2022 13:39:41 -0400	[thread overview]
Message-ID: <20220106173941.GA2963550@nvidia.com> (raw)
In-Reply-To: <1876bacbbcb6f82af3948e5c37a09da6ea3fcae5.1641474841.git.leonro@nvidia.com>

On Thu, Jan 06, 2022 at 03:15:07PM +0200, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> The ib->rec.qkey field is accessed without being initialized.
> Clear the ib_sa_multicast struct to fix the following syzkaller error/.
> 
> =====================================================
> BUG: KMSAN: uninit-value in cma_set_qkey drivers/infiniband/core/cma.c:510 [inline]
> BUG: KMSAN: uninit-value in cma_make_mc_event+0xb73/0xe00 drivers/infiniband/core/cma.c:4570
>  cma_set_qkey drivers/infiniband/core/cma.c:510 [inline]
>  cma_make_mc_event+0xb73/0xe00 drivers/infiniband/core/cma.c:4570
>  cma_iboe_join_multicast drivers/infiniband/core/cma.c:4782 [inline]
>  rdma_join_multicast+0x2b83/0x30a0 drivers/infiniband/core/cma.c:4814
>  ucma_process_join+0xa76/0xf60 drivers/infiniband/core/ucma.c:1479
>  ucma_join_multicast+0x1e3/0x250 drivers/infiniband/core/ucma.c:1546
>  ucma_write+0x639/0x6d0 drivers/infiniband/core/ucma.c:1732
>  vfs_write+0x8ce/0x2030 fs/read_write.c:588
>  ksys_write+0x28c/0x520 fs/read_write.c:643
>  __do_sys_write fs/read_write.c:655 [inline]
>  __se_sys_write fs/read_write.c:652 [inline]
>  __ia32_sys_write+0xdb/0x120 fs/read_write.c:652
>  do_syscall_32_irqs_on arch/x86/entry/common.c:114 [inline]
>  __do_fast_syscall_32+0x96/0xf0 arch/x86/entry/common.c:180
>  do_fast_syscall_32+0x34/0x70 arch/x86/entry/common.c:205
>  do_SYSENTER_32+0x1b/0x20 arch/x86/entry/common.c:248
>  entry_SYSENTER_compat_after_hwframe+0x4d/0x5c
> 
> Local variable ib.i created at:
>  cma_iboe_join_multicast drivers/infiniband/core/cma.c:4737 [inline]
>  rdma_join_multicast+0x586/0x30a0 drivers/infiniband/core/cma.c:4814
>  ucma_process_join+0xa76/0xf60 drivers/infiniband/core/ucma.c:1479
> 
> CPU: 0 PID: 29874 Comm: syz-executor.3 Not tainted 5.16.0-rc3-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> =====================================================
> 
> Fixes: b5de0c60cc30 ("RDMA/cma: Fix use after free race in roce multicast join")
> Reported-by: syzbot+8fcbb77276d43cc8b693@syzkaller.appspotmail.com
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>  drivers/infiniband/core/cma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 69c9a12dd14e..9c53e1e7de50 100644
> +++ b/drivers/infiniband/core/cma.c
> @@ -4737,7 +4737,7 @@ static int cma_iboe_join_multicast(struct rdma_id_private *id_priv,
>  	int err = 0;
>  	struct sockaddr *addr = (struct sockaddr *)&mc->addr;
>  	struct net_device *ndev = NULL;
> -	struct ib_sa_multicast ib;
> +	struct ib_sa_multicast ib = {};
>  	enum ib_gid_type gid_type;
>  	bool send_only;

We shouldn't be able to join anything except a RDMA_PS_UDP to a
multicast in the first place:

	if (id_priv->id.ps == RDMA_PS_UDP)
		ib.rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);

Multicast RC/etc is meaningless. So I guess it should be like this:

--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -4744,7 +4744,7 @@ static int cma_iboe_join_multicast(struct rdma_id_private *id_priv,
 
        send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN);
 
-       if (cma_zero_addr(addr))
+       if (cma_zero_addr(addr) || id_priv->id.ps != RDMA_PS_UDP)
                return -EINVAL;
 
        gid_type = id_priv->cma_dev->default_gid_type[id_priv->id.port_num -
@@ -4752,8 +4752,7 @@ static int cma_iboe_join_multicast(struct rdma_id_private *id_priv,
        cma_iboe_set_mgid(addr, &ib.rec.mgid, gid_type);
 
        ib.rec.pkey = cpu_to_be16(0xffff);
-       if (id_priv->id.ps == RDMA_PS_UDP)
-               ib.rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
+       ib.rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
 
        if (dev_addr->bound_dev_if)
                ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if);

  reply	other threads:[~2022-01-06 17:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 13:15 [PATCH rdma-rc] RDMA/cma: Clear all multicast request fields Leon Romanovsky
2022-01-06 17:39 ` Jason Gunthorpe [this message]
2022-01-06 18:24   ` Leon Romanovsky
2022-01-09 12:22   ` Leon Romanovsky
2022-01-10 15:36     ` Jason Gunthorpe
2022-01-10 18:05       ` Leon Romanovsky
2022-01-17 16:16         ` Jason Gunthorpe
2022-01-17 18:20           ` Leon Romanovsky
2022-01-17 18:38             ` Jason Gunthorpe
2022-01-17 19:06               ` 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=20220106173941.GA2963550@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=leon@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=syzbot+8fcbb77276d43cc8b693@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).