diff mbox series

[v2] qtnfmac: Fix possible buffer overflow in qtnf_event_handle_external_auth

Message ID 20210419145842.345787-1-leegib@gmail.com
State Accepted
Commit 130f634da1af649205f4a3dd86cbe5c126b57914
Delegated to: Kalle Valo
Headers show
Series [v2] qtnfmac: Fix possible buffer overflow in qtnf_event_handle_external_auth | expand

Commit Message

Lee Gibson April 19, 2021, 2:58 p.m. UTC
Function qtnf_event_handle_external_auth calls memcpy without
checking the length.
A user could control that length and trigger a buffer overflow.
Fix by checking the length is within the maximum allowed size.

Signed-off-by: Lee Gibson <leegib@gmail.com>
---

v2: use clamp_val() instead of min_t()

 drivers/net/wireless/quantenna/qtnfmac/event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Kalle Valo April 22, 2021, 2:40 p.m. UTC | #1
Lee Gibson <leegib@gmail.com> wrote:

> Function qtnf_event_handle_external_auth calls memcpy without
> checking the length.
> A user could control that length and trigger a buffer overflow.
> Fix by checking the length is within the maximum allowed size.
> 
> Signed-off-by: Lee Gibson <leegib@gmail.com>

Patch applied to wireless-drivers-next.git, thanks.

130f634da1af qtnfmac: Fix possible buffer overflow in qtnf_event_handle_external_auth
diff mbox series

Patch

diff --git a/drivers/net/wireless/quantenna/qtnfmac/event.c b/drivers/net/wireless/quantenna/qtnfmac/event.c
index c775c177933b..8dc80574d08d 100644
--- a/drivers/net/wireless/quantenna/qtnfmac/event.c
+++ b/drivers/net/wireless/quantenna/qtnfmac/event.c
@@ -570,8 +570,10 @@  qtnf_event_handle_external_auth(struct qtnf_vif *vif,
 		return 0;
 
 	if (ev->ssid_len) {
-		memcpy(auth.ssid.ssid, ev->ssid, ev->ssid_len);
-		auth.ssid.ssid_len = ev->ssid_len;
+		int len = clamp_val(ev->ssid_len, 0, IEEE80211_MAX_SSID_LEN);
+
+		memcpy(auth.ssid.ssid, ev->ssid, len);
+		auth.ssid.ssid_len = len;
 	}
 
 	auth.key_mgmt_suite = le32_to_cpu(ev->akm_suite);