From patchwork Wed Mar 12 01:03:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14012796 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F35518489 for ; Wed, 12 Mar 2025 01:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741741451; cv=none; b=XzsSxx2ZlzwdQfLeMeiooG+x/yhtK305qW5IL24dYRJTtBAIBCnmZaPfuGk4BiXpnx8L+khD570+taeLYPF4Z59o9p0qVvW489usF7Y35N6LlnzyL4TPKW4lTVLjoDdA0PLLoWRVLJAH4MDBnNGUzVTcMM38ig3u8tRvIiLNbeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741741451; c=relaxed/simple; bh=0DemGm/GRp20nBQIJW5eZyJqYT/ZCXelIbc4URK3eeo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OKz/JdZB6DkW+gmvwIXFZs4HYIsN+JPAj9NdN4/Thrl84dt3PNelQ0k3TcU7WLocESJX2z4fsa2CQLMYKL0rVSilrJPr9Kgfvux7s8V1GepYSrKjAoFwhFCHrKNoXf+bKPElXZphd6TI97vRUgnFDZFUO1CYVao2R9bfhtgXFUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=WiD50KkK; arc=none smtp.client-ip=52.119.213.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="WiD50KkK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1741741450; x=1773277450; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=B0Ui0wlWCBovpErHd9Be/SbR9FmP5/5nPkref8SycdA=; b=WiD50KkKkNaV1TcRoyDssSN4a5gCjPvOqZUpz5p0V5Y3G0LA3H3urVXW 1Q79Ihbvwtj7LAyw+VfUt+KIcRAgFB6iOgbLDQCUxXXE83x9+Jm4TsKpc 20o5Sn81DjsavssGhzTFgpZ0a4xwH518ZvPMLMVTF4+WpDqBsBpa+Yk5J 0=; X-IronPort-AV: E=Sophos;i="6.14,240,1736812800"; d="scan'208";a="704278589" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2025 01:03:46 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.38.20:53765] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.22.127:2525] with esmtp (Farcaster) id 523e9f49-9597-462f-ab90-eb1c905c1155; Wed, 12 Mar 2025 01:03:44 +0000 (UTC) X-Farcaster-Flow-ID: 523e9f49-9597-462f-ab90-eb1c905c1155 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 12 Mar 2025 01:03:44 +0000 Received: from 6c7e67bfbae3.amazon.com (10.88.128.133) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 12 Mar 2025 01:03:42 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net] ipv6: Fix memleak of nhc_pcpu_rth_output in fib_check_nh_v6_gw(). Date: Tue, 11 Mar 2025 18:03:25 -0700 Message-ID: <20250312010333.56001-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D037UWC002.ant.amazon.com (10.13.139.250) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org fib_check_nh_v6_gw() expects that fib6_nh_init() cleans up everything when it fails. Commit 7dd73168e273 ("ipv6: Always allocate pcpu memory in a fib6_nh") moved fib_nh_common_init() before alloc_percpu_gfp() within fib6_nh_init() but forgot to add cleanup for fib6_nh->nh_common.nhc_pcpu_rth_output in case it fails to allocate fib6_nh->rt6i_pcpu, resulting in memleak. Let's call fib_nh_common_release() and clear nhc_pcpu_rth_output in the error path. Note that we can remove the fib6_nh_release() call in nh_create_ipv6() later in net-next.git. Fixes: 7dd73168e273 ("ipv6: Always allocate pcpu memory in a fib6_nh") Signed-off-by: Kuniyuki Iwashima --- net/ipv6/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index ef2d23a1e3d5..bc6bcf5d7133 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3644,7 +3644,8 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh, in6_dev_put(idev); if (err) { - lwtstate_put(fib6_nh->fib_nh_lws); + fib_nh_common_release(&fib6_nh->nh_common); + fib6_nh->nh_common.nhc_pcpu_rth_output = NULL; fib6_nh->fib_nh_lws = NULL; netdev_put(dev, dev_tracker); }