Skip to content

Kprobes Reference

Kprobes attach to kernel functions or syscall entry/return points. They are the primary collection mechanism for process execution, network activity, file access, and security-sensitive syscall monitoring. Unlike BPF LSM hooks, kprobes can run at both entry and return (via returnArg), making them suitable for capturing return values and confirming whether an operation succeeded.

Kprobes support Post (observe) and Signal (kill) actions. The Override (block) action is not supported on kprobes. It is available only on BPF LSM hooks.


Always-on baseline policies

The sensor writes and loads the following kprobe policies at startup. They are active on every node from the first heartbeat. They cannot be removed while the sensor is running; removing them would require restarting the sensor process.

Policy fileWhat it covers
telovix-network-baselineTCP connect, close, accept; UDP sendmsg
telovix-dns-uprobegetaddrinfo hostname lookups (uprobe on libc)
telovix-privilege-baselinesetuid, setgid, setreuid, setregid, setresuid, setresgid
telovix-syscall-kprobesptrace, mount, socket, chroot, chmod/fchmodat, extended attribute writes, symlink/rename to authorized_keys, seccomp, flock, process_vm_writev, ioctl(FS_IOC_SETFLAGS), setns, unshare
telovix-listen-baselineinet_listen (new listening sockets)
telovix-file-open (3 parts)sys_openat for file reads and writes to credential, config, binary, library, log, persistence, and kernel paths
telovix-security-syscallssys_kill, sys_dup2, sys_dup3, sys_mmap with PROT_EXEC, sys_capset
telovix-kmod-monitorsys_init_module, sys_finit_module, sys_delete_module
telovix-lsm-baselineBPF LSM hooks (see LSM Hooks Reference)
telovix-process-lifecyclesys_clone, sys_execveat, sys_memfd_create, sys_chdir, sys_fchdir, sys_unshare, sys_clone3

Network baseline (telovix-network-baseline)

CallsyscallKey argsEvent kindPurpose
tcp_connectfalsesock (index 0)network_connectOutbound TCP connection attempt
tcp_closefalsesock (index 0)network_flowTCP flow completion; triggers flow duration and state recording
inet_csk_acceptfalsesock (index 0)network_acceptInbound TCP connection accepted
udp_sendmsgfalsesock (index 0)dns_query or network_connectUDP send; DNS port 53/853/5353 produces dns_query, others produce network_connect
sys_sendtotruesockaddr (index 4)network_connectUDP connect via sendto with explicit destination

These hooks are kernel-level functions (syscall: false) except for sys_sendto. They use the sock type which exposes the full socket metadata including source and destination addresses.


DNS uprobe (telovix-dns-uprobe)

CallTypeArgsEvent kind
getaddrinfo (libc uprobe)uprobestring hostname (index 0), string service (index 1)dns_lookup

The uprobe attaches to getaddrinfo in the libc shared library. The libc path is architecture-specific:

  • x86_64: /lib/x86_64-linux-gnu/libc.so.6
  • aarch64: /lib/aarch64-linux-gnu/libc.so.6

This uprobe enables the sensor to correlate hostname lookups with subsequent tcp_connect events to produce dns_resolution events.


Privilege baseline (telovix-privilege-baseline)

All hooks use syscall: true and capture return values.

CallArgsEvent kindWhat it captures
sys_setuiduint32 (new UID)privilege_changeUID change; return value confirms success
sys_setgiduint32 (new GID)privilege_changeGID change
sys_setreuidint, int (real UID, effective UID)privilege_changeReal + effective UID swap
sys_setregidint, intprivilege_changeReal + effective GID swap
sys_setresuidint, int, int (real, effective, saved)privilege_changeThree-UID change
sys_setresgidint, int, intprivilege_changeThree-GID change

Syscall kprobes (telovix-syscall-kprobes)

