Skip to contentSkip to conversation

platform/chrome: lightbar: Enforce 8-bit payload limit

PATCH In review Alexis Savery 3 participants 7 messages Jul 29 – Jul 31

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

PATCH 1/1 platform/chrome: lightbar: Enforce 8-bit payload limit

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size. However, the driver currently allows the payload chunk to bypass this limit if the EC transport layer supports a larger max_request.

When this occurs, large payloads (e.g., >255 bytes limit) overflow the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures in the EC firmware.

This change functionally clamps max_size dynamically against the struct maximum (255 bytes).

---
 drivers/platform/chrome/cros_ec_lightbar.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +8 -1
index 02a6c34e68e6..a8df36260419 100644
@@ -496,9 +496,16 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * The LIGHTBAR_CMD_SET_PROGRAM_EX payload uses a uint8_t size field.
+		 * Thus, independent of the transport limits, the maximum payload subset
+		 * that can be transmitted in a single structure is 255 bytes.
+		 */
+		const size_t max_struct_payload = 255;
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min((size_t)(ec->ec_dev->max_request - extra_bytes),
+			       max_struct_payload);
 	}
 
 	msg = alloc_lightbar_cmd_msg(ec);
Signature · 1 line
2.55.0.508.g3f0d502094-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size. However, the driver currently allows the payload chunk to bypass this limit if the EC transport layer supports a larger max_request.

Quoted 8 lines

When this occurs, large payloads (e.g., >255 bytes limit) overflow the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures in the EC firmware.

This change functionally clamps max_size dynamically against the struct maximum (255 bytes).

Quoted 30 lines
---
 drivers/platform/chrome/cros_ec_lightbar.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +8 -1
index 02a6c34e68e6..a8df36260419 100644
@@ -496,9 +496,16 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * The LIGHTBAR_CMD_SET_PROGRAM_EX payload uses a uint8_t size field.
+		 * Thus, independent of the transport limits, the maximum payload subset
+		 * that can be transmitted in a single structure is 255 bytes.
+		 */
+		const size_t max_struct_payload = 255;
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min((size_t)(ec->ec_dev->max_request - extra_bytes),
+			       max_struct_payload);
 	}
 
 	msg = alloc_lightbar_cmd_msg(ec);
Signature · 1 line
2.55.0.508.g3f0d502094-goog
#2 lore raw

PATCH v2 1/1 platform/chrome: lightbar: Limit payload size to EC bounding macro

In reply to Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size and is natively capped by the V3 packet bounds limit array EC_LPC_HOST_PACKET_SIZE. However, the driver currently allows the payload chunk to bypass this protocol limit if the SPI transmission layer negotiates a larger physical max_request.

When this occurs, large payloads (e.g., >255 bytes) integer wrap the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures downstream in the EC firmware stack.

This change clamps max_size systematically using the EC_LPC_HOST_PACKET_SIZE macro, bringing chunking in sync with EC limits and preventing uint8_t size overflows.

---
 drivers/platform/chrome/cros_ec_lightbar.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +6 -1
index 02a6c34e68e6..052606cba85f 100644
@@ -496,9 +496,14 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * The EC limits all version 3 host packets to EC_LPC_HOST_PACKET_SIZE.
+		 */
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min_t(size_t, ec->ec_dev->max_request,
+				 EC_LPC_HOST_PACKET_SIZE);
+		max_size -= extra_bytes;
 	}
 
 	msg = alloc_lightbar_cmd_msg(ec);
Signature · 1 line
2.55.0.508.g3f0d502094-goog
#3 lore raw

PATCH v3 1/1 platform/chrome: lightbar: Limit payload size to EC packet limit

In reply to Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size and is natively capped by the V3 packet bounds limit array EC_LPC_HOST_PACKET_SIZE. However, the driver currently allows the payload chunk to bypass this protocol limit if the SPI transmission layer negotiates a larger physical max_request.

When this occurs, large payloads (e.g., >255 bytes) integer wrap the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures downstream in the EC firmware stack.

This change clamps max_size systematically using the EC_LPC_HOST_PACKET_SIZE limit, bringing chunking in sync with EC limits and preventing uint8_t size overflows.

