Skip to content

Commit 3cc9a47

Browse files
jrfastabAlexei Starovoitov
authored andcommitted
bpf: sockmap, fix scatterlist update on error path in send with apply
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 <[email protected]> Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0f58e58 commit 3cc9a47

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/sockmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,16 @@ static int bpf_tcp_push(struct sock *sk, int apply_bytes,
326326
if (ret > 0) {
327327
if (apply)
328328
apply_bytes -= ret;
329+
330+
sg->offset += ret;
331+
sg->length -= ret;
329332
size -= ret;
330333
offset += ret;
331334
if (uncharge)
332335
sk_mem_uncharge(sk, ret);
333336
goto retry;
334337
}
335338

336-
sg->length = size;
337-
sg->offset = offset;
338339
return ret;
339340
}
340341

0 commit comments

Comments
 (0)