eBPF-based security platform
upatches/kernel-cve: add the CVE-2026-31431 AF_ALG mitigations
John Fastabend3ecd15205ed5
diff --git a/upatches/kernel-cve/cve-2026-31431-af-alg-block.bee b/upatches/kernel-cve/cve-2026-31431-af-alg-block.beenew file mode 100644index 00000000..528dddda--- /dev/null+++ b/upatches/kernel-cve/cve-2026-31431-af-alg-block.bee@@ -0,0 +1,15 @@+[package]+name = "cve-2026-31431-af-alg-block"+description = "Refuses AF_ALG sockets, CVE-2026-31431"+license = "GPL-2.0 OR BSD-2-Clause"+authors = ["Authors of shirudo"]++[[upatches]]+source = "sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-af-alg-block.bpf.c"++[upatches.tree]+id = "cve-2026-31431-af-alg-block"+fixes = ["CVE-2026-31431"]++[upatches.tree.selector.kconfig]+CONFIG_CRYPTO_USER_API_AEAD = ["y", "m"]diff --git a/upatches/kernel-cve/cve-2026-31431-alg-splice-block.bee b/upatches/kernel-cve/cve-2026-31431-alg-splice-block.beenew file mode 100644index 00000000..cbb6425d--- /dev/null+++ b/upatches/kernel-cve/cve-2026-31431-alg-splice-block.bee@@ -0,0 +1,15 @@+[package]+name = "cve-2026-31431-alg-splice-block"+description = "Refuses zero-copy splice into AF_ALG sockets, CVE-2026-31431"+license = "GPL-2.0 OR BSD-2-Clause"+authors = ["Authors of shirudo"]++[[upatches]]+source = "sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-alg-splice-block.bpf.c"++[upatches.tree]+id = "cve-2026-31431-alg-splice-block"+fixes = ["CVE-2026-31431"]++[upatches.tree.selector.kconfig]+CONFIG_CRYPTO_USER_API_AEAD = ["y", "m"]diff --git a/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-af-alg-block.bpf.c b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-af-alg-block.bpf.cnew file mode 100644index 00000000..c480787e--- /dev/null+++ b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-af-alg-block.bpf.c@@ -0,0 +1,26 @@+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * CVE-2026-31431 mitigation: refuse every AF_ALG socket, which takes the+ * algif_aead code the CVE is in out of reach, and with it all other use+ * of the kernel's crypto algorithms through sockets.+ */++#include "vmlinux.h"+#include <bpf/bpf_helpers.h>+#include <bpf/bpf_tracing.h>++#define AF_ALG 38+#define EPERM 1++char _license[] SEC("license") = "Dual BSD/GPL";++SEC("lsm/socket_create")+int BPF_PROG(cve_2026_31431_af_alg, int family, int type, int protocol,+ int kern)+{+ if (family == AF_ALG)+ return -EPERM;+ return 0;+}diff --git a/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-alg-splice-block.bpf.c b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-alg-splice-block.bpf.cnew file mode 100644index 00000000..d88b9518--- /dev/null+++ b/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/mitigation/cve-2026-31431-alg-splice-block.bpf.c@@ -0,0 +1,43 @@+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * CVE-2026-31431 precise mitigation. The algif_aead copy-failure path+ * writes back into its source scatter-gather pages; the bug is reachable+ * only when those pages are foreign ones aliased into the AF_ALG socket+ * by a zero-copy splice (MSG_SPLICE_PAGES), never when the data was+ * copied in by an ordinary sendmsg. This refuses exactly that: a+ * MSG_SPLICE_PAGES send to an AF_ALG socket. Every copying use of+ * AF_ALG -- aead, skcipher, hash and rng, encrypt and decrypt -- is left+ * working, unlike the socket_create block that takes AF_ALG away+ * wholesale.+ *+ * The op (encrypt/decrypt) and the algorithm type live in the crypto+ * module's private af_alg_ctx, which carries no BTF, so a shield cannot+ * read them without hard-coded offsets. The zero-copy precondition is in+ * the generic struct sock and struct msghdr, which do, so this is the+ * narrowest condition a CO-RE shield can enforce.+ */++#include "vmlinux.h"+#include <bpf/bpf_helpers.h>+#include <bpf/bpf_tracing.h>+#include <bpf/bpf_core_read.h>++#define AF_ALG 38+#define EACCES 13+/* include/linux/socket.h: MSG_SPLICE_PAGES is BIT(27), kernel-internal. */+#define MSG_SPLICE_PAGES 0x8000000++char _license[] SEC("license") = "Dual BSD/GPL";++SEC("lsm/socket_sendmsg")+int BPF_PROG(cve_2026_31431_alg_splice, struct socket *sock,+ struct msghdr *msg, int size)+{+ if (BPF_CORE_READ(sock, sk, __sk_common.skc_family) != AF_ALG)+ return 0;+ if (BPF_CORE_READ(msg, msg_flags) & MSG_SPLICE_PAGES)+ return -EACCES;+ return 0;+}