From: Bongsu Jeon <bongsu.jeon@samsung.com>
To: Nguyen Dinh Phi <phind.uet@gmail.com>,
Bongsu Jeon <bongsu.jeon@samsung.com>,
"krzysztof.kozlowski@linaro.org" <krzysztof.kozlowski@linaro.org>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com"
<syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com>
Subject: Re: [PATCH] nfc: virtual_ncidev: Add variable to check if ndev is running
Date: Mon, 20 Nov 2023 13:47:06 +0900 [thread overview]
Message-ID: <20231120044706epcms2p48c4579db14cc4f3274031036caac4718@epcms2p4> (raw)
In-Reply-To: <20231119164705.1991375-1-phind.uet@gmail.com>
On 20/11/2023 01:47, Nguyen Dinh Phi wrote:
> syzbot reported an memory leak that happens when an skb is add to
> send_buff after virtual nci closed.
> This patch adds a variable to track if the ndev is running before
> handling new skb in send function.
>
> Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> ---
> drivers/nfc/virtual_ncidev.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nfc/virtual_ncidev.c b/drivers/nfc/virtual_ncidev.c
> index b027be0b0b6f..ac8226db54e2 100644
> --- a/drivers/nfc/virtual_ncidev.c
> +++ b/drivers/nfc/virtual_ncidev.c
> @@ -20,26 +20,31 @@
> NFC_PROTO_ISO14443_MASK | \
> NFC_PROTO_ISO14443_B_MASK | \
> NFC_PROTO_ISO15693_MASK)
> +#define NCIDEV_RUNNING 0
This define isn't used.
>
> struct virtual_nci_dev {
> struct nci_dev *ndev;
> struct mutex mtx;
> struct sk_buff *send_buff;
> struct wait_queue_head wq;
> + bool running;
> };
>
> static int virtual_nci_open(struct nci_dev *ndev)
> {
> + struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
> +
> + vdev->running = true;
> return 0;
> }
>
> static int virtual_nci_close(struct nci_dev *ndev)
> {
> struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
> -
> mutex_lock(&vdev->mtx);
> kfree_skb(vdev->send_buff);
> vdev->send_buff = NULL;
> + vdev->running = false;
> mutex_unlock(&vdev->mtx);
>
> return 0;
> @@ -50,7 +55,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
> struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
>
> mutex_lock(&vdev->mtx);
> - if (vdev->send_buff) {
> + if (vdev->send_buff || !vdev->running) {
Dear Krzysztof,
I agree this defensive code.
But i think NFC submodule has to avoid this situation.(calling send function of closed nci_dev)
Could you check this?
Best regards,
Bongsu
next prev parent reply other threads:[~2023-11-20 4:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-19 16:47 Nguyen Dinh Phi
[not found] ` <CGME20231119164714epcas2p2c0480d014abc4f0f780c714a445881ca@epcms2p4>
2023-11-20 4:47 ` Bongsu Jeon [this message]
2023-11-20 9:06 ` Krzysztof Kozlowski
2023-11-20 10:39 ` Nguyen Dinh Phi
2023-11-20 10:45 ` Krzysztof Kozlowski
2023-11-20 18:23 ` Phi Nguyen
2023-11-20 18:29 ` Krzysztof Kozlowski
2023-11-20 18:32 ` Krzysztof Kozlowski
2023-11-20 18:44 ` Krzysztof Kozlowski
[not found] ` <CGME20231120184433epcas2p23e9f5db776d46ad8dd77a16dd326c1bc@epcms2p1>
2023-11-21 1:31 ` Bongsu Jeon
2023-11-21 7:05 ` Krzysztof Kozlowski
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=20231120044706epcms2p48c4579db14cc4f3274031036caac4718@epcms2p4 \
--to=bongsu.jeon@samsung.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=phind.uet@gmail.com \
--cc=syzbot+6eb09d75211863f15e3e@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
all inboxes | Powered by JetHome®