From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9829298CA3 for ; Wed, 24 Jun 2026 18:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782325397; cv=none; b=K7+uhQbiDkFoj61VmTYturEgV2WkCMRPMzuUqI2AhZEhTE+nf8nfi7l2OzwqofDWh3JRsG2lkWCaZK20KWYsMqcbg3JJ6GchV1ckkvBLjrwklkcHaDxQ5ii//+D2O8k72TDsWnFA93lwB/lPFEn8SFn6vAhBxFovWFNA7Bn3g30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782325397; c=relaxed/simple; bh=olJbLXW9rdMWRDoBt02V9oWhVMo3L7gEB6nkPiadIMQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R5UKK+S0A4gBrnxjs+Cbx0/dcWcM9KKiMj2P7E6544x8wtCDBTqHLLcGHLt2UvHPqXWFVHWpml1INg+Nb5O3gtiMuLrBAGkaEDajbCog/xQglHK+6ubnfEusLYlZBKVMmkswruGnqwPTuIqi5rbtqOaUn8oXhF//BcDZPZ70PJw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ju/ln4MO; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ju/ln4MO" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2c6ab886da6so7974675ad.0 for ; Wed, 24 Jun 2026 11:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782325394; x=1782930194; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NXjiJLfwfjaephsJ9Vb7pj+da+K3cSvnSmlpT/LBY60=; b=Ju/ln4MOfxAD2Tz5XTwg8UQR8uCjDZywWKfSOYvmkE+6OAF+e3UpQdgxWFUqZSc54T PQj4D/Rpjeb9vVPVYqrQIeVCKFKFmAhvGOz02vTGdTTg2wOWEkcAhOj/lpp5eyHp6VZ4 hx5RCmZt2gon6Z/XRDbH14c0dIGplMSOwo1msU6ZIOrRlm5aSCJ0nh+MB+FbS+8ExnLA YI/vKze2r1rK+YR+XefPTynuEmq1AOJRvQdNsdDUaui5A3t5+cWq7F9pcdTrj49VLX6G qquD5i4CxpL33sFjNn1ydr/KPWVnHlzHySv4Lp4G6OpGvsAQZnRT6Twml6VY5pivLffi 7wwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782325394; x=1782930194; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NXjiJLfwfjaephsJ9Vb7pj+da+K3cSvnSmlpT/LBY60=; b=tKrf/pn9W22SHttJbpjqsUB/FcZOJD+iYQhgRE5vSGltr/fWjMiaJxwG/NFxvpnIAs bodP80BzJgyb8NY3JGL93yR0D7O+4QB+omR4140b8G08Fsw5HBroqRrCfP4EShIuaSbj ysZSabqJaE781CuZ1qe7RK1gd8IckCsuTHm2dVhj5ehzvh8OJWCIOmIC1iu9CnyMb2CU xe7kW6z1BtmoVow8Ot4Ipn6wYiHEzEzTp7AEN/XtoJYX4ashUDTh4Yq6p6jXJI767e93 Bci3O+2f9ICKEFKliibPfhacALgu2EolUqWWMNJO6/8s/CKT+CtzLAO0Fr+OyQ7lzSeY vbDg== X-Forwarded-Encrypted: i=1; AHgh+RrvJTCI+o4Hc9KNIHf8n2ZvFRWvE5865rZPD61Nnvsx6/U8bcCW0p47brlireeaB6+MAsk9tVt00uyU3so=@vger.kernel.org X-Gm-Message-State: AOJu0YyHPUGzbs5iqO9OZPp0eFUM9GeajrEBpxvXmviztUPNytVy/Gqg C6GmIMn9B8sTJynFdrZgI1YH7nOSR4f0hMTmvn4cJ5WKYnMTK7xEGGQrHNDccOECLA== X-Gm-Gg: AfdE7cl2UVJg5UB+5gI4oJq0CCrJFATayPiZ6J80s48k+YlmH+yqUFepTaUo5Yg3eou V7VD04qpPahPvjqaHDrLY6Au90n+ZiO/o/z2fM0OIYf2BetKouAk2hFp35hMwT/RgeBcbLfQobx b8HyJGPzc1jUfwei5gxXw++15MVrVVzDTZe5FN1QQik+qlhFvRvdXPV4mWOXtkCy3p+GatJzhBp OQ62RQuoevcoGGfHGLHCfIhbxW69HgLuacC+QjZHSeIoMB9o6MxoZccnu5vY3sKvp8wXUeMJHPx QBmLKWxkPI1ZU1FIheIsrrFlMuQrydISHZ78t39cC0p97eXCvxWAxSO5vEeOqJl5B+2TX8CfXLt 8LXCkZzwYQpk3iT4AT8aQBtbeNkyMfPMhNwTcgmPgKL0K7AYfCo4Z4pMaKwxjphxxTJlGGn4hbC 38PIhHFciKm/144OHOO4xhOxy4z39HzTOfq5O8aOg6hlI4kkWGVF4VyZYgFTg= X-Received: by 2002:a17:903:2309:b0:2c3:bab9:4961 with SMTP id d9443c01a7336-2c7e158ff2fmr45803835ad.34.1782325393193; Wed, 24 Jun 2026 11:23:13 -0700 (PDT) Received: from google.com (211.37.230.35.bc.googleusercontent.com. [35.230.37.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f5ae5ecfsm3689025ad.21.2026.06.24.11.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 11:23:12 -0700 (PDT) Date: Wed, 24 Jun 2026 18:23:09 +0000 From: Benson Leung To: Maoyi Xie Cc: Benson Leung , Tzung-Bi Shih , Abhishek Pandit-Subedi , Jameson Thies , Andrei Kuchynski , Guenter Roeck , Kaixuan Li , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] platform/chrome: cros_ec_typec: reject out-of-bounds PD cap count Message-ID: References: <178229037114.3009621.14045345257767446805@maoyixie.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2yuEi8rDjEs2iff2" Content-Disposition: inline In-Reply-To: <178229037114.3009621.14045345257767446805@maoyixie.com> --2yuEi8rDjEs2iff2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 24, 2026 at 04:39:31PM +0800, Maoyi Xie wrote: > cros_typec_register_partner_pdos() copies the partner PDOs from the EC > TYPEC_STATUS response into the fixed caps_desc.pdo[PDO_MAX_OBJECTS] array. >=20 > 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); >=20 > PDO_MAX_OBJECTS is 7. source_cap_count and sink_cap_count are u8 fields > from the EC, and the only check is that they are not both zero. If either > is larger than 7, the memcpy writes past the end of the array on the stac= k. > A count of 255 overflows it by about 1 KB. >=20 > The ChromeOS EC firmware caps these counts today, so a compliant setup > does not hit this. The kernel should still validate the values from the EC > rather than trust them. >=20 > Validate the counts in cros_typec_handle_status() right after the > EC_CMD_TYPEC_STATUS command returns, and return early if either one is > above PDO_MAX_OBJECTS. >=20 > Fixes: 348a2e8c93d3 ("platform/chrome: cros_ec_typec: Register partner PD= Os") > Suggested-by: Tzung-Bi Shih > Co-developed-by: Kaixuan Li > Signed-off-by: Kaixuan Li > Signed-off-by: Maoyi Xie Reviewed-by: Benson Leung > --- > drivers/platform/chrome/cros_ec_typec.c | 6 ++++++ > 1 file changed, 6 insertions(+) >=20 > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/c= hrome/cros_ec_typec.c > index c0806c562bb9..3ae9b35b7d85 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -1158,6 +1158,12 @@ static void cros_typec_handle_status(struct cros_t= ypec_data *typec, int port_num > return; > } > =20 > + if (resp.source_cap_count > PDO_MAX_OBJECTS || > + resp.sink_cap_count > PDO_MAX_OBJECTS) { > + dev_warn(typec->dev, "Invalid PDO count from EC, port: %d\n", port_num= ); > + return; > + } > + > /* If we got a hard reset, unregister everything and return. */ > if (resp.events & PD_STATUS_EVENT_HARD_RESET) { > cros_typec_remove_partner(typec, port_num); --2yuEi8rDjEs2iff2 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCajwgjQAKCRBzbaomhzOw wnSOAQCIz50X5Z2KAhe2lj+ABVsQLpGk+n/TQ5cfeXgp+BL3VAD/Q/QWL3dA9VBd wxxcndjXxwJvLRdVBmW/cZcJyNKK9Qo= =gyKn -----END PGP SIGNATURE----- --2yuEi8rDjEs2iff2--