All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Shurong <zhang_shurong@foxmail.com>
To: gregkh@linuxfoundation.org
Cc: error27@gmail.com, xu.panda@zte.com.cn,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	Zhang Shurong <zhang_shurong@foxmail.com>
Subject: [PATCH] staging: ks7010: potential buffer overflow in ks_wlan_set_encode_ext()
Date: Sun,  9 Jul 2023 13:50:07 +0800	[thread overview]
Message-ID: <tencent_5153B668C0283CAA15AA518325346E026A09@qq.com> (raw)

The "exc->key_len" is a u16 that comes from the user.  If it's over
IW_ENCODING_TOKEN_MAX (64) that could lead to memory corruption.

Fixes: b121d84882b9 ("staging: ks7010: simplify calls to memcpy()")

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/staging/ks7010/ks_wlan_net.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index e03c87f0bfe7..0fb97a79ad0b 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -1583,8 +1583,10 @@ static int ks_wlan_set_encode_ext(struct net_device *dev,
 			commit |= SME_WEP_FLAG;
 		}
 		if (enc->key_len) {
-			memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
-			key->key_len = enc->key_len;
+			int key_len = clamp_val(enc->key_len, 0, IW_ENCODING_TOKEN_MAX);
+
+			memcpy(&key->key_val[0], &enc->key[0], key_len);
+			key->key_len = key_len;
 			commit |= (SME_WEP_VAL1 << index);
 		}
 		break;
-- 
2.30.2


             reply	other threads:[~2023-07-09  6:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09  5:50 Zhang Shurong [this message]
2023-07-09 19:21 ` [PATCH] staging: ks7010: potential buffer overflow in ks_wlan_set_encode_ext() Markus Elfring
2023-07-09 19:42   ` Greg Kroah-Hartman
2023-07-09 19:56     ` Markus Elfring
2023-07-10  5:41       ` Zhang Shurong
2023-07-10  5:47         ` Greg Kroah-Hartman
2023-07-10  6:32           ` Markus Elfring
2023-07-10  6:21         ` Markus Elfring
2023-07-10  6:08 ` [PATCH] " Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_5153B668C0283CAA15AA518325346E026A09@qq.com \
    --to=zhang_shurong@foxmail.com \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=xu.panda@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.