Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3278378iob; Mon, 16 May 2022 17:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL1eaGicyAFoKMyDnCrKe/pkWlm/IZquPzbYr2wSeZIMdumLQmljyukWDCSpA7+7Ff8cPf X-Received: by 2002:a05:6402:390b:b0:42a:acb3:bb5 with SMTP id fe11-20020a056402390b00b0042aacb30bb5mr9793813edb.236.1652749120953; Mon, 16 May 2022 17:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652749120; cv=none; d=google.com; s=arc-20160816; b=j8l8wSoHtUyFb5jGgIkZH/BWdlgDyPR9/zQnaFnx0tLzYk1SQmlordWLtTZObU8RjE 6RO+0XUUqsyMyTCU03HfKBKfhEfvmKdKnjYlFN1yOYLiI0OcpDkYs+GizGQjHS5NmCc1 4WRAHh0KmITORNbzrQgfq0pVDLjZ0hHlQvBTIYf1OCdphXn0kcq3+IL2MWWQUqsraBN+ 1EggKr3c8mevl5bYU2qIKYhLaBo7U5sxaKW3FQ03CVfGKMBpljvuYVk7FyD4aGSpEq98 h0yYUp7zHZ2Tg/iqLCXKOBp6Afa+czrl2O9hLO4yEb1P71rP6eUY9KNh20L34nphz8NS CtBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7CZq3hZYksppdDWgTVpFNGCIzx7bFivF2Uc84vgJukI=; b=SJn6HTzmj7RS6Z7K36AvtZn3CKS/dD2jtFxNycEPKQ8/BC/xdNaq8UR1o+dQGQ8dnb crrtYr/DWtu4wzwZdabETrPcVebunqOuBBMt5bOrSkfU9toACJSmA9hLzOsmPqJfHoQs cJeKeTZniUXsSGodko9Jn1jI9UscLpE9YO12d0UyGejKXlYSAhhPgAzVfgCOL86hcEjk 57FQjIueT/Ywby72ARbKweZvBWF4/AKRaeJb4va5Hv3b6GyiBTzSu2AUWtX0bdVEesBY /qpzfiaxjdkBg0nCZjC1vlofYJjhy05JX6BI3PadpuMzSclTCNl8fND59PWogwBIh6RD MJBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nhXd5sUX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id do2-20020a170906c10200b006e7bf1f2e41si986268ejc.628.2022.05.16.17.58.15; Mon, 16 May 2022 17:58:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nhXd5sUX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233161AbiEPUKv (ORCPT + 99 others); Mon, 16 May 2022 16:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347544AbiEPT5z (ORCPT ); Mon, 16 May 2022 15:57:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D3642EF2; Mon, 16 May 2022 12:49:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 71A2B60ABE; Mon, 16 May 2022 19:49:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E154C385AA; Mon, 16 May 2022 19:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730575; bh=k/5VGV2x40AoixLUsfvacPeVCkHLS+UHpXnvrAZCHTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nhXd5sUXeuPw+T/a8gQxFLlPyM7iA4pGZ5Ryhtv2aAPaygdbSxFWGHE7wruU88LZO pOhVr5moHuW5DPai+dd3yZJnqfu1Z/bN6FCnwM2sEhtlQoPGG8P1MXxrJ/dg+Dzl1P gONlNJKWpKipGrTUoz+j1QiHoks2TjiaJwQ1PhDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Habets , Taehee Yoo , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 041/102] net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe() Date: Mon, 16 May 2022 21:36:15 +0200 Message-Id: <20220516193625.180192763@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taehee Yoo [ Upstream commit 1fa89ffbc04545b7582518e57f4b63e2a062870f ] In the NIC ->probe() callback, ->mtd_probe() callback is called. If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too. In the ->mtd_probe(), which is efx_ef10_mtd_probe() it allocates and initializes mtd partiion. But mtd partition for sfc is shared data. So that allocated mtd partition data from last called efx_ef10_mtd_probe() will not be used. Therefore it must be freed. But it doesn't free a not used mtd partition data in efx_ef10_mtd_probe(). kmemleak reports: unreferenced object 0xffff88811ddb0000 (size 63168): comm "systemd-udevd", pid 265, jiffies 4294681048 (age 348.586s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmalloc_order_trace+0x19/0x120 [] __kmalloc+0x20e/0x250 [] efx_ef10_mtd_probe+0x11f/0x270 [sfc] [] efx_pci_probe.cold.17+0x3df/0x53d [sfc] [] local_pci_probe+0xdc/0x170 [] pci_device_probe+0x235/0x680 [] really_probe+0x1c2/0x8f0 [] __driver_probe_device+0x2ab/0x460 [] driver_probe_device+0x4a/0x120 [] __driver_attach+0x16e/0x320 [] bus_for_each_dev+0x110/0x190 [] bus_add_driver+0x39e/0x560 [] driver_register+0x18e/0x310 [] 0xffffffffc02e2055 [] do_one_initcall+0xc3/0x450 [] do_init_module+0x1b4/0x700 Acked-by: Martin Habets Fixes: 8127d661e77f ("sfc: Add support for Solarflare SFC9100 family") Signed-off-by: Taehee Yoo Link: https://lore.kernel.org/r/20220512054709.12513-1-ap420073@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/sfc/ef10.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index e7e2223aebbf..f5a4d8f4fd11 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -3579,6 +3579,11 @@ static int efx_ef10_mtd_probe(struct efx_nic *efx) n_parts++; } + if (!n_parts) { + kfree(parts); + return 0; + } + rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); fail: if (rc) -- 2.35.1