Skip to content

feat(uprobes): add Go string parsing and inline modification#4817

Draft
dwindsor wants to merge 7 commits intocilium:mainfrom
dwindsor:dwindsor/clear-go-string-action
Draft

feat(uprobes): add Go string parsing and inline modification#4817
dwindsor wants to merge 7 commits intocilium:mainfrom
dwindsor:dwindsor/clear-go-string-action

Conversation

@dwindsor
Copy link
Copy Markdown
Contributor

@dwindsor dwindsor commented Mar 31, 2026

Fixes #4827

Description

With the pclntab changes being merged, we now can write policies that target stripped Go binaries. The problem is, pclntab doesn't contain function signature metadata, only function location data (offset + size).

This series adds support for the go_string type and the ClearGoString Action to TracingPolicy. It requires a fairly complicated descent into the Go ABI internals, but I think the ABI has been stable enough for a while (since 1.17) to make this safe. Basically, since we have the function start location from pclntab, we just need to be able to isolate go string parameters, which are stored as a ([word][u32]) tuple (data_ptr+len). The new Go ABI (ABIInternal) is register based, with predictable slot assignments for types that haven't changed since 1.17. We go:generate the ABI slot mapping at build time, so no hard-coding.

 With this, we can use 7384893 (bpf: Allow uprobe program to change context registers) to add the ClearGoString action to go_string parameters that contain suspicious (i.e. SQL injection, environment var leak, malicious AI prompt) strings.  We don't return early here, we just make the string inert by clearing it, allowing the application to handle cleanup etc. It's difficult to return from non-LSM functions (lsm gives a lot of guarantees - locks held, refcounts guaranteed, etc).

Changelog

@dwindsor dwindsor requested a review from a team as a code owner March 31, 2026 18:49
@dwindsor dwindsor requested a review from kevsecurity March 31, 2026 18:49
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 4 times, most recently from b6e596e to 08528fe Compare March 31, 2026 19:34
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 522ea58
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69d667da3a9d9f0008ce2265
😎 Deploy Preview https://deploy-preview-4817--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 project configuration.

@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 2 times, most recently from 9893e14 to 276ab1c Compare March 31, 2026 19:40
@dwindsor dwindsor changed the title feat/uprobes: add Go string parsing and inline modification feat(uprobes): add Go string parsing and inline modification Mar 31, 2026
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 6 times, most recently from dacb94e to 1ecce4f Compare April 1, 2026 04:06
@dwindsor
Copy link
Copy Markdown
Contributor Author

dwindsor commented Apr 1, 2026

vmtests CI failing due to a verifier error on < 6.12, will fix:

❌ pkg.sensors.tracing.TestUprobeGoStringArg

@mtardy mtardy marked this pull request as draft April 3, 2026 16:01
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 6 times, most recently from d3f7dfa to 39ff357 Compare April 6, 2026 16:54
@dwindsor
Copy link
Copy Markdown
Contributor Author

dwindsor commented Apr 6, 2026

vmtests failing on kernels that don't have bpf_copy_from_user_str

424: (85) call unknown#233685214
invalid func unknown#233685214

Gating go_string support on the presence of bpf_copy_from_user_str.

@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 5 times, most recently from f6985b1 to f20dd45 Compare April 6, 2026 17:19
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch from f20dd45 to 435797e Compare April 6, 2026 17:20
@dwindsor dwindsor marked this pull request as ready for review April 6, 2026 18:39
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch from 435797e to 522ea58 Compare April 8, 2026 14:36
@dwindsor dwindsor marked this pull request as draft April 8, 2026 15:44
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch 3 times, most recently from 82e20e4 to 4f2fe41 Compare April 8, 2026 17:18
dwindsor added 5 commits April 8, 2026 13:23
Map logical argument indices to physical register slots under Go's
ABIInternal calling convention on amd64. Multi-slot types shift
subsequent arguments into higher registers. This is needed to extract
the correct argument from uprobes attached to Go functions.

Signed-off-by: David Windsor <dwindsor@gmail.com>
Wire the go_string generic type through BPF preload and event config.

Signed-off-by: David Windsor <dwindsor@gmail.com>
Expose go_string in the tracing API, generic types, and sensor path.

Signed-off-by: David Windsor <dwindsor@gmail.com>
Bump CRD schema and docs for the new go_string type.

Signed-off-by: David Windsor <dwindsor@gmail.com>
Add a small Go program and uprobe test that exercises go_string capture
on net/http.ServeContent.

Signed-off-by: David Windsor <dwindsor@gmail.com>
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch from 4f2fe41 to 1e7b5b7 Compare April 8, 2026 17:26
dwindsor added 2 commits April 8, 2026 13:32
Add a post action that clears only the Go string length register. Strings are stored
as [ptr,len] tuples in Go. We only zero len here because it's possible to do atomically
with a single aligned word-size write. Zeroing the ptr field would require another
write which cannot be performed atomically with respect to the clearing of the len field.

With len cleared to zero the header matches how the runtime treats empty results from
[]byte-to-string conversion: slicebytetostring returns "" when n==0 without reading ptr
(https://github.com/golang/go/blob/go1.24.0/src/runtime/string.go#L132-L137).

Signed-off-by: David Windsor <dwindsor@gmail.com>
Extend ActionSelector validation and generated CRD/docs for the
ClearGoString action.

Signed-off-by: David Windsor <dwindsor@gmail.com>
@dwindsor dwindsor force-pushed the dwindsor/clear-go-string-action branch from 1e7b5b7 to ae9e972 Compare April 8, 2026 17:33
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.

Unable to write policies against Go string function args

1 participant