Skip to contentSkip to conversation

Coverity: mt7915_mcu_get_chan_mib_info(): Memory - illegal accesses

DISCUSSION coverity-bot 2 participants 5 messages Dec 2, 2022 – Dec 3, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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 Feb 3 13:57:56 2022 +0100

    417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for mt7916")

Coverity reported the following:

*** CID 1527801: Memory - illegal accesses (OVERRUN) drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in mt7915_mcu_get_chan_mib_info()

2999     		start = 5;
3000     		ofs = 0;
3001     	}

3002
3003 for (i = 0; i < 5; i++) {
3004 req[i].band = cpu_to_le32(phy->mt76->band_idx);
vvv CID 1527801: Memory - illegal accesses (OVERRUN)
vvv Overrunning array "offs" of 9 4-byte elements at element index 9 (byte offset 39) using index "i + start" (which evaluates to 9).
3005 req[i].offs = cpu_to_le32(offs[i + start]);
3006

3007     		if (!is_mt7915(&dev->mt76) && i == 3)
3008     			break;
3009     	}

3010

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: 1527801 ("Memory - illegal accesses")

Fixes 417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for mt7916")

Thanks for your attention!

Signature · 1 line
Coverity-bot
#1 lore raw
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:

https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!j7j_C0KpO4VD2yMOodvpeIexTGq4fhy2yq6nokNua9u4LToiUOLk4ou8JFFNrXkrh80d5BK2k44faRQstHE9$

Quoted 30 lines

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

Thu Feb 3 13:57:56 2022 +0100

    417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Coverity reported the following:

*** CID 1527801: Memory - illegal accesses (OVERRUN) drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in mt7915_mcu_get_chan_mib_info()

2999     		start = 5;
3000     		ofs = 0;
3001     	}

3002
3003 for (i = 0; i < 5; i++) {
3004 req[i].band = cpu_to_le32(phy->mt76->band_idx);
vvv CID 1527801: Memory - illegal accesses (OVERRUN)
vvv Overrunning array "offs" of 9 4-byte elements at element
index 9 (byte offset 39) using index "i + start" (which evaluates to 9).
3005 req[i].offs = cpu_to_le32(offs[i + start]);
3006

3007     		if (!is_mt7915(&dev->mt76) && i == 3)
3008     			break;
3009     	}
Quoted 7 lines

3010

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

I think this is a false postive as the subsequent check 'if (!is_mt7915(&dev->mt76) && i == 3)' should break array "offs" of 8.

Ryder

Quoted 7 lines

Addresses-Coverity-ID: 1527801 ("Memory - illegal accesses")

Fixes 417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Thanks for your attention!

author
#2 lore raw
Quoted 41 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:

https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!j7j_C0KpO4VD2yMOodvpeIexTGq4fhy2yq6nokNua9u4LToiUOLk4ou8JFFNrXkrh80d5BK2k44faRQstHE9$

Quoted 32 lines

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

Thu Feb 3 13:57:56 2022 +0100

    417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Coverity reported the following:

*** CID 1527801: Memory - illegal accesses (OVERRUN) drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in mt7915_mcu_get_chan_mib_info()

2999     		start = 5;
3000     		ofs = 0;
3001     	}

3002
3003 for (i = 0; i < 5; i++) {
3004 req[i].band = cpu_to_le32(phy->mt76->band_idx);
vvv CID 1527801: Memory - illegal accesses (OVERRUN)
vvv Overrunning array "offs" of 9 4-byte elements at element
index 9 (byte offset 39) using index "i + start" (which evaluates to 9).
3005 req[i].offs = cpu_to_le32(offs[i + start]);
3006

3007     		if (!is_mt7915(&dev->mt76) && i == 3)
3008     			break;
3009     	}

3010

Quoted 8 lines
Quoted 5 lines

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

I think this is a false postive as the subsequent check 'if (!is_mt7915(&dev->mt76) && i == 3)' should break array "offs" of 8.

Ah, okay. What if is_mt7915(&dev->mt76) is always true?

-Kees

Quoted 10 lines

Ryder

Quoted 7 lines

Addresses-Coverity-ID: 1527801 ("Memory - illegal accesses")

Fixes 417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Thanks for your attention!

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 5 lines · Kees Cook
Quoted 1 line
Quoted 3 lines · Ryder Lee
Quoted 2 lines · coverity-bot

