linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wl1251: Fix possible buffer overflow in wl1251_cmd_scan
@ 2021-03-17 12:18 Lee Gibson
  2021-04-18  6:54 ` Kalle Valo
  2021-04-28 11:55 ` [PATCH v2] " Lee Gibson
  0 siblings, 2 replies; 4+ messages in thread
From: Lee Gibson @ 2021-03-17 12:18 UTC (permalink / raw)
  To: kvalo; +Cc: davem, kuba, linux-wireless, netdev, linux-kernel, Lee Gibson

Function wl1251_cmd_scan 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>
---
 drivers/net/wireless/ti/wl1251/cmd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ti/wl1251/cmd.c b/drivers/net/wireless/ti/wl1251/cmd.c
index 498c8db2eb48..e4d028a53d91 100644
--- a/drivers/net/wireless/ti/wl1251/cmd.c
+++ b/drivers/net/wireless/ti/wl1251/cmd.c
@@ -455,8 +455,11 @@ int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
 	}
 
 	cmd->params.ssid_len = ssid_len;
-	if (ssid)
-		memcpy(cmd->params.ssid, ssid, ssid_len);
+	if (ssid) {
+		int len = min_t(int, ssid_len, IEEE80211_MAX_SSID_LEN);
+
+		memcpy(cmd->params.ssid, ssid, len);
+	}
 
 	ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
 	if (ret < 0) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] wl1251: Fix possible buffer overflow in wl1251_cmd_scan
  2021-03-17 12:18 [PATCH] wl1251: Fix possible buffer overflow in wl1251_cmd_scan Lee Gibson
@ 2021-04-18  6:54 ` Kalle Valo
  2021-04-28 11:55 ` [PATCH v2] " Lee Gibson
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2021-04-18  6:54 UTC (permalink / raw)
  To: Lee Gibson; +Cc: davem, kuba, linux-wireless, netdev, linux-kernel

Lee Gibson <leegib@gmail.com> writes:

> Function wl1251_cmd_scan 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>

Please fix the commit log, the user cannot control this length as
cfg80211 checks it before handling it to wl1251. Unless I'm missing
something.

> ---
>  drivers/net/wireless/ti/wl1251/cmd.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/ti/wl1251/cmd.c b/drivers/net/wireless/ti/wl1251/cmd.c
> index 498c8db2eb48..e4d028a53d91 100644
> --- a/drivers/net/wireless/ti/wl1251/cmd.c
> +++ b/drivers/net/wireless/ti/wl1251/cmd.c
> @@ -455,8 +455,11 @@ int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
>  	}
>  
>  	cmd->params.ssid_len = ssid_len;

If you are checking the length, you should also check ssid_len here.

> -	if (ssid)
> -		memcpy(cmd->params.ssid, ssid, ssid_len);
> +	if (ssid) {
> +		int len = min_t(int, ssid_len, IEEE80211_MAX_SSID_LEN);
> +
> +		memcpy(cmd->params.ssid, ssid, len);
> +	}

Please use clamp_val().

Also another (and IMHO better) way to cleanup this is to provide a
pointer to struct cfg80211_ssid, which makes it clear that the length
can be trusted and not length checking is not needed. So something like
this:

int wl1251_cmd_scan(struct wl1251 *wl, const struct cfg80211_ssid *ssid,
		    struct ieee80211_channel *channels[],
		    unsigned int n_channels, unsigned int n_probes)

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] wl1251: Fix possible buffer overflow in wl1251_cmd_scan
  2021-03-17 12:18 [PATCH] wl1251: Fix possible buffer overflow in wl1251_cmd_scan Lee Gibson
  2021-04-18  6:54 ` Kalle Valo
@ 2021-04-28 11:55 ` Lee Gibson
  2021-06-15 13:36   ` Kalle Valo
  1 sibling, 1 reply; 4+ messages in thread
From: Lee Gibson @ 2021-04-28 11:55 UTC (permalink / raw)
  To: kvalo; +Cc: davem, kuba, linux-wireless, netdev, linux-kernel, Lee Gibson

Function wl1251_cmd_scan calls memcpy without checking the length.
Harden 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/ti/wl1251/cmd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ti/wl1251/cmd.c b/drivers/net/wireless/ti/wl1251/cmd.c
index 498c8db2eb48..d7a869106782 100644
--- a/drivers/net/wireless/ti/wl1251/cmd.c
+++ b/drivers/net/wireless/ti/wl1251/cmd.c
@@ -454,9 +454,12 @@ int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
 		cmd->channels[i].channel = channels[i]->hw_value;
 	}
 
-	cmd->params.ssid_len = ssid_len;
-	if (ssid)
-		memcpy(cmd->params.ssid, ssid, ssid_len);
+	if (ssid) {
+		int len = clamp_val(ssid_len, 0, IEEE80211_MAX_SSID_LEN);
+
+		cmd->params.ssid_len = len;
+		memcpy(cmd->params.ssid, ssid, len);
+	}
 
 	ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
 	if (ret < 0) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] wl1251: Fix possible buffer overflow in wl1251_cmd_scan
  2021-04-28 11:55 ` [PATCH v2] " Lee Gibson
@ 2021-06-15 13:36   ` Kalle Valo
  0 siblings, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2021-06-15 13:36 UTC (permalink / raw)
  To: Lee Gibson; +Cc: davem, kuba, linux-wireless, netdev, linux-kernel, Lee Gibson

Lee Gibson <leegib@gmail.com> wrote:

> Function wl1251_cmd_scan calls memcpy without checking the length.
> Harden 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.

d10a87a3535c wl1251: Fix possible buffer overflow in wl1251_cmd_scan

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20210428115508.25624-1-leegib@gmail.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-15 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 12:18 [PATCH] wl1251: Fix possible buffer overflow in wl1251_cmd_scan Lee Gibson
2021-04-18  6:54 ` Kalle Valo
2021-04-28 11:55 ` [PATCH v2] " Lee Gibson
2021-06-15 13:36   ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).