Skip to contentSkip to conversation

media: dib8000: validate SNR exponent before shifting

PATCH Superseded Ilya Krutskih 2 participants 2 messages Oct 22

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: dib8000: validate SNR exponent before shifting

Decode the SNR exponent as a signed value instead of storing it in a u32. Subtracting 0x40 from the unsigned exponent currently causes it to wrap around when the encoded value represents a negative number.

Keep the signal and noise mantissas unsigned, as they are used in unsigned fixed-point arithmetic. Check exponent values before shifting by check_shl_overflow().

Return the existing invalid SNR value when the exponent cannot be represented safely.

Fixes 77e2c0f5d471 ("V4L/DVB (12900): DiB8000: added support for DiBcom ISDB-T/ISDB-Tsb demodulator DiB8000")
---
 drivers/media/dvb-frontends/dib8000.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/dvb-frontends/dib8000.c +5 -2
index d291113291e0..442ec06e34dc 100644
@@ -11,6 +11,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/mutex.h>
+#include <linux/overflow.h>
 #include <asm/div64.h>
 
 #include <linux/int_log.h>
@@ -3873,7 +3874,8 @@ static u32 dib8000_get_snr(struct dvb_frontend *fe)
 	exp = (val & 0x3f);
 	if ((exp & 0x20) != 0)
 		exp -= 0x40;
-	n <<= exp+16;
+	if (check_shl_overflow(n, exp + 16, &n))
+		return 0xffffffff;
 
 	if (state->revision != 0x8090)
 		val = dib8000_read_word(state, 543);
@@ -3883,7 +3885,8 @@ static u32 dib8000_get_snr(struct dvb_frontend *fe)
 	exp = (val & 0x3f);
 	if ((exp & 0x20) != 0)
 		exp -= 0x40;
-	s <<= exp+16;
+	if (check_shl_overflow(s, exp + 16, &s))
+		return 0xffffffff;
 
 	if (n > 0) {
 		u32 t = (s/n) << 16;
Signature · 1 line
2.43.0
#1 lore raw

On 10/22/26 8:23 PM, Ilya Krutskih wrote:

Please consider using --no-git-fallback with scripts/get_maintainer.pl --
I don't see what do I have to do with this patch (other than fixing another bug in this driver earlier).

Quoted 2 lines

Decode the SNR exponent as a signed value instead of storing it in a u32.

I don't see where are you changing the type from u32 in this version of
patch -- this phrase seems to be copied from the 1st (internal) version...

Quoted 2 lines

Subtracting 0x40 from the unsigned exponent currently causes it to wrap around when the encoded value represents a negative number.

Seems to be the intended effect...

Quoted 2 lines

Keep the signal and noise mantissas unsigned, as they are used in unsigned fixed-point arithmetic.

Again, this phrase seems to be (mindlessly?) copied from the 1st
version... :-)

Quoted 1 line

Check exponent values before shifting by check_shl_overflow().

Yes, that's what the patch below actually does! :-)

drivers/media/dvb-frontends/dib8000.c

Quoted 14 lines

Return the existing invalid SNR value when the exponent cannot be represented safely.

Fixes 77e2c0f5d471 ("V4L/DVB (12900): DiB8000: added support for DiBcom ISDB-T/ISDB-Tsb demodulator DiB8000")
---
 drivers/media/dvb-frontends/dib8000.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/dvb-frontends/dib8000.c +0 -0
index d291113291e0..442ec06e34dc 100644

[...]> @@ -3873,7 +3874,8 @@ static u32 dib8000_get_snr(struct dvb_frontend *fe)

drivers/media/dvb-frontends/dib8000.c static u32 dib8000_get_snr(struct dvb_frontend *fe) · line 3877

Quoted 5 lines
        exp = (val & 0x3f);
        if ((exp & 0x20) != 0)
                exp -= 0x40;
drivers/media/dvb-frontends/dib8000.c +1 -1
-       n <<= exp+16;
+       if (check_shl_overflow(n, exp + 16, &n))

The question is whether the hardware can actually return exp < -16 or > 15...

Quoted 5 lines
drivers/media/dvb-frontends/dib8000.c +1 -0
+               return 0xffffffff;
 
        if (state->revision != 0x8090)
                val = dib8000_read_word(state, 543);

drivers/media/dvb-frontends/dib8000.c static u32 dib8000_get_snr(struct dvb_frontend *fe) · line 3892

Quoted 9 lines
drivers/media/dvb-frontends/dib8000.c +2 -1
@@ -3883,7 +3885,8 @@ static u32 dib8000_get_snr(struct dvb_frontend *fe)
        exp = (val & 0x3f);
        if ((exp & 0x20) != 0)
                exp -= 0x40;
-       s <<= exp+16;
+       if (check_shl_overflow(s, exp + 16, &s))
+               return 0xffffffff;
 
        if (n > 0) {
                u32 t = (s/n) << 16;[...]

MBR, Sergey