From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: David Howells <dhowells@redhat.com>, Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: joel@jms.id.au, eajames@linux.vnet.ibm.com, andrew@aj.id.au,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fsi:fsi-sbefifo: Fix possible concurrency use-after-free bugs in sbefifo_user_release
Date: Thu, 03 Jan 2019 14:27:56 +1100 [thread overview]
Message-ID: <fd0a4a0da544908204d8558895d469c6d87b6743.camel@kernel.crashing.org> (raw)
In-Reply-To: <26864.1546421693@warthog.procyon.org.uk>
On Wed, 2019-01-02 at 09:34 +0000, David Howells wrote:
> Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>
> > + mutex_lock(&user->file_lock);
> > sbefifo_release_command(user);
> > free_page((unsigned long)user->cmd_page);
> > + mutex_unlock(&user->file_lock);
>
> It shouldn't be necessary to do the free_page() call inside the locked
> section.
True. However, I didn't realize read/write could be concurrent with
release so we have another problem.
I assume when release is called, no new read/write can be issued, I am
correct ? So all we have to protect against is a read/write that has
started prior to release being called, right ?
In that case, what can happen is that release() wins the race on the
mutex, frees everything, then read or write starts using feed stuff.
This is nasty to fix because the mutex is in the user structure,
so even looking at the mutex is racy if release is called.
The right fix, would be, I think, for "user" (pointed to by file-
>private_data) to be protected by a kref. That doesn't close it
completely as the free in release() can still lead to the structure
becoming re-used before read/write tries to get the kref but after it
has NULL checked the private data.
So to make that solid, I would also RCU-defer the actual freeing and
use RCU around dereferencing file->private_data
Now, I yet have to see other chardevs do any of the above, do that mean
they are all hopelessly racy ?
Cheers,
Ben.
next prev parent reply other threads:[~2019-01-03 3:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-26 13:56 Jia-Ju Bai
2019-01-02 9:34 ` David Howells
2019-01-03 3:27 ` Benjamin Herrenschmidt [this message]
2019-01-03 4:26 ` Benjamin Herrenschmidt
2019-01-04 0:47 ` Benjamin Herrenschmidt
2019-01-04 2:26 ` Jia-Ju Bai
2019-01-04 3:26 ` Benjamin Herrenschmidt
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=fd0a4a0da544908204d8558895d469c6d87b6743.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=andrew@aj.id.au \
--cc=baijiaju1990@gmail.com \
--cc=dhowells@redhat.com \
--cc=eajames@linux.vnet.ibm.com \
--cc=joel@jms.id.au \
--cc=linux-kernel@vger.kernel.org \
/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®