* [PATCH] greybus: verify the received message size covers the message header
@ 2026-11-12 7:12 Shunbo Shi
2026-11-12 7:17 ` sashiko-bot
0 siblings, 1 reply; 5+ messages in thread
From: Shunbo Shi @ 2026-11-12 7:12 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, linux-kernel, greybus-dev, syzbot+0b456664585fa81a47f6
In gb_connection_recv(), the size of the received data is checked
against sizeof(struct gb_operation_msg_hdr) and against the message
size encoded in the header (msg_size), but msg_size itself is never
checked against the header size.
If a peer sends a message whose header claims a size smaller than
the header itself (e.g. header.size == 3), the two existing checks
both pass (size >= sizeof(header) and size >= msg_size), and the
message is dispatched with the undersized msg_size.
In gb_operation_create_incoming(), this leads to an unsigned
integer underflow in:
request_size = size - sizeof(struct gb_operation_msg_hdr);
The underflowed request_size then wraps back around in
gb_operation_message_alloc():
message_size = payload_size + sizeof(*header);
causing kzalloc() to allocate a buffer that is too small to hold
the message header. When the response is later prepared in
gb_operation_response_alloc(), reading
request_header->operation_id reads past the end of the undersized
allocation, triggering a KASAN slab-out-of-bounds report. When
header.size is zero, kzalloc(0) returns ZERO_SIZE_PTR and the
same read dereferences an invalid address.
Verify msg_size >= sizeof(header) in gb_connection_recv() so that
the "Caller has made sure we at least have a message header"
assumption in gb_operation_create_incoming() actually holds.
Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=0b456664585fa81a47f6
Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com>
---
drivers/greybus/operation.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index 7e12ffb2dd60..da53c0e026f0 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -1047,6 +1047,13 @@ void gb_connection_recv(struct gb_connection *connection,
/* Use memcpy as data may be unaligned */
memcpy(&header, data, sizeof(header));
msg_size = le16_to_cpu(header.size);
+ if (msg_size < sizeof(header)) {
+ dev_err_ratelimited(dev,
+ "%s: invalid message header size (%zu < %zu)\n",
+ connection->name, msg_size,
+ sizeof(header));
+ return;
+ }
if (size < msg_size) {
dev_err_ratelimited(dev,
"%s: incomplete message 0x%04x of type 0x%02x received (%zu < %zu)\n",
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] greybus: verify the received message size covers the message header
2026-11-12 7:12 [PATCH] greybus: verify the received message size covers the message header Shunbo Shi
@ 2026-11-12 7:17 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-12 7:17 UTC (permalink / raw)
To: Shunbo Shi; +Cc: linux-usb
> In gb_connection_recv(), the size of the received data is checked
> against sizeof(struct gb_operation_msg_hdr) and against the message
> size encoded in the header (msg_size), but msg_size itself is never
> checked against the header size.
>
> If a peer sends a message whose header claims a size smaller than
> the header itself (e.g. header.size == 3), the two existing checks
> both pass (size >= sizeof(header) and size >= msg_size), and the
> message is dispatched with the undersized msg_size.
>
> In gb_operation_create_incoming(), this leads to an unsigned
> integer underflow in:
>
> request_size = size - sizeof(struct gb_operation_msg_hdr);
>
> [ ... ]
>
> Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
> Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
> Closes: https://syzbot.org/bug?extid=0b456664585fa81a47f6
> Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112071228.33017-1-shishunbo@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] greybus: verify the received message size covers the message header
2026-11-12 5:56 [syzbot] [greybus?] [usb?] KASAN: slab-out-of-bounds Read in gb_operation_work syzbot
@ 2026-11-12 8:22 ` Shunbo Shi
2026-11-12 8:27 ` sashiko-bot
2026-11-12 8:43 ` Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Shunbo Shi @ 2026-11-12 8:22 UTC (permalink / raw)
To: syzbot+0b456664585fa81a47f6
Cc: elder, gregkh, greybus-dev, johan, linux-kernel, linux-media,
linux-staging, linux-usb, syzkaller-bugs
In gb_connection_recv(), the size of the received data is checked
against sizeof(struct gb_operation_msg_hdr) and against the message
size encoded in the header (msg_size), but msg_size itself is never
checked against the header size.
If a peer sends a message whose header claims a size smaller than
the header itself (e.g. header.size == 3), the two existing checks
both pass (size >= sizeof(header) and size >= msg_size), and the
message is dispatched with the undersized msg_size.
In gb_operation_create_incoming(), this leads to an unsigned
integer underflow in:
request_size = size - sizeof(struct gb_operation_msg_hdr);
The underflowed request_size then wraps back around in
gb_operation_message_alloc():
message_size = payload_size + sizeof(*header);
causing kzalloc() to allocate a buffer that is too small to hold
the message header. When the response is later prepared in
gb_operation_response_alloc(), reading
request_header->operation_id reads past the end of the undersized
allocation, triggering a KASAN slab-out-of-bounds report. When
header.size is zero, kzalloc(0) returns ZERO_SIZE_PTR and the
same read dereferences an invalid address.
Verify msg_size >= sizeof(header) in gb_connection_recv() so that
the "Caller has made sure we at least have a message header"
assumption in gb_operation_create_incoming() actually holds.
Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=0b456664585fa81a47f6
Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com>
---
drivers/greybus/operation.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index 7e12ffb2dd60..da53c0e026f0 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -1047,6 +1047,13 @@ void gb_connection_recv(struct gb_connection *connection,
/* Use memcpy as data may be unaligned */
memcpy(&header, data, sizeof(header));
msg_size = le16_to_cpu(header.size);
+ if (msg_size < sizeof(header)) {
+ dev_err_ratelimited(dev,
+ "%s: invalid message header size (%zu < %zu)\n",
+ connection->name, msg_size,
+ sizeof(header));
+ return;
+ }
if (size < msg_size) {
dev_err_ratelimited(dev,
"%s: incomplete message 0x%04x of type 0x%02x received (%zu < %zu)\n",
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] greybus: verify the received message size covers the message header
2026-11-12 8:22 ` [PATCH] greybus: verify the received message size covers the message header Shunbo Shi
@ 2026-11-12 8:27 ` sashiko-bot
2026-11-12 8:43 ` Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-12 8:27 UTC (permalink / raw)
To: Shunbo Shi; +Cc: linux-usb
> In gb_connection_recv(), the size of the received data is checked
> against sizeof(struct gb_operation_msg_hdr) and against the message
> size encoded in the header (msg_size), but msg_size itself is never
> checked against the header size.
>
> If a peer sends a message whose header claims a size smaller than
> the header itself (e.g. header.size == 3), the two existing checks
> both pass (size >= sizeof(header) and size >= msg_size), and the
> message is dispatched with the undersized msg_size.
>
> In gb_operation_create_incoming(), this leads to an unsigned
> integer underflow in:
>
> request_size = size - sizeof(struct gb_operation_msg_hdr);
>
> [ ... ]
>
> Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
> Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
> Closes: https://syzbot.org/bug?extid=0b456664585fa81a47f6
> Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112082230.33584-1-shishunbo@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] greybus: verify the received message size covers the message header
2026-11-12 8:22 ` [PATCH] greybus: verify the received message size covers the message header Shunbo Shi
2026-11-12 8:27 ` sashiko-bot
@ 2026-11-12 8:43 ` Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2026-11-12 8:43 UTC (permalink / raw)
To: Shunbo Shi
Cc: syzbot+0b456664585fa81a47f6, elder, gregkh, greybus-dev, johan,
linux-kernel, linux-media, linux-staging, linux-usb,
syzkaller-bugs
On Thu, Nov 12, 2026 at 08:22:29AM +0000, Shunbo Shi wrote:
> In gb_connection_recv(), the size of the received data is checked
> against sizeof(struct gb_operation_msg_hdr) and against the message
> size encoded in the header (msg_size), but msg_size itself is never
> checked against the header size.
>
> If a peer sends a message whose header claims a size smaller than
> the header itself (e.g. header.size == 3), the two existing checks
> both pass (size >= sizeof(header) and size >= msg_size), and the
> message is dispatched with the undersized msg_size.
>
> In gb_operation_create_incoming(), this leads to an unsigned
> integer underflow in:
>
> request_size = size - sizeof(struct gb_operation_msg_hdr);
>
> The underflowed request_size then wraps back around in
> gb_operation_message_alloc():
>
> message_size = payload_size + sizeof(*header);
>
> causing kzalloc() to allocate a buffer that is too small to hold
> the message header. When the response is later prepared in
> gb_operation_response_alloc(), reading
> request_header->operation_id reads past the end of the undersized
> allocation, triggering a KASAN slab-out-of-bounds report. When
> header.size is zero, kzalloc(0) returns ZERO_SIZE_PTR and the
> same read dereferences an invalid address.
>
> Verify msg_size >= sizeof(header) in gb_connection_recv() so that
> the "Caller has made sure we at least have a message header"
> assumption in gb_operation_create_incoming() actually holds.
>
> Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
> Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
> Closes: https://syzbot.org/bug?extid=0b456664585fa81a47f6
> Signed-off-by: Shunbo Shi <shishunbo@cmss.chinamobile.com>
> ---
> drivers/greybus/operation.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
> index 7e12ffb2dd60..da53c0e026f0 100644
> --- a/drivers/greybus/operation.c
> +++ b/drivers/greybus/operation.c
> @@ -1047,6 +1047,13 @@ void gb_connection_recv(struct gb_connection *connection,
> /* Use memcpy as data may be unaligned */
> memcpy(&header, data, sizeof(header));
> msg_size = le16_to_cpu(header.size);
> + if (msg_size < sizeof(header)) {
> + dev_err_ratelimited(dev,
> + "%s: invalid message header size (%zu < %zu)\n",
> + connection->name, msg_size,
> + sizeof(header));
> + return;
> + }
> if (size < msg_size) {
Combine the conditions:
if (msg_size < sizeof(header) || msg_size > size) {
regards,
dan carpenter
> dev_err_ratelimited(dev,
> "%s: incomplete message 0x%04x of type 0x%02x received (%zu < %zu)\n",
> --
> 2.53.0
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-12 8:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 7:12 [PATCH] greybus: verify the received message size covers the message header Shunbo Shi
2026-11-12 7:17 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-12 5:56 [syzbot] [greybus?] [usb?] KASAN: slab-out-of-bounds Read in gb_operation_work syzbot
2026-11-12 8:22 ` [PATCH] greybus: verify the received message size covers the message header Shunbo Shi
2026-11-12 8:27 ` sashiko-bot
2026-11-12 8:43 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox