All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: eth-uclass: change state before stop() in eth_halt()
@ 2022-11-30 16:42 Niel Fourie
  2022-12-01  8:24 ` Lukasz Majewski
  0 siblings, 1 reply; 11+ messages in thread
From: Niel Fourie @ 2022-11-30 16:42 UTC (permalink / raw)
  To: u-boot; +Cc: Niel Fourie, Ramon Fried, Marek Vasut, Lukasz Majewski

In eth_halt(), change the private uclass state before calling
stop() instead of afterwards, to avoid writing to memory which
may have been freed during stop().

In the ethernet gadget implementation, the gadget device gets
probed during start() and removed during stop(), which includes
freeing `uclass_priv_` to which `priv` is pointing. Writing to
`priv` after stop() may corrupt the `fd` member of `struct
malloc_chunk`, which represents the freed block, and could cause
hard-to-debug crashes on subsequent calls to malloc()/free().

Signed-off-by: Niel Fourie <lusus@denx.de>
Cc: Ramon Fried <rfried.dev@gmail.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Lukasz Majewski <lukma@denx.de>
---
 net/eth-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index f41da4b37b3..bc3b9751e32 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -342,9 +342,9 @@ void eth_halt(void)
 	if (!priv || !priv->running)
 		return;
 
-	eth_get_ops(current)->stop(current);
 	priv->state = ETH_STATE_PASSIVE;
 	priv->running = false;
+	eth_get_ops(current)->stop(current);
 }
 
 int eth_is_active(struct udevice *dev)
-- 
2.38.1


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

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

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-30 16:42 [PATCH] net: eth-uclass: change state before stop() in eth_halt() Niel Fourie
2022-12-01  8:24 ` Lukasz Majewski
2022-12-01 10:44   ` Marek Vasut
2022-12-02 10:36     ` Niel Fourie
2022-12-03 23:50       ` Ramon Fried
2022-12-04  2:20         ` Marek Vasut
2022-12-04  2:17       ` Marek Vasut
2022-12-05 12:06         ` Niel Fourie
2022-12-05 15:33           ` Niel Fourie
2022-12-05 16:20             ` Marek Vasut
2022-12-05 16:18           ` Marek Vasut

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.