media: cec: extron-da-hd-4k-plus: add sanity check
Subsystems (3)
PATCH 1/1 media: cec: extron-da-hd-4k-plus: add sanity check
Add check to prevent overflowing msg.msg[] in case the incoming data is malformed.
---
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +2 -1
@@ -657,7 +657,8 @@ static void extron_process_received(struct extron_port *port, const char *data)if (!port || port->disconnected)return ; -if (len <5 || (len -2 ) %3 || data[len -2 ] !='*' ) +if (len <5 || ((len -2 ) /3 >sizeof (msg.msg)) || + (len -2 ) %3 || data[len -2 ] !='*' ) goto malformed;while (*data !='*' ) {
Quoted 4 lines · Hans Verkuil
Add check to prevent overflowing msg.msg[] in case the incoming data is malformed.
Signed-off-by Hans Verkuil <[email protected]>
Regards,
Hans
Quoted 16 lines
---
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +2
-1@@ -657,7 +657,8 @@ static void extron_process_received(struct extron_port *port, const char *data)if (!port || port->disconnected)return ; -if (len <5 || (len -2 ) %3 || data[len -2 ] !='*' ) +if (len <5 || ((len -2 ) /3 >sizeof (msg.msg)) || + (len -2 ) %3 || data[len -2 ] !='*' ) goto malformed;while (*data !='*' ) {
Sean Young
Reviewed-byQuoted 8 lines · Hans Verkuil
Quoted 4 lines · Hans Verkuil
Add check to prevent overflowing msg.msg[] in case the incoming data is malformed.
Signed-off-by Hans Verkuil <[email protected]>Fixes 056f2821b631 ("media: cec: extron-da-hd-4k-plus: add the Extron DA HD 4K Plus CEC driver")
Looks good.
Quoted 22 lines
Regards,
Hans
Quoted 16 lines
---
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +2
-1@@ -657,7 +657,8 @@ static void extron_process_received(struct extron_port *port, const char *data)if (!port || port->disconnected)return ; -if (len <5 || (len -2 ) %3 || data[len -2 ] !='*' ) +if (len <5 || ((len -2 ) /3 >sizeof (msg.msg)) || + (len -2 ) %3 || data[len -2 ] !='*' ) goto malformed;while (*data !='*' ) {
Hi Hans,
Thank you for the patch.
Quoted 10 lines · Hans Verkuil
Add check to prevent overflowing msg.msg[] in case the incoming data is malformed.
Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +0
-0
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c static void extron_process_received(struct extron_port *port, const char *data) · line 660
Quoted 5 lines
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +1
-1@@ -657,7 +657,8 @@ static void extron_process_received(struct extron_port *port, const char *data)if (!port || port->disconnected)return ; -if (len <5 || (len -2 ) %3 || data[len -2 ] !='*' ) + if (len < 5 || ((len - 2) / 3 > sizeof(msg.msg)) ||
I think you should use ARRAY_SIZE
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c static void extron_process_received(struct extron_port *port, const char *data) · line 661
Quoted 1 line
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +1
-0+ (len - 2) % 3 || data[len - 2] != '*')
This seems correct, but I think the code would be easier to read and maintain if you wrote
int len; /* The last two bytes are ignored because ... */ len = strlen(data) - 2; /* * Ensure the data has at least one message, at most the number * of messages that fit in msg.msg, and no extra bytes. */ if (len < 3 || len / 3 > ARRAY_SIZE(msg.msg) || len % 3)
goto malformed;
if (data[len] != '*')
goto malformed;
Quoted 4 lines
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +0
-0goto malformed;while (*data !='*' ) {
Signature · 3 lines
Regards, Laurent Pinchart