Skip to content

bpf: prevent cluster ID from being incorrectly retrieved from mark when aliased#43258

Merged
giorio94 merged 2 commits intocilium:mainfrom
giorio94:mio/bpf-cluster-id-mark-2
Dec 11, 2025
Merged

bpf: prevent cluster ID from being incorrectly retrieved from mark when aliased#43258
giorio94 merged 2 commits intocilium:mainfrom
giorio94:mio/bpf-cluster-id-mark-2

Conversation

@giorio94
Copy link
Copy Markdown
Member

Please refer to the individual commits for additional details.

Set the backport/affect labels coherently with #42551 and #43159.

The `ctx_get_cluster_id_mark` helper function allows to retrieve the
cluster ID stored inside of `skb->mark`, and it does so after having
checked the magic part, to prevent reading it from unrelated data.
However, the check incorrectly uses `MARK_MAGIC_CLUSTER_ID` as mask,
hence potentially misinterpreting other partially overlapping magic
values (e.g., `MARK_MAGIC_IDENTITY`) as matching as well.

Let's get this fixed by checking that the magic part exactly matches
`MARK_MAGIC_CLUSTER_ID`, and update the corresponding setter function
to override the entire mark content, similarly to what `set_identity_mark`
also does.

Fixes: 9ef6388 ("bpf: Add helper functions to transfer ClusterID with mark")
Fixes: 5313b0d ("bpf: clear mark content before storing the cluster ID")
Suggested-by: Julian Wiedmann <jwi@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 requested a review from a team as a code owner December 11, 2025 09:35
@giorio94 giorio94 added area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. affects/v1.16 This issue affects v1.16 branch affects/v1.17 This issue affects v1.17 branch needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch labels Dec 11, 2025
@giorio94 giorio94 marked this pull request as draft December 11, 2025 09:37
@giorio94 giorio94 force-pushed the mio/bpf-cluster-id-mark-2 branch from 12a1ce5 to f86ecc1 Compare December 11, 2025 09:40
@giorio94 giorio94 marked this pull request as ready for review December 11, 2025 09:46
@giorio94
Copy link
Copy Markdown
Member Author

/test

Copy link
Copy Markdown
Member

@julianwiedmann julianwiedmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes make sense to me, thank you! Just that one little nit to address.

I feel like set_identity_mark() and ctx_set_cluster_id_mark() are converging more & more. But the bit-shift forest is too deep for me to have confidence in how it might be unified.

@giorio94
Copy link
Copy Markdown
Member Author

I feel like set_identity_mark() and ctx_set_cluster_id_mark() are converging more & more. But the bit-shift forest is too deep for me to have confidence in how it might be unified.

Agree, that's unfortunately fairly convoluted and difficult to reason about. And yep, there's probably room for unifying the logic constructing the cluster ID related part of the mark, which matches in both cases.

@giorio94 giorio94 force-pushed the mio/bpf-cluster-id-mark-2 branch from 9b0405a to 8c37ac9 Compare December 11, 2025 10:05
Currently, the `ctx_get_cluster_id_mark` helper function partially
resets the content of `skb->mark` after having retrieved the cluster
ID value. However, this is potentially misleading, and does not match
the behavior of the other getter functions. Hence, let's remove the
explicit cleanup step, and let subsequent setter calls (e.g., of
`set_identity_mark`) to take care of resetting it.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the mio/bpf-cluster-id-mark-2 branch from 8c37ac9 to 149626c Compare December 11, 2025 10:14
@giorio94
Copy link
Copy Markdown
Member Author

/test

@julianwiedmann julianwiedmann added the area/clustermesh Relates to multi-cluster routing functionality in Cilium. label Dec 11, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Dec 11, 2025
@giorio94 giorio94 added this pull request to the merge queue Dec 11, 2025
Merged via the queue into cilium:main with commit f2feafa Dec 11, 2025
75 checks passed
@giorio94 giorio94 deleted the mio/bpf-cluster-id-mark-2 branch December 11, 2025 13:18
@kaworu kaworu mentioned this pull request Dec 12, 2025
7 tasks
@kaworu kaworu added the backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. label Dec 12, 2025
@kaworu kaworu removed the needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch label Dec 12, 2025
@github-actions github-actions bot added backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. and removed backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. labels Dec 17, 2025
@cilium-release-bot cilium-release-bot bot moved this to Released in cilium v1.19.0 Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects/v1.16 This issue affects v1.16 branch affects/v1.17 This issue affects v1.17 branch area/clustermesh Relates to multi-cluster routing functionality in Cilium. area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.

Projects

No open projects
Status: Released

Development

Successfully merging this pull request may close these issues.

4 participants