mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: wilco_ec: Reject out-of-bounds property length
@ 2026-11-18 10:15 Maoyi Xie
  2026-11-18 19:49 ` Benson Leung
  0 siblings, 1 reply; 2+ messages in thread
From: Maoyi Xie @ 2026-11-18 10:15 UTC (permalink / raw)
  To: Tzung-Bi Shih, Benson Leung; +Cc: chrome-platform, linux-kernel, stable

wilco_ec_get_property() copies rs.length bytes from rs.data into
prop_msg->data without checking rs.length, which comes from the EC.
Both buffers hold WILCO_EC_PROPERTY_MAX_SIZE (4) bytes, so a larger
length reads past rs on the stack and writes past the caller's message.

Return -EBADMSG for such a length, as the file does for other bad
responses.

Found with a CodeQL-based static analysis tool that we are developing.
I used an LLM to help write this patch and a userspace harness. The
harness runs the unmodified properties.c against a model of the EC
under AddressSanitizer. It reports the copy for lengths 5 to 255, and
nothing with this patch. Not tested on hardware, only compile-tested
with W=1.

Fixes: 0c0b7ea23aed ("platform/chrome: wilco_ec: Add property helper library")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
 drivers/platform/chrome/wilco_ec/properties.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/platform/chrome/wilco_ec/properties.c b/drivers/platform/chrome/wilco_ec/properties.c
index 9951c8db04da065..4ca7e874804c28e 100644
--- a/drivers/platform/chrome/wilco_ec/properties.c
+++ b/drivers/platform/chrome/wilco_ec/properties.c
@@ -70,6 +70,8 @@ int wilco_ec_get_property(struct wilco_ec_device *ec,
 	ret = send_property_msg(ec, &rq, &rs);
 	if (ret < 0)
 		return ret;
+	if (rs.length > WILCO_EC_PROPERTY_MAX_SIZE)
+		return -EBADMSG;
 
 	prop_msg->length = rs.length;
 	memcpy(prop_msg->data, rs.data, rs.length);

base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] platform/chrome: wilco_ec: Reject out-of-bounds property length
  2026-11-18 10:15 [PATCH] platform/chrome: wilco_ec: Reject out-of-bounds property length Maoyi Xie
@ 2026-11-18 19:49 ` Benson Leung
  0 siblings, 0 replies; 2+ messages in thread
From: Benson Leung @ 2026-11-18 19:49 UTC (permalink / raw)
  To: Maoyi Xie
  Cc: Tzung-Bi Shih, Benson Leung, chrome-platform, linux-kernel, stable

[-- Attachment #1: Type: text/plain, Size: 1837 bytes --]

Hi Maoyi,


On Wed, Nov 18, 2026 at 06:15:55PM +0800, Maoyi Xie wrote:
> wilco_ec_get_property() copies rs.length bytes from rs.data into
> prop_msg->data without checking rs.length, which comes from the EC.
> Both buffers hold WILCO_EC_PROPERTY_MAX_SIZE (4) bytes, so a larger
> length reads past rs on the stack and writes past the caller's message.
> 
> Return -EBADMSG for such a length, as the file does for other bad
> responses.
> 
> Found with a CodeQL-based static analysis tool that we are developing.
> I used an LLM to help write this patch and a userspace harness. The
> harness runs the unmodified properties.c against a model of the EC
> under AddressSanitizer. It reports the copy for lengths 5 to 255, and
> nothing with this patch. Not tested on hardware, only compile-tested
> with W=1.
> 
> Fixes: 0c0b7ea23aed ("platform/chrome: wilco_ec: Add property helper library")
> Cc: stable@vger.kernel.org
> Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>A

Reviewed-by: Benson Leung <bleung@chromium.org>

Thanks,
Benson

> ---
>  drivers/platform/chrome/wilco_ec/properties.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/platform/chrome/wilco_ec/properties.c b/drivers/platform/chrome/wilco_ec/properties.c
> index 9951c8db04da065..4ca7e874804c28e 100644
> --- a/drivers/platform/chrome/wilco_ec/properties.c
> +++ b/drivers/platform/chrome/wilco_ec/properties.c
> @@ -70,6 +70,8 @@ int wilco_ec_get_property(struct wilco_ec_device *ec,
>  	ret = send_property_msg(ec, &rq, &rs);
>  	if (ret < 0)
>  		return ret;
> +	if (rs.length > WILCO_EC_PROPERTY_MAX_SIZE)
> +		return -EBADMSG;
>  
>  	prop_msg->length = rs.length;
>  	memcpy(prop_msg->data, rs.data, rs.length);
> 
> base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 19:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 10:15 [PATCH] platform/chrome: wilco_ec: Reject out-of-bounds property length Maoyi Xie
2026-11-18 19:49 ` Benson Leung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®