linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@codeaurora.org>
To: Stanislav Yakovlev <stas.yakovlev@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Jeff Garzik <jgarzik@pobox.com>,
	James Ketrenos <jketreno@linux.intel.com>,
	wireless <linux-wireless@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Linus Torvalds <torvalds@linuxfoundation.org>
Subject: Re: [PATCH] ipw2x00: potential buffer overflow in libipw_wx_set_encodeext()
Date: Sun, 11 Apr 2021 12:03:11 +0300	[thread overview]
Message-ID: <87blalmbw0.fsf@codeaurora.org> (raw)
In-Reply-To: <CA++WF2PBo1Mok+bnnUCEZxbbEacX7FcU7PYAPTo=iqgOb2+f3Q@mail.gmail.com> (Stanislav Yakovlev's message of "Sat, 10 Apr 2021 10:59:49 +0400")

Stanislav Yakovlev <stas.yakovlev@gmail.com> writes:

> On Tue, 2 Mar 2021 at 15:16, 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>
>> ---
>>  drivers/net/wireless/intel/ipw2x00/libipw_wx.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)

[...]

>> --- 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 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.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

      reply	other threads:[~2021-04-11  9:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 11:16 [PATCH] ipw2x00: potential buffer overflow in libipw_wx_set_encodeext() Dan Carpenter
2021-04-10  6:59 ` Stanislav Yakovlev
2021-04-11  9:03   ` Kalle Valo [this message]

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=87blalmbw0.fsf@codeaurora.org \
    --to=kvalo@codeaurora.org \
    --cc=dan.carpenter@oracle.com \
    --cc=jgarzik@pobox.com \
    --cc=jketreno@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=stas.yakovlev@gmail.com \
    --cc=torvalds@linuxfoundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).