Skip to content

Commit 4363023

Browse files
jrfastabborkmann
authored andcommitted
bpf, sockmap: Avoid failures from skb_to_sgvec when skb has frag_list
When skb has a frag_list its possible for skb_to_sgvec() to fail. This happens when the scatterlist has fewer elements to store pages than would be needed for the initial skb plus any of its frags. This case appears rare, but is possible when running an RX parser/verdict programs exposed to the internet. Currently, when this happens we throw an error, break the pipe, and kfree the msg. This effectively breaks the application or forces it to do a retry. Lets catch this case and handle it by doing an skb_linearize() on any skb we receive with frags. At this point skb_to_sgvec should not fail because the failing conditions would require frags to be in place. Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> Link: https://lore.kernel.org/bpf/160556576837.73229.14800682790808797635.stgit@john-XPS-13-9370
1 parent 2443ca6 commit 4363023

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

net/core/skmsg.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,16 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
423423
struct sock *sk,
424424
struct sk_msg *msg)
425425
{
426-
int num_sge = skb_to_sgvec(skb, msg->sg.data, 0, skb->len);
427-
int copied;
426+
int num_sge, copied;
428427

428+
/* skb linearize may fail with ENOMEM, but lets simply try again
429+
* later if this happens. Under memory pressure we don't want to
430+
* drop the skb. We need to linearize the skb so that the mapping
431+
* in skb_to_sgvec can not error.
432+
*/
433+
if (skb_linearize(skb))
434+
return -EAGAIN;
435+
num_sge = skb_to_sgvec(skb, msg->sg.data, 0, skb->len);
429436
if (unlikely(num_sge < 0)) {
430437
kfree(msg);
431438
return num_sge;

0 commit comments

Comments
 (0)