diff mbox series

ar5523: check NULL before memcpy() in ar5523_cmd()

Message ID 20190930140207.28638-1-efremov@linux.com
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series ar5523: check NULL before memcpy() in ar5523_cmd() | expand

Commit Message

Denis Efremov Sept. 30, 2019, 2:02 p.m. UTC
memcpy() call with "idata == NULL && ilen == 0" results in undefined
behavior in ar5523_cmd(). For example, NULL is passed in callchain
"ar5523_stat_work() -> ar5523_cmd_write() -> ar5523_cmd()". This patch
adds idata check before memcpy() call in ar5523_cmd() to prevent an
undefined behavior.

Cc: Pontus Fuchs <pontus.fuchs@gmail.com>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: stable@vger.kernel.org
Signed-off-by: Denis Efremov <efremov@linux.com>
---
 drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Laight Sept. 30, 2019, 3:35 p.m. UTC | #1
From: Denis Efremov
> Sent: 30 September 2019 15:02
> 
> memcpy() call with "idata == NULL && ilen == 0" results in undefined
> behavior in ar5523_cmd(). For example, NULL is passed in callchain
> "ar5523_stat_work() -> ar5523_cmd_write() -> ar5523_cmd()". This patch
> adds idata check before memcpy() call in ar5523_cmd() to prevent an
> undefined behavior.
> 
...
> Signed-off-by: Denis Efremov <efremov@linux.com>
> ---
>  drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
> index b94759daeacc..f25af5bc5282 100644
> --- a/drivers/net/wireless/ath/ar5523/ar5523.c
> +++ b/drivers/net/wireless/ath/ar5523/ar5523.c
> @@ -255,7 +255,8 @@ static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata,
> 
>  	if (flags & AR5523_CMD_FLAG_MAGIC)
>  		hdr->magic = cpu_to_be32(1 << 24);
> -	memcpy(hdr + 1, idata, ilen);
> +	if (idata)
> +		memcpy(hdr + 1, idata, ilen);

That would be better as if (ilen) ...

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
index b94759daeacc..f25af5bc5282 100644
--- a/drivers/net/wireless/ath/ar5523/ar5523.c
+++ b/drivers/net/wireless/ath/ar5523/ar5523.c
@@ -255,7 +255,8 @@  static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata,
 
 	if (flags & AR5523_CMD_FLAG_MAGIC)
 		hdr->magic = cpu_to_be32(1 << 24);
-	memcpy(hdr + 1, idata, ilen);
+	if (idata)
+		memcpy(hdr + 1, idata, ilen);
 
 	cmd->odata = odata;
 	cmd->olen = olen;