wifi: mwifiex: Replace strlcpy with strscpy
PATCH 1/1 wifi: mwifiex: Replace strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest).
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
--- drivers/net/wireless/marvell/mwifiex/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/main.c +2 -3
@@ -725,9 +725,8 @@ static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,* manufacturing mode is enabled */ if (mfg_mode) { -if (strlcpy (adapter->fw_name,MFG_FIRMWARE , -sizeof (adapter->fw_name)) >= -sizeof (adapter->fw_name)) { +if (strscpy (adapter->fw_name,MFG_FIRMWARE , +sizeof (adapter->fw_name)) <0 ) {pr_err ("%s: fw_name too long!\n" , __func__);return -1 ; }
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
Quoted 7 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
Quoted 7 lines
Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest).
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89Signed-off-by Azeem Shaikh <[email protected]>
Signature · 1 line
Kees Cook
Kees Cook
AppliedQuoted 8 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().[...]
Applied, thanks!
[1/1] wifi: mwifiex: Replace strlcpy with strscpy
https://git.kernel.org/kees/c/5469fb73e96d
Best regards,
Signature · 1 line
Kees Cook
Quoted 8 lines · Kees Cook
Quoted 7 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
Quoted 6 lines
Quoted 1 line
[...]
Applied, thanks!
[1/1] wifi: mwifiex: Replace strlcpy with strscpy
https://git.kernel.org/kees/c/5469fb73e96d
And the same question here, why are you taking wifi patches without acks? And this already fixed differently in wireless-next so our trees conflict now:
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 14 lines · Kalle Valo
Quoted 12 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().[...]
Applied, thanks!
Quoted 8 lines
Quoted 2 lines
[1/1] wifi: mwifiex: Replace strlcpy with strscpy
https://git.kernel.org/kees/c/5469fb73e96dAnd the same question here, why are you taking wifi patches without acks? And this already fixed differently in wireless-next so our trees conflict now:
Thanks for pointing that out! I saw no feedback on Azeem's patch, so it looked like it was being ignored.
For the patch you linked to -- it's okay to have lost the overflow detection and warning?
Regardless, I will drop this from my tree.
-Kees
Signature · 1 line
Kees Cook
Brian Norris
maintainerQuoted 6 lines · Kees Cook
Quoted 1 line · Kalle Valo
For the patch you linked to -- it's okay to have lost the overflow detection and warning?
It's a fixed constant string being copied into a larger fixed array. It really doesn't matter functionality-wise. At best, the error check would be useful for human readers or automated tools. So I didn't bother complaining one way or another, as it took enough tries for the submitter to get things right in the first place.
Brian
Quoted 5 lines · Brian Norris
Quoted 4 lines · Kees Cook
Quoted 8 lines
Quoted 2 lines
For the patch you linked to -- it's okay to have lost the overflow detection and warning?
It's a fixed constant string being copied into a larger fixed array. It really doesn't matter functionality-wise. At best, the error check would be useful for human readers or automated tools. So I didn't bother complaining one way or another, as it took enough tries for the submitter to get things right in the first place.
Gotcha. Thanks!
Signature · 1 line
Kees Cook