CallKey selectorEvent kindPurpose
sys_ptraceNone (all ptrace calls)ptraceDebugger attach, trace operations
sys_setnsNonenamespace_createNamespace switch
sys_mountNone (all mounts)mountFilesystem mount
sys_socketindex 0 == 44 (AF_XDP)socket_createAF_XDP raw socket creation (kernel bypass indicator)
sys_chrootNonechrootChroot jail creation
sys_fchmodatindex 2 Mask 3072 (setuid/setgid bits)setcapSUID/SGID bit set on a file
sys_chmodindex 1 Mask 3072 (setuid/setgid bits)setcapSUID/SGID bit set
sys_setxattrNonefile_writeExtended attribute write
sys_lsetxattrNonefile_writeExtended attribute write (symlink)
sys_fsetxattrNonefile_writeExtended attribute write (fd)
sys_ioctlindex 1 == 21520 (FS_IOC_SETFLAGS, 0x5410)file_writechattr immutable flag set (suppressed for shell binaries)
sys_symlinkatindex 2 Postfix authorized_keysfile_writeSymlink targeting authorized_keys
sys_symlinkindex 1 Postfix authorized_keysfile_writeSymlink targeting authorized_keys
sys_renameat2index 3 Postfix authorized_keysfile_writeRename into authorized_keys
sys_renameatindex 3 Postfix authorized_keysfile_writeRename into authorized_keys
sys_renameindex 1 Postfix authorized_keysfile_writeRename into authorized_keys
sys_seccompindex 0 == 1 (SECCOMP_SET_MODE_FILTER)file_writeSeccomp filter installation
sys_flockindex 1 Mask 2 (exclusive lock)file_writeExclusive file lock (single-instance guard pattern)
sys_process_vm_writevNoneptraceCross-process memory write (ptrace-equivalent capability)

The sys_socket hook uses selector index 0 == 44 which corresponds to AF_XDP (eXpress Data Path), a kernel-bypass socket family. Creating an AF_XDP socket is an indicator that a process may be bypassing the normal network stack and thus eBPF visibility.

The sys_ioctl hook fires on FS_IOC_SETFLAGS (0x5410 = 21520 decimal), which is the chattr immutable flag ioctl. Events are suppressed for known shell binaries because shells use the numerically-identical TIOCSPGRP ioctl for job control.

The mask value 3072 for sys_chmod/sys_fchmodat captures mode bits 0o6000 (octal), which is the bitmask for SUID (0o4000) and SGID (0o2000).


Listen baseline (telovix-listen-baseline)

CallArgsEvent kind
inet_listensock (index 0), int backlog (index 1)network_listen

Fires when a process calls listen() to accept incoming TCP connections. Every new listening socket is recorded.


File open policies (telovix-file-open, telovix-file-open-2, telovix-file-open-3)

All three policies hook sys_openat (syscall: true) with args int (dirfd, index 0), string (path, index 1), int (flags, index 2).

The single policy was split into three parts because Tetragon enforces a maximum of 5 selectors per policy (reduced from 8 in older versions). With 19+ selectors, the original single policy exceeded that limit and failed to load.

Policy 1 (telovix-file-open) monitors:

  • Credential files: /etc/shadow, /etc/passwd, /etc/sudoers, /etc/gshadow, /etc/pam.d/
  • Kubernetes credentials: /var/run/secrets/kubernetes.io/, /etc/kubernetes/, /root/.kube/
  • SSH server host keys: /etc/ssh/ssh_host*
  • System binary directories: /usr/bin/, /usr/sbin/, /bin/, /sbin/
  • Library directories: /lib/, /lib64/, /usr/lib/, and architecture-specific security subdirectories
  • Security logs: /var/log/auth*, /var/log/secure, /var/log/audit/
  • Persistence paths: /etc/profile*, /etc/bash.bashrc, /etc/systemd/system/, /etc/udev/rules.d/
  • Kernel module paths: /lib/modules/, /etc/modprobe.d/, /proc/sysrq-trigger, /sys/kernel/
  • DPDK/VFIO paths: /dev/vfio/, /dev/hugepages/, SR-IOV sysfs paths (telecom user plane bypass detection)
  • Per-user shell rc files (Postfix match on /.bashrc, /.zshrc, etc.)
  • PAM module files: pam_unix.so, pam_exec.so, etc.
  • LD preload hijack: /etc/ld.so*

