linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers
@ 2022-12-07  9:39 Victor Ding
  2022-12-07 22:54 ` Prashant Malani
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Victor Ding @ 2022-12-07  9:39 UTC (permalink / raw)
  To: linux-kernel, chrome-platform
  Cc: pmalani, groeck, dustin, gustavoars, gregkh, sebastian.reichel,
	dnojiri, lee.jones, bleung, tinghan.shen, tzungbi, Victor Ding,
	Enric Balletbo i Serra, Heikki Krogerus

`cros_typec_get_switch_handles` allocates four pointers when obtaining
type-c switch handles. These pointers are all freed if failing to obtain
any of them; therefore, pointers in `port` become stale. The stale
pointers eventually cause use-after-free or double free in later code
paths. Zeroing out all pointer fields after freeing to eliminate these
stale pointers.

Fixes: f28adb41dab4 ("platform/chrome: cros_ec_typec: Register Type C switches")
Fixes: 1a8912caba02 ("platform/chrome: cros_ec_typec: Get retimer handle")
Signed-off-by: Victor Ding <victording@chromium.org>
---

Changes in v2:
- Updated commit messages;
- No code changes.

 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 2a7ff14dc37e..59de4ce01fab 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -173,10 +173,13 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
 
 role_sw_err:
 	typec_switch_put(port->ori_sw);
+	port->ori_sw = NULL;
 ori_sw_err:
 	typec_retimer_put(port->retimer);
+	port->retimer = NULL;
 retimer_sw_err:
 	typec_mux_put(port->mux);
+	port->mux = NULL;
 mux_err:
 	return -ENODEV;
 }
-- 
2.39.0.rc0.267.gcb52ba06e7-goog


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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07  9:39 [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
@ 2022-12-07 22:54 ` Prashant Malani
  2022-12-08  2:01   ` Tzung-Bi Shih
  2022-12-08  2:00 ` patchwork-bot+chrome-platform
  2022-12-08  2:00 ` patchwork-bot+chrome-platform
  2 siblings, 1 reply; 5+ messages in thread
From: Prashant Malani @ 2022-12-07 22:54 UTC (permalink / raw)
  To: Victor Ding
  Cc: linux-kernel, chrome-platform, groeck, dustin, gustavoars,
	gregkh, sebastian.reichel, dnojiri, lee.jones, bleung,
	tinghan.shen, tzungbi, Enric Balletbo i Serra, Heikki Krogerus

On Dec 07 09:39, Victor Ding wrote:
> `cros_typec_get_switch_handles` allocates four pointers when obtaining
> type-c switch handles. These pointers are all freed if failing to obtain
> any of them; therefore, pointers in `port` become stale. The stale
> pointers eventually cause use-after-free or double free in later code
> paths. Zeroing out all pointer fields after freeing to eliminate these
> stale pointers.
> 
> Fixes: f28adb41dab4 ("platform/chrome: cros_ec_typec: Register Type C switches")
> Fixes: 1a8912caba02 ("platform/chrome: cros_ec_typec: Get retimer handle")
> Signed-off-by: Victor Ding <victording@chromium.org>
Acked-by: Prashant Malani <pmalani@chromium.org>

Hey Tzung-Bi, it looks like you've already created a tag for the
v6.2 pull request, so I don't know if it's too late to apply this
for the current dev cycle.
So, I've not applied it, but have left the Acked-by tag.

Please feel free to apply it if there's still room for it before
you send out the pull request.

Thanks!

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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07  9:39 [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
  2022-12-07 22:54 ` Prashant Malani
  2022-12-08  2:00 ` patchwork-bot+chrome-platform
@ 2022-12-08  2:00 ` patchwork-bot+chrome-platform
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-12-08  2:00 UTC (permalink / raw)
  To: Victor Ding
  Cc: linux-kernel, chrome-platform, pmalani, groeck, dustin,
	gustavoars, gregkh, sebastian.reichel, dnojiri, lee.jones,
	bleung, tinghan.shen, tzungbi, enric.balletbo, heikki.krogerus

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Wed,  7 Dec 2022 09:39:40 +0000 you wrote:
> `cros_typec_get_switch_handles` allocates four pointers when obtaining
> type-c switch handles. These pointers are all freed if failing to obtain
> any of them; therefore, pointers in `port` become stale. The stale
> pointers eventually cause use-after-free or double free in later code
> paths. Zeroing out all pointer fields after freeing to eliminate these
> stale pointers.
> 
> [...]

