[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221207040049.1.I1864b6a7ee98824118b93677868d22d3750f439b@changeid>
Date: Wed, 7 Dec 2022 04:01:08 +0000
From: Victor Ding <victording@...omium.org>
To: linux-kernel@...r.kernel.org, chrome-platform@...ts.linux.dev
Cc: tinghan.shen@...iatek.com, gustavoars@...nel.org,
sebastian.reichel@...labora.com, dnojiri@...omium.org,
bleung@...omium.org, lee.jones@...aro.org, pmalani@...omium.org,
groeck@...omium.org, tzungbi@...nel.org,
gregkh@...uxfoundation.org, dustin@...ett.net,
Victor Ding <victording@...omium.org>
Subject: [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers
`cros_typec_get_switch_handles` allocates several pointers when
obtaining four handles. These pointers are all freed if failing to
obtain any of the four handles; therefore, pointers in `port` becomes
stale. The stale pointers eventually cause use-after-free or double in
later code paths.
This patch proposes to elimite these stale pointers by zeroing them out
right after they are freed.
Signed-off-by: Victor Ding <victording@...omium.org>
---
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
Powered by blists - more mailing lists