public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Jason Gunthorpe <jgg@mellanox.com>
Cc: "linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"syzbot+adb15cf8c2798e4e0db4@syzkaller.appspotmail.com" 
	<syzbot+adb15cf8c2798e4e0db4@syzkaller.appspotmail.com>,
	"syzbot+e5579222b6a3edd96522@syzkaller.appspotmail.com" 
	<syzbot+e5579222b6a3edd96522@syzkaller.appspotmail.com>,
	"syzbot+4b628fcc748474003457@syzkaller.appspotmail.com" 
	<syzbot+4b628fcc748474003457@syzkaller.appspotmail.com>,
	"syzbot+29ee8f76017ce6cf03da@syzkaller.appspotmail.com" 
	<syzbot+29ee8f76017ce6cf03da@syzkaller.appspotmail.com>,
	"syzbot+6956235342b7317ec564@syzkaller.appspotmail.com" 
	<syzbot+6956235342b7317ec564@syzkaller.appspotmail.com>,
	"syzbot+b358909d8d01556b790b@syzkaller.appspotmail.com" 
	<syzbot+b358909d8d01556b790b@syzkaller.appspotmail.com>,
	"syzbot+6b46b135602a3f3ac99e@syzkaller.appspotmail.com" 
	<syzbot+6b46b135602a3f3ac99e@syzkaller.appspotmail.com>,
	"syzbot+8458d13b13562abf6b77@syzkaller.appspotmail.com" 
	<syzbot+8458d13b13562abf6b77@syzkaller.appspotmail.com>,
	"syzbot+bd034f3fdc0402e942ed@syzkaller.appspotmail.com" 
	<syzbot+bd034f3fdc0402e942ed@syzkaller.appspotmail.com>,
	"syzbot+c92378b32760a4eef756@syzkaller.appspotmail.com" 
	<syzbot+c92378b32760a4eef756@syzkaller.appspotmail.com>,
	"syzbot+68b44a1597636e0b342c@syzkaller.appspotmail.com" 
	<syzbot+68b44a1597636e0b342c@syzkaller.appspotmail.com>
Subject: Re: [PATCH] RDMA/ucma: Put a lock around every call to the rdma_cm layer
Date: Tue, 18 Feb 2020 22:07:01 -0800	[thread overview]
Message-ID: <20200219060701.GG1075@sol.localdomain> (raw)
In-Reply-To: <20200218210432.GA31966@ziepe.ca>

On Tue, Feb 18, 2020 at 09:04:36PM +0000, Jason Gunthorpe wrote:
> The rdma_cm must be used single threaded.
> 
> This appears to be a bug in the design, as it does have lots of locking
> that seems like it should allow concurrency. However, when it is all said
> and done every single place that uses the cma_exch() scheme is broken, and
> all the unlocked reads from the ucma of the cm_id data are wrong too.
> 
> syzkaller has been finding endless bugs related to this.
> 
> Fixing this in any elegant way is some enormous amount of work. Take a
> very big hammer and put a mutex around everything to do with the
> ucma_context at the top of every syscall.
> 
> Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace")
> Reported-by: syzbot+adb15cf8c2798e4e0db4@syzkaller.appspotmail.com
> Reported-by: syzbot+e5579222b6a3edd96522@syzkaller.appspotmail.com
> Reported-by: syzbot+4b628fcc748474003457@syzkaller.appspotmail.com
> Reported-by: syzbot+29ee8f76017ce6cf03da@syzkaller.appspotmail.com
> Reported-by: syzbot+6956235342b7317ec564@syzkaller.appspotmail.com
> Reported-by: syzbot+b358909d8d01556b790b@syzkaller.appspotmail.com
> Reported-by: syzbot+6b46b135602a3f3ac99e@syzkaller.appspotmail.com
> Reported-by: syzbot+8458d13b13562abf6b77@syzkaller.appspotmail.com
> Reported-by: syzbot+bd034f3fdc0402e942ed@syzkaller.appspotmail.com
> Reported-by: syzbot+c92378b32760a4eef756@syzkaller.appspotmail.com
> Reported-by: syzbot+68b44a1597636e0b342c@syzkaller.appspotmail.com
> Cc: Eric Biggers <ebiggers@kernel.org>
> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
> ---
>  drivers/infiniband/core/ucma.c | 50 ++++++++++++++++++++++++++++++++--
>  1 file changed, 48 insertions(+), 2 deletions(-)
> 
> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-rc
> 
> Lets see if I told syzkaller about this properly..
> 
> EricB: If there are other rdma_cm related hits in syzkaller besides
> these 11 lets include them as  well. I wasn't able to find a way to
> search for things, this list is from your past email, thanks.
> 

