Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: tcpm: Fix out-of-bounds read of the pds and pd_list arrays
@ 2026-12-04  9:21 Kyle Tso
  2026-12-04  9:34 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyle Tso @ 2026-12-04  9:21 UTC (permalink / raw)
  To: gregkh, heikki.krogerus, badhri; +Cc: linux-usb, linux-kernel, stable, Kyle Tso

select_usb_power_delivery_show() iterates through port->pds (via the
pd_get() callback) and tcpm_find_pd_data() iterates through
port->pd_list until they find a NULL entry. However, tcpm_fw_get_caps()
allocates only port->pd_count entries for each array, and
tcpm_port_register_pd() fills all of them. Without a NULL terminator,
both loops read and dereference one entry past the end:

  Unable to handle kernel paging request at virtual address
  adacafaea9a8ac1a
  Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
  pc : select_usb_power_delivery_show+0xa4/0x110
  lr : select_usb_power_delivery_show+0x90/0x110
  Call trace:
   select_usb_power_delivery_show+0xa4/0x110
   dev_attr_show+0x38/0x74
   sysfs_kf_seq_show+0xb4/0x130
   kernfs_seq_show+0x44/0x54
   seq_read_iter+0x158/0x4ec
   kernfs_fop_read_iter+0x68/0x1bc
   vfs_read+0x230/0x2c0
   ksys_read+0x78/0xe8
   __arm64_sys_read+0x1c/0x2c
   invoke_syscall+0x58/0x118
   el0_svc_common+0xb4/0xf4
   do_el0_svc+0x24/0x80
   el0_svc+0x2c/0x90
   el0t_64_sync_handler+0x68/0xb4
   el0t_64_sync+0x1a4/0x1a8

Allocate one extra, zeroed entry for both arrays so that they are
always NULL-terminated.

Fixes: cd099cde4ed2 ("usb: typec: tcpm: Support multiple capabilities")
Cc: stable@vger.kernel.org
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Kyle Tso <kyletso@google.com>
---
Changes in v2:
- Rebase onto usb-testing (commit 4dd10fbbeb9c converted devm_kcalloc()
  to devm_kzalloc_objs()).
- Collect Acked-by from Heikki Krogerus.

Tooling note (Documentation/process/generated-content.rst):
An LLM assisted with rebasing the patch onto usb-testing and preparing
the v2 submission. Build-verified drivers/usb/typec/tcpm/tcpm.o with
ARCH=arm64 LLVM=1 W=1 (both CONFIG_PM=y with C=1 sparse and CONFIG_PM=n).

v1: https://lore.kernel.org/r/20261013081549.2375441-1-kyletso@google.com

 drivers/usb/typec/tcpm/tcpm.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index b95946d42162..4bbc833de19b 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -8424,15 +8424,22 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, struct fwnode_handle *fwnode
 		}
 	}
 
+	/*
+	 * Allocate one extra entry for each array to keep them NULL-terminated.
+	 * select_usb_power_delivery_show() iterates through port->pds (via the
+	 * pd_get callback) until it finds a NULL entry. Similarly,
+	 * tcpm_find_pd_data() iterates through port->pd_list until it finds a
+	 * NULL entry.
+	 */
 	port->pds = devm_kzalloc_objs(port->dev, struct usb_power_delivery *,
-				      port->pd_count);
+				      port->pd_count + 1);
 	if (!port->pds) {
 		ret = -ENOMEM;
 		goto put_capabilities;
 	}
 
 	port->pd_list = devm_kzalloc_objs(port->dev, struct pd_data *,
-					  port->pd_count);
+					  port->pd_count + 1);
 	if (!port->pd_list) {
 		ret = -ENOMEM;
 		goto put_capabilities;

base-commit: 7018748a0ac67b08688dee4b26d226952346d38e
-- 
2.56.1.915.g69d5ec7298-goog


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

end of thread, other threads:[~2026-12-04  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:21 [PATCH v2] usb: typec: tcpm: Fix out-of-bounds read of the pds and pd_list arrays Kyle Tso
2026-12-04  9:34 ` sashiko-bot

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