Hi,
While reading drivers/staging/greybus/loopback.c in current mainline (4dce97c), I found what looks like an out-of-bounds read.
In gb_loopback_request_handler(), case GB_LOOPBACK_TYPE_TRANSFER:
len = le32_to_cpu(request->len);
if (len > gb_dev.size_max) { ... return -EINVAL; }
...
memcpy(response->data, request->data, len);
'len' comes from the remote device and is only checked against gb_dev.size_max (the maximum payload size of the connection). It is never checked against the size of the payload that was actually received. A device can send a small request with a large 'len', and the kernel will copy bytes from beyond the end of the request buffer into the response, which is then sent back to the device. This is a heap over-read and a possible information leak.
raw.c in the same driver already validates len against payload_size in the equivalent place.
Untested suggested fix (not compiled or run on hardware):
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -650,6 +650,12 @@ static int gb_loopback_request_handler(struct gb_operation *operation)
len, gb_dev.size_max);
return -EINVAL;
}
+ if (len > operation->request->payload_size - sizeof(*request)) {
+ dev_err(dev, "transfer request length exceeds payload (%zu > %zu)\n",
+ len,
+ operation->request->payload_size - sizeof(*request));
+ return -EINVAL;
+ }
if (!gb_operation_response_alloc(operation,
len + sizeof(*response),
The subtraction is safe because payload_size >= sizeof(*request) is already checked a few lines earlier.
Thanks,
Sahanur Molla