Unfortunately I haven't had time to work on syzkaller bugs lately, so I can't
provide an updated list until I go through the long backlog of bugs.

A comment on the patch below:

> @@ -1112,13 +1134,17 @@ static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf,
>  	if (cmd.conn_param.valid) {
>  		ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
>  		mutex_lock(&file->mut);
> +		mutex_lock(&ctx->mutex);
>  		ret = __rdma_accept(ctx->cm_id, &conn_param, NULL);
> +		mutex_unlock(&ctx->mutex);
>  		if (!ret)
>  			ctx->uid = cmd.uid;
>  		mutex_unlock(&file->mut);

This is nesting the new ucma_context::mutex inside the existing ucma_file::mut.

> @@ -1403,6 +1443,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
>  	if (IS_ERR(ctx))
>  		return PTR_ERR(ctx);
>  
> +	mutex_lock(&ctx->mutex);
>  	mutex_lock(&file->mut);
>  	mc = ucma_alloc_multicast(ctx);
>  	if (!mc) {

... but this is doing the opposite.  So it can deadlock.

What's the intended order?

Also, are these two separate mutexes actually needed?  I.e., did you consider
using the existing ucma_file::mut, but it didn't work or it wasn't fine-grained
enough?  (It looks like one ucma_file can have multiple ucma_contexts.)

- Eric

  parent reply	other threads:[~2020-02-19  6:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 21:04 [PATCH] RDMA/ucma: Put a lock around every call to the rdma_cm layer Jason Gunthorpe
2020-02-18 22:10 ` KASAN: use-after-free Read in rdma_listen (2) syzbot
2020-02-19  6:07 ` Eric Biggers [this message]
2020-02-19 20:22   ` [PATCH] RDMA/ucma: Put a lock around every call to the rdma_cm layer Jason Gunthorpe
2020-03-07 20:41     ` Eric Biggers
2020-03-09 19:30       ` Jason Gunthorpe
2020-06-27 22:57         ` Eric Biggers
2020-06-29 14:30           ` Jason Gunthorpe
2020-11-16 20:46           ` Jason Gunthorpe
2020-02-27 20:42 ` Jason Gunthorpe

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=20200219060701.GG1075@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=jgg@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=syzbot+29ee8f76017ce6cf03da@syzkaller.appspotmail.com \
    --cc=syzbot+4b628fcc748474003457@syzkaller.appspotmail.com \
    --cc=syzbot+68b44a1597636e0b342c@syzkaller.appspotmail.com \
    --cc=syzbot+6956235342b7317ec564@syzkaller.appspotmail.com \
    --cc=syzbot+6b46b135602a3f3ac99e@syzkaller.appspotmail.com \
    --cc=syzbot+8458d13b13562abf6b77@syzkaller.appspotmail.com \
    --cc=syzbot+adb15cf8c2798e4e0db4@syzkaller.appspotmail.com \
    --cc=syzbot+b358909d8d01556b790b@syzkaller.appspotmail.com \
    --cc=syzbot+bd034f3fdc0402e942ed@syzkaller.appspotmail.com \
    --cc=syzbot+c92378b32760a4eef756@syzkaller.appspotmail.com \
    --cc=syzbot+e5579222b6a3edd96522@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