mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuanqiang Luo <xuanqiang.luo@linux.dev>
To: Kaiwen Shi <skwkevin@mail.ustc.edu.cn>,
	alex.aring@gmail.com, stefan@datenfreihafen.org,
	miquel.raynal@bootlin.com, linux-wpan@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v3] mac802154: fix data race and NULL deref on local->assoc_dev
Date: Fri, 28 Aug 2026 15:17:57 +0800	[thread overview]
Message-ID: <7a6ba0f3-efc0-45f1-a372-ced250733b62@linux.dev> (raw)
In-Reply-To: <20260827221339.885245-1-skwkevin@mail.ustc.edu.cn>


在 2026/8/28 06:13, Kaiwen Shi 写道:
> @@ -599,25 +603,38 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
>   		goto clear_assoc;
>   	}
>   
> -	if (local->assoc_status != IEEE802154_ASSOCIATION_SUCCESSFUL) {
> -		if (local->assoc_status == IEEE802154_PAN_AT_CAPACITY)
> +	/* The association is complete: clear the associating bit and snapshot
> +	 * the result under the same lock, so a second (e.g. malicious) ASSOC
> +	 * RESP can no longer pass the recheck below and overwrite
> +	 * assoc_status/assoc_addr before they are consumed.
> +	 */
> +	spin_lock(&local->assoc_lock);
> +	clear_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);

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.

> +	resp_status = local->assoc_status;
> +	resp_short_addr = local->assoc_addr;
> +	spin_unlock(&local->assoc_lock);
> +
> +	if (resp_status != IEEE802154_ASSOCIATION_SUCCESSFUL) {
> +		if (resp_status == IEEE802154_PAN_AT_CAPACITY)
>   			ret = -ERANGE;
>   		else
>   			ret = -EPERM;
>   
>   		dev_warn(&sdata->dev->dev,
>   			 "Negative ASSOC RESP received from %8phC: %s\n", &ceaddr,
> -			 local->assoc_status == IEEE802154_PAN_AT_CAPACITY ?
> +			 resp_status == IEEE802154_PAN_AT_CAPACITY ?
>   			 "PAN at capacity" : "access denied");
> -		goto clear_assoc;
> +		return ret;
>   	}
>   
> -	ret = 0;
> -	*short_addr = local->assoc_addr;
> +	*short_addr = resp_short_addr;
> +
> +	return 0;
>   
>   clear_assoc:
> +	spin_lock(&local->assoc_lock);
>   	clear_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);
> -	local->assoc_dev = NULL;
> +	spin_unlock(&local->assoc_lock);
>   
>   	return ret;
>   }
> @@ -639,19 +656,23 @@ int mac802154_process_association_resp(struct ieee802154_sub_if_data *sdata,
>   		     dest->mode != IEEE802154_EXTENDED_ADDRESSING))
>   		return -EINVAL;
>   
> -	if (unlikely(dest->extended_addr != wpan_dev->extended_addr ||
> -		     src->extended_addr != local->assoc_dev->extended_addr))
> +	spin_lock(&local->assoc_lock);
> +	if (unlikely(!test_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing) ||
> +		     dest->extended_addr != wpan_dev->extended_addr ||
> +		     src->extended_addr != local->assoc_dev_extended_addr)) {
> +		spin_unlock(&local->assoc_lock);
>   		return -ENODEV;
> +	}
>   
>   	memcpy(&resp_pl, skb->data, sizeof(resp_pl));
>   	local->assoc_addr = resp_pl.short_addr;
>   	local->assoc_status = resp_pl.status;

here

> +	complete(&local->assoc_done);
> +	spin_unlock(&local->assoc_lock);
>   
>   	dev_dbg(&skb->dev->dev,
>   		"ASSOC RESP 0x%x received from %8phC, getting short address %04x\n",
> -		local->assoc_status, &deaddr, local->assoc_addr);
> -
> -	complete(&local->assoc_done);
> +		resp_pl.status, &deaddr, resp_pl.short_addr);
>   
>   	return 0;
>   }
>
> base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f

Thanks,
Xuanqiang


  reply	other threads:[~2026-08-28  7:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 22:13 Kaiwen Shi
2026-08-28  7:17 ` Xuanqiang Luo [this message]
2026-08-29 23:02   ` Kaiwen Shi

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=7a6ba0f3-efc0-45f1-a372-ced250733b62@linux.dev \
    --to=xuanqiang.luo@linux.dev \
    --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=skwkevin@mail.ustc.edu.cn \
    --cc=stable@vger.kernel.org \
    --cc=stefan@datenfreihafen.org \
    /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®