From: John Fastabend <john.fastabend@gmail.com>
To: borkmann@iogearbox.net, ast@kernel.org
Cc: netdev@vger.kernel.org
Subject: [bpf PATCH 1/3] bpf: sockmap, fix scatterlist update on error path in send with apply
Date: Wed, 02 May 2018 10:47:27 -0700 [thread overview]
Message-ID: <20180502174727.17875.95306.stgit@john-Precision-Tower-5810> (raw)
In-Reply-To: <20180502173954.17875.19624.stgit@john-Precision-Tower-5810>
When the call to do_tcp_sendpage() fails to send the complete block
requested we either retry if only a partial send was completed or
abort if we receive a error less than or equal to zero. Before
returning though we must update the scatterlist length/offset to
account for any partial send completed.
Before this patch we did this at the end of the retry loop, but
this was buggy when used while applying a verdict to fewer bytes
than in the scatterlist. When the scatterlist length was being set
we forgot to account for the apply logic reducing the size variable.
So the result was we chopped off some bytes in the scatterlist without
doing proper cleanup on them. This results in a WARNING when the
sock is tore down because the bytes have previously been charged to
the socket but are never uncharged.
The simple fix is to simply do the accounting inside the retry loop
subtracting from the absolute scatterlist values rather than trying
to accumulate the totals and subtract at the end.
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
kernel/bpf/sockmap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 634415c..943929a 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -326,6 +326,9 @@ static int bpf_tcp_push(struct sock *sk, int apply_bytes,
if (ret > 0) {
if (apply)
apply_bytes -= ret;
+
+ sg->offset += ret;
+ sg->length -= ret;
size -= ret;
offset += ret;
if (uncharge)
@@ -333,8 +336,6 @@ static int bpf_tcp_push(struct sock *sk, int apply_bytes,
goto retry;
}
- sg->length = size;
- sg->offset = offset;
return ret;
}
next prev parent reply other threads:[~2018-05-02 17:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 17:47 [bpf PATCH 0/3] sockmap error path fixes John Fastabend
2018-05-02 17:47 ` John Fastabend [this message]
2018-05-02 18:51 ` [bpf PATCH 1/3] bpf: sockmap, fix scatterlist update on error path in send with apply David Miller
2018-05-02 17:47 ` [bpf PATCH 2/3] bpf: sockmap, zero sg_size on error when buffer is released John Fastabend
2018-05-02 18:51 ` David Miller
2018-05-02 17:47 ` [bpf PATCH 3/3] bpf: sockmap, fix error handling in redirect failures John Fastabend
2018-05-02 18:51 ` David Miller
2018-05-02 19:34 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180502174727.17875.95306.stgit@john-Precision-Tower-5810 \
--to=john.fastabend@gmail.com \
--cc=ast@kernel.org \
--cc=borkmann@iogearbox.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox