Skip to content

Conversation

kobrineli
Copy link
Contributor

@kobrineli kobrineli commented May 7, 2025

Fixes: #3712

Description

Currently Tetragon parses ip address as only ipv4 or ipv6, while all ipv4 address can be used as ipv6 in ::ffff:X.X.X.X form.
In Go IP.To4() method works correctly if the address have such form, so Tetragon will add this address only in IPv4 map.
Later, when this address is used with AF_INET6, Tetragon BPF code will try to use only ipv6 map, leading to false positive event.

To fix this, we need to add ipv4 address in both ipv4 and ipv6 maps in case the original string contains colon (meaning IPv4-mapped form).

Changelog

tracingpolicy: support IPv4-mapped IPv6 address form in selectors.

@kobrineli kobrineli requested a review from a team as a code owner May 7, 2025 14:05
@kobrineli kobrineli requested a review from kkourt May 7, 2025 14:05
@kobrineli
Copy link
Contributor Author

With this fix policy from the issue works correctly:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "tcp-connect"
spec:
  kprobes:
    - call: "tcp_connect"
      syscall: false
      args:
        - index: 0
          type: "sock"
      selectors:
        - matchArgs:
            - index: 0
              operator: "NotDAddr"
              values:
                - 127.0.0.1
                - ::1
                - ::ffff:127.0.0.1

@kobrineli
Copy link
Contributor Author

@kkourt
Hi! Could you look at these changes, please?

@kobrineli kobrineli force-pushed the issue-3712/ipv4-in-ipv6-form-support branch from ec2af8f to a4f73c0 Compare May 7, 2025 14:15
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks, the change makes sense to me but I believe the implementation could be improved.

CC: @kevsecurity

Copy link

netlify bot commented May 9, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 2f5d19f
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/681def6a2ba77600084db00c
😎 Deploy Preview https://deploy-preview-3714--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kobrineli
Copy link
Contributor Author

@kkourt
Hi! Thanks for the review. I've made adjustments but with some changes.
Moreover, I've noticed that my original proposal had a flaw: in case of invalid ipv4 address, if the original string didn't contain colon, err6 would remain nil and the error wouldn't be returned.

Added unit tests, covering every case of the function.

@kkourt
Copy link
Contributor

kkourt commented May 9, 2025

@kkourt Hi! Thanks for the review. I've made adjustments but with some changes. Moreover, I've noticed that my original proposal had a flaw: in case of invalid ipv4 address, if the original string didn't contain colon, err6 would remain nil and the error wouldn't be returned.

Added unit tests, covering every case of the function.

Thanks!

Can you please squash the changes from my feedback into the relevant original commits? (git rebase --interactive using the squash and fixup actions should help). if you want, feel free to keep the unit test in a separate patch but if you opt to do so please add a descriptive commit message.

Also, once done, please force-push the new branch and notify the reviewers by clicking on the github button "Re-request review".

Thanks!

1

@kobrineli kobrineli force-pushed the issue-3712/ipv4-in-ipv6-form-support branch from 56af3c5 to f5c87bb Compare May 9, 2025 13:09
@kobrineli kobrineli requested a review from kkourt May 9, 2025 13:09
@kobrineli kobrineli force-pushed the issue-3712/ipv4-in-ipv6-form-support branch from f5c87bb to aa97cf4 Compare May 9, 2025 13:23
@kobrineli
Copy link
Contributor Author

@kkourt
Done

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great to me!

Please find a minor comment below.

@kobrineli kobrineli force-pushed the issue-3712/ipv4-in-ipv6-form-support branch from aa97cf4 to 613ad51 Compare May 12, 2025 08:51
@kobrineli kobrineli requested a review from kkourt May 12, 2025 08:51
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

I kicked off the CI as well. Assuming everything's green I'll merge the PR when the CI is done.

@kkourt kkourt added the release-note/minor This PR introduces a minor user-visible change label May 12, 2025
@kobrineli
Copy link
Contributor Author

@kkourt
Hi! Could you restart CI, please?
Errors don't seem to be related to PR changes.

@kkourt
Copy link
Contributor

kkourt commented May 13, 2025

@kkourt Hi! Could you restart CI, please? Errors don't seem to be related to PR changes.

The errors keep happening, even though I agree that they do not seem to be related. Would need to investigate fruther.
I created an issue #3732 for this. CC: @tpapagian

IPv4 addresses can be represented in IPv6 form as
`::ffff:X.X.X.X` and may be used during connections with
address family AF_INET6.

This patch supports ipv4-mapped ipv6 address by using `netip`
for parsing addresses, which parses ipv4-mapped addresses correctly.

Fixes: cilium#3712
Signed-off-by: Kobrin Ilay <[email protected]>
@kobrineli kobrineli force-pushed the issue-3712/ipv4-in-ipv6-form-support branch from 613ad51 to bb742ff Compare May 13, 2025 12:44
@kobrineli
Copy link
Contributor Author

@kkourt @kevsecurity
Changed parseAddr method to make it use netip.ParseAddr and net.ParseCIDR methods, now it looks much better.
Unit tests for IPv4-mapped IPv6 address pass successfully.

@kobrineli kobrineli requested a review from kevsecurity May 13, 2025 12:47
Copy link
Contributor

@kevsecurity kevsecurity left a comment

Choose a reason for hiding this comment

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

Yep, that looks much better.

@kevsecurity kevsecurity merged commit 792590e into cilium:main May 13, 2025
0 of 3 checks passed
@kevsecurity
Copy link
Contributor

Thanks. I hit merge as @kkourt had previously approved, and I wasn't sure if you have merge permissions.

@kobrineli
Copy link
Contributor Author

I don't, thanks!

@kkourt
Copy link
Contributor

kkourt commented May 13, 2025

Thanks. I hit merge as @kkourt had previously approved, and I wasn't sure if you have merge permissions.

There were some CI issues that I was hoping to resolve before merging the PR.
And it seems that the CI never finished after the new changes were pushed (or maybe I'm missing something?)

@kevsecurity
Copy link
Contributor

Thanks. I hit merge as @kkourt had previously approved, and I wasn't sure if you have merge permissions.

There were some CI issues that I was hoping to resolve before merging the PR. And it seems that the CI never finished after the new changes were pushed (or maybe I'm missing something?)

Sorry. It looked complete here, except with quay failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR introduces a minor user-visible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NotDAddr filter error with ::ffff:127.0.0.1
3 participants