linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Coverity: mt7996_hw_queue_read(): Integer handling issues
@ 2022-12-02 22:11 coverity-bot
  2022-12-03  4:40 ` Ryder Lee
  0 siblings, 1 reply; 3+ messages in thread
From: coverity-bot @ 2022-12-02 22:11 UTC (permalink / raw)
  To: Shayne Chen
  Cc: Lorenzo Bianconi, linux-wireless, Jakub Kicinski, Kalle Valo,
	StanleyYP Wang, Matthias Brugger, Peter Chiu, Eric Dumazet,
	Money Wang, linux-arm-kernel, netdev, Howard Hsu, linux-mediatek,
	Felix Fietkau, David S. Miller, Evelyn Tsai, linux-kernel,
	MeiChia Chiu, Paolo Abeni, Sean Wang, Bo Jiao, Ryder Lee,
	Sujuan Chen, 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-20221202 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 Dec 1 17:29:14 2022 +0100
    98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")

Coverity reported the following:

*** CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460 in mt7996_hw_queue_read()
454     	for (i = 0; i < size; i++) {
455     		u32 ctrl, head, tail, queued;
456
457     		if (val & BIT(map[i].index))
458     			continue;
459
vvv     CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
vvv     Suspicious implicit sign extension: "map[i].qid" with type "u8" (8 bits, unsigned) is promoted in "map[i].qid << 24" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned).  If "map[i].qid << 24" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.
460     		ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);
461     		mt76_wr(dev, MT_FL_Q0_CTRL, ctrl);
462
463     		head = mt76_get_field(dev, MT_FL_Q2_CTRL,
464     				      GENMASK(11, 0));
465     		tail = mt76_get_field(dev, MT_FL_Q2_CTRL,

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: 1527813 ("Integer handling issues")
Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")

Thanks for your attention!

-- 
Coverity-bot

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

* Re: Coverity: mt7996_hw_queue_read(): Integer handling issues
  2022-12-02 22:11 Coverity: mt7996_hw_queue_read(): Integer handling issues coverity-bot
@ 2022-12-03  4:40 ` Ryder Lee
  2022-12-06 23:37   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Ryder Lee @ 2022-12-03  4:40 UTC (permalink / raw)
  To: keescook, Shayne Chen (陳軒丞)
  Cc: StanleyYP Wang (王侑邦),
	linux-mediatek, linux-kernel,
	Howard-YH Hsu (許育豪),
	gustavo, Evelyn Tsai (蔡珊鈺),
	Money Wang (王信安),
	linux-hardening, nbd, MeiChia Chiu (邱美嘉),
	lorenzo, kuba, Sean Wang, kvalo, edumazet,
	Sujuan Chen (陈素娟),
	Chui-hao Chiu (邱垂浩),
	linux-arm-kernel, netdev, pabeni, matthias.bgg, davem,
	linux-next, linux-wireless, Bo Jiao (焦波)

On Fri, 2022-12-02 at 14:11 -0800, coverity-bot wrote:
> Hello!
> 
> This is an experimental semi-automated report about issues detected
> by
> Coverity from a scan of next-20221202 as part of the linux-next scan
> project:
> 
https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!jBOoj6LMqqA8E0AyjKQTa-0rVzcFiZ3BbpciEIn7so974kcMBeG4zZm-QU4AudLXY7-jNUSt0unzAt2zirSF$ 
>  
> 
> You're getting this email because you were associated with the
> identified
> lines of code (noted below) that were touched by commits:
> 
>   Thu Dec 1 17:29:14 2022 +0100
>     98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi
> 7 (802.11be) devices")
> 
> Coverity reported the following:
> 
> *** CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460 in
> mt7996_hw_queue_read()
> 454     	for (i = 0; i < size; i++) {
> 455     		u32 ctrl, head, tail, queued;
> 456
> 457     		if (val & BIT(map[i].index))
> 458     			continue;
> 459
> vvv     CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> vvv     Suspicious implicit sign extension: "map[i].qid" with type
> "u8" (8 bits, unsigned) is promoted in "map[i].qid << 24" to type
> "int" (32 bits, signed), then sign-extended to type "unsigned long"
> (64 bits, unsigned).  If "map[i].qid << 24" is greater than
> 0x7FFFFFFF, the upper bits of the result will all be 1.
> 460     		ctrl = BIT(31) | (map[i].pid << 10) |
> (map[i].qid << 24);

u32 ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);

