diff mbox series

[1/2] wifi: ath11k: fix temperature event locking

Message ID 20231019104211.13769-2-johan+linaro@kernel.org (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series wifi: ath11k: fix event locking | expand

Commit Message

Johan Hovold Oct. 19, 2023, 10:42 a.m. UTC
The ath11k active pdevs are protected by RCU but the temperature event
handling code calling ath11k_mac_get_ar_by_pdev_id() was not marked as a
read-side critical section as reported by RCU lockdep:

	=============================
	WARNING: suspicious RCU usage
	6.6.0-rc6 #7 Not tainted
	-----------------------------
	drivers/net/wireless/ath/ath11k/mac.c:638 suspicious rcu_dereference_check() usage!

	other info that might help us debug this:

	rcu_scheduler_active = 2, debug_locks = 1
	no locks held by swapper/0/0.
	...
	Call trace:
	...
	 lockdep_rcu_suspicious+0x16c/0x22c
	 ath11k_mac_get_ar_by_pdev_id+0x194/0x1b0 [ath11k]
	 ath11k_wmi_tlv_op_rx+0xa84/0x2c1c [ath11k]
	 ath11k_htc_rx_completion_handler+0x388/0x510 [ath11k]

Mark the code in question as an RCU read-side critical section to avoid
any potential use-after-free issues.

Fixes: a41d10348b01 ("ath11k: add thermal sensor device support")
Cc: stable@vger.kernel.org      # 5.7
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 drivers/net/wireless/ath/ath11k/wmi.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jeff Johnson Oct. 19, 2023, 3:04 p.m. UTC | #1
On 10/19/2023 3:42 AM, Johan Hovold wrote:
> The ath11k active pdevs are protected by RCU but the temperature event
> handling code calling ath11k_mac_get_ar_by_pdev_id() was not marked as a
> read-side critical section as reported by RCU lockdep:

How do I enable this? Just enable CONFIG_PROVE_RCU?
Of course I'd also need to exercise the code path...

> 
> 	=============================
> 	WARNING: suspicious RCU usage
> 	6.6.0-rc6 #7 Not tainted
> 	-----------------------------
> 	drivers/net/wireless/ath/ath11k/mac.c:638 suspicious rcu_dereference_check() usage!
> 
> 	other info that might help us debug this:
> 
> 	rcu_scheduler_active = 2, debug_locks = 1
> 	no locks held by swapper/0/0.
> 	...
> 	Call trace:
> 	...
> 	 lockdep_rcu_suspicious+0x16c/0x22c
> 	 ath11k_mac_get_ar_by_pdev_id+0x194/0x1b0 [ath11k]
> 	 ath11k_wmi_tlv_op_rx+0xa84/0x2c1c [ath11k]
> 	 ath11k_htc_rx_completion_handler+0x388/0x510 [ath11k]
> 
> Mark the code in question as an RCU read-side critical section to avoid
> any potential use-after-free issues.
> 
> Fixes: a41d10348b01 ("ath11k: add thermal sensor device support")
> Cc: stable@vger.kernel.org      # 5.7
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---
>   drivers/net/wireless/ath/ath11k/wmi.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c
> index 23ad6825e5be..980ff588325d 100644
> --- a/drivers/net/wireless/ath/ath11k/wmi.c
> +++ b/drivers/net/wireless/ath/ath11k/wmi.c
> @@ -8383,6 +8383,8 @@ ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
>   	ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev temperature ev temp %d pdev_id %d\n",
>   		   ev->temp, ev->pdev_id);
>   
> +	rcu_read_lock();
> +
>   	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
>   	if (!ar) {
>   		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);

aren't you missing an unlock() in this error path?

perhaps have a goto cleanup that does both the unlock() and the kfree()?

> @@ -8392,6 +8394,8 @@ ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
>   
>   	ath11k_thermal_event_temperature(ar, ev->temp);
>   
> +	rcu_read_unlock();
> +
>   	kfree(tb);
>   }
>
Jeff Johnson Oct. 19, 2023, 3:07 p.m. UTC | #2
On 10/19/2023 8:04 AM, Jeff Johnson wrote:
> perhaps have a goto cleanup that does both the unlock() and the kfree()?

or goto exit to be consistent with others, including the DFS radar event
Johan Hovold Oct. 19, 2023, 3:17 p.m. UTC | #3
On Thu, Oct 19, 2023 at 08:04:55AM -0700, Jeff Johnson wrote:
> On 10/19/2023 3:42 AM, Johan Hovold wrote:
> > The ath11k active pdevs are protected by RCU but the temperature event
> > handling code calling ath11k_mac_get_ar_by_pdev_id() was not marked as a
> > read-side critical section as reported by RCU lockdep:
> 
> How do I enable this? Just enable CONFIG_PROVE_RCU?

Yeah, via CONFIG_PROVE_LOCKING.

> Of course I'd also need to exercise the code path...

Right, this one I hit when reading out the sensor temperature (e.g.
using lm_sensors).
 
> > +	rcu_read_lock();
> > +
> >   	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
> >   	if (!ar) {
> >   		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
> 
> aren't you missing an unlock() in this error path?
> 
> perhaps have a goto cleanup that does both the unlock() and the kfree()?

Bah, I am, thanks for catching that.

Spent too much time on scanning for further instances that I didn't
check the first one properly. Sorry about that. Will send a v2.

Johan
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c
index 23ad6825e5be..980ff588325d 100644
--- a/drivers/net/wireless/ath/ath11k/wmi.c
+++ b/drivers/net/wireless/ath/ath11k/wmi.c
@@ -8383,6 +8383,8 @@  ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev temperature ev temp %d pdev_id %d\n",
 		   ev->temp, ev->pdev_id);
 
+	rcu_read_lock();
+
 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
 	if (!ar) {
 		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
@@ -8392,6 +8394,8 @@  ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
 
 	ath11k_thermal_event_temperature(ar, ev->temp);
 
+	rcu_read_unlock();
+
 	kfree(tb);
 }