All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers
@ 2022-12-07  4:01 Victor Ding
  2022-12-07  8:02 ` Prashant Malani
  0 siblings, 1 reply; 3+ messages in thread
From: Victor Ding @ 2022-12-07  4:01 UTC (permalink / raw)
  To: linux-kernel, chrome-platform
  Cc: tinghan.shen, gustavoars, sebastian.reichel, dnojiri, bleung,
	lee.jones, pmalani, groeck, tzungbi, gregkh, dustin, Victor Ding

`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@chromium.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


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

* Re: [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07  4:01 [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
@ 2022-12-07  8:02 ` Prashant Malani
  2022-12-07  9:08   ` Victor Ding
  0 siblings, 1 reply; 3+ messages in thread
From: Prashant Malani @ 2022-12-07  8:02 UTC (permalink / raw)
  To: Victor Ding
  Cc: linux-kernel, chrome-platform, tinghan.shen, gustavoars,
	sebastian.reichel, dnojiri, bleung, lee.jones, groeck, tzungbi,
	gregkh, dustin

Hi Victor,

On Tue, Dec 6, 2022 at 8:02 PM Victor Ding <victording@chromium.org> wrote:
>
> `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
Please use the imperative form [1]

> to elimite these stale pointers by zeroing them out

s/elimite/eliminate

> right after they are freed.
>
> Signed-off-by: Victor Ding <victording@chromium.org>
This should have a "Fixes" tag.

Best regards,

-Prashant

[1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

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

* Re: [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers
  2022-12-07  8:02 ` Prashant Malani
@ 2022-12-07  9:08   ` Victor Ding
  0 siblings, 0 replies; 3+ messages in thread
From: Victor Ding @ 2022-12-07  9:08 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, chrome-platform, tinghan.shen, gustavoars,
	sebastian.reichel, dnojiri, bleung, lee.jones, groeck, tzungbi,
	gregkh, dustin

Hi Prashant,

Thank you for reviewing. I'll update accordingly in the next revision.

On Wed, Dec 7, 2022 at 7:02 PM Prashant Malani <pmalani@chromium.org> wrote:
>
> Hi Victor,
>
> On Tue, Dec 6, 2022 at 8:02 PM Victor Ding <victording@chromium.org> wrote:
> >
> > `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
> Please use the imperative form [1]
>
> > to elimite these stale pointers by zeroing them out
>
> s/elimite/eliminate
>
> > right after they are freed.
> >
> > Signed-off-by: Victor Ding <victording@chromium.org>
> This should have a "Fixes" tag.
>
> Best regards,
>
> -Prashant
>
> [1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

Best regards,
Victor

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

end of thread, other threads:[~2022-12-07  9:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  4:01 [PATCH] platform/chrome: cros_ec_typec: zero out stale pointers Victor Ding
2022-12-07  8:02 ` Prashant Malani
2022-12-07  9:08   ` Victor Ding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.