netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Coverity: iwl_mvm_sec_key_add(): Memory - corruptions
@ 2022-11-18 16:54 coverity-bot
  2022-11-18 21:04 ` Johannes Berg
  0 siblings, 1 reply; 4+ messages in thread
From: coverity-bot @ 2022-11-18 16:54 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Luca Coelho, Haim Dreyfuss, Miri Korenblit, Petr Stourac,
	linux-kernel, Mordechay Goodstein, Jakub Kicinski, Eric Dumazet,
	Nathan Errera, Paolo Abeni, Shaul Triebitz, netdev,
	Gregory Greenman, Abhishek Naik, Jose Ignacio Tornos Martinez,
	Ayala Beker, David S. Miller, linux-wireless, Sriram R,
	Kalle Valo, Mike Golant, Emmanuel Grumbach, Gustavo A. R. Silva,
	linux-next, linux-hardening

Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221118 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

  Thu Nov 10 13:26:51 2022 +0200
    5c75a208c244 ("wifi: iwlwifi: mvm: support new key API")

Coverity reported the following:

*** CID 1527370:  Memory - corruptions  (OVERRUN)
drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c:123 in iwl_mvm_sec_key_add()
117
118     	if (WARN_ON(keyconf->keylen > sizeof(cmd.u.add.key)))
119     		return -EINVAL;
120
121     	if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
122     	    keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
vvv     CID 1527370:  Memory - corruptions  (OVERRUN)
vvv     Overrunning buffer pointed to by "cmd.u.add.key + 3" of 32 bytes by passing it to a function which accesses it at byte offset 34 using argument "keyconf->keylen" (which evaluates to 32). [Note: The source code implementation of the function has been overridden by a builtin model.]
123     		memcpy(cmd.u.add.key + IWL_SEC_WEP_KEY_OFFSET, keyconf->key,
124     		       keyconf->keylen);
125     	else
126     		memcpy(cmd.u.add.key, keyconf->key, keyconf->keylen);
127
128     	if (keyconf->cipher == WLAN_CIPHER_SUITE_TKIP) {

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527370 ("Memory - corruptions")
Fixes: 5c75a208c244 ("wifi: iwlwifi: mvm: support new key API")

keyconf->keylen is only bounds-checked against sizeof(cmd.u.add.key),
but the memcpy() is starting a write at key + 3.

Thanks for your attention!

-- 
Coverity-bot

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Coverity: iwl_mvm_sec_key_add(): Memory - corruptions
  2022-11-18 16:54 Coverity: iwl_mvm_sec_key_add(): Memory - corruptions coverity-bot
@ 2022-11-18 21:04 ` Johannes Berg
  2022-11-18 22:25   ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2022-11-18 21:04 UTC (permalink / raw)
  To: coverity-bot
  Cc: Luca Coelho, Haim Dreyfuss, Miri Korenblit, Petr Stourac,
	linux-kernel, Mordechay Goodstein, Jakub Kicinski, Eric Dumazet,
	Nathan Errera, Paolo Abeni, Shaul Triebitz, netdev,
	Gregory Greenman, Abhishek Naik, Jose Ignacio Tornos Martinez,
	Ayala Beker, David S. Miller, linux-wireless, Sriram R,
	Kalle Valo, Mike Golant, Emmanuel Grumbach, Gustavo A. R. Silva,
	linux-next, linux-hardening

On Fri, 2022-11-18 at 08:54 -0800, coverity-bot wrote:
> 
> *** CID 1527370:  Memory - corruptions  (OVERRUN)
> drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c:123 in iwl_mvm_sec_key_add()
> 117
> 118     	if (WARN_ON(keyconf->keylen > sizeof(cmd.u.add.key)))
> 119     		return -EINVAL;
> 120
> 121     	if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
> 122     	    keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
> vvv     CID 1527370:  Memory - corruptions  (OVERRUN)
> vvv     Overrunning buffer pointed to by "cmd.u.add.key + 3" of 32 bytes by passing it to a function which accesses it at byte offset 34 using argument "keyconf->keylen" (which evaluates to 32). [Note: The source code implementation of the function has been overridden by a builtin model.]
> 123     		memcpy(cmd.u.add.key + IWL_SEC_WEP_KEY_OFFSET, keyconf->key,
> 124     		       keyconf->keylen);
> 125     	else
> 126     		memcpy(cmd.u.add.key, keyconf->key, keyconf->keylen);
> 127
> 128     	if (keyconf->cipher == WLAN_CIPHER_SUITE_TKIP) {
> 
> If this is a false positive, please let us know so we can mark it as
> such, or teach the Coverity rules to be smarter. If not, please make
> sure fixes get into linux-next. :) For patches fixing this, please
> include these lines (but double-check the "Fixes" first):
> 

Well, I don't think you can teach coverity this easily, but the
WARN_ON() check there is not really meant to protect this - WEP keys
must have a length of either 5 or 13 bytes (40 or 104 bits!).

So there's no issue here, but I'm not surprised that coverity wouldn't
be able to figure that out through the stack.

johannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Coverity: iwl_mvm_sec_key_add(): Memory - corruptions
  2022-11-18 21:04 ` Johannes Berg
@ 2022-11-18 22:25   ` Kees Cook
  2022-11-22 16:46     ` Johannes Berg
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2022-11-18 22:25 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Luca Coelho, Haim Dreyfuss, Miri Korenblit, Petr Stourac,
	linux-kernel, Mordechay Goodstein, Jakub Kicinski, Eric Dumazet,
	Nathan Errera, Paolo Abeni, Shaul Triebitz, netdev,
	Gregory Greenman, Abhishek Naik, Jose Ignacio Tornos Martinez,
	Ayala Beker, David S. Miller, linux-wireless, Sriram R,
	Kalle Valo, Mike Golant, Emmanuel Grumbach, Gustavo A. R. Silva,
	linux-next, linux-hardening

On Fri, Nov 18, 2022 at 10:04:38PM +0100, Johannes Berg wrote:
> On Fri, 2022-11-18 at 08:54 -0800, coverity-bot wrote:
> > 
> > *** CID 1527370:  Memory - corruptions  (OVERRUN)
> > drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c:123 in iwl_mvm_sec_key_add()
> > 117
> > 118     	if (WARN_ON(keyconf->keylen > sizeof(cmd.u.add.key)))
> > 119     		return -EINVAL;
> > 120
> > 121     	if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
> > 122     	    keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
> > vvv     CID 1527370:  Memory - corruptions  (OVERRUN)
> > vvv     Overrunning buffer pointed to by "cmd.u.add.key + 3" of 32 bytes by passing it to a function which accesses it at byte offset 34 using argument "keyconf->keylen" (which evaluates to 32). [Note: The source code implementation of the function has been overridden by a builtin model.]
> > 123     		memcpy(cmd.u.add.key + IWL_SEC_WEP_KEY_OFFSET, keyconf->key,
> > 124     		       keyconf->keylen);
> > 125     	else
> > 126     		memcpy(cmd.u.add.key, keyconf->key, keyconf->keylen);
> > 127
> > 128     	if (keyconf->cipher == WLAN_CIPHER_SUITE_TKIP) {
> > 
> > If this is a false positive, please let us know so we can mark it as
> > such, or teach the Coverity rules to be smarter. If not, please make
> > sure fixes get into linux-next. :) For patches fixing this, please
> > include these lines (but double-check the "Fixes" first):
> > 
> 
> Well, I don't think you can teach coverity this easily, but the
> WARN_ON() check there is not really meant to protect this - WEP keys
> must have a length of either 5 or 13 bytes (40 or 104 bits!).
> 
> So there's no issue here, but I'm not surprised that coverity wouldn't
> be able to figure that out through the stack.

Gotcha. And some other layer is doing the verification that cipher and
keylen are correctly matched?

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Coverity: iwl_mvm_sec_key_add(): Memory - corruptions
  2022-11-18 22:25   ` Kees Cook
@ 2022-11-22 16:46     ` Johannes Berg
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2022-11-22 16:46 UTC (permalink / raw)
  To: Kees Cook
  Cc: Luca Coelho, Haim Dreyfuss, Miri Korenblit, Petr Stourac,
	linux-kernel, Mordechay Goodstein, Jakub Kicinski, Eric Dumazet,
	Nathan Errera, Paolo Abeni, Shaul Triebitz, netdev,
	Gregory Greenman, Abhishek Naik, Jose Ignacio Tornos Martinez,
	Ayala Beker, David S. Miller, linux-wireless, Sriram R,
	Kalle Valo, Mike Golant, Emmanuel Grumbach, Gustavo A. R. Silva,
	linux-next, linux-hardening

On Fri, 2022-11-18 at 14:25 -0800, Kees Cook wrote:
> On Fri, Nov 18, 2022 at 10:04:38PM +0100, Johannes Berg wrote:
> > On Fri, 2022-11-18 at 08:54 -0800, coverity-bot wrote:
> > > 
> > > *** CID 1527370:  Memory - corruptions  (OVERRUN)
> > > drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c:123 in iwl_mvm_sec_key_add()
> > > 117
> > > 118     	if (WARN_ON(keyconf->keylen > sizeof(cmd.u.add.key)))
> > > 119     		return -EINVAL;
> > > 120
> > > 121     	if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
> > > 122     	    keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
> > > vvv     CID 1527370:  Memory - corruptions  (OVERRUN)
> > > vvv     Overrunning buffer pointed to by "cmd.u.add.key + 3" of 32 bytes by passing it to a function which accesses it at byte offset 34 using argument "keyconf->keylen" (which evaluates to 32). [Note: The source code implementation of the function has been overridden by a builtin model.]
> > > 123     		memcpy(cmd.u.add.key + IWL_SEC_WEP_KEY_OFFSET, keyconf->key,
> > > 124     		       keyconf->keylen);
> > > 125     	else
> > > 126     		memcpy(cmd.u.add.key, keyconf->key, keyconf->keylen);
> > > 127
> > > 128     	if (keyconf->cipher == WLAN_CIPHER_SUITE_TKIP) {
> > > 
> > > If this is a false positive, please let us know so we can mark it as
> > > such, or teach the Coverity rules to be smarter. If not, please make
> > > sure fixes get into linux-next. :) For patches fixing this, please
> > > include these lines (but double-check the "Fixes" first):
> > > 
> > 
> > Well, I don't think you can teach coverity this easily, but the
> > WARN_ON() check there is not really meant to protect this - WEP keys
> > must have a length of either 5 or 13 bytes (40 or 104 bits!).
> > 
> > So there's no issue here, but I'm not surprised that coverity wouldn't
> > be able to figure that out through the stack.
> 
> Gotcha. And some other layer is doing the verification that cipher and
> keylen are correctly matched?


Yes, the key must come through cfg80211_validate_key_settings() at some
point.

johannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-22 16:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 16:54 Coverity: iwl_mvm_sec_key_add(): Memory - corruptions coverity-bot
2022-11-18 21:04 ` Johannes Berg
2022-11-18 22:25   ` Kees Cook
2022-11-22 16:46     ` Johannes Berg

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