upatch.dev

CVE-2026-85604

Grav before 2.0.18 Remote Code Execution via sort filter

Refuses subprocess execution by PHP serving Grav to mitigate CVE-2026-85604.

High 8.7Vetted

EPSS 0.9%: the estimated chance this CVE is exploited in the next 30 days, as of 24 Nov 2026.

At a glance

CVE-2026-85604 is a high (CVSS 8.7) vulnerability in Grav, published 4 September 2026. A vetted upatch, cve-2026-85604-exec-block, blocks it on running Linux machines with shirudo until Grav is upgraded.

Severity
High 8.7 CVSS 4.0
Chance of exploitation
0.9% in the next 30 days (EPSS, 24 Nov 2026)
Known exploited
No, not on CISA’s KEV list
Weakness
CWE-94
Affected software
Grav (getgrav)
Upatch status
Vetted, merged into the registry
How to apply
Build, sign and roll out with shirudo

Overview

CVE-2026-85604 (GHSA-p6qj-p5m7-f62h), published on 4 September 2026, is a remote code execution vulnerability in Grav before 2.0.19 (affecting versions up to 2.0.17). In system/src/Grav/Common/Twig/Extension/GravExtension.php, the sortFunc wrapper calls CoreExtension::sort($env, false, $array ?? [], $arrow), hardcoding Twig's $isSandboxed argument to false. Because that flag is what enforces Twig's rule that callables in sandbox mode must be Closure instances, the |sort filter accepts a plain string function name inside the sandbox where |map, |filter and |reduce refuse it. The remaining Utils::isDangerousFunction() denylist misses spl_autoload, which performs a PHP include of a lowercase path and extension, allowing an authenticated user with page-write rights (admin.pages or api.pages.write) to include their own .md page file and run arbitrary PHP code and OS commands as the web server user.

Official description

Grav before 2.0.18 (affected versions <= 2.0.17) contains a remote code execution vulnerability in the Twig sort filter. The sortFunc wrapper in GravExtension.php hardcodes Twig's isSandboxed argument to false, so unlike |map/|filter/|reduce, |sort accepts a plain function name inside the sandbox; the remaining denylist misses spl_autoload, which performs a PHP include. An authenticated user with only page-write rights (admin.pages or api.pages.write) can supply a crafted payload (e.g., via form frontmatter rendered by the Email plugin) that invokes spl_autoload through the sort filter, resulting in arbitrary PHP execution as the web server user.

Affected versions

Software Affected Fixed in
Grav <= 2.0.17 2.0.19

Sources

More references from NVD (2)

Mitigation

The program attaches to lsm/bprm_check_security and returns -EPERM when:

  1. The current task or its parent task has a command name starting with php (such as php or php-fpm), and
  2. The task's current working directory is named grav or grav-admin.

Refusals from earlier BPF LSM programs on the same hook are preserved. A per-CPU array map refused counts blocked executions.

Side effects

  • PHP processes whose working directory is grav or grav-admin cannot execve external binaries (such as /bin/sh, sendmail or git).
  • Normal Grav page rendering, Twig template evaluation, file caching and PHP-internal operations do not spawn external binaries and continue working.
  • Other processes on the machine, including root shells, sshd and package managers, are unaffected.

Preemption model and cost

The program holds no locks and shares only a per-CPU counter updated with __sync_fetch_and_add, making it safe under all kernel preemption models including PREEMPT_LAZY, PREEMPT_DYNAMIC and PREEMPT_RT. It runs only on execve (bprm_check_security), checks the 3-byte php prefix of comm first, and returns immediately for all non-PHP processes.

The policy

76 lines of BPF C, attached at lsm/bprm_check_security.

// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>

#define EPERM 1

char _license[] SEC("license") = "Dual BSD/GPL";

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, __u64);
} refused SEC(".maps");

