From: Eli Billauer <eli.billauer@gmail.com>
To: Hyunwoo Kim <imv4bel@gmail.com>
Cc: gregkh@linuxfoundation.org, arnd@arndb.de,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
stern@rowland.harvard.edu
Subject: Re: [PATCH v2] char: xillybus: Prevent use-after-free due to race condition
Date: Sun, 13 Nov 2022 11:03:20 +0200 [thread overview]
Message-ID: <c9a03f08-8117-cd24-b4e3-9e097e3069f2@gmail.com> (raw)
In-Reply-To: <20221113084740.GA6458@ubuntu>
On 13/11/2022 10:47, Hyunwoo Kim wrote:
> And, even if the mutex_unlock(&unit_mutex); of xillybus_find_inode()
> is finally moved, xdev may be released before kref_get() is executed
> if xillyusb_disconnect() ends just before the function returns.
> (Of course, this is an extremely rare case.)
>
> So, in xillyusb_open() we need to move kref_get() above xillybus_find_inode().
First of all, that's impossible. kref_get() is called on a member of a
specific @xdev's struct, and it's xillybus_find_inode()'s job to find
it. So before the call to xillybus_find_inode(), we don't know which
@xdev it is. That's the tricky part of all this.
The solution of this submitted patch was a lock that briefly prevents
the kref_put() of all @xdevs. The way it works is that if an @xdev is
found by xillybus_find_inode(), it necessarily means that
xillyusb_disconnect()'s call to xillybus_cleanup_chrdev() hasn't
returned (yet). Therefore, holding @kref_mutex guarantees that the
kref_put() call, which is later on, isn't reached for the @xdev that has
been found.
If you've found a flaw in this mechanism, please be more specific about it.
Regards,
Eli
next prev parent reply other threads:[~2022-11-13 9:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 9:42 [PATCH v2] char: xillybus: Prevent use-after-free due to race condition Eli Billauer
2022-10-30 16:23 ` Alan Stern
2022-10-30 18:55 ` Eli Billauer
2022-11-13 8:05 ` Hyunwoo Kim
2022-11-13 8:30 ` Eli Billauer
2022-11-13 8:47 ` Hyunwoo Kim
2022-11-13 9:03 ` Eli Billauer [this message]
2022-11-13 9:14 ` Hyunwoo Kim
2022-11-13 11:36 ` Eli Billauer
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=c9a03f08-8117-cd24-b4e3-9e097e3069f2@gmail.com \
--to=eli.billauer@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=imv4bel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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