ipw2x00: potential buffer overflow in libipw_wx_set_encodeext()
PATCH 1/1 ipw2x00: potential buffer overflow in libipw_wx_set_encodeext()
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.
--- drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/ipw2x00/libipw_wx.c +4 -2
@@ -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 len =min_t (int, ext->key_len,SCM_KEY_LEN ); + +memcpy (sec.keys[idx], ext->key, len); + sec.key_sizes[idx] = len; sec.flags |= (1 << idx);if (ext->alg ==IW_ENCODE_ALG_WEP ) { sec.encode_alg[idx] =SEC_ALG_WEP ;
Signature · 1 line
2.30.1
Quoted 10 lines · Dan Carpenter
The "
ext->key_len" is a u16 that comes from the user. If it's overSCM_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 <[email protected]>--- drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Thanks, and sorry for the long review.
Stanislav.
Quoted 20 lines
drivers/net/wireless/intel/ipw2x00/libipw_wx.c +4
-3@@ -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 len =min_t (int, ext->key_len,SCM_KEY_LEN ); + +memcpy (sec.keys[idx], ext->key, len); + sec.key_sizes[idx] = len; sec.flags |= (1 << idx);if (ext->alg ==IW_ENCODE_ALG_WEP ) { sec.encode_alg[idx] =SEC_ALG_WEP ; --2.30.1
Quoted 11 lines · Stanislav Yakovlev
Quoted 10 lines · Dan Carpenter
The "
ext->key_len" is a u16 that comes from the user. If it's overSCM_KEY_LEN(32) that could lead to memory corruption.Fixes e0d369d1d969 ("[PATCH] ieee82011: Added WE-18 support todefault wireless extension handler")
Signed-off-by Dan Carpenter <[email protected]>--- drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
[...]
Quoted 5 lines
Quoted 5 lines
drivers/net/wireless/intel/ipw2x00/libipw_wx.c +0
-0@@ -633,8 +633,10 @@ int libipw_wx_set_encodeext(struct libipw_device *ieee, }
Quoted 10 lines
drivers/net/wireless/intel/ipw2x00/libipw_wx.c int libipw_wx_set_encodeext(struct libipw_device *ieee, · line 642
Quoted 10 lines
drivers/net/wireless/intel/ipw2x00/libipw_wx.c +4
-2if (ext->alg !=IW_ENCODE_ALG_NONE ) { -memcpy (sec.keys[idx], ext->key, ext->key_len); - sec.key_sizes[idx] = ext->key_len; +int len =min_t (int, ext->key_len,SCM_KEY_LEN ); + +memcpy (sec.keys[idx], ext->key, len); + sec.key_sizes[idx] = len; sec.flags |= (1 << idx);if (ext->alg ==IW_ENCODE_ALG_WEP ) { sec.encode_alg[idx] =SEC_ALG_WEP ;
In another thread Linus gave a good tip about clamp_val(), I think it should be used it here as well to make the check safer and more readable. And also elsewhere in wireless code with similar limits.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches