From: Greg KH <gregkh@linuxfoundation.org>
To: Lin Ma <linma@zju.edu.cn>
Cc: Duoming Zhou <duoming@zju.edu.cn>,
krzysztof.kozlowski@linaro.org, pabeni@redhat.com,
linux-kernel@vger.kernel.org, davem@davemloft.net,
alexander.deucher@amd.com, akpm@linux-foundation.org,
broonie@kernel.org, netdev@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH net v4] nfc: ... device_is_registered() is data race-able
Date: Thu, 28 Apr 2022 16:12:20 +0200 [thread overview]
Message-ID: <YmqgxNkXVetmrtde@kroah.com> (raw)
In-Reply-To: <6ad27014.42f6.1807072bb39.Coremail.linma@zju.edu.cn>
On Thu, Apr 28, 2022 at 09:53:28PM +0800, Lin Ma wrote:
> Hello there
>
> >
> > How do you physically remove a NFC device from a system? What types of
> > busses are they on? If non-removable one, then odds are there's not
> > going to be many races so this is a low-priority thing. If they can be
> > on removable busses (USB, PCI, etc.), then that's a bigger thing.
>
> Well, these are great questions we didn't even touch to yet.
> For the BT, HAMRADIO, and NFC/NCI code, we simply use pseudo-terminal + line
> discipline to emulate a malicious device from user-space (CAP_NET_ADMIN required).
>
> We will then survey the actual physical bus for the IRL used NFC device.
>
> >
> > But again, the NFC bus code should handle all of this for the drivers,
> > there's nothing special about NFC that should warrant a special need for
> > this type of thing.
> >
>
> Agree, but in my opinion, every layer besides the bus code has to handle this race.
>
> The cleanup routine is from
> "down" to "up" like ... -> TTY -> NFCMRVL -> NCI -> NFC core
> while the other routines, like netlink command is from "up" to "down"
> user space -> netlink -> NFC -> NCI -> NFCMRVL -> ...
>
> Their directions are totally reversed hence only each layer of the stack perform good
> synchronization can the code be race free.
>
> For example, this detaching event awake code in bus, the running task in higher layer
> is not aware of this. The cleanup of each layer has to make sure any running code won't
> cause use-after-free.
That is what proper reference counting is supposed to be for. Perhaps
you are running into a driver subsystem that is not doing that well, or
at all?
Try adding the needed references and the use-after-free should almost be
impossible to happen.
thanks,
greg k-h
next prev parent reply other threads:[~2022-04-28 14:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 1:14 [PATCH net v4] nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs Duoming Zhou
2022-04-28 0:45 ` Jakub Kicinski
2022-04-28 4:03 ` duoming
2022-04-28 7:15 ` [PATCH net v4] nfc: ... device_is_registered() is data race-able Lin Ma
2022-04-28 7:38 ` Greg KH
2022-04-28 7:55 ` Lin Ma
2022-04-28 8:16 ` Greg KH
2022-04-28 8:49 ` Lin Ma
2022-04-28 9:20 ` Greg KH
2022-04-28 13:06 ` Jakub Kicinski
2022-04-28 13:22 ` Lin Ma
2022-04-28 13:37 ` Greg KH
2022-04-28 13:53 ` Lin Ma
2022-04-28 14:12 ` Greg KH [this message]
2022-04-29 3:17 ` Lin Ma
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=YmqgxNkXVetmrtde@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.deucher@amd.com \
--cc=broonie@kernel.org \
--cc=davem@davemloft.net \
--cc=duoming@zju.edu.cn \
--cc=krzysztof.kozlowski@linaro.org \
--cc=kuba@kernel.org \
--cc=linma@zju.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).