From: Niel Fourie <lusus@denx.de>
To: u-boot@lists.denx.de
Cc: Niel Fourie <lusus@denx.de>, Ramon Fried <rfried.dev@gmail.com>,
Marek Vasut <marex@denx.de>, Lukasz Majewski <lukma@denx.de>
Subject: [PATCH] net: eth-uclass: change state before stop() in eth_halt()
Date: Wed, 30 Nov 2022 17:42:25 +0100 [thread overview]
Message-ID: <20221130164225.766877-1-lusus@denx.de> (raw)
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
next reply other threads:[~2022-11-30 16:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-30 16:42 Niel Fourie [this message]
2022-12-01 8:24 ` [PATCH] net: eth-uclass: change state before stop() in eth_halt() 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221130164225.766877-1-lusus@denx.de \
--to=lusus@denx.de \
--cc=lukma@denx.de \
--cc=marex@denx.de \
--cc=rfried.dev@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.