Skip to content

Commit 9d7f6b6

Browse files
committed
Add documentation for arg.Resolve feature
Signed-off-by: Tristan d'Audibert <[email protected]>
1 parent b7a5fce commit 9d7f6b6

File tree

1 file changed

+96
-0
lines changed
  • docs/content/en/docs/concepts/tracing-policy

1 file changed

+96
-0
lines changed

Diff for: docs/content/en/docs/concepts/tracing-policy/hooks.md

+96
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,102 @@ The `maxData` flag does not work with `returnCopy` flag at the moment, so it's
400400
usable only for syscalls/functions that do not require return probe to read the
401401
data.
402402

403+
### Attribute resolution
404+
405+
This functionality allows you to dynamically extract specific attributes from
406+
kernel structures passed as parameters to Kprobes and LSM hooks.
407+
For example, when using the `bprm_check_security` LSM hook, you can access and
408+
display attributes from the parameter `struct linux_binprm *bprm` at index 0.
409+
This parameter contains many informations you may want to access.
410+
With the resolve flag, you can easily access fields such as
411+
`mm.owner.real_parent.comm`, which provides the parent process comm.
412+
413+
#### How it works
414+
415+
The following tracing policy demonstrates how to use the resolve flag to extract the
416+
parent process's comm during the execution of a binary:
417+
418+
```yaml
419+
apiVersion: cilium.io/v1alpha1
420+
kind: TracingPolicy
421+
metadata:
422+
name: "lsm"
423+
spec:
424+
lsmhooks:
425+
- hook: "bprm_check_security"
426+
args:
427+
- index: 0 # struct linux_binprm *bprm
428+
type: "string"
429+
resolve: "mm.owner.real_parent.comm"
430+
selectors:
431+
- matchActions:
432+
- action: Post
433+
```
434+
- `index` flag : The parameter at index 0 is a pointer to the
435+
`struct linux_binprm`.
436+
- `resolve` flag : Using the resolve flag, the policy extracts the
437+
`mm.owner.real_parent.comm` field, representing the parent process's comm.
438+
439+
{{< caution >}}
440+
- This feature requires you to read the kernel structure definitions to find what you're
441+
looking for in the hook parameter attributes. For instance, if you want to have a look
442+
at what is available inside `struct linux_binprm`, take a look at its definition in
443+
[include/linux/binfmts.h](https://elixir.bootlin.com/linux/v6.12.5/source/include/linux/binfmts.h#L18)
444+
- Some structures are dynamic. This means that they may change at runtime.
445+
{{< /caution >}}
446+
447+
Tetragon can also handle some structures such as `struct file` or `struct
448+
path` and a few others. This means you can also extract the whole struct, if it is
449+
available in the attributes of the parameter, and set the type with the correct type
450+
like this :
451+
452+
```yaml
453+
...
454+
lsmhooks:
455+
- hook: "bprm_check_security"
456+
args:
457+
- index: 0 # struct linux_binprm *bprm
458+
type: "file"
459+
resolve: "file"
460+
...
461+
```
462+
Or
463+
```yaml
464+
...
465+
lsmhooks:
466+
- hook: "bprm_check_security"
467+
args:
468+
- index: 0
469+
type: "path"
470+
resolve: "file.f_path"
471+
...
472+
```
473+
474+
The following tracing policy demonstrates how to use the `resolve` flag on nested
475+
pointers. For exemple, the hook `security_inode_copy_up` (defined in
476+
[security/security.c](https://elixir.bootlin.com/linux/v6.12.5/source/security/security.c#L2753))
477+
takes two parameters: `struct dentry *src` and `struct cred **new`. The resolve
478+
flag allows you to access fields within these nested structures transparently.
479+
480+
```yaml
481+
apiVersion: cilium.io/v1alpha1
482+
kind: TracingPolicy
483+
metadata:
484+
name: "lsm"
485+
spec:
486+
kprobes:
487+
- call: "security_inode_copy_up"
488+
args:
489+
- index: 0 # struct dentry *src
490+
type: "int64"
491+
- index: 1 # struct cred **new
492+
type: "int"
493+
resolve: "user.uid.val"
494+
selectors:
495+
- matchActions:
496+
- action: Post
497+
```
498+
403499
## Return values
404500

405501
A `TracingPolicy` spec can specify that the return value should be reported in

0 commit comments

Comments
 (0)