Skip to content

Commit 420e306

Browse files
Sebasteuopelwell
authored andcommitted
staging: vc04_services: vchiq-mmal: validate component index in event_to_host_cb()
event_to_host_cb() uses msg->u.event_to_host.client_component as an index into the instance->component[] array (size VCHIQ_MMAL_MAX_COMPONENTS = 64) without bounds validation. While the kernel generally trusts the hardware it is bound to, a bounds check here hardens the driver against potential firmware bugs that could otherwise cause an uncontrolled out-of-bounds array access and kernel crash. Add a bounds check on comp_idx before using it as an array index and move the component pointer assignment after the validation. Use pr_err_ratelimited() to avoid log flooding. Note: this file does not currently have access to a struct device, so dev_err() is not available. Cc: stable@vger.kernel.org Fixes: b18ee53 ("staging: bcm2835: Break MMAL support out from camera") Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
1 parent c787ed0 commit 420e306

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,19 @@ static void event_to_host_cb(struct vchiq_mmal_instance *instance,
479479
struct mmal_msg *msg, u32 msg_len)
480480
{
481481
int comp_idx = msg->u.event_to_host.client_component;
482-
struct vchiq_mmal_component *component =
483-
&instance->component[comp_idx];
482+
struct vchiq_mmal_component *component;
484483
struct vchiq_mmal_port *port = NULL;
485484
struct mmal_msg_context *msg_context;
486485
u32 port_num = msg->u.event_to_host.port_num;
487486

487+
if (comp_idx < 0 || comp_idx >= VCHIQ_MMAL_MAX_COMPONENTS) {
488+
pr_err_ratelimited("%s: component index %d out of range\n",
489+
__func__, comp_idx);
490+
return;
491+
}
492+
493+
component = &instance->component[comp_idx];
494+
488495
if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
489496
pr_err("%s: MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n",
490497
__func__);

0 commit comments

Comments
 (0)