Coverity: mt7996_hw_queue_read(): Integer handling issues
Subsystems (4)
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):
Addresses-Coverity-ID: 1527813 ("Integer handling issues")
Thanks for your attention!
Signature · 1 line
Coverity-bot
Quoted 7 lines · coverity-bot
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:
Quoted 21 lines
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-Fi7 (802.11be) devices")
Coverity reported the following:
*** CID 1527813: Integer handling issues (
SIGN_EXTENSION)drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460inmt7996_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
Quoted 8 lines
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 than0x7FFFFFFF, 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
Quoted 5 lines
461
mt76_wr(dev, MT_FL_Q0_CTRL, ctrl);
462463 head = mt76_get_field(dev, MT_FL_Q2_CTRL, 464 GENMASK(11, 0)); 465 tail = mt76_get_field(dev, MT_FL_Q2_CTRL,
Quoted 39 lines · Ryder Lee
Quoted 7 lines · coverity-bot
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:Quoted 21 lines
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-Fi7 (802.11be) devices")
Coverity reported the following:
*** CID 1527813: Integer handling issues (
SIGN_EXTENSION)drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460inmt7996_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;
459Quoted 8 lines
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 than0x7FFFFFFF, the upper bits of the result will all be 1.
460 ctrl = BIT(31) | (map[i].pid << 10) |
(map[i].qid << 24);
Quoted 3 lines
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".
Signature · 1 line
Kees Cook