From: duoming@zju.edu.cn
To: "Paolo Abeni" <pabeni@redhat.com>
Cc: krzk@kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, akpm@linux-foundation.org,
davem@davemloft.net, gregkh@linuxfoundation.org,
alexander.deucher@amd.com, broonie@kernel.org
Subject: Re: Re: [PATCH V2] drivers: nfc: nfcmrvl: fix double free bug in nfcmrvl_nci_unregister_dev()
Date: Tue, 12 Apr 2022 18:59:49 +0800 (GMT+08:00) [thread overview]
Message-ID: <2ce990b6.a886.1801d6dfe04.Coremail.duoming@zju.edu.cn> (raw)
In-Reply-To: <3daec73abc2f21809a8057b6a9729a70d2877231.camel@redhat.com>
Hello,
On Tue, 12 Apr 2022 00:28:16 -0700 Paolo Abeni wrote:
> > There is a potential double bug in nfcmrvl usb driver between
> > unregister and resume operation.
> >
> > The race that cause that double free bug can be shown as below:
> >
> > (FREE) | (USE)
> > | nfcmrvl_resume
> > | nfcmrvl_submit_bulk_urb
> > | nfcmrvl_bulk_complete
> > | nfcmrvl_nci_recv_frame
> > | nfcmrvl_fw_dnld_recv_frame
> > | queue_work
> > | fw_dnld_rx_work
> > | fw_dnld_over
> > | release_firmware
> > | kfree(fw); //(1)
> > nfcmrvl_disconnect |
> > nfcmrvl_nci_unregister_dev |
> > nfcmrvl_fw_dnld_abort |
> > fw_dnld_over | ...
> > if (priv->fw_dnld.fw) |
> > release_firmware |
> > kfree(fw); //(2) |
> > ... | priv->fw_dnld.fw = NULL;
> >
> > When nfcmrvl usb driver is resuming, we detach the device.
> > The release_firmware() will deallocate firmware in position (1),
> > but firmware will be deallocated again in position (2), which
> > leads to double free.
> >
> > This patch reorders nfcmrvl_fw_dnld_deinit() before nfcmrvl_fw_dnld_abort()
> > in order to prevent double free bug. Because destroy_workqueue() will
> > not return until all work items are finished. The priv->fw_dnld.fw will
> > be set to NULL after work items are finished and fw_dnld_over() called by
> > nfcmrvl_nci_unregister_dev() will check whether priv->fw_dnld.fw is NULL.
> > So the double free bug could be prevented.
> >
> > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
>
> This looks like a -net candidates, could you please add a suitable
> fixes tag?
I found my patch is not a comprehensive fix, because the fw_dnld_timeout()
could also reach fw_dnld_over(), which leads to double free bugs among
fw_dnld_rx_work(), fw_dnld_timeout() and nfcmrvl_nci_unregister_dev().
I sent a patch set "Fix double free bugs in nfcmrvl module" just now, and add
a fixes tag in it.
Best regards,
Duoming Zhou
prev parent reply other threads:[~2022-04-12 12:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-10 13:52 Duoming Zhou
2022-04-11 6:51 ` Krzysztof Kozlowski
2022-04-12 7:28 ` Paolo Abeni
2022-04-12 10:59 ` duoming [this message]
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=2ce990b6.a886.1801d6dfe04.Coremail.duoming@zju.edu.cn \
--to=duoming@zju.edu.cn \
--cc=akpm@linux-foundation.org \
--cc=alexander.deucher@amd.com \
--cc=broonie@kernel.org \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=krzk@kernel.org \
--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
all inboxes | Powered by JetHome®