Skip to content

Commit 4fcfdfb

Browse files
jrfastabborkmann
authored andcommitted
bpf: sockmap, fix double page_put on ENOMEM error in redirect path
In the case where the socket memory boundary is hit the redirect path returns an ENOMEM error. However, before checking for this condition the redirect scatterlist buffer is setup with a valid page and length. This is never unwound so when the buffers are released latter in the error path we do a put_page() and clear the scatterlist fields. But, because the initial error happens before completing the scatterlist buffer we end up with both the original buffer and the redirect buffer pointing to the same page resulting in duplicate put_page() calls. To fix this simply move the initial configuration of the redirect scatterlist buffer below the sock memory check. Found this while running TCP_STREAM test with netperf using Cilium. Fixes: fa24669 ("bpf: sockmap, BPF_F_INGRESS flag for BPF_SK_SKB_STREAM_VERDICT") Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent e20f733 commit 4fcfdfb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/bpf/sockmap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,6 @@ static int bpf_tcp_ingress(struct sock *sk, int apply_bytes,
524524
i = md->sg_start;
525525

526526
do {
527-
r->sg_data[i] = md->sg_data[i];
528-
529527
size = (apply && apply_bytes < md->sg_data[i].length) ?
530528
apply_bytes : md->sg_data[i].length;
531529

@@ -536,6 +534,7 @@ static int bpf_tcp_ingress(struct sock *sk, int apply_bytes,
536534
}
537535

538536
sk_mem_charge(sk, size);
537+
r->sg_data[i] = md->sg_data[i];
539538
r->sg_data[i].length = size;
540539
md->sg_data[i].length -= size;
541540
md->sg_data[i].offset += size;

0 commit comments

Comments
 (0)