diff mbox series

[v2] ipw2x00: potential buffer overflow in libipw_wx_set_encodeext()

Message ID YHaoA1i+8uT4ir4h@mwanda
State Accepted
Commit 260a9ad9446723d4063ed802989758852809714d
Delegated to: Kalle Valo
Headers show
Series [v2] ipw2x00: potential buffer overflow in libipw_wx_set_encodeext() | expand

Commit Message

Dan Carpenter April 14, 2021, 8:29 a.m. UTC
The "ext->key_len" is a u16 that comes from the user.  If it's over
SCM_KEY_LEN (32) that could lead to memory corruption.

Fixes: e0d369d1d969 ("[PATCH] ieee82011: Added WE-18 support to default wireless extension handler")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: use clamp_val() instead of min_t()

 drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stanislav Yakovlev April 14, 2021, 11:09 a.m. UTC | #1
On Wed, 14 Apr 2021 at 12:30, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The "ext->key_len" is a u16 that comes from the user.  If it's over
> SCM_KEY_LEN (32) that could lead to memory corruption.
>
> Fixes: e0d369d1d969 ("[PATCH] ieee82011: Added WE-18 support to default wireless extension handler")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: use clamp_val() instead of min_t()
>
>  drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>

Cc: stable@vger.kernel.org
Acked-by: Stanislav Yakovlev <stas.yakovlev@gmail.com>

Stanislav.
Kalle Valo April 17, 2021, 5:36 p.m. UTC | #2
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> The "ext->key_len" is a u16 that comes from the user.  If it's over
> SCM_KEY_LEN (32) that could lead to memory corruption.
> 
> Fixes: e0d369d1d969 ("[PATCH] ieee82011: Added WE-18 support to default wireless extension handler")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Stanislav Yakovlev <stas.yakovlev@gmail.com>

Patch applied to wireless-drivers-next.git, thanks.

260a9ad94467 ipw2x00: potential buffer overflow in libipw_wx_set_encodeext()
diff mbox series

Patch

diff --git a/drivers/net/wireless/intel/ipw2x00/libipw_wx.c b/drivers/net/wireless/intel/ipw2x00/libipw_wx.c
index a0cf78c418ac..903de34028ef 100644
--- a/drivers/net/wireless/intel/ipw2x00/libipw_wx.c
+++ b/drivers/net/wireless/intel/ipw2x00/libipw_wx.c
@@ -633,8 +633,10 @@  int libipw_wx_set_encodeext(struct libipw_device *ieee,
 	}
 
 	if (ext->alg != IW_ENCODE_ALG_NONE) {
-		memcpy(sec.keys[idx], ext->key, ext->key_len);
-		sec.key_sizes[idx] = ext->key_len;
+		int key_len = clamp_val(ext->key_len, 0, SCM_KEY_LEN);
+
+		memcpy(sec.keys[idx], ext->key, key_len);
+		sec.key_sizes[idx] = key_len;
 		sec.flags |= (1 << idx);
 		if (ext->alg == IW_ENCODE_ALG_WEP) {
 			sec.encode_alg[idx] = SEC_ALG_WEP;