From: Leon Romanovsky <leon@kernel.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: bongsu.jeon@samsung.com, krzysztof.kozlowski@linaro.org,
netdev@vger.kernel.org, syzkaller@googlegroups.com
Subject: Re: [PATCH] nfc: Allow to create multiple virtual nci devices
Date: Tue, 1 Nov 2022 08:06:44 +0200 [thread overview]
Message-ID: <Y2C3dAk2B5B681Wq@unreal> (raw)
In-Reply-To: <CACT4Y+Y=W2xazqDmrSFDS5ocbsc+H-ZAiHTD1era=dFR4V0gOA@mail.gmail.com>
On Mon, Oct 31, 2022 at 08:36:57AM -0700, Dmitry Vyukov wrote:
> On Mon, 31 Oct 2022 at 02:23, Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Sun, Oct 30, 2022 at 03:29:19PM +0100, Dmitry Vyukov wrote:
> > > The current virtual nci driver is great for testing and fuzzing.
> > > But it allows to create at most one "global" device which does not allow
> > > to run parallel tests and harms fuzzing isolation and reproducibility.
> > > Restructure the driver to allow creation of multiple independent devices.
> > > This should be backwards compatible for existing tests.
> > >
> > > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> > > Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
> > > Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > Cc: netdev@vger.kernel.org
> > > ---
> > > drivers/nfc/virtual_ncidev.c | 143 ++++++++++++++++-------------------
> > > 1 file changed, 66 insertions(+), 77 deletions(-)
> >
> > <...>
> >
> > > static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
> > > {
> > > - mutex_lock(&nci_mutex);
> > > - if (state != virtual_ncidev_enabled) {
> > > - mutex_unlock(&nci_mutex);
> > > - kfree_skb(skb);
> > > - return 0;
> > > - }
> > > + struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
> > >
> > > - if (send_buff) {
> > > - mutex_unlock(&nci_mutex);
> > > + mutex_lock(&vdev->mtx);
> > > + if (vdev->send_buff) {
> > > + mutex_unlock(&vdev->mtx);
> > > kfree_skb(skb);
> >
> > You probably need to set vdev->send_buff to NULL here.
>
> Hi Leon,
>
> Thanks for looking at this.
>
> Are you sure about setting vdev->send_buff to NULL?
> We already have a "cached" skb in vdev->send_buff, we received a new
> one in 'skb' and freed it.
> I assumed the intention is to keep vdev->send_buff intact.
You are right.
>
> > > return -1;
> > > }
> > > - send_buff = skb_copy(skb, GFP_KERNEL);
> > > - mutex_unlock(&nci_mutex);
> > > - wake_up_interruptible(&wq);
> > > + vdev->send_buff = skb_copy(skb, GFP_KERNEL);
> >
> > You don't check return value of skb_copy(), it can fail, but
> > this function will return 0 (success). Do you do it deliberately?
> >
> > If yes, please add a comment to the code, as it is not clear.
>
> Good question. I just kept all of this logic as it is now and only
> removed the global vars.
I know :)
>
> I guess we need something like this, right?
>
> vdev->send_buff = skb_copy(skb, GFP_KERNEL);
> if (!vdev->send_buff) {
> mutex_unlock(&vdev->mtx);
> return -1;
> }
>
> Though, it's called only from nci_send_frame() and its return value is
> never checked :)
I would say that the most important part is do not continue after
skb_copy() failure.
Thanks
>
> $ git grep nci_send_frame
> include/net/nfc/nci_core.h:int nci_send_frame(struct nci_dev *ndev,
> struct sk_buff *skb);
> net/nfc/nci/core.c:int nci_send_frame(struct nci_dev *ndev, struct sk_buff *skb)
> net/nfc/nci/core.c:EXPORT_SYMBOL(nci_send_frame);
> drivers/nfc/nfcmrvl/fw_dnld.c:
> nci_send_frame(priv->ndev, out_skb);
> drivers/nfc/nfcmrvl/fw_dnld.c: nci_send_frame(priv->ndev, out_skb);
> drivers/nfc/nfcmrvl/fw_dnld.c:
> nci_send_frame(priv->ndev, out_skb);
> net/nfc/nci/core.c: nci_send_frame(ndev, skb);
> net/nfc/nci/core.c: nci_send_frame(ndev, skb);
>
>
> > Thanks
> >
> > > + mutex_unlock(&vdev->mtx);
> > > + wake_up_interruptible(&vdev->wq);
> > > consume_skb(skb);
> > >
> > > return 0;
next prev parent reply other threads:[~2022-11-01 6:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 14:29 [PATCH] nfc: Allow to create multiple virtual nci devices Dmitry Vyukov
2022-10-30 14:33 ` Dmitry Vyukov
2022-10-31 9:23 ` Leon Romanovsky
2022-10-31 15:36 ` Dmitry Vyukov
2022-11-01 6:06 ` Leon Romanovsky [this message]
2022-11-03 18:18 ` Dmitry Vyukov
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=Y2C3dAk2B5B681Wq@unreal \
--to=leon@kernel.org \
--cc=bongsu.jeon@samsung.com \
--cc=dvyukov@google.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=syzkaller@googlegroups.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).