From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 41BFA3B47D9 for ; Fri, 26 Jun 2026 18:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782498773; cv=none; b=DRFk/hgQD0Aag2+mEYrq+t48zi3yn6RKHTm5ZMdpsWXP1PmnEI+TGzLbtYXGq9hyZAwZZsglFwcqpbRqB30mKm10SMcWdTsno6MFGbc7Bor1xAy+OQR76ypFGy9Cb+T4O79Hfv73msYBb9MUBz3nIuKz4htyU2eh4nUOMIXHNMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782498773; c=relaxed/simple; bh=qWVeFXV/b46sEnDgc7WPG0MAzRYDPZ3XT3mpcYSBxrA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iCHN0t7J5daEmgfSbGla8OZwcHi83cqZ9/9wnKDg705xr/e4+lMjZoAkx7ijGkAGcad/vAwvovCrFYgw4ff+VYOD+FdhBtc6amcFJ6ZsgUF2IPYJe8mKZ1ZcVhvm1JghAanwQ2qU/HuLOjSyojxN813lrczYEcBX/HWKyMCR9n0= 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=o3nmqUVV; arc=none smtp.client-ip=209.85.214.170 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="o3nmqUVV" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2c81d971f9cso6806135ad.0 for ; Fri, 26 Jun 2026 11:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782498770; x=1783103570; 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=F5iRXh9pMrYUUv4kaKZyGm378pwkxZvl04HUf2Y2obM=; b=o3nmqUVVMe3rQzjkIPnsXvvIny2lTW97HRf3gzDvrmZ5RlWUSfEQtVQEZEx/QxqDm4 6Uwa4SRkc8/xPB8PnvXOQxtK+QlOi8C/gIup+S9KWH708vlO1DqOhe9PbpXIrot5LoAk wO1YNk1oQvwnK2YqIwWrV9Sz0X1w9sdMYbc6hp4lhRncI9ij4fzR27Czp2zugNTTCO4M frL9FIhEsY0w6uhmAuv3JrqNuUakN9YfnDDBnoA1NfBAuUYjz9lTA6UYUKZvy60fQ7Ih K6ODF0DOaHc4WkS4ikFnmE0DEU4S0JRfjwA9vGF+PKSK01b5IQJTDET+rpZ37be484cD lbMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782498770; x=1783103570; 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=F5iRXh9pMrYUUv4kaKZyGm378pwkxZvl04HUf2Y2obM=; b=nFHeryDVD9ZrM6lxKIQ6rSJzy3MrXxH8LG700oaavWNgysXuAkwZLcEHMi6CyWeMWA wC0HuZPvY8pJgz7us6EbA9azo5aQFmwkLbk84x5XSOWZS0Cnu7h9OLqBNzce+zBGr6yS /HhwoC9nuNk6mWeKbNBKpQTkqh70GgV2puE7KW4KS/w+wqqQ/v4uPxwApKxVeap25dr9 2B2OjlFZL70tdIJdGnF5gXr051qv1FGLSMx+EmojkYxdpyZwe5B52XDU7HzZiLVzBW7n X0GIkkOkOrqUJQpX+FGjlQEznM5qtfiVZC9iXOx2T6iY8CpRztfFIe7W5nTH0aIYw16/ DRUw== X-Forwarded-Encrypted: i=1; AHgh+RoIN9xyoaE7zNOUrC0z64eiREYvUPTopLHhkf0UXDdrF8zF+aSHpmtDblLWU1ed0xfNfy+z1Bi6nwq0x8A=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/F/j4G7qdbSV9FW9vz67qzODOGEeprEpdHOLQfEm46A9WxVpX XE/ebnm2MYLa/JWAeJwaDScnpfLVpTzP87eXUO7PTghnRF4g7Q+aS1WUTLZszpri+g== X-Gm-Gg: AfdE7ckKgCznUDlZLwlOLiPsk6Vi8W+ptq/6SoJ8q7DZkLuV3IYgV+OcdAuLaane4RL Eb5G/aMkOAJiVL5eCiyHFZptDahTPoljG2nfoaOIYuuGNEGuR2EvnJsJ8xvJXujPEjmAp/vjmoC JQsw7AzFwg3UAoVeeN183cqGk0RvD/y+TivNoJ5e0YL4ktS4oxoyPYTlvc8eZ78HCWq85ar8Ig/ 0/zfSZuASBm+0kiF1elH35wpPkgNYGlLMGUl0UKSwGi8/Vne3lpK04M2GK8AsmvvH4moMLbF7VY LhVC49sRqKcgBGPylasilkOM2Cko3F8Y33JiuxixcDVcTLNorEUEhq9HALLHIF/AQqUJ7MGDmL9 CpU0aBrpKlSy0akCVcBo5QFPOWb9AlDV0J//tEDle6kA3MDkU1sb2Qul0z5qUHVD7+pDj/1kd0J yzcwICH704Al5x+s3xh3Fl1OkU4kPoZ5HpAIPwh9IolP9D37cT X-Received: by 2002:a17:903:90d:b0:2c1:41f8:7ef5 with SMTP id d9443c01a7336-2c7c3ff85b9mr138052725ad.22.1782498769659; Fri, 26 Jun 2026 11:32:49 -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-2c7f64cfdcbsm43503655ad.62.2026.06.26.11.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 11:32:46 -0700 (PDT) Date: Fri, 26 Jun 2026 18:32:43 +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 v2] platform/chrome: cros_ec_typec: reject out-of-bounds PD cap count Message-ID: References: <20260625130056.3378097-1-maoyixie.tju@gmail.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="W5LVQOzyA6UIaTVT" Content-Disposition: inline In-Reply-To: <20260625130056.3378097-1-maoyixie.tju@gmail.com> --W5LVQOzyA6UIaTVT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 25, 2026 at 09:00:56PM +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. 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 stack. > A count of 255 overflows it by about 1 KB. The EC source arrays are only > seven entries wide. A larger count reads past them too. >=20 > The ChromeOS EC firmware caps these counts today, so a compliant setup > does not hit this. The kernel should still validate these values rather > than trust them. >=20 > Validate the counts in cros_typec_register_partner_pdos() next to the > memcpy. Skip the PDO registration if either count is above PDO_MAX_OBJECT= S. > The rest of cros_typec_handle_status() still runs so events are handled > and cleared. >=20 > Fixes: 348a2e8c93d3 ("platform/chrome: cros_ec_typec: Register partner PD= Os") > Suggested-by: Tzung-Bi Shih > Suggested-by: Andrei Kuchynski > Co-developed-by: Kaixuan Li > Signed-off-by: Kaixuan Li > Signed-off-by: Maoyi Xie Reviewed-by: Benson Leung > --- > v2: Move the check into cros_typec_register_partner_pdos() next to the > memcpy it guards. v1 put it at the top of cros_typec_handle_status() > and returned early. That skipped the rest of the status handling and > left events uncleared. >=20 > v1: https://lore.kernel.org/r/178229037114.3009621.14045345257767446805@m= aoyixie.com >=20 > 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..50a68819ceb7 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -1119,6 +1119,12 @@ static void cros_typec_register_partner_pdos(struc= t cros_typec_data *typec, > if (!resp->source_cap_count && !resp->sink_cap_count) > 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; > + } > + > port->partner_pd =3D typec_partner_usb_power_delivery_register(port->pa= rtner, &desc); > if (IS_ERR(port->partner_pd)) { > dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n= ", port_num); --W5LVQOzyA6UIaTVT Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCaj7FywAKCRBzbaomhzOw ws7cAQC5ndIkEaBQ8kq3zFUNXs4fuP/TD4ObikCfE/4G3cHKdgEAnLxUUYmXJdIJ DuAaMN/x5U5zQMc6DtqaGcckaUmAYgA= =z7p8 -----END PGP SIGNATURE----- --W5LVQOzyA6UIaTVT--