Skip to content

Commit 311a064

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 e538839 commit 311a064

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c

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

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

0 commit comments

Comments
 (0)