Here is the summary with links:
  - [v2] platform/chrome: cros_ec_typec: zero out stale pointers
    https://git.kernel.org/chrome-platform/c/9a8aadcf0b45

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07  9:39 [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
  2022-12-07 22:54 ` Prashant Malani
@ 2022-12-08  2:00 ` patchwork-bot+chrome-platform
  2022-12-08  2:00 ` patchwork-bot+chrome-platform
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-12-08  2:00 UTC (permalink / raw)
  To: Victor Ding
  Cc: linux-kernel, chrome-platform, pmalani, groeck, dustin,
	gustavoars, gregkh, sebastian.reichel, dnojiri, lee.jones,
	bleung, tinghan.shen, tzungbi, enric.balletbo, heikki.krogerus

Hello:

This patch was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Wed,  7 Dec 2022 09:39:40 +0000 you wrote:
> `cros_typec_get_switch_handles` allocates four pointers when obtaining
> type-c switch handles. These pointers are all freed if failing to obtain
> any of them; therefore, pointers in `port` become stale. The stale
> pointers eventually cause use-after-free or double free in later code
> paths. Zeroing out all pointer fields after freeing to eliminate these
> stale pointers.
> 
> [...]

Here is the summary with links:
  - [v2] platform/chrome: cros_ec_typec: zero out stale pointers
    https://git.kernel.org/chrome-platform/c/9a8aadcf0b45

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07 22:54 ` Prashant Malani
@ 2022-12-08  2:01   ` Tzung-Bi Shih
  0 siblings, 0 replies; 5+ messages in thread
From: Tzung-Bi Shih @ 2022-12-08  2:01 UTC (permalink / raw)
  To: Prashant Malani
  Cc: Victor Ding, linux-kernel, chrome-platform, groeck, dustin,
	gustavoars, gregkh, sebastian.reichel, dnojiri, lee.jones,
	bleung, tinghan.shen, Enric Balletbo i Serra, Heikki Krogerus

On Wed, Dec 07, 2022 at 10:54:17PM +0000, Prashant Malani wrote:
> On Dec 07 09:39, Victor Ding wrote:
> > `cros_typec_get_switch_handles` allocates four pointers when obtaining
> > type-c switch handles. These pointers are all freed if failing to obtain
> > any of them; therefore, pointers in `port` become stale. The stale
> > pointers eventually cause use-after-free or double free in later code
> > paths. Zeroing out all pointer fields after freeing to eliminate these
> > stale pointers.
> > 
> > Fixes: f28adb41dab4 ("platform/chrome: cros_ec_typec: Register Type C switches")
> > Fixes: 1a8912caba02 ("platform/chrome: cros_ec_typec: Get retimer handle")
> > Signed-off-by: Victor Ding <victording@chromium.org>
> Acked-by: Prashant Malani <pmalani@chromium.org>
> 
> Hey Tzung-Bi, it looks like you've already created a tag for the
> v6.2 pull request, so I don't know if it's too late to apply this
> for the current dev cycle.
> So, I've not applied it, but have left the Acked-by tag.
> 
> Please feel free to apply it if there's still room for it before
> you send out the pull request.

Given that the patch fixes an use-after-free, let's include this in the
coming merge window.  Have queued.

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

end of thread, other threads:[~2022-12-08  2:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  9:39 [PATCH v2] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
2022-12-07 22:54 ` Prashant Malani
2022-12-08  2:01   ` Tzung-Bi Shih
2022-12-08  2:00 ` patchwork-bot+chrome-platform
2022-12-08  2:00 ` patchwork-bot+chrome-platform

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).