Skip to content

Commit 0ceadb5

Browse files
Victor Dinggregkh
authored andcommitted
platform/chrome: cros_ec_typec: zero out stale pointers
[ Upstream commit 9a8aadc ] `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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 49c98b5 commit 0ceadb5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
157157

158158
role_sw_err:
159159
typec_switch_put(port->ori_sw);
160+
port->ori_sw = NULL;
160161
ori_sw_err:
161162
typec_mux_put(port->mux);
163+
port->mux = NULL;
162164
mux_err:
163165
return -ENODEV;
164166
}

0 commit comments

Comments
 (0)