]> git.baikalelectronics.ru Git - kernel.git/commit
rxrpc: Fix an insufficiently large sglist in rxkad_verify_packet_2()
authorDavid Howells <dhowells@redhat.com>
Wed, 24 Aug 2022 21:39:28 +0000 (22:39 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 10:04:55 +0000 (12:04 +0200)
commit57d504029721c1d1ce1613c1459ad5d174405c0a
treefa7d6368372cf217b7e2e22cb0a74546217a4b5d
parent022fa48710aeecba4478f91308a1ca0f93031f90
rxrpc: Fix an insufficiently large sglist in rxkad_verify_packet_2()

[ Upstream commit e78450df9cec0103b572695cdbfc92f2c486cf56 ]

rxkad_verify_packet_2() has a small stack-allocated sglist of 4 elements,
but if that isn't sufficient for the number of fragments in the socket
buffer, we try to allocate an sglist large enough to hold all the
fragments.

However, for large packets with a lot of fragments, this isn't sufficient
and we need at least one additional fragment.

The problem manifests as skb_to_sgvec() returning -EMSGSIZE and this then
getting returned by userspace.  Most of the time, this isn't a problem as
rxrpc sets a limit of 5692, big enough for 4 jumbo subpackets to be glued
together; occasionally, however, the server will ignore the reported limit
and give a packet that's a lot bigger - say 19852 bytes with ->nr_frags
being 7.  skb_to_sgvec() then tries to return a "zeroth" fragment that
seems to occur before the fragments counted by ->nr_frags and we hit the
end of the sglist too early.

Note that __skb_to_sgvec() also has an skb_walk_frags() loop that is
recursive up to 24 deep.  I'm not sure if I need to take account of that
too - or if there's an easy way of counting those frags too.

Fix this by counting an extra frag and allocating a larger sglist based on
that.

Fixes: fab10f15f7d3 ("rxrpc: Use skb_unshare() rather than skb_cow_data()")
Reported-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-afs@lists.infradead.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/rxrpc/rxkad.c