From patchwork Wed Feb 12 08:23:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bastien Curutchet (eBPF Foundation)" X-Patchwork-Id: 13971360 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 3BFC8204F73; Wed, 12 Feb 2025 08:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739348642; cv=none; b=d9WdP1sO9Rl+gyCrlDgSeSQTKajC/xVmXQp2QXSFUsiZ6a4Lpz+1EqIxwyLHvvG6XDuRrf3FTAbQQdARUBUhl4Z8djEH1l8veZFWeVgWIj6hYogi+sR1KOQ7cwYi+kiIgj5x63I2mtPfSinX0Umy9RT3YLDDgeRlqvARA7FvrLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739348642; c=relaxed/simple; bh=LpaPWoiB+g2dZg4RH65TksDMWJxJR2hl7G8gp/2a+JQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iSuu5/2B6yuuDs9afz0ALHvxCQvzi3zZMCA5b5Xl/pGoIaNPO4lA8/805AaNRt0sfj1pRkRBs+juRtNkErwDY8Hq8AaQFSwdWYMLZt9syVQqTADt9f85SFqQQgd5FqFQFO2Jn/P4R4vUyPsvf2RgXdD/+UVP/8GCjxEzPARhdeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Mkim0CQx; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Mkim0CQx" Received: by mail.gandi.net (Postfix) with ESMTPSA id C1D2543289; Wed, 12 Feb 2025 08:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739348631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tMNmo27RCKq+NidQSuiZLt0mDuPz+SlkNdNrtjuqQ1w=; b=Mkim0CQx1ffL8Tkbj0lZvahivBWaWVOicx/icr+g9hyjzNWg16sFjP+sticyJmDFkDHtZt YhdZY9tafwnZaR4Hkgblm/6eYDRejoht9+B2BpitWM7kH5nNQsYIMf41jlgHhF/3cc5vQm OXfxLykWydq+WTnXLAuNqzRssWgA/3ulCZLiL0w9/EGiMrL07D3DgdBpaK1md4UMoADK0W NDSvlvKozqse6xxWbrRqSqFCh2PABA0yf+yx6oEwL0w8hUC1Na5VLE9DNYdQB0wyQ55ooR JFBp5Gs5alewRIALE74+TDgygrIR/bIAoXr3CiiCJ4mwCdxdpuNAT5YnVqv1yw== From: "Bastien Curutchet (eBPF Foundation)" Date: Wed, 12 Feb 2025 09:23:47 +0100 Subject: [PATCH net 1/2] rtnetlink: Fix rtnl_net_cmp_locks() when DEBUG is off Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250212-rtnetlink_leak-v1-1-27bce9a3ac9a@bootlin.com> References: <20250212-rtnetlink_leak-v1-0-27bce9a3ac9a@bootlin.com> In-Reply-To: <20250212-rtnetlink_leak-v1-0-27bce9a3ac9a@bootlin.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Nikolay Aleksandrov , Kuniyuki Iwashima Cc: Alexis Lothore , Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (eBPF Foundation)" , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegfeeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpedfuegrshhtihgvnhcuvehurhhuthgthhgvthculdgvuefrhfcuhfhouhhnuggrthhiohhnmddfuceosggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepgeefudfhuedttdeiffetffeljeffkeevveeiuddtgeejleeftdejgedtjedttdfhnecukfhppeeltddrkeelrdduieefrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledtrdekledrudeifedruddvjedphhgvlhhopegludelvddrudeikedrgedvrdehgegnpdhmrghilhhfrhhomhepsggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudefpdhrtghpthhtohepnhgvthguvghvsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhunhhihihusegrmhgriihonhdrtghomhdprhgtphhtthhopehprggsvghnihesrhgvughhrghtrdgtohhmpdhrtghpthhtohepsggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhin hdrtghomhdprhgtphhtthhopehsthgrsghlvgesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhohhrmhhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmrgiivghtsehgohhoghhlvgdrtghomh X-GND-Sasl: bastien.curutchet@bootlin.com X-Patchwork-Delegate: kuba@kernel.org rtnl_net_cmp_locks() always returns -1 if CONFIG_DEBUG_NET_SMALL_RTNL is disabled. However, if CONFIG_DEBUG_NET_SMALL_RTNL is enabled, it returns 0 when both inputs are equal. It is then used by rtnl_nets_add() to call put_net() if the net to be added is already present in the struct rtnl_nets. As a result, when rtnl_nets_add() is called on an already present net, put_net() is called only if DEBUG is on. Add the input comparison in the DEBUG off case so that put_net() is always called in this scenario. Fixes: cbaaa6326bc5 ("rtnetlink: Introduce struct rtnl_nets and helpers.") Cc: stable@vger.kernel.org Signed-off-by: Bastien Curutchet (eBPF Foundation) --- net/core/rtnetlink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index cb7fad8d1f95ff287810229c341de6a6d20a9c07..94111d3383788566f2296039e68549e2b40d5a4a 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -275,6 +275,9 @@ EXPORT_SYMBOL(lockdep_rtnl_net_is_held); #else static int rtnl_net_cmp_locks(const struct net *net_a, const struct net *net_b) { + if (net_eq(net_a, net_b)) + return 0; + /* No need to swap */ return -1; } From patchwork Wed Feb 12 08:23:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bastien Curutchet (eBPF Foundation)" X-Patchwork-Id: 13971361 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 E01E927183A; Wed, 12 Feb 2025 08:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739348642; cv=none; b=mLgy3F2Wjit/6l/pzL1pqmWY5WSpWiZbRdw66DVjLYtPLHmwqX0o80JExSh+t0i7ctPIQBYw3fCShXQ/8WT1xbZfEddUjIISpAK3z9lS1YitDD5+Gfe0kLupdmD+H7uz15uL10990o7SIJiBeCcL7SKZpvzhAB6oHYSfXJTxC04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739348642; c=relaxed/simple; bh=d0rMPfnONv/9V88xXXShYjjqNokK2s86RyuUEgMmcI0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZIEol5acXlp+umQC4dBNBCR9nC19bDULZsODwt1khU4U1TrgmlL07b5Jb3HY4AE2Cp4irEBjegQqiDmGubnvcGODy2P6m+WM3smhepkoOVMQgMgsAqb+MJu4TpKmlnNP7fg5wpfMyWKnhBA2augPYvmW7s1j9ERT8QN1Ggw6llg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=SzsOk28V; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="SzsOk28V" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7E51D4328E; Wed, 12 Feb 2025 08:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739348632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RR2/+YTVmAUHPpKBQsKq78NYGWJcAyMxsNjAeG/knP4=; b=SzsOk28V8Ypgm0NnAD52AU2GxIBtbWOEXyQS/dJYPFwn9LVPqnA8XfXFsJtAUcBCAkPsp5 KKnZ8itnI5uvJHTxKK7w2+IUAywMcCyy7IS/mZI7Yhe4snIoB+4MkDdBd9pTWg+B1szRPJ tGyxtKzwFSr7FceHFyn3HidLDqIlFZAyOHK+27ZFrYJm1qydnw45m4ayCDfdXDc27PT9U6 j7nnddQxUX8QX09nfrFDC6HRuudDVpDLw+55mQzbbGvPjOpKC7fl8bUBos39qcsXRySOzk RHP1sVBGYgJmnqBfbjn/ZkIJNQG6Jclh8b7pKwiZKi8KVn1/oeEVo+/I4ZkGkw== From: "Bastien Curutchet (eBPF Foundation)" Date: Wed, 12 Feb 2025 09:23:48 +0100 Subject: [PATCH net 2/2] rtnetlink: Release nets when leaving rtnl_setlink() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250212-rtnetlink_leak-v1-2-27bce9a3ac9a@bootlin.com> References: <20250212-rtnetlink_leak-v1-0-27bce9a3ac9a@bootlin.com> In-Reply-To: <20250212-rtnetlink_leak-v1-0-27bce9a3ac9a@bootlin.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Nikolay Aleksandrov , Kuniyuki Iwashima Cc: Alexis Lothore , Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (eBPF Foundation)" , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegfeeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpedfuegrshhtihgvnhcuvehurhhuthgthhgvthculdgvuefrhfcuhfhouhhnuggrthhiohhnmddfuceosggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepgeefudfhuedttdeiffetffeljeffkeevveeiuddtgeejleeftdejgedtjedttdfhnecukfhppeeltddrkeelrdduieefrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledtrdekledrudeifedruddvjedphhgvlhhopegludelvddrudeikedrgedvrdehgegnpdhmrghilhhfrhhomhepsggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudefpdhrtghpthhtohepnhgvthguvghvsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhunhhihihusegrmhgriihonhdrtghomhdprhgtphhtthhopehprggsvghnihesrhgvughhrghtrdgtohhmpdhrtghpthhtohepsggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhin hdrtghomhdprhgtphhtthhopehsthgrsghlvgesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhohhrmhhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmrgiivghtsehgohhoghhlvgdrtghomh X-GND-Sasl: bastien.curutchet@bootlin.com X-Patchwork-Delegate: kuba@kernel.org rtnl_setlink() uses the rtnl_nets_* helpers but never calls the rtnl_nets_destroy(). It leads to small memory leaks. Call rtnl_nets_destroy() before exiting to properly decrement the nets' reference counters. Fixes: 636af13f213b ("rtnetlink: Register rtnl_dellink() and rtnl_setlink() with RTNL_FLAG_DOIT_PERNET_WIP.") Cc: stable@vger.kernel.org Signed-off-by: Bastien Curutchet (eBPF Foundation) --- net/core/rtnetlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 94111d3383788566f2296039e68549e2b40d5a4a..e4ac14c081a48e36f5381e025a3991c90827c2bf 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3441,6 +3441,7 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, rtnl_nets_unlock(&rtnl_nets); errout: + rtnl_nets_destroy(&rtnl_nets); return err; }