Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: tda10071: fix unsigned sign extension overflow

The shifting of buf[3] by 24 bits to the left will be promoted to
a 32 bit signed int and then sign-extended to an unsigned long. In
the unlikely event that the the top bit of buf[3] is set then all
then all the upper bits end up as also being set because of
the sign-extension and this affect the ev->post_bit_error sum.
Fix this by using the temporary u32 variable bit_error to avoid
the sign-extension promotion. This also removes the need to do the
computation twice.

Addresses-Coverity: ("Unintended sign extension")

Fixes: 267897a4708f ("[media] tda10071: implement DVBv5 statistics")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Colin Ian King and committed by
Mauro Carvalho Chehab
a7463e2d 889968a4

+5 -4
+5 -4
drivers/media/dvb-frontends/tda10071.c
··· 470 470 goto error; 471 471 472 472 if (dev->delivery_system == SYS_DVBS) { 473 - dev->dvbv3_ber = buf[0] << 24 | buf[1] << 16 | 474 - buf[2] << 8 | buf[3] << 0; 475 - dev->post_bit_error += buf[0] << 24 | buf[1] << 16 | 476 - buf[2] << 8 | buf[3] << 0; 473 + u32 bit_error = buf[0] << 24 | buf[1] << 16 | 474 + buf[2] << 8 | buf[3] << 0; 475 + 476 + dev->dvbv3_ber = bit_error; 477 + dev->post_bit_error += bit_error; 477 478 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 478 479 c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 479 480 dev->block_error += buf[4] << 8 | buf[5] << 0;