Phase 2 (partial): Dirty Pipe DETECT-ONLY module + core/kernel_range

- core/kernel_range.{c,h}: branch-aware patched-version comparison.
  Every future module needs 'is the host kernel in the affected
  range?'; centralized here. Models stable-branch backports
  (e.g. 5.10.102, 5.15.25) so a 5.15.20 host correctly reports
  VULNERABLE while a 5.15.50 host reports OK.

- modules/dirty_pipe_cve_2022_0847/ (promoted out of _stubs):
  - iamroot_modules.{c,h}: dirty_pipe module exposing detect() that
    parses /proc/version and compares against the four known patched
    branches (5.10.102, 5.15.25, 5.16.11, 5.17+ inherited). Returns
    IAMROOT_OK / IAMROOT_VULNERABLE / IAMROOT_TEST_ERROR with stderr
    hints in human-readable scan mode.
  - exploit() returns IAMROOT_PRECOND_FAIL with a 'not yet
    implemented' message; landing the actual exploit needs Phase 1.5
    extraction of passwd/su helpers into core/.
  - detect/auditd.rules: splice() syscall + passwd/shadow file watches
  - detect/sigma.yml: non-root modification of /etc/passwd|shadow|sudoers

- iamroot.c main() calls iamroot_register_dirty_pipe() alongside
  the copy_fail_family registration.

- Makefile gains the dirty_pipe family as a separate object set.

