Skip to contentSkip to conversation

bpf: allow CGROUP_SKB programs to use bpf_get_current_cgroup_id() helper

PATCH In review Roman Gushchin 2 participants 5 messages Jun 6, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: allow CGROUP_SKB programs to use bpf_get_current_cgroup_id() helper

Currently bpf_get_current_cgroup_id() is not supported for CGROUP_SKB programs. An attempt to load such a program generates an error like this:

    libbpf:
    0: (b7) r6 = 0
    ...
    8: (63) *(u32 *)(r10 -28) = r6
    9: (85) call bpf_get_current_cgroup_id#80
    unknown func bpf_get_current_cgroup_id#80

There are no particular reasons for denying it, and we have some use cases where it might be useful.

So let's add it to the list of allowed helpers.

Cc Yonghong Song <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 net/core/filter.c | 4 ++++
 1 file changed, 4 insertions(+)
net/core/filter.c +4 -0
index 55bfc941d17a..19724bb1860d 100644
@@ -5919,6 +5919,10 @@ cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_sk_storage_get_proto;
 	case BPF_FUNC_sk_storage_delete:
 		return &bpf_sk_storage_delete_proto;
+#ifdef CONFIG_CGROUPS
+	case BPF_FUNC_get_current_cgroup_id:
+		return &bpf_get_current_cgroup_id_proto;
+#endif
 #ifdef CONFIG_INET
 	case BPF_FUNC_tcp_sock:
 		return &bpf_tcp_sock_proto;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Roman Gushchin

Currently bpf_get_current_cgroup_id() is not supported for CGROUP_SKB programs. An attempt to load such a program generates an error like this:

    libbpf:
    0: (b7) r6 = 0
    ...
    8: (63) *(u32 *)(r10 -28) = r6
    9: (85) call bpf_get_current_cgroup_id#80
    unknown func bpf_get_current_cgroup_id#80
Quoted 2 lines

There are no particular reasons for denying it, and we have some use cases where it might be useful.

Ah, sorry, it's not so simple, as we probably need to take the cgroup pointer from the socket, not from current.

So the implementation of the helper should be different for this type of programs.

So I wonder if it's better to introduce a new helper bpf_get_sock_cgroup_id()?

What do you think?

Thanks!

maintainer
#2 lore raw
Quoted 17 lines · Roman Gushchin
Quoted 10 lines · Roman Gushchin

Currently bpf_get_current_cgroup_id() is not supported for CGROUP_SKB programs. An attempt to load such a program generates an error like this:

    libbpf:
    0: (b7) r6 = 0
    ...
    8: (63) *(u32 *)(r10 -28) = r6
    9: (85) call bpf_get_current_cgroup_id#80
    unknown func bpf_get_current_cgroup_id#80
Quoted 2 lines

There are no particular reasons for denying it, and we have some use cases where it might be useful.

Ah, sorry, it's not so simple, as we probably need to take the cgroup pointer from the socket, not from current.

Quoted 7 lines

So the implementation of the helper should be different for this type of programs.

So I wonder if it's better to introduce a new helper bpf_get_sock_cgroup_id()?

What do you think?

We do have bpf_skb_cgroup_id(), did you give that a try?

Thanks,
Daniel

#3 lore raw
Quoted 21 lines · Daniel Borkmann
Quoted 20 lines · Roman Gushchin
Quoted 10 lines · Roman Gushchin

Currently bpf_get_current_cgroup_id() is not supported for CGROUP_SKB programs. An attempt to load such a program generates an error like this:

    libbpf:
    0: (b7) r6 = 0
    ...
    8: (63) *(u32 *)(r10 -28) = r6
    9: (85) call bpf_get_current_cgroup_id#80
    unknown func bpf_get_current_cgroup_id#80
Quoted 2 lines

There are no particular reasons for denying it, and we have some use cases where it might be useful.

Ah, sorry, it's not so simple, as we probably need to take the cgroup pointer from the socket, not from current.

So the implementation of the helper should be different for this type of programs.

Quoted 6 lines
Quoted 4 lines

So I wonder if it's better to introduce a new helper bpf_get_sock_cgroup_id()?

What do you think?

We do have bpf_skb_cgroup_id(), did you give that a try?

It also isn't supported for CGROUP_SKB, but other than that looks exactly what I need.

Thank you for pointing at it!

maintainer
#4 lore raw
Quoted 25 lines · Roman Gushchin
Quoted 24 lines · Daniel Borkmann
Quoted 23 lines · Roman Gushchin
Quoted 10 lines · Roman Gushchin

Currently bpf_get_current_cgroup_id() is not supported for CGROUP_SKB programs. An attempt to load such a program generates an error like this:

    libbpf:
    0: (b7) r6 = 0
    ...
    8: (63) *(u32 *)(r10 -28) = r6
    9: (85) call bpf_get_current_cgroup_id#80
    unknown func bpf_get_current_cgroup_id#80
Quoted 2 lines

There are no particular reasons for denying it, and we have some use cases where it might be useful.

Ah, sorry, it's not so simple, as we probably need to take the cgroup pointer from the socket, not from current.

So the implementation of the helper should be different for this type of programs.

So I wonder if it's better to introduce a new helper bpf_get_sock_cgroup_id()?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

What do you think?

We do have bpf_skb_cgroup_id(), did you give that a try?

It also isn't supported for CGROUP_SKB, but other than that looks exactly what I need.

Thank you for pointing at it!

Yes, the helper would need to be enabled there.

Cheers,
Daniel