All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Lukasz Majewski <lukma@denx.de>, Niel Fourie <lusus@denx.de>
Cc: u-boot@lists.denx.de, Ramon Fried <rfried.dev@gmail.com>
Subject: Re: [PATCH] net: eth-uclass: change state before stop() in eth_halt()
Date: Thu, 1 Dec 2022 11:44:13 +0100	[thread overview]
Message-ID: <0bb976c3-0bc3-09fb-6afa-1643efe49d8e@denx.de> (raw)
In-Reply-To: <20221201092414.765944d9@wsk>

On 12/1/22 09:24, Lukasz Majewski wrote:
> On Wed, 30 Nov 2022 17:42:25 +0100
> Niel Fourie <lusus@denx.de> wrote:
> 
>> 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)
> 
> Reviewed-by: Lukasz Majewski <lukma@denx.de>

How come nobody triggered this problem with regular ethernet in U-Boot ?

If this is isolated to USB gadget ethernet, then please do not hack 
around this in core networking code, but rather fix the USB ethernet 
gadget itself. It seems that gadget code should not unregister the 
gadget in drivers/usb/gadget/ether.c _usb_eth_halt() , at least not fully.

  reply	other threads:[~2022-12-01 10:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=0bb976c3-0bc3-09fb-6afa-1643efe49d8e@denx.de \
    --to=marex@denx.de \
    --cc=lukma@denx.de \
    --cc=lusus@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.