---
 drivers/platform/chrome/cros_ec_lightbar.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +6 -1
index 02a6c34e68e6..052606cba85f 100644
@@ -496,9 +496,14 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * The EC limits all version 3 host packets to EC_LPC_HOST_PACKET_SIZE.
+		 */
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min_t(size_t, ec->ec_dev->max_request,
+				 EC_LPC_HOST_PACKET_SIZE);
+		max_size -= extra_bytes;
 	}
 
 	msg = alloc_lightbar_cmd_msg(ec);
Signature · 1 line
2.55.0.508.g3f0d502094-goog
maintainer
#4 lore raw

Re: [PATCH v3] platform/chrome: lightbar: Limit payload size to EC packet limit

Quoted 2 lines · Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size and is natively capped by the V3

The u8 size field can't wrap or contain the payload itself. To be more technically accurate, please rephrase "encapsulates".

Quoted 3 lines

packet bounds limit array EC_LPC_HOST_PACKET_SIZE. However, the driver currently allows the payload chunk to bypass this protocol limit if the SPI transmission layer negotiates a larger physical max_request.

EC_LPC_HOST_PACKET_SIZE is only for LPC. Protocol SPI uses another value (e.g., SPI_MAX_REQUEST_SIZE).

drivers/platform/chrome/cros_ec_lightbar.c static ssize_t program_store(struct device *dev, struct device_attribute *attr, · line 506

Quoted 13 lines
drivers/platform/chrome/cros_ec_lightbar.c +6 -1
@@ -496,9 +496,14 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * The EC limits all version 3 host packets to EC_LPC_HOST_PACKET_SIZE.
+		 */
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min_t(size_t, ec->ec_dev->max_request,
+				 EC_LPC_HOST_PACKET_SIZE);
+		max_size -= extra_bytes;

How about:

    max_size = min(ec->ec_dev->max_request - extra_bytes,
                   sizeof(param->set_program_ex.size));
#5 lore raw

PATCH v4 1/1 platform/chrome: lightbar: Limit payload to max packet size

In reply to Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size and is natively capped by the V3 packet bounds limit array EC_LPC_HOST_PACKET_SIZE. However, the driver currently allows the payload chunk to bypass this protocol limit if the SPI transmission layer negotiates a larger physical max_request.

When this occurs, large payloads (e.g., >255 bytes) integer wrap the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures downstream in the EC firmware stack.

This change clamps max_size systematically using the maximum structural type boundary of the size variable, bringing chunking in sync with the hardware limitations without artificially binding to a specific protocol.

---
 drivers/platform/chrome/cros_ec_lightbar.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +6 -1
index 02a6c34e68e6..c9740a3bb5a1 100644
@@ -496,9 +496,14 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
 			return -EINVAL;
 		}
 	} else {
+		/*
+		 * Bound the payload strictly by the maximum value the structural
+		 * size field can natively support.
+		 */
 		extra_bytes = offsetof(typeof(*param), set_program_ex) +
 			sizeof(param->set_program_ex);
-		max_size = ec->ec_dev->max_request - extra_bytes;
+		max_size = min_t(size_t, ec->ec_dev->max_request - extra_bytes,
+				 type_max(typeof(param->set_program_ex.size)));
 	}
 
 	msg = alloc_lightbar_cmd_msg(ec);
Signature · 1 line
2.55.0.508.g3f0d502094-goog
maintainer
#6 lore raw

Re: [PATCH v4] platform/chrome: lightbar: Limit payload to max packet size

Quoted 11 lines · Alexis Savery

The LIGHTBAR_CMD_SET_PROGRAM_EX command encapsulates its payload data with an 8-bit size field uint8_t size and is natively capped by the V3 packet bounds limit array EC_LPC_HOST_PACKET_SIZE. However, the driver currently allows the payload chunk to bypass this protocol limit if the SPI transmission layer negotiates a larger physical max_request.

When this occurs, large payloads (e.g., >255 bytes) integer wrap the 8-bit size variable when assigning param->set_program_ex.size, causing truncation and parse failures downstream in the EC firmware stack.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[1/1] platform/chrome: lightbar: Limit payload to max packet size

      commit: ed1d1f519c56c6c2ffa13f3d52cd77beb023db13

Thanks!