Skip to content

Commit 9974d37

Browse files
liujian56borkmann
authored andcommitted
skmsg: Fix invalid last sg check in sk_msg_recvmsg()
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: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Liu Jian <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent edb2c34 commit 9974d37

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/skmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
462462

463463
if (copied == len)
464464
break;
465-
} while (i != msg_rx->sg.end);
465+
} while (!sg_is_last(sge));
466466

467467
if (unlikely(peek)) {
468468
msg_rx = sk_psock_next_msg(psock, msg_rx);
@@ -472,7 +472,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
472472
}
473473

474474
msg_rx->sg.start = i;
475-
if (!sge->length && msg_rx->sg.start == msg_rx->sg.end) {
475+
if (!sge->length && sg_is_last(sge)) {
476476
msg_rx = sk_psock_dequeue_msg(psock);
477477
kfree_sk_msg(msg_rx);
478478
}

0 commit comments

Comments
 (0)