platform/chrome: wilco_ec: Reject out-of-bounds property length
PATCH 1/1 platform/chrome: wilco_ec: Reject out-of-bounds property length
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.
--- drivers/platform/chrome/wilco_ec/properties.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/chrome/wilco_ec/properties.c +2 -0
@@ -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
Signature · 1 line
2.34.1
Hi Maoyi,
Quoted 15 lines · Maoyi Xie
wilco_ec_get_property()copies rs.length bytes from rs.data intoprop_msg->datawithout checking rs.length, which comes from the EC. Both buffers holdWILCO_EC_PROPERTY_MAX_SIZE(4) bytes, so a larger length reads past rs on the stack and writes past the caller's message.Return
-EBADMSGfor 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.cagainst 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.
Quoted 3 lines
Fixes 0c0b7ea23aed ("platform/chrome: wilco_ec: Add property helper library")Signed-off-by Maoyi Xie <[email protected]>A
Thanks,
Benson
Quoted 22 lines
--- drivers/platform/chrome/wilco_ec/properties.c | 2 ++ 1 file changed, 2 insertions(+)drivers/platform/chrome/wilco_ec/properties.c +2
-0@@ -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:
7e1392a42ea288d70a266f6553fe06f57f8647eaSignature · 1 line
2.34.1
Tzung-Bi Shih
maintainerQuoted 9 lines · Maoyi Xie
wilco_ec_get_property()copies rs.length bytes from rs.data intoprop_msg->datawithout checking rs.length, which comes from the EC. Both buffers holdWILCO_EC_PROPERTY_MAX_SIZE(4) bytes, so a larger length reads past rs on the stack and writes past the caller's message.Return
-EBADMSGfor such a length, as the file does for other bad responses.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
[1/1] platform/chrome: wilco_ec: Reject out-of-bounds property length
commit: 1491040b5f396b23021f2905d18599e2e0bd5908
Thanks!