Skip to content

Commit 820ed3f

Browse files
jrfastabborkmann
authored andcommitted
bpf: sockmap, free memory on sock close with cork data
If a socket with pending cork data is closed we do not return the memory to the socket until the garbage collector free's the psock structure. The garbage collector though can run after the sock has completed its close operation. If this ordering happens the sock code will through a WARN_ON because there is still outstanding memory accounted to the sock. To resolve this ensure we return memory to the sock when a socket is closed. Signed-off-by: John Fastabend <[email protected]> Fixes: 91843d5 ("bpf: sockmap, add msg_cork_bytes() helper") Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 4608f06 commit 820ed3f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/bpf/sockmap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ static void bpf_tcp_close(struct sock *sk, long timeout)
211211
close_fun = psock->save_close;
212212

213213
write_lock_bh(&sk->sk_callback_lock);
214+
if (psock->cork) {
215+
free_start_sg(psock->sock, psock->cork);
216+
kfree(psock->cork);
217+
psock->cork = NULL;
218+
}
219+
214220
list_for_each_entry_safe(md, mtmp, &psock->ingress, list) {
215221
list_del(&md->list);
216222
free_start_sg(psock->sock, md);

0 commit comments

Comments
 (0)