Hello!

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

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!j7j_C0KpO4VD2yMOodvpeIexTGq4fhy2yq6nokNua9u4LToiUOLk4ou8JFFNrXkrh80d5BK2k44faRQstHE9$

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines

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

Thu Feb 3 13:57:56 2022 +0100

    417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Coverity reported the following:

*** CID 1527801: Memory - illegal accesses (OVERRUN) drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in mt7915_mcu_get_chan_mib_info()

2999     		start = 5;
3000     		ofs = 0;
3001     	}

3002
3003 for (i = 0; i < 5; i++) {
3004 req[i].band = cpu_to_le32(phy->mt76->band_idx);
vvv CID 1527801: Memory - illegal accesses (OVERRUN)
vvv Overrunning array "offs" of 9 4-byte elements at element
index 9 (byte offset 39) using index "i + start" (which evaluates to
9).
3005 req[i].offs = cpu_to_le32(offs[i + start]);
3006

3007     		if (!is_mt7915(&dev->mt76) && i == 3)
3008     			break;
3009     	}

3010

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

Quoted 6 lines
Quoted 2 lines

I think this is a false postive as the subsequent check 'if (!is_mt7915(&dev->mt76) && i == 3)' should break array "offs" of 8.

Ah, okay. What if is_mt7915(&dev->mt76) is always true?

-Kees

	int start = 0;

	if (!is_mt7915(&dev->mt76)) {
		start = 5;
		ofs = 0;
	}

	for (i = 0; i < 5; i++) {
		req[i].band = cpu_to_le32(phy->band_idx);
		req[i].offs = cpu_to_le32(offs[i + start]);

		if (!is_mt7915(&dev->mt76) && i == 3) //
			break;
	}

For 'is_mt7915' case, start:0 and i: 0 1 2 3 4, whereas !is_mt7915' case, start:5 and i: 0 1 2 3 (then break).

I know it's a bit tricky. This is used to differentiate chipset revision.

Ryder

author
#4 lore raw
Quoted 81 lines · Ryder Lee
Quoted 5 lines · Kees Cook
Quoted 1 line
Quoted 3 lines · Ryder Lee
Quoted 2 lines · coverity-bot

Hello!

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

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!j7j_C0KpO4VD2yMOodvpeIexTGq4fhy2yq6nokNua9u4LToiUOLk4ou8JFFNrXkrh80d5BK2k44faRQstHE9$

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines

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

Thu Feb 3 13:57:56 2022 +0100

    417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for

mt7916")

Coverity reported the following:

*** CID 1527801: Memory - illegal accesses (OVERRUN) drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in mt7915_mcu_get_chan_mib_info()

2999     		start = 5;
3000     		ofs = 0;
3001     	}

3002
3003 for (i = 0; i < 5; i++) {
3004 req[i].band = cpu_to_le32(phy->mt76->band_idx);
vvv CID 1527801: Memory - illegal accesses (OVERRUN)
vvv Overrunning array "offs" of 9 4-byte elements at element
index 9 (byte offset 39) using index "i + start" (which evaluates to
9).
3005 req[i].offs = cpu_to_le32(offs[i + start]);
3006

3007     		if (!is_mt7915(&dev->mt76) && i == 3)
3008     			break;
3009     	}

3010

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

Quoted 6 lines
Quoted 2 lines

I think this is a false postive as the subsequent check 'if (!is_mt7915(&dev->mt76) && i == 3)' should break array "offs" of 8.

Ah, okay. What if is_mt7915(&dev->mt76) is always true?

-Kees

	int start = 0;

	if (!is_mt7915(&dev->mt76)) {
		start = 5;
		ofs = 0;
	}

	for (i = 0; i < 5; i++) {
		req[i].band = cpu_to_le32(phy->band_idx);
		req[i].offs = cpu_to_le32(offs[i + start]);

		if (!is_mt7915(&dev->mt76) && i == 3) //
			break;
	}
Quoted 5 lines

For 'is_mt7915' case, start:0 and i: 0 1 2 3 4, whereas !is_mt7915' case, start:5 and i: 0 1 2 3 (then break).

I know it's a bit tricky. This is used to differentiate chipset revision.

Ah-ha! Gotcha now. Thanks for the details and sorry for the noise! :)

-Kees

Signature · 1 line
Kees Cook