wl1251: Fix possible buffer overflow in wl1251_cmd_scan
Subsystems (3)
PATCH 1/1 wl1251: Fix possible buffer overflow in wl1251_cmd_scan
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.
--- drivers/net/wireless/ti/wl1251/cmd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/ti/wl1251/cmd.c +5 -2
@@ -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 ) {
Signature · 1 line
2.25.1
Quoted 5 lines · Lee Gibson
Function
wl1251_cmd_scancalls 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 <[email protected]>
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 int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len, · line 457
Quoted 12 lines
--- drivers/net/wireless/ti/wl1251/cmd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/net/wireless/ti/wl1251/cmd.c +0
-0@@ -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.
drivers/net/wireless/ti/wl1251/cmd.c int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len, · line 462
Quoted 7 lines
drivers/net/wireless/ti/wl1251/cmd.c +5
-2-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)
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
PATCH v2 1/1 wl1251: Fix possible buffer overflow in wl1251_cmd_scan
In reply to Lee GibsonFunction wl1251_cmd_scan calls memcpy without checking the length. Harden by checking the length is within the maximum allowed size.
---
v2: use clamp_val() instead of min_t()
drivers/net/wireless/ti/wl1251/cmd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/ti/wl1251/cmd.c +6 -3
@@ -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 ) {
Signature · 1 line
2.25.1
Quoted 4 lines · Lee Gibson
Function
wl1251_cmd_scancalls memcpy without checking the length. Harden by checking the length is within the maximum allowed size.Signed-off-by Lee Gibson <[email protected]>
Patch applied to wireless-drivers-next.git, thanks.
d10a87a3535c wl1251: Fix possible buffer overflow in wl1251_cmd_scan
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches