]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: mctp: handle skb cleanup on sock_queue failures
authorJeremy Kerr <jk@codeconstruct.com.au>
Wed, 18 Dec 2024 03:53:01 +0000 (11:53 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:29:57 +0000 (13:29 +0100)
commit6c6f477f64563fdc7cf09f52d927c73317b4c721
tree4ce770b78c918d24789d9047a482efd0fc3fe869
parent116b937eb4bb62d0421236124de206742fe8c00b
net: mctp: handle skb cleanup on sock_queue failures

[ Upstream commit ce1219c3f76bb131d095e90521506d3c6ccfa086 ]

Currently, we don't use the return value from sock_queue_rcv_skb, which
means we may leak skbs if a message is not successfully queued to a
socket.

Instead, ensure that we're freeing the skb where the sock hasn't
otherwise taken ownership of the skb by adding checks on the
sock_queue_rcv_skb() to invoke a kfree on failure.

In doing so, rather than using the 'rc' value to trigger the
kfree_skb(), use the skb pointer itself, which is more explicit.

Also, add a kunit test for the sock delivery failure cases.

Fixes: 4a992bbd3650 ("mctp: Implement message fragmentation & reassembly")
Cc: stable@vger.kernel.org
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://patch.msgid.link/20241218-mctp-next-v2-1-1c1729645eaa@codeconstruct.com.au
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/mctp/route.c