Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: really only enforce bind rejection when in hostns #11210

Merged
merged 1 commit into from Apr 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions bpf/bpf_sock.c
Expand Up @@ -322,7 +322,7 @@ static __always_inline int __sock4_post_bind(struct bpf_sock *ctx,
.dport = ctx_src_port(ctx),
};

if (!sock_proto_enabled(ctx->protocol))
if (!sock_proto_enabled(ctx->protocol) || !ctx_in_hostns(ctx_full))
return 0;

svc = lb4_lookup_service(&key);
Expand All @@ -332,8 +332,7 @@ static __always_inline int __sock4_post_bind(struct bpf_sock *ctx,
* (without remote hosts).
*/
key.dport = ctx_src_port(ctx);
svc = sock4_nodeport_wildcard_lookup(&key, false,
ctx_in_hostns(ctx_full));
svc = sock4_nodeport_wildcard_lookup(&key, false, true);
}

/* If the sockaddr of this socket overlaps with a NodePort
Expand Down Expand Up @@ -595,16 +594,15 @@ static __always_inline int __sock6_post_bind(struct bpf_sock *ctx)
.dport = ctx_src_port(ctx),
};

if (!sock_proto_enabled(ctx->protocol))
if (!sock_proto_enabled(ctx->protocol) || !ctx_in_hostns(ctx))
return 0;

ctx_get_v6_src_address(ctx, &key.address);

svc = lb6_lookup_service(&key);
if (!svc) {
key.dport = ctx_src_port(ctx);
svc = sock6_nodeport_wildcard_lookup(&key, false,
ctx_in_hostns(ctx));
svc = sock6_nodeport_wildcard_lookup(&key, false, true);
if (!svc)
return sock6_post_bind_v4_in_v6(ctx);
}
Expand Down