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

Add sock and skb matchArgs selectors #1008

Merged
merged 5 commits into from May 24, 2023

Conversation

kevsecurity
Copy link
Contributor

Tetragon can specify arguments of type sock and skb, but doesn't have the ability to match on these (complex) arguments. This series adds selector operators: SAddr, DAddr, SPort, DPort, and Protocol. These can be used to match on either sock or skb types. See commits for details.

@kevsecurity kevsecurity requested a review from a team as a code owner May 17, 2023 13:58
@kevsecurity kevsecurity requested a review from mtardy May 17, 2023 13:58
@kevsecurity kevsecurity force-pushed the pr/kevsecurity/add-ipv4-selectors branch 2 times, most recently from 02cd33f to 3b15e91 Compare May 17, 2023 14:05
@jrfastab
Copy link
Contributor

for the code LGTM.

@jrfastab
Copy link
Contributor

I wouldn't block this PR but MATCH_MAX_ARGS should probably be resolved at some point. One idea would be to use a read-only map and walk it with a proper for loop on newer kernels. Then you could have a map sized as large as needed to fit the args.

@kevsecurity
Copy link
Contributor Author

I wouldn't block this PR but MATCH_MAX_ARGS should probably be resolved at some point. One idea would be to use a read-only map and walk it with a proper for loop on newer kernels. Then you could have a map sized as large as needed to fit the args.

I think the solution was to put the matchargs in a hash and then look up the arg to see if it's there. I'm going to convert all matchArgs over.

@kevsecurity kevsecurity force-pushed the pr/kevsecurity/add-ipv4-selectors branch from 3b15e91 to ddcb476 Compare May 23, 2023 10:14
@netlify
Copy link

netlify bot commented May 23, 2023

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 98ff038
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/646c96edef64640008c0bc2a
😎 Deploy Preview https://deploy-preview-1008--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 settings.

@kevsecurity kevsecurity force-pushed the pr/kevsecurity/add-ipv4-selectors branch 2 times, most recently from 72de723 to 98ff038 Compare May 23, 2023 10:35
Currently we retrieve port numbers on struct sock and struct sk_buff
types in their native endianness (typically network order, but see
later). We then convert the endianness to host order (assuming host order
is little endian) in golang before printing them out. In order to
support the option to match on port numbers in BPF, we should convert
them to host order endianness (using bpf_ntohs) at the point that we read
them. In addition, while both source and dest ports in sk_buff are in
network order, the source port in struct sock is in host order, leading
to a bug where the source port was reported incorrectly.

This commit converts port numbers to host order in BPF at the point of
retrieval, and removes the endianness swap in golang.

Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
@kevsecurity kevsecurity force-pushed the pr/kevsecurity/add-ipv4-selectors branch 5 times, most recently from 72d80b7 to b01ed0e Compare May 23, 2023 17:37
Both the sock and skb types contain an IPv4 tuple. In preparation for
matching on aspects of the tuple (and for IPv6 tuples), extract the
tuple as its own type and share it across both sock and skb types.

Also, fix reading the protocol on kernels <v5.6 where the protocol field
in struct sock is 8 bits of a u32.

Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
The sock type converts the protocol number to the corresponding string
when it outputs the message. The skb type does not do this. Add the
protocol string field to the skb type (it currently has an int proto
field) and populate it.

Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Allow sock and skb argument types to match on source and destination
IPv4 address and port, and also on protocol. New operators added: SAddr,
DAddr, SPort, DPort, Protocol. Each can match multiple values.
See examples/tracingpolicy/tcp-connect.yaml and datagram.yaml for
examples.

Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Add a sock test that matches on a TCP connection to 127.0.0.1:2112 and
a skb test that matches on a UDP connection to 127.0.0.1:53.

Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
@kevsecurity kevsecurity force-pushed the pr/kevsecurity/add-ipv4-selectors branch from b01ed0e to 06bed45 Compare May 24, 2023 10:49
@kevsecurity kevsecurity merged commit 726cad0 into main May 24, 2023
21 checks passed
@kevsecurity kevsecurity deleted the pr/kevsecurity/add-ipv4-selectors branch May 24, 2023 11:49
@kevsecurity kevsecurity mentioned this pull request Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants