Skip to contentSkip to conversation

ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait

PATCH Superseded Carl Huang 4 participants 4 messages Feb 11, 2018 – Mar 1, 2018 Qualcomm Atheros ATH10K wireless driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Carl Huang

author
#0 lore raw

PATCH 1/1 ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait

The skb may be freed in tx completion context before trace_ath10k_wmi_cmd is called. This can be easily captured when KASAN(Kernel Address Sanitizer) is enabled. The fix is to add a reference count to the skb and release it after trace_ath10k_wmi_cmd is called.

---
 drivers/net/wireless/ath/ath10k/wmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath10k/wmi.c +3 -0
index 58dc218..e63aedb 100644
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2005-2011 Atheros Communications Inc.
  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -1742,8 +1743,10 @@ int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
 	cmd_hdr->cmd_id = __cpu_to_le32(cmd);
 
 	memset(skb_cb, 0, sizeof(*skb_cb));
+	skb_get(skb);
 	ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
 	trace_ath10k_wmi_cmd(ar, cmd_id, skb->data, skb->len, ret);
+	dev_kfree_skb(skb);
 
 	if (ret)
 		goto err_pull;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Carl Huang

The skb may be freed in tx completion context before trace_ath10k_wmi_cmd is called. This can be easily captured when KASAN(Kernel Address Sanitizer) is enabled. The fix is to add a reference count to the skb and release it after trace_ath10k_wmi_cmd is called.

I think it makes more sense to simply call the trace function before ath10k_htc_send. Also, for a trivial change like this it probably does not make sense to add a Copyright line either.

- Felix

#2 lore raw
Quoted 4 lines

-----Original Message-----
From: ath10k [mailto:[email protected]] On Behalf Of Fel=

ix

Quoted 14 lines

Fietkau
Sent: Sunday, February 11, 2018 5:59 PM
To: Carl Huang <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH] ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait
=20

Quoted 6 lines · Carl Huang

The skb may be freed in tx completion context before trace_ath10k_wmi_cmd is called. This can be easily captured when KASAN(Kernel Address Sanitizer) is enabled. The fix is to add a reference count to the skb and release it after trace_ath10k_wmi_cmd is called.

Quoted 3 lines
Quoted 1 line

I think it makes more sense to simply call the trace function before ath10k_htc_send. Also, for a trivial change like this it probably does no=

t make

Quoted 2 lines

sense to add a Copyright line either.
=20

Agree that Moving the trace function before ath10k_htc_send is more simple,=
but then the parameter ret=20
has no meaning and can't trace the return value of ath10k_htc_send. Beside= s that, skb->data and skb->len=20
have different value if putting trace function before ath10k_htc_send, and = this may be fine since the main
purpose is to trace the wmi information and not htc header information.

For the Copyright line, need Kalle Valo to comment.=20

Quoted 5 lines

=20
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

Tested-by on v1 1/1
#3 lore raw
In reply to Carl Huang
Quoted 16 lines · Carl Huang

The skb may be freed in tx completion context before trace_ath10k_wmi_cmd is called. This can be easily captured when KASAN(Kernel Address Sanitizer) is enabled. The fix is to add a reference count to the skb and release it after trace_ath10k_wmi_cmd is called.

---
 drivers/net/wireless/ath/ath10k/wmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath10k/wmi.c +0 -0
index 58dc218..e63aedb 100644

drivers/net/wireless/ath/ath10k/wmi.c line 4

Quoted 4 lines
drivers/net/wireless/ath/ath10k/wmi.c +1 -0
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2005-2011 Atheros Communications Inc.
  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.

I agree with Felix that this seems excessive for a 2-line bugfix. But I'm not a lawyer or a maintainer, and I have no power here :)

(On the practical side: it's annoying that the copyright line has to be the one to provide conflicts when backporting.)

drivers/net/wireless/ath/ath10k/wmi.c int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb, · line 1749

Quoted 11 lines
drivers/net/wireless/ath/ath10k/wmi.c +2 -0
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -1742,8 +1743,10 @@ int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
 	cmd_hdr->cmd_id = __cpu_to_le32(cmd);
 
 	memset(skb_cb, 0, sizeof(*skb_cb));
+	skb_get(skb);
 	ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
 	trace_ath10k_wmi_cmd(ar, cmd_id, skb->data, skb->len, ret);
+	dev_kfree_skb(skb);

It does feel like capturing before the command is sent might make more sense. Otherwise, you may be concurrently dumping the buffer and DMA'ing to a device. If you really need to trace the return code, you could do that separately.

Brian

Quoted 3 lines
drivers/net/wireless/ath/ath10k/wmi.c +0 -0
 	if (ret)
 		goto err_pull;