]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
greybus: gb-beagleplay: bound bootloader receive buffering
authorPengpeng Hou <pengpeng@iscas.ac.cn>
Thu, 2 Apr 2026 05:40:16 +0000 (13:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Apr 2026 13:55:09 +0000 (15:55 +0200)
cc1352_bootloader_rx() appends each serdev chunk into the fixed
rx_buffer before parsing bootloader packets. The helper can keep
leftover bytes between callbacks and may receive multiple packets in one
callback, so a single count value is not constrained by one packet
length.

Check that the incoming chunk fits in the remaining receive buffer space
before memcpy(). If it does not, drop the staged data and consume the
bytes instead of overflowing rx_buffer.

Fixes: 0cf7befa3ea2 ("greybus: gb-beagleplay: Add firmware upload API")
Cc: stable <stable@kernel.org>
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Link: https://patch.msgid.link/20260402054016.38587-1-pengpeng@iscas.ac.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/greybus/gb-beagleplay.c

index 305066febbe7770a565a66b214c3bfaa89c922c8..244966d56c9ba99ddc185d7c15b9fc331aedaf1d 100644 (file)
@@ -623,6 +623,13 @@ static size_t cc1352_bootloader_rx(struct gb_beagleplay *bg, const u8 *data,
                return count;
        }
 
+       if (count > sizeof(bg->rx_buffer) - bg->rx_buffer_len) {
+               dev_warn(&bg->sd->dev,
+                        "dropping oversized bootloader receive chunk");
+               bg->rx_buffer_len = 0;
+               return count;
+       }
+
        memcpy(bg->rx_buffer + bg->rx_buffer_len, data, count);
        bg->rx_buffer_len += count;