Skip to content

Commit 9a8aadc

Browse files
Victor DingTzung-Bi Shih
authored andcommitted
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: f28adb4 ("platform/chrome: cros_ec_typec: Register Type C switches") Fixes: 1a8912c ("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
1 parent 5a2d966 commit 9a8aadc

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,13 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
173173

174174
role_sw_err:
175175
typec_switch_put(port->ori_sw);
176+
port->ori_sw = NULL;
176177
ori_sw_err:
177178
typec_retimer_put(port->retimer);
179+
port->retimer = NULL;
178180
retimer_sw_err:
179181
typec_mux_put(port->mux);
182+
port->mux = NULL;
180183
mux_err:
181184
return -ENODEV;
182185
}

0 commit comments

Comments
 (0)