]> git.baikalelectronics.ru Git - kernel.git/commit
skmsg: Fix invalid last sg check in sk_msg_recvmsg()
authorLiu Jian <liujian56@huawei.com>
Tue, 28 Jun 2022 12:36:16 +0000 (20:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:30 +0000 (14:23 +0200)
commit74a198920dff3c6f2d1d9c879bb77f4492b994c7
tree597509fb7f65bccaa022efc94b891d0f65e27dd6
parent2ad986a2b042e9d995093197181a695031c4d38f
skmsg: Fix invalid last sg check in sk_msg_recvmsg()

[ Upstream commit 2307767bbc55092907aa69f52c0180c140fbae26 ]

In sk_psock_skb_ingress_enqueue function, if the linear area + nr_frags +
frag_list of the SKB has NR_MSG_FRAG_IDS blocks in total, skb_to_sgvec
will return NR_MSG_FRAG_IDS, then msg->sg.end will be set to
NR_MSG_FRAG_IDS, and in addition, (NR_MSG_FRAG_IDS - 1) is set to the last
SG of msg. Recv the msg in sk_msg_recvmsg, when i is (NR_MSG_FRAG_IDS - 1),
the sk_msg_iter_var_next(i) will change i to 0 (not NR_MSG_FRAG_IDS), the
judgment condition "msg_rx->sg.start==msg_rx->sg.end" and
"i != msg_rx->sg.end" can not work.

As a result, the processed msg cannot be deleted from ingress_msg list.
But the length of all the sge of the msg has changed to 0. Then the next
recvmsg syscall will process the msg repeatedly, because the length of sge
is 0, the -EFAULT error is always returned.

Fixes: 38506f4bbc9d ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Liu Jian <liujian56@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220628123616.186950-1-liujian56@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/skmsg.c