Policies 2 and 3 cover additional paths with the same sys_openat hook, split across additional selector groups.

Event kind: file_open


Security syscalls (telovix-security-syscalls)

CallKey selectorEvent kindPurpose
sys_killNonesignalSignal sent between processes
sys_dup2Nonefd_dupFile descriptor duplication
sys_dup3Nonefd_dupFile descriptor duplication (with flags)
sys_mmapindex 2 Mask 4 (PROT_EXEC)mmap_execExecutable memory mapping (JIT, shellcode detection)
sys_capsetNonecap_changeCapability set change

The sys_mmap selector Mask: 4 captures mappings with PROT_EXEC set in the protection flags (bit 2). This detects code injection and JIT compilation into anonymous executable memory regions.


Kernel module monitor (telovix-kmod-monitor)

CallArgsEvent kindPurpose
sys_init_moduleuint64 (memory image)module_load or kmod_loadKernel module loading from memory
sys_finit_moduleint (fd)module_load or kmod_loadKernel module loading from file descriptor
sys_delete_modulestring (name), int (flags)module_loadKernel module unloading

This policy is removed during kernel module enforcement activation (block-kmod-load template). The LSM-based kernel_read_file hook in telovix-lsm-baseline handles blocking; this kprobe policy handles observation only.


Process lifecycle (telovix-process-lifecycle)

CallArgsEvent kindPurpose
sys_cloneuint64 (flags)namespace_create or process_forkProcess creation and namespace flags detection
sys_execveatint (dirfd), string (path), int (flags)process_execExecution from file descriptor
sys_memfd_createstring (name), uint64 (flags)mmap_execAnonymous in-memory file creation (fileless execution)
sys_chdirstring (path)chdirWorking directory change (return value captured)
sys_fchdirint (fd)chdirWorking directory change via fd
sys_unshareint (flags)namespace_createNamespace detach without fork
sys_clone3uint64 (struct clone_args flags field)namespace_create or process_forkModern clone variant (container runtimes)

The comment in the source notes: "sys_clone3: modern clone variant used by unshare --fork and newer container runtimes."


Writing custom kprobe rules

Custom kprobe rules follow the same TracingPolicy schema. A minimal observe rule:

yaml
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: telovix-custom-observe-execve-args
spec:
  kprobes:
    - call: sys_execve
      syscall: true
      args:
        - index: 0
          type: string
        - index: 1
          type: string
      selectors:
        - matchArgs:
            - index: 1
              operator: Prefix
              values:
                - "/tmp/"
          matchActions:
            - action: Post

Common arg types for kprobes:

Type stringUsed for
stringNull-terminated string arguments (file paths, names)
intSigned 32-bit integers
uint32Unsigned 32-bit integers (UIDs, GIDs)
uint64Unsigned 64-bit integers (memory addresses, clone flags)
int64Signed 64-bit integers
sockSocket objects (kernel struct sock *)
sockaddrSocket address structures

Limitations of kprobes

  • No Override action: kprobes cannot block operations. Use BPF LSM hooks for pre-execution denial.
  • PREEMPT_RT kernels: kprobes with syscall: true that use BPF_MODIFY_RETURN fail verification on real-time kernels. The sensor detects RT kernels at startup and loads RT-safe policies only.
  • Return value hooks (returnArg): Available but the function must be compiled with frame pointers or be accessible to BTF. Not all kernel functions support return kprobes on all kernel versions.

Further reading

Released under the Telovix Commercial License.