Netdev List
 help / color / mirror / Atom feed
From: Kaiwen Shi <skwkevin@mail.ustc.edu.cn>
To: Xuanqiang Luo <xuanqiang.luo@linux.dev>
Cc: Alexander Aring <alex.aring@gmail.com>,
	Stefan Schmidt <stefan@datenfreihafen.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	linux-wpan@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Kaiwen Shi <skwkevin@mail.ustc.edu.cn>
Subject: Re: [PATCH net v3] mac802154: fix data race and NULL deref on local->assoc_dev
Date: Sun, 30 Aug 2026 07:02:28 +0800	[thread overview]
Message-ID: <20260829230228.1786426-1-skwkevin@mail.ustc.edu.cn> (raw)
In-Reply-To: <7a6ba0f3-efc0-45f1-a372-ced250733b62@linux.dev>

Hi Xuanqiang,

> I think this clear_bit() should be moved to
> mac802154_process_association_resp(), after saving the first valid
> response and before calling complete().
>
> Clearing it only after wait_for_completion() returns may still leave a
> window, since the woken waiter may not acquire assoc_lock before the
> next work item runs. Clearing it earlier in the response handler ensures
> that subsequent responses fail the in-lock
> IEEE802154_IS_ASSOCIATING check and cannot overwrite the saved result.

Good catch, you are right. complete() is issued while the handler still
holds assoc_lock, so between the wake-up and the waiter taking that lock
another response can get in, pass the recheck and replace
assoc_status/assoc_addr before perform_association() has consumed them.

I reproduced it on a debug kernel: on v3 the bit is still set when the
wait returns, later responses keep being accepted after that point, and
the association ends up with an address from one of them instead of the
first one. With the clear_bit() moved, none is accepted.

So v4 does what you suggested: clear_bit() right after the result is
stored and before complete(), both under assoc_lock. The timeout and error
paths still clear it under the lock. The success and negative paths do not
need to any more, because a wait that returns success now means the
handler has already cleared the bit.

One thing I got wrong earlier, while I am at it. In my v2 reply I said
wpan_dev->association_lock is not held on either of the two paths
involved. That was wrong. nl802154_associate() takes it around
rdev_associate(), so it is held for the whole of
mac802154_perform_association(), the wait for the response included. That
rules out reusing it here: the handler would only get that mutex once the
association has already timed out. The v4 commit message states this
correctly.

A v4 follows.

Thanks,
Kaiwen


      reply	other threads:[~2026-08-29 23:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 22:13 [PATCH net v3] mac802154: fix data race and NULL deref on local->assoc_dev Kaiwen Shi
2026-08-28  7:17 ` Xuanqiang Luo
2026-08-29 23:02   ` Kaiwen Shi [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=20260829230228.1786426-1-skwkevin@mail.ustc.edu.cn \
    --to=skwkevin@mail.ustc.edu.cn \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stefan@datenfreihafen.org \
    --cc=xuanqiang.luo@linux.dev \
    /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