* [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb()
2026-03-29 6:21 [PATCH 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
@ 2026-03-29 6:21 ` Sebastian Josue Alba Vives
2026-03-29 6:35 ` Greg Kroah-Hartman
2026-03-29 6:21 ` [PATCH 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive() Sebastian Josue Alba Vives
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 6:21 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
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 any bounds validation. The client_component value comes
from the VideoCore GPU firmware via VCHIQ message passing.
A malicious or buggy GPU firmware could send a crafted
MMAL_MSG_TYPE_EVENT_TO_HOST message with client_component >= 64 (or
negative), causing an out-of-bounds array access in kernel memory. This
results in reading/dereferencing a bogus vchiq_mmal_component structure
from memory beyond the array, which can lead to kernel crashes or
potentially arbitrary kernel memory access.
Add a bounds check on comp_idx before using it as an array index.
Move the component pointer assignment after the validation.
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index d36ad71cc..4772126d7 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -477,12 +477,19 @@ static void event_to_host_cb(struct vchiq_mmal_instance *instance,
struct mmal_msg *msg, u32 msg_len)
{
int comp_idx = msg->u.event_to_host.client_component;
- struct vchiq_mmal_component *component =
- &instance->component[comp_idx];
+ struct vchiq_mmal_component *component;
struct vchiq_mmal_port *port = NULL;
struct mmal_msg_context *msg_context;
u32 port_num = msg->u.event_to_host.port_num;
+ if (comp_idx < 0 || comp_idx >= VCHIQ_MMAL_MAX_COMPONENTS) {
+ pr_err("%s: component index %d out of range\n",
+ __func__, comp_idx);
+ return;
+ }
+
+ component = &instance->component[comp_idx];
+
if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
pr_err("%s: MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n",
__func__);
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb()
2026-03-29 6:21 ` [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb() Sebastian Josue Alba Vives
@ 2026-03-29 6:35 ` Greg Kroah-Hartman
2026-03-29 7:06 ` Sebastián Alba
0 siblings, 1 reply; 12+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-29 6:35 UTC (permalink / raw)
To: Sebastian Josue Alba Vives
Cc: Florian Fainelli, bcm-kernel-feedback-list, linux-staging,
linux-rpi-kernel, linux-arm-kernel, linux-media, Dave Stevenson,
kernel-list
On Sun, Mar 29, 2026 at 12:21:11AM -0600, Sebastian Josue Alba Vives wrote:
> From: Sebastián Alba Vives <sebasjosue84@gmail.com>
>
> 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 any bounds validation. The client_component value comes
> from the VideoCore GPU firmware via VCHIQ message passing.
>
> A malicious or buggy GPU firmware could send a crafted
> MMAL_MSG_TYPE_EVENT_TO_HOST message with client_component >= 64 (or
> negative), causing an out-of-bounds array access in kernel memory. This
> results in reading/dereferencing a bogus vchiq_mmal_component structure
> from memory beyond the array, which can lead to kernel crashes or
> potentially arbitrary kernel memory access.
The kernel trusts the hardware the driver is bound to, so this shouldn't
be happening ever, right?
>
> Add a bounds check on comp_idx before using it as an array index.
> Move the component pointer assignment after the validation.
>
> Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
> Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
No cc: stable?
> ---
> drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> index d36ad71cc..4772126d7 100644
> --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> @@ -477,12 +477,19 @@ static void event_to_host_cb(struct vchiq_mmal_instance *instance,
> struct mmal_msg *msg, u32 msg_len)
> {
> int comp_idx = msg->u.event_to_host.client_component;
> - struct vchiq_mmal_component *component =
> - &instance->component[comp_idx];
> + struct vchiq_mmal_component *component;
> struct vchiq_mmal_port *port = NULL;
> struct mmal_msg_context *msg_context;
> u32 port_num = msg->u.event_to_host.port_num;
>
> + if (comp_idx < 0 || comp_idx >= VCHIQ_MMAL_MAX_COMPONENTS) {
> + pr_err("%s: component index %d out of range\n",
> + __func__, comp_idx);
dev_err() is best, right?
And are you going to allow a malicious hardware device to spam the
kernel log? :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb()
2026-03-29 6:35 ` Greg Kroah-Hartman
@ 2026-03-29 7:06 ` Sebastián Alba
0 siblings, 0 replies; 12+ messages in thread
From: Sebastián Alba @ 2026-03-29 7:06 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Florian Fainelli, bcm-kernel-feedback-list, linux-staging,
linux-rpi-kernel, linux-arm-kernel, linux-media, Dave Stevenson,
kernel-list
Hi Greg,
> The kernel trusts the hardware the driver is bound to, so this
> shouldn't be happening ever, right?
You're right that the kernel generally trusts hardware it's bound to.
This is a defensive hardening patch - a malformed index from buggy
firmware would currently cause an uncontrolled OOB access, while with
the check we get a clean error return. Happy to reframe the commit
message as hardening rather than a security fix if you prefer.
> No cc: stable?
Will add Cc: stable@vger.kernel.org in v2.
> dev_err() is best, right?
Agreed, will switch to dev_err() in v2. I'll need to thread the
struct device through - will check how other functions in this
file handle it.
> And are you going to allow a malicious hardware device to spam
> the kernel log? :)
Good point, will switch to dev_err_ratelimited() in v2.
I'll send a v2 addressing all of these. Thanks for the review.
Sebastián
El dom, 29 mar 2026 a las 0:35, Greg Kroah-Hartman
(<gregkh@linuxfoundation.org>) escribió:
>
> On Sun, Mar 29, 2026 at 12:21:11AM -0600, Sebastian Josue Alba Vives wrote:
> > From: Sebastián Alba Vives <sebasjosue84@gmail.com>
> >
> > 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 any bounds validation. The client_component value comes
> > from the VideoCore GPU firmware via VCHIQ message passing.
> >
> > A malicious or buggy GPU firmware could send a crafted
> > MMAL_MSG_TYPE_EVENT_TO_HOST message with client_component >= 64 (or
> > negative), causing an out-of-bounds array access in kernel memory. This
> > results in reading/dereferencing a bogus vchiq_mmal_component structure
> > from memory beyond the array, which can lead to kernel crashes or
> > potentially arbitrary kernel memory access.
>
> The kernel trusts the hardware the driver is bound to, so this shouldn't
> be happening ever, right?
>
> >
> > Add a bounds check on comp_idx before using it as an array index.
> > Move the component pointer assignment after the validation.
> >
> > Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
> > Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
>
> No cc: stable?
>
> > ---
> > drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> > index d36ad71cc..4772126d7 100644
> > --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> > +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> > @@ -477,12 +477,19 @@ static void event_to_host_cb(struct vchiq_mmal_instance *instance,
> > struct mmal_msg *msg, u32 msg_len)
> > {
> > int comp_idx = msg->u.event_to_host.client_component;
> > - struct vchiq_mmal_component *component =
> > - &instance->component[comp_idx];
> > + struct vchiq_mmal_component *component;
> > struct vchiq_mmal_port *port = NULL;
> > struct mmal_msg_context *msg_context;
> > u32 port_num = msg->u.event_to_host.port_num;
> >
> > + if (comp_idx < 0 || comp_idx >= VCHIQ_MMAL_MAX_COMPONENTS) {
> > + pr_err("%s: component index %d out of range\n",
> > + __func__, comp_idx);
>
> dev_err() is best, right?
>
> And are you going to allow a malicious hardware device to spam the
> kernel log? :)
>
> thanks,
>
> greg k-h
--
Sebastián Alba
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive()
2026-03-29 6:21 [PATCH 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
2026-03-29 6:21 ` [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb() Sebastian Josue Alba Vives
@ 2026-03-29 6:21 ` Sebastian Josue Alba Vives
2026-03-29 6:21 ` [PATCH 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set() Sebastian Josue Alba Vives
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 6:21 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
inline_receive() copies payload data from a VCHIQ message into a
destination buffer using payload_in_message as the copy length, but
never validates that this length fits within the destination buffer
(msg_context->u.bulk.buffer->buffer_size).
While the caller validates payload_in_message <= MMAL_VC_SHORT_DATA
(128) to prevent overreading the source, the destination buffer may be
smaller than 128 bytes. This is inconsistent with bulk_receive() which
does check buffer_size before copying. A VideoCore GPU sending a short
inline payload to a smaller destination buffer would cause a heap buffer
overflow in kernel memory.
Add a bounds check against buffer_size and truncate the copy length if
it exceeds the destination capacity, matching the defensive pattern used
in bulk_receive().
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
.../vc04_services/vchiq-mmal/mmal-vchiq.c | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 4772126d7..e18471930 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -368,12 +368,26 @@ static int inline_receive(struct vchiq_mmal_instance *instance,
struct mmal_msg *msg,
struct mmal_msg_context *msg_context)
{
+ u32 payload_len = msg->u.buffer_from_host.payload_in_message;
+
+ /*
+ * Ensure the payload fits within the destination buffer.
+ * The caller already validates payload_len <= MMAL_VC_SHORT_DATA
+ * against the source, but the destination buffer may be smaller.
+ * bulk_receive() performs this check; inline_receive() must too.
+ */
+ if (payload_len > msg_context->u.bulk.buffer->buffer_size) {
+ payload_len = msg_context->u.bulk.buffer->buffer_size;
+ pr_warn("inline_receive: payload truncated (%u > %lu)\n",
+ msg->u.buffer_from_host.payload_in_message,
+ msg_context->u.bulk.buffer->buffer_size);
+ }
+
memcpy(msg_context->u.bulk.buffer->buffer,
msg->u.buffer_from_host.short_data,
- msg->u.buffer_from_host.payload_in_message);
+ payload_len);
- msg_context->u.bulk.buffer_used =
- msg->u.buffer_from_host.payload_in_message;
+ msg_context->u.bulk.buffer_used = payload_len;
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set()
2026-03-29 6:21 [PATCH 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
2026-03-29 6:21 ` [PATCH 1/4] staging: vc04_services: vchiq-mmal: fix OOB array access in event_to_host_cb() Sebastian Josue Alba Vives
2026-03-29 6:21 ` [PATCH 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive() Sebastian Josue Alba Vives
@ 2026-03-29 6:21 ` Sebastian Josue Alba Vives
2026-03-29 6:21 ` [PATCH 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get() Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
4 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 6:21 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
port_parameter_set() copies value_size bytes from the caller-supplied
value buffer into the stack-allocated struct mmal_msg's
port_parameter_set.value field, which is u32[96] (384 bytes). There is
no bounds check on value_size before the memcpy.
While current in-tree callers pass small fixed-size structures, the
function is exported via EXPORT_SYMBOL_GPL and accessible to any GPL
kernel module. A caller passing value_size > 384 would overflow the
stack-allocated mmal_msg structure, potentially leading to stack
corruption and code execution.
Add a bounds check rejecting value_size larger than the value field.
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index e18471930..11af71309 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1361,6 +1361,14 @@ static int port_parameter_set(struct vchiq_mmal_instance *instance,
struct mmal_msg *rmsg;
struct vchiq_header *rmsg_handle;
+ if (value_size >
+ sizeof(m.u.port_parameter_set.value)) {
+ pr_err("port_parameter_set: value_size %u exceeds max %zu\n",
+ value_size,
+ sizeof(m.u.port_parameter_set.value));
+ return -EINVAL;
+ }
+
m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
m.u.port_parameter_set.component_handle = port->component->handle;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get()
2026-03-29 6:21 [PATCH 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
` (2 preceding siblings ...)
2026-03-29 6:21 ` [PATCH 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set() Sebastian Josue Alba Vives
@ 2026-03-29 6:21 ` Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
4 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 6:21 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
port_parameter_get() subtracts 2 * sizeof(u32) from the GPU firmware's
reply size field to compute the parameter value size. The reply size is
a u32 provided by the VideoCore firmware. If the firmware returns a
size smaller than 8, the subtraction wraps around to a large value due
to unsigned integer underflow.
The underflowed size is then:
1) Used in a comparison that selects the wrong copy path
2) Stored back to the caller via *value_size, propagating a bogus
size (up to ~4GB) to subsequent operations
Add a minimum size check before the subtraction and return -EPROTO if
the reply is malformed.
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 11af71309..914ab9215 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1436,6 +1436,10 @@ static int port_parameter_get(struct vchiq_mmal_instance *instance,
/* port_parameter_get_reply.size includes the header,
* whilst *value_size doesn't.
*/
+ if (rmsg->u.port_parameter_get_reply.size < (2 * sizeof(u32))) {
+ ret = -EPROTO;
+ goto release_msg;
+ }
rmsg->u.port_parameter_get_reply.size -= (2 * sizeof(u32));
if (ret || rmsg->u.port_parameter_get_reply.size > *value_size) {
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues
2026-03-29 6:21 [PATCH 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
` (3 preceding siblings ...)
2026-03-29 6:21 ` [PATCH 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get() Sebastian Josue Alba Vives
@ 2026-03-29 7:15 ` Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 1/4] staging: vc04_services: vchiq-mmal: validate component index in event_to_host_cb() Sebastian Josue Alba Vives
` (3 more replies)
4 siblings, 4 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives
Changes since v1:
- Reframed patch 1 as hardening rather than security fix (Greg)
- Switched pr_err/pr_warn to ratelimited variants (Greg)
- Added Cc: stable to all patches (Greg)
- Note: dev_err() not used as this file has no struct device access
This series adds defensive bounds checks to the MMAL VCHIQ driver
which handles multimedia message passing between the ARM CPU and the
VideoCore GPU on all Raspberry Pi models.
Reported-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v2 1/4] staging: vc04_services: vchiq-mmal: validate component index in event_to_host_cb()
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
@ 2026-03-29 7:15 ` Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive() Sebastian Josue Alba Vives
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives, stable
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
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: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index d36ad71cc..9c6533f82 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -477,12 +477,19 @@ static void event_to_host_cb(struct vchiq_mmal_instance *instance,
struct mmal_msg *msg, u32 msg_len)
{
int comp_idx = msg->u.event_to_host.client_component;
- struct vchiq_mmal_component *component =
- &instance->component[comp_idx];
+ struct vchiq_mmal_component *component;
struct vchiq_mmal_port *port = NULL;
struct mmal_msg_context *msg_context;
u32 port_num = msg->u.event_to_host.port_num;
+ if (comp_idx < 0 || comp_idx >= VCHIQ_MMAL_MAX_COMPONENTS) {
+ pr_err_ratelimited("%s: component index %d out of range\n",
+ __func__, comp_idx);
+ return;
+ }
+
+ component = &instance->component[comp_idx];
+
if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
pr_err("%s: MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n",
__func__);
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive()
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 1/4] staging: vc04_services: vchiq-mmal: validate component index in event_to_host_cb() Sebastian Josue Alba Vives
@ 2026-03-29 7:15 ` Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set() Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get() Sebastian Josue Alba Vives
3 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives, stable
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
inline_receive() copies payload data from a VCHIQ message into a
destination buffer using payload_in_message as the copy length, but
never validates that this length fits within the destination buffer
(msg_context->u.bulk.buffer->buffer_size).
While the caller validates payload_in_message <= MMAL_VC_SHORT_DATA
(128) to prevent overreading the source, the destination buffer may be
smaller than 128 bytes. This is inconsistent with bulk_receive() which
does check buffer_size before copying.
Add a bounds check against buffer_size and truncate the copy length if
it exceeds the destination capacity, matching the defensive pattern used
in bulk_receive(). Use pr_warn_ratelimited() for the truncation warning.
Cc: stable@vger.kernel.org
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
.../vc04_services/vchiq-mmal/mmal-vchiq.c | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 9c6533f82..44e5246f1 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -368,12 +368,26 @@ static int inline_receive(struct vchiq_mmal_instance *instance,
struct mmal_msg *msg,
struct mmal_msg_context *msg_context)
{
+ u32 payload_len = msg->u.buffer_from_host.payload_in_message;
+
+ /*
+ * Ensure the payload fits within the destination buffer.
+ * The caller already validates payload_len <= MMAL_VC_SHORT_DATA
+ * against the source, but the destination buffer may be smaller.
+ * bulk_receive() performs this check; inline_receive() must too.
+ */
+ if (payload_len > msg_context->u.bulk.buffer->buffer_size) {
+ payload_len = msg_context->u.bulk.buffer->buffer_size;
+ pr_warn_ratelimited("inline_receive: payload truncated (%u > %lu)\n",
+ msg->u.buffer_from_host.payload_in_message,
+ msg_context->u.bulk.buffer->buffer_size);
+ }
+
memcpy(msg_context->u.bulk.buffer->buffer,
msg->u.buffer_from_host.short_data,
- msg->u.buffer_from_host.payload_in_message);
+ payload_len);
- msg_context->u.bulk.buffer_used =
- msg->u.buffer_from_host.payload_in_message;
+ msg_context->u.bulk.buffer_used = payload_len;
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set()
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 1/4] staging: vc04_services: vchiq-mmal: validate component index in event_to_host_cb() Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 2/4] staging: vc04_services: vchiq-mmal: add buffer size check in inline_receive() Sebastian Josue Alba Vives
@ 2026-03-29 7:15 ` Sebastian Josue Alba Vives
2026-03-29 7:15 ` [PATCH v2 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get() Sebastian Josue Alba Vives
3 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives, stable
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
port_parameter_set() copies value_size bytes from the caller-supplied
value buffer into the stack-allocated struct mmal_msg's
port_parameter_set.value field, which is u32[96] (384 bytes). There is
no bounds check on value_size before the memcpy.
While current in-tree callers pass small fixed-size structures, the
function is exported via EXPORT_SYMBOL_GPL and accessible to any GPL
kernel module. A caller passing value_size > 384 would overflow the
stack-allocated mmal_msg structure.
Add a bounds check rejecting value_size larger than the value field.
Cc: stable@vger.kernel.org
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 44e5246f1..18e805b92 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1361,6 +1361,14 @@ static int port_parameter_set(struct vchiq_mmal_instance *instance,
struct mmal_msg *rmsg;
struct vchiq_header *rmsg_handle;
+ if (value_size >
+ sizeof(m.u.port_parameter_set.value)) {
+ pr_err_ratelimited("port_parameter_set: value_size %u exceeds max %zu\n",
+ value_size,
+ sizeof(m.u.port_parameter_set.value));
+ return -EINVAL;
+ }
+
m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
m.u.port_parameter_set.component_handle = port->component->handle;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v2 4/4] staging: vc04_services: vchiq-mmal: fix integer underflow in port_parameter_get()
2026-03-29 7:15 ` [PATCH v2 0/4] staging: vc04_services: vchiq-mmal: fix multiple memory safety issues Sebastian Josue Alba Vives
` (2 preceding siblings ...)
2026-03-29 7:15 ` [PATCH v2 3/4] staging: vc04_services: vchiq-mmal: prevent stack overflow in port_parameter_set() Sebastian Josue Alba Vives
@ 2026-03-29 7:15 ` Sebastian Josue Alba Vives
3 siblings, 0 replies; 12+ messages in thread
From: Sebastian Josue Alba Vives @ 2026-03-29 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Florian Fainelli
Cc: bcm-kernel-feedback-list, linux-staging, linux-rpi-kernel,
linux-arm-kernel, linux-media, Dave Stevenson, kernel-list,
Sebastián Alba Vives, stable
From: Sebastián Alba Vives <sebasjosue84@gmail.com>
port_parameter_get() subtracts 2 * sizeof(u32) from the VideoCore
firmware's reply size field to compute the parameter value size. If
the firmware returns a size smaller than 8, the subtraction wraps
around to a large value due to unsigned integer underflow.
The underflowed size is then used in a comparison that selects the
wrong copy path and stored back to the caller via *value_size,
propagating a bogus size to subsequent operations.
Add a minimum size check before the subtraction and return -EPROTO
if the reply is malformed.
Cc: stable@vger.kernel.org
Fixes: b18ee53ad297 ("staging: bcm2835: Break MMAL support out from camera")
Signed-off-by: Sebastián Alba Vives <sebasjosue84@gmail.com>
---
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 18e805b92..f2bb5ce0a 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1436,6 +1436,10 @@ static int port_parameter_get(struct vchiq_mmal_instance *instance,
/* port_parameter_get_reply.size includes the header,
* whilst *value_size doesn't.
*/
+ if (rmsg->u.port_parameter_get_reply.size < (2 * sizeof(u32))) {
+ ret = -EPROTO;
+ goto release_msg;
+ }
rmsg->u.port_parameter_get_reply.size -= (2 * sizeof(u32));
if (ret || rmsg->u.port_parameter_get_reply.size > *value_size) {
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread