Skip to content

Shut down the socket in homa_sock_destroy if close didn't - #136

Open
Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/sock-destroy-unlink
Open

Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/sock-destroy-unlink

Conversation

@Stuartwastaken

Copy link
Copy Markdown
Contributor

homa_socket links a new socket into the socktab, but since 2e848bd only homa_sock_shutdown (via homa_close) unlinks it. When inet_create fails after ->init, which is what happens when a cgroup BPF_CGROUP_INET_SOCK_CREATE program rejects the socket (net/ipv4/af_inet.c), it cleans up with sk_common_release, which calls ->destroy and ->unhash but never ->close. The socket is then freed while its homa_sock_link is still in the socktab, so homa_timer's socktab scan, homa_sock_find and homa_socktab_destroy read and refcount freed memory. It needs a deny program to be attached to the caller's cgroup; after that, any process in that cgroup can leave a stale entry with a single socket() call.

This calls homa_sock_shutdown at the start of homa_sock_destroy. It returns immediately when the socket is already shut down, so the normal close path doesn't change. The new homa_sock_destroy__unlink_socket test creates a socket and calls only homa_sock_destroy: without the fix, homa_sock_find still returns the socket, and AddressSanitizer reports a use-after-return in homa_socktab_fill_scan during teardown. With it, all 885 unit tests and the smoke tests pass.

* Since 2e848bd only homa_sock_shutdown unlinks a socket from the
  socktab. If inet_create fails after homa_socket (for example, a cgroup
  BPF program rejects the new socket), it calls only sk_common_release,
  so the freed socket stayed in the socktab, where homa_timer reads it
  on every tick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant