Skip to contentSkip to conversation

sbc: Fix stack overflow read in sbc_crc8.

PATCH In review Joshua Kessinger 2 participants 2 messages Feb 21, 2018 – Sep 11, 2018 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sbc: Fix stack overflow read in sbc_crc8.

When encoding or decoding with JOINT_STEREO and 8 subbands the crc_pos is 88 bits. In this case there are no extra bits which need to be added to the CRC, but there is still a read 1 byte past the end of the crc_header stack variable.

---
 sbc/sbc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sbc/sbc.c +1 -1
index 606f11c..7f1efaa 100644
@@ -190,7 +190,7 @@ static uint8_t sbc_crc8(const uint8_t *data, size_t len)
 	for (i = 0; i < len / 8; i++)
 		crc = crc_table[crc ^ data[i]];
 
-	octet = data[i];
+	octet = len % 8 ? data[i] : 0;
 	for (i = 0; i < len % 8; i++) {
 		char bit = ((octet ^ crc) & 0x80) >> 7;
 
Signature · 1 line
2.16.1.291.g4437f3f132-goog
#1 lore raw

Hi Joshua,

Quoted 14 lines · Joshua Kessinger

When encoding or decoding with JOINT_STEREO and 8 subbands the crc_pos is 88 bits. In this case there are no extra bits which need to be added to the CRC, but there is still a read 1 byte past the end of the crc_header stack variable.

---
 sbc/sbc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sbc/sbc.c +0 -0
index 606f11c..7f1efaa 100644

sbc/sbc.c static uint8_t sbc_crc8(const uint8_t *data, size_t len)

Quoted 9 lines
sbc/sbc.c +1 -2
@@ -190,7 +190,7 @@ static uint8_t sbc_crc8(const uint8_t *data, size_t len)
        for (i = 0; i < len / 8; i++)
                crc = crc_table[crc ^ data[i]];
 
-       octet = data[i];
+       octet = len % 8 ? data[i] : 0;
        for (i = 0; i < len % 8; i++) {
                char bit = ((octet ^ crc) & 0x80) >> 7;
 
--

Looks like we forgot about this one, it is now applied after removing the signed-off-by line.

Signature · 1 line
Luiz Augusto von Dentz