All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Rebello <nathan.c.rebello@gmail.com>
To: linux-usb@vger.kernel.org
Cc: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org,
	Nathan Rebello <nathan.c.rebello@gmail.com>
Subject: [PATCH 2/2] usb: typec: ucsi: clamp returned length in ucsi_run_command()
Date: Thu, 19 Feb 2026 11:49:24 -0500	[thread overview]
Message-ID: <20260219164925.3249-3-nathan.c.rebello@gmail.com> (raw)
In-Reply-To: <20260219164925.3249-1-nathan.c.rebello@gmail.com>

ucsi_run_command() returns UCSI_CCI_LENGTH(cci) as the data length to
callers. This value comes directly from the CCI register and reflects
the length reported by the PPM firmware, not the actual number of bytes
copied into the caller's buffer (which is bounded by the size parameter
passed to sync_control).

If the firmware reports a length larger than the buffer provided by the
caller, callers such as ucsi_register_altmodes() will iterate past the
end of their stack buffer when computing:

    num = len / sizeof(alt[0]);
    for (j = 0; j < num; j++)  /* reads past alt[2] */

Clamp the return value to the buffer size to prevent out-of-bounds reads.

Fixes: bdc62f2bae8f ("usb: typec: ucsi: Simplified registration and I/O API")
Signed-off-by: Nathan Rebello <nathan.c.rebello@gmail.com>
---
 drivers/usb/typec/ucsi/ucsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 7109d3bd39b4..5791597fe662 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -140,7 +140,7 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
 	if (ret)
 		return ret;
 
-	return err ?: UCSI_CCI_LENGTH(*cci);
+	return err ?: min_t(u32, UCSI_CCI_LENGTH(*cci), size);
 }
 
 static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
-- 
2.43.0.windows.1


      parent reply	other threads:[~2026-02-19 16:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19 16:49 [PATCH 0/2] usb: typec: ucsi: fix input validation in UCSI core Nathan Rebello
2026-02-19 16:49 ` [PATCH 1/2] usb: typec: ucsi: validate connector number in ucsi_connector_change() Nathan Rebello
2026-02-20  6:09   ` Greg KH
2026-02-20  6:34   ` Nathan Rebello
2026-02-20  6:53     ` Greg KH
2026-03-11 13:10   ` Greg KH
2026-03-11 21:49     ` Nathan Rebello
2026-03-12  5:03       ` Greg KH
2026-03-12  5:44         ` Nathan Rebello
2026-02-19 16:49 ` Nathan Rebello [this message]

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=20260219164925.3249-3-nathan.c.rebello@gmail.com \
    --to=nathan.c.rebello@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.