From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Maoyi Xie <maoyixie.tju@gmail.com>
Cc: Benson Leung <bleung@chromium.org>,
Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
Jameson Thies <jthies@google.com>,
chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: platform/chrome: cros_ec_typec: unbounded PD cap count in cros_typec_register_partner_pdos()
Date: Wed, 24 Jun 2026 05:50:20 +0000 [thread overview]
Message-ID: <ajtwHGY7MaeClHN_@google.com> (raw)
In-Reply-To: <178214588280.2375438.11710758336343332732@maoyixie.com>
On Tue, Jun 23, 2026 at 12:31:22AM +0800, Maoyi Xie wrote:
> Hi all,
>
> I think cros_typec_register_partner_pdos() in
> drivers/platform/chrome/cros_ec_typec.c can overflow the on stack
> caps_desc.pdo array when the EC reports a large capability count. I would
> appreciate it if you could take a look.
>
> The function copies the partner PDOs from the EC response into a fixed array.
>
> struct usb_power_delivery_capabilities_desc caps_desc = {};
> ...
> if (!resp->source_cap_count && !resp->sink_cap_count)
> return;
> ...
> memcpy(caps_desc.pdo, resp->source_cap_pdos,
> sizeof(u32) * resp->source_cap_count);
> ...
> memcpy(caps_desc.pdo, resp->sink_cap_pdos,
> sizeof(u32) * resp->sink_cap_count);
>
> caps_desc.pdo is u32 pdo[PDO_MAX_OBJECTS], and PDO_MAX_OBJECTS is 7. The only
> check on the counts is that they are not both zero. resp->source_cap_count
> and resp->sink_cap_count are u8 fields from the EC TYPEC_STATUS response. If
> either is larger than 7, the memcpy writes past the 7 element pdo array on
> the stack. For a count of 255 that is about 1 KB.
Correct. This is indeed a potential stack overflow.
>
> The counts come from the EC and reflect what the attached Type-C partner
> advertised. A malicious or malfunctioning partner or EC can push the count
> past 7.
>
> I reproduced the overflow on 7.1-rc7 by running the same copy with the 7
> element pdo array and a count above 7. The copy past the array trips the
> stack protector.
>
> Kernel panic ... stack-protector: Kernel stack is corrupted
How did you reproduce the overflow? Was this by modifying the EC firmware
to send larger counts, or can this be triggered by a non-compliant USB-C
partner device?
>
> A clamp of the count to PDO_MAX_OBJECTS before each copy would close it.
>
> Does this look like a real bug to you, and is clamping to PDO_MAX_OBJECTS the
> right fix? If so I am happy to send a proper patch with a Fixes tag and Cc
> stable.
Yes, this is a bug. Clamping is necessary.
Generally, the `resp` should be validated immediately after the
EC_CMD_TYPEC_STATUS command returns in cros_typec_handle_status() and exit
earlier if the counts are out of bounds.
next prev parent reply other threads:[~2026-06-24 5:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 16:31 platform/chrome: cros_ec_typec: unbounded PD cap count in cros_typec_register_partner_pdos() Maoyi Xie
2026-06-24 5:50 ` Tzung-Bi Shih [this message]
2026-06-24 7:00 ` Maoyi Xie
2026-06-24 8:21 ` Tzung-Bi Shih
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajtwHGY7MaeClHN_@google.com \
--to=tzungbi@kernel.org \
--cc=abhishekpandit@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=jthies@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox