Netdev List
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Yuxuan-Hu <yuxuanhu@buaa.edu.cn>,
	Yuxuan Hu <20373622@buaa.edu.cn>,
	gregkh@linuxfoundation.org, johan@kernel.org,
	davem@davemloft.net, u.kleine-koenig@pengutronix.de,
	Jonathan.Cameron@huawei.com, francesco.dolcini@toradex.com,
	jirislaby@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, sy2239101@buaa.edu.cn
Subject: Re: [PATCH] nfc: pn533: Fix null-ptr-deref in pn533_recv_frame()
Date: Wed, 24 Apr 2024 20:13:31 +0200	[thread overview]
Message-ID: <8a01c6b2-ca30-448c-8ba8-34720891b461@kernel.org> (raw)
In-Reply-To: <fdc7ada8-6ca9-4835-982a-3e45ee7ac009@buaa.edu.cn>

On 24/04/2024 16:00, Yuxuan-Hu wrote:
> Hi Krzysztof,
> Thanks for your reply.
> 
> On 2024/4/24 13:36, Krzysztof Kozlowski wrote:
>> A bit better solution would be to NULL-ify dev->cmd at the beginning of
>> pn533_send_async_complete(), because that seems logical. The complete
>> callback takes ownership of dev->cmd, so why it performs the assignment
>> at the end?
>>
>> However even above code will keep the race open for short period.
>> Probably some locking would solve it or checking for dev->cmd in few
>> places with barriers.
>>
>> Best regards,
>> Krzysztof
> 
> I think adding a lock seems to be a better solution, however, acquire a 
> lock on each access to dev->cmd does not seem to be an appropriate 
> implementation.
> I wonder whether you think it is appropriate to acquire a lock at the 
> beginning of pn533_recv_frame(), and release it when 
> pn533_wq_cmd_complete() is finished, thus ensuring that another work 
> will not start when one pn533_wq_cmd_complete() work is not yet finished.

I don't know this driver well enough, but it currently does not have any
locking around this so it assumes pn533_recv_frame() cannot start
concurrently, before complete callback finishes.

This could be solved, if it makes sense.

However maybe it would be enough to take:
1. Move contents of dev->cmd to another member in dev (e.g.
dev->cmd_in_progress), first checking if that member is empty (then
maybe wait? or return -EBUSY?)
2. dev->cmd = NULL
3. queue_work (see also explanation of barriers there)
4. The cmd_complete_work workqueue takes ownership of
dev->cmd_in_progress and NULL-ifies it at end of work + barrier.

Best regards,
Krzysztof


  reply	other threads:[~2024-04-24 18:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22  8:04 [PATCH] nfc: pn533: Fix null-ptr-deref in pn533_recv_frame() Yuxuan Hu
2024-04-24  5:36 ` Krzysztof Kozlowski
2024-04-24 14:00   ` Yuxuan-Hu
2024-04-24 18:13     ` Krzysztof Kozlowski [this message]
2024-04-24  5:38 ` Krzysztof Kozlowski
2024-04-24  6:06 ` Markus Elfring

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=8a01c6b2-ca30-448c-8ba8-34720891b461@kernel.org \
    --to=krzk@kernel.org \
    --cc=20373622@buaa.edu.cn \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=baijiaju1990@gmail.com \
    --cc=davem@davemloft.net \
    --cc=francesco.dolcini@toradex.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sy2239101@buaa.edu.cn \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=yuxuanhu@buaa.edu.cn \
    /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