]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: fix a memleak when uncloning an skb dst and its metadata
authorAntoine Tenart <atenart@kernel.org>
Mon, 7 Feb 2022 17:13:19 +0000 (18:13 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Feb 2022 11:44:51 +0000 (12:44 +0100)
commitc1ff27d100e2670b03cbfddb9117e5f9fc672540
treed0e1e4f2a9a98fa518c9fabeb12f3bb068c4f068
parent39a269fbb80a9e905818d332aebe6651fd7a1ee9
net: fix a memleak when uncloning an skb dst and its metadata

[ Upstream commit 9eeabdf17fa0ab75381045c867c370f4cc75a613 ]

When uncloning an skb dst and its associated metadata, a new
dst+metadata is allocated and later replaces the old one in the skb.
This is helpful to have a non-shared dst+metadata attached to a specific
skb.

The issue is the uncloned dst+metadata is initialized with a refcount of
1, which is increased to 2 before attaching it to the skb. When
tun_dst_unclone returns, the dst+metadata is only referenced from a
single place (the skb) while its refcount is 2. Its refcount will never
drop to 0 (when the skb is consumed), leading to a memory leak.

Fix this by removing the call to dst_hold in tun_dst_unclone, as the
dst+metadata refcount is already 1.

Fixes: fc4099f17240 ("openvswitch: Fix egress tunnel info.")
Cc: Pravin B Shelar <pshelar@ovn.org>
Reported-by: Vlad Buslov <vladbu@nvidia.com>
Tested-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/dst_metadata.h