From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69B53EB64D8 for ; Wed, 14 Jun 2023 14:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245648AbjFNO6r (ORCPT ); Wed, 14 Jun 2023 10:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245239AbjFNO6p (ORCPT ); Wed, 14 Jun 2023 10:58:45 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5CBA1FC2; Wed, 14 Jun 2023 07:58:44 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f8d258f203so6443375e9.1; Wed, 14 Jun 2023 07:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686754723; x=1689346723; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=cwHOEAiF9KfcpBV2FsuQGv04SjS1N5o4UGAs/GJkRIM=; b=HrgN3iTZqEJnZ+cWUam2y0hNTwU7zJQIh+PO2OOD1V0dKK6Day4ODu61szESSCbcVg 8nECpsSl57fgDUiNVhyWExWfwOKMrDojt4Mw2EyAgDm4RLWeRScrIYMlERBFgZySiuMy VDg6BE6FvUSGBzdoOT0k7Wqa+gHrrXVM8hMTARr4fL7mY9IDKASQrP+ub1K5Z2OBGKtp 4k4F3SzICfcZg1djHXBtey23xFNDUyAmIaTa9P/ssQe7DlCGSz8nsJl1mUnGYyIyBJ+N /yFNP9kWASak6rO6lZ/d5e+a7Js7yLeG685kqdZnQpSz3zMP7SPknRbe426IrgA9UEPa cZMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686754723; x=1689346723; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cwHOEAiF9KfcpBV2FsuQGv04SjS1N5o4UGAs/GJkRIM=; b=lBeh4DM6ydGyxlaol739nMQtQFEGXyoP9toWo3g6Kuy2LjDSK4H69RHhbAfA4NRfdD NVCp3S96qgb9zKrFqHmrbqeo6noq95qs14S+OburfM4gMQ+rGu/pBOoHOOWDnN5aFKQe W0E//gFJSJ7k6JrJydS5kB/vUMlXqSR6BtCQyZaJKT7O3Lir7G1gvLhA87P7Edgjagc8 fsfO7tYSbDQdK6diY+px26K6Mjk12IXr11UrbUA+gxMSu37EISeoYP8fsxoXiomJZ1XI kIB4/pCP/W8K+ppzLIKh1rrjdIhvmiap55I3bWbUWVZq129iY6yZ8rN4GtvpD6Iy5Ubw ywxQ== X-Gm-Message-State: AC+VfDxzVDMV62aTwsy1LlIxiTXk9OxPlUcO3X9Owu7N6yHz9V+fcwSO 5tqN7iIq2grDiWhJ/vbGenE= X-Google-Smtp-Source: ACHHUZ42J+w43AeCv+jIRznzv9mpK6x3YnnHigR05cUDdfxwPzyO8LQJ2mQRRGGDh7MzUrt4gXUKKQ== X-Received: by 2002:a1c:6a18:0:b0:3f6:a966:ee8d with SMTP id f24-20020a1c6a18000000b003f6a966ee8dmr9847496wmc.26.1686754722830; Wed, 14 Jun 2023 07:58:42 -0700 (PDT) Received: from Ansuel-xps. (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.gmail.com with ESMTPSA id p11-20020a1c740b000000b003f733c1129fsm17703302wmc.33.2023.06.14.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 07:58:42 -0700 (PDT) Message-ID: <6489d5a2.1c0a0220.c53b2.acb0@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 14 Jun 2023 10:18:20 +0200 From: Christian Marangi To: Simon Horman Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jose Abreu , stable@vger.kernel.org Subject: Re: [net PATCH] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open References: <20230614073241.6382-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Wed, Jun 14, 2023 at 04:55:10PM +0200, Simon Horman wrote: > On Wed, Jun 14, 2023 at 09:32:41AM +0200, Christian Marangi wrote: > > Fix a possible memory leak in __stmmac_open when stmmac_init_phy fails. > > It's also needed to free everything allocated by stmmac_setup_dma_desc > > and not just the dma_conf struct. > > > > Correctly call free_dma_desc_resources on the new dma_conf passed to > > __stmmac_open on error. > > > > Reported-by: Jose Abreu > > Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") > > Signed-off-by: Christian Marangi > > Cc: stable@vger.kernel.org > > --- > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > index fa07b0d50b46..0966ab86fde2 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > @@ -3877,10 +3877,10 @@ static int __stmmac_open(struct net_device *dev, > > > > stmmac_hw_teardown(dev); > > init_error: > > - free_dma_desc_resources(priv, &priv->dma_conf); > > phylink_disconnect_phy(priv->phylink); > > init_phy_error: > > pm_runtime_put(priv->device); > > + free_dma_desc_resources(priv, dma_conf); > > Hi Christian, > > Are these resources allocated by the caller? > If so, perhaps it would be clearer if a symmetric approach > was taken and the caller handled freeing them on error. > Yes, they are. Handling in the caller would require some additional delta to this and some duplicated code but if preferred I can implement it. I can provide a v2 shortly if it's ok and you prefer this implementation. > > return ret; > > } > > > > -- > > 2.40.1 > > > > -- Ansuel From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A2A7EB64D8 for ; Wed, 14 Jun 2023 14:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ImQHv5vAdcd+txCqTZygtfs9mgypxDVY5KSojrmIDH8=; b=lBxpYHyEIBHf9p AMX5s6ZufkoX/atIqU8EI6Z3+av1VHTIciGHYZiCKqCAUmhpB1zV+Fe9a9fwIcoksHrhaMBHBvApx alepZ4ILxvsJndhTLsXB+UzaNjwJW0w6l1T7YkzLmz+G1F0FYPzemnfKrRtfd4AenbQZr0iUfGBFL cBEwq4lnrt3ZHnWN5WUIyqI2MJiDJFlbnp6wrcVAu9rttoclba8YoHb5rPSB8vkehKX+1F/oRBorZ hd9jOLdluBhB8qpiGRF8y3v9AYCEjTtvv/hpXlXteVqtskaiNYrzghJniMPj0XEmtz/6LQDJMsGkX IKl1WusN969gfu46+eQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9RxP-00Bym6-2B; Wed, 14 Jun 2023 14:58:47 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9RxN-00BykK-0y for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2023 14:58:46 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f738f579ceso6412645e9.3 for ; Wed, 14 Jun 2023 07:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686754723; x=1689346723; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=cwHOEAiF9KfcpBV2FsuQGv04SjS1N5o4UGAs/GJkRIM=; b=HrgN3iTZqEJnZ+cWUam2y0hNTwU7zJQIh+PO2OOD1V0dKK6Day4ODu61szESSCbcVg 8nECpsSl57fgDUiNVhyWExWfwOKMrDojt4Mw2EyAgDm4RLWeRScrIYMlERBFgZySiuMy VDg6BE6FvUSGBzdoOT0k7Wqa+gHrrXVM8hMTARr4fL7mY9IDKASQrP+ub1K5Z2OBGKtp 4k4F3SzICfcZg1djHXBtey23xFNDUyAmIaTa9P/ssQe7DlCGSz8nsJl1mUnGYyIyBJ+N /yFNP9kWASak6rO6lZ/d5e+a7Js7yLeG685kqdZnQpSz3zMP7SPknRbe426IrgA9UEPa cZMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686754723; x=1689346723; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cwHOEAiF9KfcpBV2FsuQGv04SjS1N5o4UGAs/GJkRIM=; b=ZxpZh9GJvx4Hyti0aul1jtP+xOxv8Km0Z/m7fzyPOSndYp/ICRdKpLwUiq8YM+fwu4 hmGTGREXOZ6EX65DqjnBLIKcU3XJSfnqRcd4e1gz2wyXZIs6CWn42zpsfRKN+Nzvj/qu 4/ixe/UERls4oiSX/qk6BbEqS/wBez0fmjKESW0l9VdtmwEUbDIFR18/A3tWEWc+RcnP VuqpCGBnwhcn3+5PF12aEYgqqY241f9xGti23nQVRMx0R7oOcwKoisDk5yTGAq6zcRbi H3TOpjS7fr2bsS1RUE6clCyR2pYhs2OgL2t6qWD1zmWfktft/WLq6EqreFSza+er5YW8 Wr2A== X-Gm-Message-State: AC+VfDyeH0lGgp7kla72WaI3vA2vsKzl6MQ+rTM9NlpS8RrIBCSTmWCS IV0fOeHIJRMFf3vgaJORtT4= X-Google-Smtp-Source: ACHHUZ42J+w43AeCv+jIRznzv9mpK6x3YnnHigR05cUDdfxwPzyO8LQJ2mQRRGGDh7MzUrt4gXUKKQ== X-Received: by 2002:a1c:6a18:0:b0:3f6:a966:ee8d with SMTP id f24-20020a1c6a18000000b003f6a966ee8dmr9847496wmc.26.1686754722830; Wed, 14 Jun 2023 07:58:42 -0700 (PDT) Received: from Ansuel-xps. (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.gmail.com with ESMTPSA id p11-20020a1c740b000000b003f733c1129fsm17703302wmc.33.2023.06.14.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 07:58:42 -0700 (PDT) Message-ID: <6489d5a2.1c0a0220.c53b2.acb0@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 14 Jun 2023 10:18:20 +0200 From: Christian Marangi To: Simon Horman Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jose Abreu , stable@vger.kernel.org Subject: Re: [net PATCH] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open References: <20230614073241.6382-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230614_075845_339696_6EBD0DD9 X-CRM114-Status: GOOD ( 24.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jun 14, 2023 at 04:55:10PM +0200, Simon Horman wrote: > On Wed, Jun 14, 2023 at 09:32:41AM +0200, Christian Marangi wrote: > > Fix a possible memory leak in __stmmac_open when stmmac_init_phy fails. > > It's also needed to free everything allocated by stmmac_setup_dma_desc > > and not just the dma_conf struct. > > > > Correctly call free_dma_desc_resources on the new dma_conf passed to > > __stmmac_open on error. > > > > Reported-by: Jose Abreu > > Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") > > Signed-off-by: Christian Marangi > > Cc: stable@vger.kernel.org > > --- > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > index fa07b0d50b46..0966ab86fde2 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > @@ -3877,10 +3877,10 @@ static int __stmmac_open(struct net_device *dev, > > > > stmmac_hw_teardown(dev); > > init_error: > > - free_dma_desc_resources(priv, &priv->dma_conf); > > phylink_disconnect_phy(priv->phylink); > > init_phy_error: > > pm_runtime_put(priv->device); > > + free_dma_desc_resources(priv, dma_conf); > > Hi Christian, > > Are these resources allocated by the caller? > If so, perhaps it would be clearer if a symmetric approach > was taken and the caller handled freeing them on error. > Yes, they are. Handling in the caller would require some additional delta to this and some duplicated code but if preferred I can implement it. I can provide a v2 shortly if it's ok and you prefer this implementation. > > return ret; > > } > > > > -- > > 2.40.1 > > > > -- Ansuel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel