diff options
author | Victor Ding <victording@chromium.org> | 2022-12-07 12:39:40 +0300 |
---|---|---|
committer | Tzung-Bi Shih <tzungbi@kernel.org> | 2022-12-08 04:44:48 +0300 |
commit | 9a8aadcf0b459c1257b9477fd6402e1d5952ae07 (patch) | |
tree | 0ab55fc9e54665a80f8820213849339fee1b8d78 | |
parent | 5a2d96623670155d94aca72c320c0ac27bdc6bd2 (diff) | |
download | linux-9a8aadcf0b459c1257b9477fd6402e1d5952ae07.tar.xz |
platform/chrome: cros_ec_typec: zero out stale pointers
`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>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20221207093924.v2.1.I1864b6a7ee98824118b93677868d22d3750f439b@changeid
-rw-r--r-- | drivers/platform/chrome/cros_ec_typec.c | 3 |
1 files changed, 3 insertions, 0 deletions
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; } |