Skip to contentSkip to conversation

staging: greybus: fix size_t underflow in cap_get_ims_certificate()

PATCH In review Delene Tchio Romuald 2 participants 2 messages Apr 4 – Apr 5

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: fix size_t underflow in cap_get_ims_certificate()

In cap_get_ims_certificate(), the certificate size is computed as:

  *size = op->response->payload_size - sizeof(*response);

Both operands are size_t (unsigned), so if a malformed Greybus module sends a response with payload_size smaller than sizeof(*response), the subtraction wraps to a very large value. The subsequent memcpy() then causes a heap buffer overflow.

Add a payload size validation before the subtraction to ensure the response is large enough to contain the fixed-size response header.

---
 drivers/staging/greybus/authentication.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/staging/greybus/authentication.c +6 -0
index 97b9937bb..1c14ad184 100644
@@ -132,6 +132,12 @@ static int cap_get_ims_certificate(struct gb_cap *cap, u32 class, u32 id,
 
 	response = op->response->payload;
 	*result = response->result_code;
+
+	if (op->response->payload_size < sizeof(*response)) {
+		ret = -EINVAL;
+		goto done;
+	}
+
 	*size = op->response->payload_size - sizeof(*response);
 	memcpy(certificate, response->certificate, *size);
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Delene Tchio Romuald

In cap_get_ims_certificate(), the certificate size is computed as:

  *size = op->response->payload_size - sizeof(*response);

Both operands are size_t (unsigned), so if a malformed Greybus module sends a response with payload_size smaller than sizeof(*response), the subtraction wraps to a very large value. The subsequent memcpy() then causes a heap buffer overflow.

How can you have a "malformed greybus module"?

Please fix your ai tool's threat model to be realistic :)

thanks,

greg k-h