diff mbox series

[1/1] mwifiex: Fix possible buffer overflows in mwifiex_config_scan

Message ID 20201208124523.8169-1-ruc_zhangxiaohui@163.com
State Superseded
Headers show
Series [1/1] mwifiex: Fix possible buffer overflows in mwifiex_config_scan | expand

Commit Message

Xiaohui Zhang Dec. 8, 2020, 12:45 p.m. UTC
From: Zhang Xiaohui <ruc_zhangxiaohui@163.com>

mwifiex_config_scan() calls memcpy() without checking
the destination size may trigger a buffer overflower,
which a local user could use to cause denial of service
or the execution of arbitrary code.
Fix it by putting the length check before calling memcpy().

Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
---
 drivers/net/wireless/marvell/mwifiex/scan.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Kalle Valo Dec. 8, 2020, 2:29 p.m. UTC | #1
Xiaohui Zhang <ruc_zhangxiaohui@163.com> writes:

> From: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
>
> mwifiex_config_scan() calls memcpy() without checking
> the destination size may trigger a buffer overflower,
> which a local user could use to cause denial of service
> or the execution of arbitrary code.
> Fix it by putting the length check before calling memcpy().
>
> Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
> ---
>  drivers/net/wireless/marvell/mwifiex/scan.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
> index c2a685f63..b1d90678f 100644
> --- a/drivers/net/wireless/marvell/mwifiex/scan.c
> +++ b/drivers/net/wireless/marvell/mwifiex/scan.c
> @@ -930,6 +930,8 @@ mwifiex_config_scan(struct mwifiex_private *priv,
>  				    "DIRECT-", 7))
>  				wildcard_ssid_tlv->max_ssid_length = 0xfe;
>  
> +			if (ssid_len > 1)
> +				ssid_len = 1;
>  			memcpy(wildcard_ssid_tlv->ssid,
>  			       user_scan_in->ssid_list[i].ssid, ssid_len);

min_t()?
Julian Calaby Dec. 9, 2020, 12:36 a.m. UTC | #2
Hi Xiaohui,

On Wed, Dec 9, 2020 at 12:07 AM Xiaohui Zhang <ruc_zhangxiaohui@163.com> wrote:
>
> From: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
>
> mwifiex_config_scan() calls memcpy() without checking
> the destination size may trigger a buffer overflower,
> which a local user could use to cause denial of service
> or the execution of arbitrary code.
> Fix it by putting the length check before calling memcpy().
>
> Signed-off-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
> ---
>  drivers/net/wireless/marvell/mwifiex/scan.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
> index c2a685f63..b1d90678f 100644
> --- a/drivers/net/wireless/marvell/mwifiex/scan.c
> +++ b/drivers/net/wireless/marvell/mwifiex/scan.c
> @@ -930,6 +930,8 @@ mwifiex_config_scan(struct mwifiex_private *priv,
>                                     "DIRECT-", 7))
>                                 wildcard_ssid_tlv->max_ssid_length = 0xfe;
>
> +                       if (ssid_len > 1)
> +                               ssid_len = 1;
>                         memcpy(wildcard_ssid_tlv->ssid,
>                                user_scan_in->ssid_list[i].ssid, ssid_len);

Can ssid_len ever be 0 here?

If it can't, should we just set ssid_len to 1 unconditionally?

If it can, should we just skip the memcpy as it won't do anything?

Thanks,
diff mbox series

Patch

diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
index c2a685f63..b1d90678f 100644
--- a/drivers/net/wireless/marvell/mwifiex/scan.c
+++ b/drivers/net/wireless/marvell/mwifiex/scan.c
@@ -930,6 +930,8 @@  mwifiex_config_scan(struct mwifiex_private *priv,
 				    "DIRECT-", 7))
 				wildcard_ssid_tlv->max_ssid_length = 0xfe;
 
+			if (ssid_len > 1)
+				ssid_len = 1;
 			memcpy(wildcard_ssid_tlv->ssid,
 			       user_scan_in->ssid_list[i].ssid, ssid_len);