Hmm ...where's type "int" (32 bits, signed) from?

Ryder
> 461     		mt76_wr(dev, MT_FL_Q0_CTRL, ctrl);
> 462
> 463     		head = mt76_get_field(dev, MT_FL_Q2_CTRL,
> 464     				      GENMASK(11, 0));
> 465     		tail = mt76_get_field(dev, MT_FL_Q2_CTRL,

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

* Re: Coverity: mt7996_hw_queue_read(): Integer handling issues
  2022-12-03  4:40 ` Ryder Lee
@ 2022-12-06 23:37   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2022-12-06 23:37 UTC (permalink / raw)
  To: Ryder Lee
  Cc: Shayne Chen (陳軒丞),
	StanleyYP Wang (王侑邦),
	linux-mediatek, linux-kernel,
	Howard-YH Hsu (許育豪),
	gustavo, Evelyn Tsai (蔡珊鈺),
	Money Wang (王信安),
	linux-hardening, nbd, MeiChia Chiu (邱美嘉),
	lorenzo, kuba, Sean Wang, kvalo, edumazet,
	Sujuan Chen (陈素娟),
	Chui-hao Chiu (邱垂浩),
	linux-arm-kernel, netdev, pabeni, matthias.bgg, davem,
	linux-next, linux-wireless, Bo Jiao (焦波)

On Sat, Dec 03, 2022 at 04:40:09AM +0000, Ryder Lee wrote:
> On Fri, 2022-12-02 at 14:11 -0800, coverity-bot wrote:
> > Hello!
> > 
> > This is an experimental semi-automated report about issues detected
> > by
> > Coverity from a scan of next-20221202 as part of the linux-next scan
> > project:
> > 
> https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!jBOoj6LMqqA8E0AyjKQTa-0rVzcFiZ3BbpciEIn7so974kcMBeG4zZm-QU4AudLXY7-jNUSt0unzAt2zirSF$ 
> >  
> > 
> > You're getting this email because you were associated with the
> > identified
> > lines of code (noted below) that were touched by commits:
> > 
> >   Thu Dec 1 17:29:14 2022 +0100
> >     98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi
> > 7 (802.11be) devices")
> > 
> > Coverity reported the following:
> > 
> > *** CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460 in
> > mt7996_hw_queue_read()
> > 454     	for (i = 0; i < size; i++) {
> > 455     		u32 ctrl, head, tail, queued;
> > 456
> > 457     		if (val & BIT(map[i].index))
> > 458     			continue;
> > 459
> > vvv     CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > vvv     Suspicious implicit sign extension: "map[i].qid" with type
> > "u8" (8 bits, unsigned) is promoted in "map[i].qid << 24" to type
> > "int" (32 bits, signed), then sign-extended to type "unsigned long"
> > (64 bits, unsigned).  If "map[i].qid << 24" is greater than
> > 0x7FFFFFFF, the upper bits of the result will all be 1.
> > 460     		ctrl = BIT(31) | (map[i].pid << 10) |
> > (map[i].qid << 24);
> 
> u32 ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);
> 
> Hmm ...where's type "int" (32 bits, signed) from?

	map[i].qid is promoted to int before the "<< 24".

-- 
Kees Cook

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

end of thread, other threads:[~2022-12-06 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02 22:11 Coverity: mt7996_hw_queue_read(): Integer handling issues coverity-bot
2022-12-03  4:40 ` Ryder Lee
2022-12-06 23:37   ` Kees Cook

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