static __always_inline void count_refused(void)
{
	__u32 key = 0;
	__u64 *value = bpf_map_lookup_elem(&refused, &key);

	if (value)
		__sync_fetch_and_add(value, 1);
}

static __always_inline int earlier_verdict(int ret)
{
	return ret >= -4095 && ret < 0 ? ret : -EPERM;
}

static __always_inline bool is_php_comm(const char *comm)
{
	return comm[0] == 'p' && comm[1] == 'h' && comm[2] == 'p';
}

static __always_inline bool is_grav_cwd(struct task_struct *task)
{
	const struct dentry *dentry = BPF_CORE_READ(task, fs, pwd.dentry);
	const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
	__u32 len = BPF_CORE_READ(dentry, d_name.len);
	char buf[8] = {};

	if (!dentry || (len != 4 && len != 10) || !name)
		return false;
	if (bpf_probe_read_kernel(buf, 4, name))
		return false;
	return buf[0] == 'g' && buf[1] == 'r' && buf[2] == 'a' && buf[3] == 'v';
}

SEC("lsm/bprm_check_security")
int BPF_PROG(cve_2026_85604_exec_block, struct linux_binprm *bprm, int ret)
{
	struct task_struct *task;
	struct task_struct *parent;
	char comm[16] = {};
	char pcomm[16] = {};

	if (ret)
		return earlier_verdict(ret);
	bpf_get_current_comm(&comm, sizeof(comm));
	task = bpf_get_current_task_btf();
	if (!is_php_comm(comm)) {
		parent = BPF_CORE_READ(task, real_parent);
		if (!parent || bpf_probe_read_kernel(&pcomm, sizeof(pcomm), &parent->comm))
			return 0;
		if (!is_php_comm(pcomm))
			return 0;
	}
	if (!is_grav_cwd(task))
		return 0;
	count_refused();
	return -EPERM;
}

Process

How this upatch was written, checked and reviewed, from the registry’s history.

  1. 4 Sept 2026CVECVE published
  2. 25 Nov 2026Pull requestPull request #39 openedAdd CVE-2026-85604: Refuses subprocess execution by PHP serving Gravromanlab
  3. 25 Nov 2026ReviewReviewedqodo-code-review[bot] (automated)
  4. 25 Nov 2026MergeMerged #39romanlab

No human review is recorded on GitHub for this upatch yet.

Evidence

On Grav 2.0.17, the loaded upatch blocked subprocess execution triggered after reaching the Twig sort filter sandbox bypass with spl_autoload.

Tested
25 Nov 2026
Target
Grav 2.0.17 (grav-admin-v2.0.17.zip) on PHP 8, loopback only
Kernel
7.4-shirudo-ci-20261123
Architecture
x86_64
Distribution
Ubuntu 26.04
Results
StateTwig |sort('spl_autoload') includes probe and spawns /bin/true
Before loadingreached
Upatch loadedblocked
After unloadingreached
tools-test.log Output of tools/test --setup showing the payload reached before, blocked while loaded, and reached again after unloading.
tools/test --setup, 2026-11-25T12:01:36Z
Target: shirudo test VM, Linux 7.4-shirudo-ci-20261123, x86_64, swtpm
cve-2026-85604
  setup   done         GRAV_URL=http://127.0.0.1:8088/upatchprobe
  before  reached      Twig |sort('spl_autoload') included probe_target.md and ran /bin/true
  loaded  blocked      Twig |sort('spl_autoload') ran probe_target.md but subprocess execution was refused
  after   reached      Twig |sort('spl_autoload') included probe_target.md and ran /bin/true
  PASS: reached before, blocked while loaded, reached again after

Use it

Build the upatch from source, sign it with your own shirudo key, and publish it to your own OCI registry. Machines that follow your upatch tree load it within about a minute.

Build and sign
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-85604
Publish and roll out
shirudo bpm push build/packages/cve-2026-85604-1.0.0.bee oci://<registry>/<namespace>/cve-2026-85604 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-85604-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>