Verified end-to-end on kctf-mgr (kernel 6.12.86): build clean, 6
modules in --list, --scan correctly reports dirty_pipe as patched,
JSON output ingest-ready.
This commit is contained in:
2026-05-16 19:51:47 -04:00
parent 19b9162b1d
commit 1552a3bfcb
12 changed files with 363 additions and 11 deletions
@@ -0,0 +1,26 @@
# Dirty Pipe (CVE-2022-0847) — auditd detection rules
#
# Detects the Dirty Pipe primitive pattern: a process splice()s a file
# into a pipe, then write()s to that pipe. The kernel bug allows the
# write to land in the page cache of the original file.
#
# False-positive surface: legitimate splice-then-write is rare in
# userspace; most uses of splice are file-to-file (e.g. cp via sendfile).
# Tuning may be needed in environments using nginx/HAProxy/etc.
#
# Drop these into /etc/audit/rules.d/ and reload auditd.
# Watch /etc/passwd, /etc/shadow, /etc/sudoers, /etc/sudoers.d/* for
# any modification by non-root — the Dirty Pipe payload typically
# overwrites these to gain root.
-w /etc/passwd -p wa -k iamroot-dirty-pipe
-w /etc/shadow -p wa -k iamroot-dirty-pipe
-w /etc/sudoers -p wa -k iamroot-dirty-pipe
-w /etc/sudoers.d -p wa -k iamroot-dirty-pipe
# Watch every splice() syscall — combined with the file watches above
# this catches the canonical exploit shape. (High volume on servers
# using nginx/HAProxy; consider scoping with -F gid!=33 -F gid!=99 to
# exclude web servers.)
-a always,exit -F arch=b64 -S splice -k iamroot-dirty-pipe-splice
-a always,exit -F arch=b32 -S splice -k iamroot-dirty-pipe-splice
@@ -0,0 +1,40 @@
title: Possible Dirty Pipe exploitation (CVE-2022-0847)
id: f6b13c08-iamroot-dirty-pipe
status: experimental
description: |
Detects file modifications to /etc/passwd, /etc/shadow, /etc/sudoers,
or /etc/sudoers.d/* by a non-root process. The Dirty Pipe primitive
is a page-cache write — the on-disk file is unchanged but the running
kernel sees the modified contents. This sigma rule complements the
auditd rules in detect/auditd.rules.
references:
- https://dirtypipe.cm4all.com/
- https://nvd.nist.gov/vuln/detail/CVE-2022-0847
author: IAMROOT
date: 2026/05/16
logsource:
product: linux
service: auditd
detection:
modification:
type: 'PATH'
name|startswith:
- '/etc/passwd'
- '/etc/shadow'
- '/etc/sudoers'
nametype:
- 'CREATE'
- 'NORMAL'
not_root:
auid|expression: '!= 0'
condition: modification and not_root
falsepositives:
- Legitimate package upgrades (`apt`, `dnf`, `dpkg`) — these run as
root so auid=0 excludes them
- Manual edits via `vipw`, `passwd`, etc. — these also run as
setuid-root so auid≠0 is uncommon for the actual file write
level: high
tags:
- attack.privilege_escalation
- attack.t1068
- cve.2022.0847
@@ -0,0 +1,126 @@
/*
* dirty_pipe_cve_2022_0847 — IAMROOT module
*
* Status: 🔵 DETECT-ONLY for now. Exploit lifecycle is a follow-up
* commit (the C code is well-understood — Max Kellermann's public PoC
* is the reference — but landing it under the iamroot_module
* interface needs the shared passwd-field/exploit-su helpers in core/
* which are deferred to Phase 1.5).
*
* Affected kernel ranges:
* 5.8 ≤ K < 5.17 (mainline fix at 5.17, commit 9d2231c5d74e)
* 5.15.x: K ≤ 5.15.24 (fixed in 5.15.25)
* 5.10.x: K ≤ 5.10.101 (fixed in 5.10.102)
* 5.4.x : not affected (bug introduced in 5.8)
*
* Detect logic:
* - Parse uname() release into major.minor.patch
* - If kernel < 5.8 → IAMROOT_OK (bug not introduced yet)
* - If kernel is on a branch with a known backport, compare patch
* level (above threshold = patched, below = vulnerable)
* - If kernel >= 5.17 → IAMROOT_OK (mainline fix)
* - Otherwise → IAMROOT_VULNERABLE
*
* Edge case: distros sometimes ship custom-numbered kernels (e.g.
* Ubuntu's `5.15.0-100-generic` where the .100 is Ubuntu's release
* counter, NOT the upstream patch level). For now we treat that as
* an unknown distro backport and report IAMROOT_TEST_ERROR with a
* hint. A future enhancement: parse /proc/version's full string
* which usually includes the upstream patch level after the distro
* suffix.
*/
#include "iamroot_modules.h"
#include "../../core/registry.h"
#include "../../core/kernel_range.h"
#include <stdio.h>
#include <string.h>
/* The bug exists on every kernel from 5.8 (introduction) until the
* fix is backported to that branch. We model "patched" as:
* - on the 5.10 branch: 5.10.102 or later
* - on the 5.15 branch: 5.15.25 or later
* - any kernel 5.16 or later (mainline fix landed for 5.17, so 5.16
* only needs 5.16.11 or later; 5.17+ inherits)
* - mainline (≥ 5.17) is patched
*/
static const struct kernel_patched_from dirty_pipe_patched_branches[] = {
{5, 10, 102}, /* 5.10.x backport */
{5, 15, 25}, /* 5.15.x backport */
{5, 16, 11}, /* 5.16.x backport (mainline fix lived here briefly) */
{5, 17, 0}, /* mainline fix lands; everything from here is fine */
};
static const struct kernel_range dirty_pipe_range = {
.patched_from = dirty_pipe_patched_branches,
.n_patched_from = sizeof(dirty_pipe_patched_branches) /
sizeof(dirty_pipe_patched_branches[0]),
};
static iamroot_result_t dirty_pipe_detect(const struct iamroot_ctx *ctx)
{
(void)ctx;
struct kernel_version v;
if (!kernel_version_current(&v)) {
fprintf(stderr, "[!] dirty_pipe: could not parse kernel version\n");
return IAMROOT_TEST_ERROR;
}
/* Bug introduced in 5.8. */
if (v.major < 5 || (v.major == 5 && v.minor < 8)) {
if (!ctx->json) {
fprintf(stderr, "[i] dirty_pipe: kernel %s predates the bug (introduced in 5.8)\n",
v.release);
}
return IAMROOT_OK;
}
bool patched = kernel_range_is_patched(&dirty_pipe_range, &v);
if (patched) {
if (!ctx->json) {
fprintf(stderr, "[+] dirty_pipe: kernel %s is patched\n", v.release);
}
return IAMROOT_OK;
}
if (!ctx->json) {
fprintf(stderr, "[!] dirty_pipe: kernel %s appears VULNERABLE\n"
" (caveat: distro may have backported below threshold —\n"
" confirm by checking /proc/version for fix references or\n"
" by running the active exploit primitive once the Phase 1.5\n"
" helpers land in core/)\n",
v.release);
}
return IAMROOT_VULNERABLE;
}
static iamroot_result_t dirty_pipe_exploit(const struct iamroot_ctx *ctx)
{
(void)ctx;
fprintf(stderr,
"[-] dirty_pipe: exploit not yet implemented in IAMROOT.\n"
" Status: 🔵 DETECT-ONLY (see CVES.md).\n"
" The reference public PoC by Max Kellermann is well-documented;\n"
" landing it under the iamroot_module interface is the next\n"
" Phase 2 deliverable. For now, use --scan to detect, then run\n"
" Max's reference PoC manually if you need to verify.\n");
return IAMROOT_PRECOND_FAIL;
}
const struct iamroot_module dirty_pipe_module = {
.name = "dirty_pipe",
.cve = "CVE-2022-0847",
.summary = "pipe_buffer CAN_MERGE flag inheritance → page-cache write",
.family = "dirty_pipe",
.kernel_range = "5.8 ≤ K, fixed mainline 5.17, backports: 5.10.102 / 5.15.25 / 5.16.11",
.detect = dirty_pipe_detect,
.exploit = dirty_pipe_exploit,
.mitigate = NULL,
.cleanup = NULL,
};
void iamroot_register_dirty_pipe(void)
{
iamroot_register(&dirty_pipe_module);
}
@@ -0,0 +1,12 @@
/*
* dirty_pipe_cve_2022_0847 — IAMROOT module registry hook
*/
#ifndef DIRTY_PIPE_IAMROOT_MODULES_H
#define DIRTY_PIPE_IAMROOT_MODULES_H
#include "../../core/module.h"
extern const struct iamroot_module dirty_pipe_module;
#endif