Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8560FC4332F for ; Sun, 18 Dec 2022 02:39:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D3AD585377; Sun, 18 Dec 2022 03:39:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671331153; bh=9L5qRQICF1OKbU+1fjV4n0GOTTWfEFk30nNaMxjFIlE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=H4MN+HFSF9ekDgfGb6wEHjMM8gr3gU+3zrLqESpq58GzTQrZv+xN6ptOKut3np2Hc iy4cfJIoRMjYbFBsACW6BpDhz9tDYbIJjaj9VMHvzN+QJ9JqaX0zY7AZkvD+EBy1lU Jj2DrQc8JdeHJ+2Ms3RSRAEjiJk7KoUum84OV9fQ9zhp8RM1QpMnpZsDyQwBQDtqdE AvKfCTyUEc87y0hHEuN5YTuFDGYrqdoNXXoLv/RfZC5Q/1VKIFjXmv+BOjURwCqqkc 53ATEa2yxr6viReDmvCNkXz4pDmWo+WPbBbHtPqIKae/f0Xnvt/sNkbQqtP7khYgkK SQpoM6lr4LuUw== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 7B4E884C4B; Sun, 18 Dec 2022 03:39:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671331151; bh=9L5qRQICF1OKbU+1fjV4n0GOTTWfEFk30nNaMxjFIlE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=k2/wTbXdsfSLUZNDoNYUy2CV3Ee5lCLRyaoVhgk7JGJf62GMxVpzJrwRzGUnWR3qv MDOLIeiNqaSRMQ3HE3g+FEuIIbMOLsRwVAP6kEC253281Nq/pPbaoj6HSIWDOAuH+o 4FUHTdVLqSnF9B4zk7NkyyPgv50viOKoTgMuB0Suxc+fIa4uPBytXTn9FfZnc+VuVa 8On8IvMo21xQv2VFm1nUpOI7ysrEYuzXp4JutJcnFnNWdg7s7ZXzsc5gnr0rSH9JER Uh0BtelggQWsTNEmgXvQWUz0fsGua7mc7Ipg+VDlp0WE1daXk8WAwsWM3pg8NB4lZE Mt5Udidqp401A== Message-ID: <97fc9e0d-e396-503e-8d57-b268290ec78f@denx.de> Date: Sun, 18 Dec 2022 02:43:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2] net: eth-uclass: revalidate priv after stop() in eth_halt() Content-Language: en-US To: Niel Fourie , u-boot@lists.denx.de Cc: Ramon Fried , Lukasz Majewski References: <20221212152945.1870385-1-lusus@denx.de> From: Marek Vasut In-Reply-To: <20221212152945.1870385-1-lusus@denx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 12/12/22 16:29, Niel Fourie wrote: > In eth_halt(), reread and revalidate priv after calling stop(), > as it may have been freed, leaving a dangling pointer. > > 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 > Cc: Ramon Fried > Cc: Marek Vasut > Cc: Lukasz Majewski > --- > Changes for v2: > - Revalidate priv instead of changing state before stop() > - Added explanational comment > > This patch my be dropped if the patch which addresses the root cause > ("usb: gadget: ether: split start/stop from init/halt") is accepted. > > net/eth-uclass.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/net/eth-uclass.c b/net/eth-uclass.c > index f41da4b37b3..7d5783b5cab 100644 > --- a/net/eth-uclass.c > +++ b/net/eth-uclass.c > @@ -341,8 +341,11 @@ void eth_halt(void) > priv = dev_get_uclass_priv(current); > if (!priv || !priv->running) > return; > - This shouldn't be here. > eth_get_ops(current)->stop(current); > + /* Ethernet gadget frees priv during stop, workaround until fixed... */ > + priv = dev_get_uclass_priv(current); > + if (!priv || !priv->running) > + return; > priv->state = ETH_STATE_PASSIVE; > priv->running = false; > } My understanding of discussion in [PATCH] usb: gadget: ether: split start/stop from init/halt is that this patch is not needed with the aforementioned one applied.