ar5523: check NULL before memcpy() in ar5523_cmd()
Subsystems (4)
PATCH 1/1 ar5523: check NULL before memcpy() in ar5523_cmd()
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.
--- drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ar5523/ar5523.c +2 -1
@@ -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;
Signature · 1 line
2.21.0
From: Denis Efremov
Quoted 8 lines
Sent: 30 September 2019 15:02
memcpy()call with "idata == NULL && ilen == 0" results in undefined behavior inar5523_cmd(). For example, NULL is passed in callchain "ar5523_stat_work()->ar5523_cmd_write()->ar5523_cmd()". This patch adds idata check beforememcpy()call inar5523_cmd()to prevent an undefined behavior.
...
Quoted 10 lines
Signed-off-by Denis Efremov <[email protected]>--- drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/wireless/ath/ar5523/ar5523.c +0
-0
drivers/net/wireless/ath/ar5523/ar5523.c static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata, · line 259
Quoted 6 lines
drivers/net/wireless/ath/ar5523/ar5523.c +2
-1@@ -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)
PATCH v2 1/1 ar5523: check NULL before memcpy() in ar5523_cmd()
In reply to Denis Efremovmemcpy() 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 ilen check before memcpy() call in ar5523_cmd() to prevent an undefined behavior.
---
V2: check ilen instead of idata as suggested by David Laight.
drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ar5523/ar5523.c +2 -1
@@ -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 (ilen) +memcpy (hdr +1 , idata, ilen); cmd->odata = odata; cmd->olen = olen;
Signature · 1 line
2.21.0
Quoted 6 lines · Denis Efremov
memcpy()call with "idata == NULL && ilen == 0" results in undefined behavior inar5523_cmd(). For example, NULL is passed in callchain "ar5523_stat_work()->ar5523_cmd_write()->ar5523_cmd()". This patch adds ilen check beforememcpy()call inar5523_cmd()to prevent an undefined behavior.
Quoted 7 lines
Cc Pontus Fuchs <[email protected]>Cc Kalle Valo <[email protected]>Cc "David S. Miller" <[email protected]>Cc David Laight <[email protected]>Signed-off-by Denis Efremov <[email protected]>Signed-off-by Kalle Valo <[email protected]>
Patch applied to ath-next branch of ath.git, thanks.
315cee426f87 ar5523: check NULL before memcpy() in ar5523_cmd()
Signature · 3 lines
https://patchwork.kernel.org/patch/11167401/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches