Commit 9047f19e authored by John Fastabend's avatar John Fastabend Committed by Alexei Starovoitov

bpf, sockmap: Remove dropped data on errors in redirect case

In the sk_skb redirect case we didn't handle the case where we overrun
the sk_rmem_alloc entry on ingress redirect or sk_wmem_alloc on egress.
Because we didn't have anything implemented we simply dropped the skb.
This meant data could be dropped if socket memory accounting was in
place.

This fixes the above dropped data case by moving the memory checks
later in the code where we actually do the send or recv. This pushes
those checks into the workqueue and allows us to return an EAGAIN error
which in turn allows us to try again later from the workqueue.

Fixes: 51199405 ("bpf: skb_verdict, support SK_PASS on RX BPF path")
Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160226863689.5692.13861422742592309285.stgit@john-Precision-5820-Tower
parent 29545f49
...@@ -433,10 +433,12 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb) ...@@ -433,10 +433,12 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb, static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb,
u32 off, u32 len, bool ingress) u32 off, u32 len, bool ingress)
{ {
if (ingress) if (!ingress) {
return sk_psock_skb_ingress(psock, skb); if (!sock_writeable(psock->sk))
else return -EAGAIN;
return skb_send_sock_locked(psock->sk, skb, off, len); return skb_send_sock_locked(psock->sk, skb, off, len);
}
return sk_psock_skb_ingress(psock, skb);
} }
static void sk_psock_backlog(struct work_struct *work) static void sk_psock_backlog(struct work_struct *work)
...@@ -709,30 +711,28 @@ static void sk_psock_skb_redirect(struct sk_buff *skb) ...@@ -709,30 +711,28 @@ static void sk_psock_skb_redirect(struct sk_buff *skb)
{ {
struct sk_psock *psock_other; struct sk_psock *psock_other;
struct sock *sk_other; struct sock *sk_other;
bool ingress;
sk_other = tcp_skb_bpf_redirect_fetch(skb); sk_other = tcp_skb_bpf_redirect_fetch(skb);
/* This error is a buggy BPF program, it returned a redirect
* return code, but then didn't set a redirect interface.
*/
if (unlikely(!sk_other)) { if (unlikely(!sk_other)) {
kfree_skb(skb); kfree_skb(skb);
return; return;
} }
psock_other = sk_psock(sk_other); psock_other = sk_psock(sk_other);
/* This error indicates the socket is being torn down or had another
* error that caused the pipe to break. We can't send a packet on
* a socket that is in this state so we drop the skb.
*/
if (!psock_other || sock_flag(sk_other, SOCK_DEAD) || if (!psock_other || sock_flag(sk_other, SOCK_DEAD) ||
!sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) { !sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) {
kfree_skb(skb); kfree_skb(skb);
return; return;
} }
ingress = tcp_skb_bpf_ingress(skb);
if ((!ingress && sock_writeable(sk_other)) ||
(ingress &&
atomic_read(&sk_other->sk_rmem_alloc) <=
sk_other->sk_rcvbuf)) {
skb_queue_tail(&psock_other->ingress_skb, skb); skb_queue_tail(&psock_other->ingress_skb, skb);
schedule_work(&psock_other->work); schedule_work(&psock_other->work);
} else {
kfree_skb(skb);
}
} }
static void sk_psock_tls_verdict_apply(struct sk_buff *skb, int verdict) static void sk_psock_tls_verdict_apply(struct sk_buff *skb, int verdict)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment