-
Notifications
You must be signed in to change notification settings - Fork 181
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
--filter-track-skb can track skbs re-built from veth_convert_skb_to_xdp_buff #391
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…dp_buff When XDP is attached to a veth, skbs will be consumed and re-created on that veth. This is done in the function veth_convert_skb_to_xdp_buff(): ``` // drivers/net/veth.c static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, struct xdp_buff *xdp, struct sk_buff **pskb) { struct sk_buff *skb = *pskb; [...] nskb = build_skb(page_address(page), PAGE_SIZE); [...] skb_copy_header(nskb, skb); [...] consume_skb(skb); skb = nskb; [...] } ``` This causes problems for pwru --filter-track-skb because of the new skb addresses. I ran into a lot of situations where I lost track of NAT-ed traffic at veth when cilium kind cluster is created by "kind.sh --xdp". This patch allows pwru to keep track of the new skbs at XDP-attached veth devices. Signed-off-by: gray <[email protected]>
jschwinger233
force-pushed
the
gray/track-veth-convert
branch
from
June 30, 2024 15:17
d272792
to
6feeb90
Compare
brb
approved these changes
Jul 7, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Merged
jschwinger233
added a commit
to jschwinger233/pwru
that referenced
this pull request
Jul 12, 2024
cilium#391 allows --track-skb to track new skb on veth, it relies on a map lookup to decide whether to track or not: ``` SEC("kprobe/veth_convert_skb_to_xdp_buff") int kprobe_veth_convert_skb_to_xdp_buff(struct pt_regs *ctx) { [...] u64 skb_head = (u64) BPF_CORE_READ(skb, head); if (bpf_map_lookup_elem(&skb_heads, &skb_head)) { [...] } return BPF_OK; } ``` However, when --track-skb-by-stackid is used along with --track-skb, the tracked skbs have risks not being recorded in skb_heads map. This is because: 1. cilium#384 no more updates skb_heads map when track reason is "by_stackid". 2. cilium#339 changes --track-skb from tracking &skb to tracking skb->head. So imagine an skb whose original skb->head = 0xa, whose value is updated to 0xb after a while. The first time pwru sees this skb, skb_heads map will insert 0xa entry. However, after skb->head is set to 0xb, pwru sees the skb being tracked due to "by_stackid", we won't insert 0xb entry into skb_heads map. Then when the skb is on veth, we can't find an entry by looking up 0xb from skb_heads map, ending up with losing track of veth skb again. This patch fixes the issue by raising the priority of track_by_filter: if an skb can be defined as tracked_by_filter and tracked_by_stackid, use tracked_by_filter over tracked_by_stackid. Another issue cilium#339 brings about is, an skb can have multiple skb->head stored in skb_heads map during its lifetime, but we only clean the latest value at kprobe_skb_lifetime_termination. This issue is beyond this patch. Signed-off-by: gray <[email protected]>
jschwinger233
added a commit
to jschwinger233/pwru
that referenced
this pull request
Jul 12, 2024
cilium#391 allows --track-skb to track new skb on veth, it relies on a map lookup to decide whether to track or not: ``` SEC("kprobe/veth_convert_skb_to_xdp_buff") int kprobe_veth_convert_skb_to_xdp_buff(struct pt_regs *ctx) { [...] u64 skb_head = (u64) BPF_CORE_READ(skb, head); if (bpf_map_lookup_elem(&skb_heads, &skb_head)) { [...] } return BPF_OK; } ``` However, when --track-skb-by-stackid is used along with --track-skb, the tracked skbs have risks not being recorded in skb_heads map. This is because: 1. cilium#384 no more updates skb_heads map when track reason is "by_stackid". 2. cilium#339 changes --track-skb from using &skb to skb->head. So imagine an skb whose original skb->head = 0xa, the value is updated to 0xb after a while. The first time pwru sees this skb, skb_heads map will insert 0xa entry, this is correct. However, after skb->head being set to 0xb, pwru will verdict the skb of being tracked due to "by_stackid", we end up not inserting 0xb entry into skb_heads map. Then the skb reaches veth, pwru can't find an entry by looking up 0xb from skb_heads map, we are losing track of veth skb again. This patch fixes the issue by raising the priority of track_by_filter: if an skb can be defined as both tracked_by_filter and tracked_by_stackid, use tracked_by_filter over tracked_by_stackid. Another issue cilium#339 brings about is, an skb can have multiple skb->head stored in skb_heads map during its lifetime, but we only clean the latest value at kprobe_skb_lifetime_termination. This issue is beyond this patch. Signed-off-by: gray <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When XDP is attached to a veth, skbs will be consumed and re-created on that veth. This is done in the function veth_convert_skb_to_xdp_buff():
This causes problems for pwru --filter-track-skb because of the new skb addresses. I ran into a lot of situations where I lost track of NAT-ed traffic at veth when cilium kind cluster is created by "kind.sh --xdp".
This patch allows pwru to keep track of the new skbs at XDP-attached veth devices.