]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
bpf, sockhash: Fix memory leak when unlinking sockets in sock_hash_free
authorJakub Sitnicki <jakub@cloudflare.com>
Sun, 7 Jun 2020 20:52:28 +0000 (22:52 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 9 Jun 2020 17:59:04 +0000 (10:59 -0700)
commit33a7c831565c43a7ee2f38c7df4c4a40e1dfdfed
tree4fc699753e28804774c573e851794ef7c8acc1b5
parent487082fb7bd2a32b66927d2b22e3a81b072b44f0
bpf, sockhash: Fix memory leak when unlinking sockets in sock_hash_free

When sockhash gets destroyed while sockets are still linked to it, we will
walk the bucket lists and delete the links. However, we are not freeing the
list elements after processing them, leaking the memory.

The leak can be triggered by close()'ing a sockhash map when it still
contains sockets, and observed with kmemleak:

  unreferenced object 0xffff888116e86f00 (size 64):
    comm "race_sock_unlin", pid 223, jiffies 4294731063 (age 217.404s)
    hex dump (first 32 bytes):
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      81 de e8 41 00 00 00 00 c0 69 2f 15 81 88 ff ff  ...A.....i/.....
    backtrace:
      [<00000000dd089ebb>] sock_hash_update_common+0x4ca/0x760
      [<00000000b8219bd5>] sock_hash_update_elem+0x1d2/0x200
      [<000000005e2c23de>] __do_sys_bpf+0x2046/0x2990
      [<00000000d0084618>] do_syscall_64+0xad/0x9a0
      [<000000000d96f263>] entry_SYSCALL_64_after_hwframe+0x49/0xb3

Fix it by freeing the list element when we're done with it.

Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200607205229.2389672-2-jakub@cloudflare.com
net/core/sock_map.c