CVE-2026-60004
Gitea before 1.27.1 allows remote code execution via the diffpatch API through Git hook installation.
Refuses creating or executing Git post-index-change hooks under Gitea to mitigate CVE-2026-60004.
Critical 9.8VettedKnown exploited
EPSS 24%: the estimated chance this CVE is exploited in the next 30 days, as of 24 Nov 2026.
At a glance
CVE-2026-60004 is a critical (CVSS 9.8) vulnerability in Gitea, published 26 August 2026 and on CISA's Known Exploited Vulnerabilities list. A vetted upatch, cve-2026-60004-hook-block, blocks it on running Linux machines with shirudo until Gitea is upgraded.
- Severity
- Critical 9.8 CVSS 3.1
- Chance of exploitation
- 24% in the next 30 days (EPSS, 24 Nov 2026)
- Known exploited
- Yes, on CISA’s KEV list since 25 Aug 2026
- Weakness
- CWE-94
- Affected software
- Gitea
- Upatch status
- Vetted, merged into the registry
- How to apply
- Build, sign and roll out with shirudo
Overview
CVE-2026-60004 (GHSA-rcr6-4jqh-j84m) is a remote code execution vulnerability in Gitea 1.17.0 through 1.27.0, fixed in 1.27.1. In services/repository/files/patch.go, ApplyDiffPatch clones the target repository into a temporary bare repository (t.Clone(ctx, opts.OldBranch, true)) and runs git apply --index --recount --cached --ignore-whitespace --whitespace=fix --binary -3. When a user with repository write access submits the same diff adding an executable file at hooks/post-index-change twice to POST /api/v1/repos/{owner}/{repo}/diffpatch, the second request triggers an add/add collision in git apply -3. Git's three-way merge fallback checks out the conflicting path into the working tree; because the temporary clone is bare, the repository root is $GIT_DIR, so git apply writes hooks/post-index-change directly into the live hooks/ directory and executes it when writing the index.
Official description
Gitea before 1.27.1 allows remote code execution via the diffpatch API through Git hook installation.
Affected versions
Gitea:
| Branch | Affected | Fixed in |
|---|---|---|
| 1.17 to 1.27 | 1.17.0 to 1.27.0 | 1.27.1 |
Kernels: the lsm/inode_create program uses the four-argument inode_create LSM hook prototype starting with const struct mnt_idmap *idmap, and lsm/bprm_check_security uses struct linux_binprm *bprm.
Sources
More references from NVD (3)
Mitigation
Two BPF LSM programs return -EPERM when Gitea or a descendant process (up to 6 levels in real_parent, matching a task comm or executable name of gitea or gitea-*) operates on a post-index-change file inside a directory named hooks:
| Hook | Refused |
|---|---|
lsm/inode_create |
Creating post-index-change (or post-index-change.* / post-index-change_* temporary lock files) inside hooks/ |
lsm/bprm_check_security |
Executing hooks/post-index-change |
Each program checks the target dentry name (post-index-change) first and returns 0 immediately on any other file name. Only when the file name and parent directory (hooks) match does it inspect the task ancestry for gitea. The refused per-CPU array counts refusals at index 0 (inode_create) and index 1 (bprm_check_security).
Side effects
- Any
diffpatchrequest to a vulnerable Gitea instance that attempts to check outhooks/post-index-changeinto the temporary bare clone fails atgit applywithPermission denied(HTTP 500), and any pre-existinghooks/post-index-changecannot be executed by Gitea'sgitsubprocesses. - Gitea itself only installs and manages
pre-receive,update,post-receiveandproc-receivehooks in repositories; it never usespost-index-change. Normal repository creation, commits, pushes, pulls anddiffpatchrequests on ordinary repository paths continue to work. - Processes outside Gitea's process tree are unaffected.
Preemption model and cost
The programs keep no state beyond the refused per-CPU counter map, updated with __sync_fetch_and_add, making them safe under all preemption models including PREEMPT_LAZY and PREEMPT_RT. On every file creation and program execution whose dentry length is outside 17..32 bytes or whose name does not start with post-index-change, the hook returns after a single dentry length check.
The policy
139 lines of BPF C, attached at lsm/inode_create and 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";
enum {
REFUSED_CREATE,
REFUSED_EXEC,
NR_COUNTERS,
};
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, NR_COUNTERS);
__type(key, __u32);
__type(value, __u64);
} refused SEC(".maps");
static __always_inline void count(__u32 key)
{
__u64 *value = bpf_map_lookup_elem(&refused, &key);
if (value)
__sync_fetch_and_add(value, 1);
}
static __always_inline bool is_hooks_dir(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
char buf[8] = {};
if (!dentry || BPF_CORE_READ(dentry, d_name.len) != 5)
return false;
if (bpf_probe_read_kernel_str(buf, sizeof(buf), name) < 0)
return false;
return buf[0] == 'h' && buf[1] == 'o' && buf[2] == 'o' &&
buf[3] == 'k' && buf[4] == 's' && buf[5] == 0;
}
static __always_inline bool is_post_index_change(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
__u32 len = BPF_CORE_READ(dentry, d_name.len);
char buf[24] = {};
if (!dentry || len < 17 || len > 32)
return false;
if (bpf_probe_read_kernel_str(buf, sizeof(buf), name) < 0)
return false;
return buf[0] == 'p' && buf[1] == 'o' && buf[2] == 's' &&
buf[3] == 't' && buf[4] == '-' && buf[5] == 'i' &&
buf[6] == 'n' && buf[7] == 'd' && buf[8] == 'e' &&
buf[9] == 'x' && buf[10] == '-' && buf[11] == 'c' &&
buf[12] == 'h' && buf[13] == 'a' && buf[14] == 'n' &&
buf[15] == 'g' && buf[16] == 'e' &&
(buf[17] == 0 || buf[17] == '.' || buf[17] == '_');
}
static __always_inline bool is_gitea_name(const char *buf)
{
return buf[0] == 'g' && buf[1] == 'i' && buf[2] == 't' &&
buf[3] == 'e' && buf[4] == 'a' &&
(buf[5] == 0 || buf[5] == '-');
}
static __always_inline bool task_is_gitea(const struct task_struct *task)
{
const struct dentry *exe;
const unsigned char *ename;
char comm[16] = {};
char ebuf[16] = {};
if (!task)
return false;
if (BPF_CORE_READ_INTO(&comm, task, comm) == 0 && is_gitea_name(comm))
return true;
exe = BPF_CORE_READ(task, mm, exe_file, f_path.dentry);
ename = BPF_CORE_READ(exe, d_name.name);
if (ename && bpf_probe_read_kernel_str(ebuf, sizeof(ebuf), ename) > 0 &&
is_gitea_name(ebuf))
return true;
return false;
}
static __always_inline bool under_gitea(void)
{
struct task_struct *task = bpf_get_current_task_btf();
#pragma unroll
for (int i = 0; i < 6; i++) {
if (!task)
break;
if (task_is_gitea(task))
return true;
task = BPF_CORE_READ(task, real_parent);
}
return false;
}
static __always_inline int earlier_verdict(int ret)
{
return ret >= -4095 && ret < 0 ? ret : -EPERM;
}
SEC("lsm/inode_create")
int BPF_PROG(cve_2026_60004_create, const struct mnt_idmap *idmap,
struct inode *dir, struct dentry *dentry, umode_t mode, int ret)
{
if (ret)
return earlier_verdict(ret);
if (!is_post_index_change(dentry))
return 0;
if (!is_hooks_dir(BPF_CORE_READ(dentry, d_parent)) || !under_gitea())
return 0;
count(REFUSED_CREATE);
return -EPERM;
}
SEC("lsm/bprm_check_security")
int BPF_PROG(cve_2026_60004_exec, struct linux_binprm *bprm, int ret)
{
const struct dentry *dentry = BPF_CORE_READ(bprm, file, f_path.dentry);
if (ret)
return earlier_verdict(ret);
if (!is_post_index_change(dentry))
return 0;
if (!is_hooks_dir(BPF_CORE_READ(dentry, d_parent)) || !under_gitea())
return 0;
count(REFUSED_EXEC);
return -EPERM;
}
The package: name, license, the program and the CVE it fixes.
[package]
name = "cve-2026-60004"
description = "Refuses creating or executing Git post-index-change hooks under Gitea to mitigate CVE-2026-60004"
license = "GPL-2.0 OR BSD-2-Clause"
[[upatches]]
source = "cve-2026-60004-hook-block.bpf.c"
[upatches.tree]
id = "cve-2026-60004-hook-block"
fixes = ["CVE-2026-60004"]
Process
How this upatch was written, checked and reviewed, from the registry’s history.
- 26 Aug 2026CVECVE published
- 25 Nov 2026Pull requestPull request #12 openedAdd CVE-2026-60004: Refuses creating or executing Git post-index-change hooks under Gitearomanlab
- 25 Nov 2026MergeMerged #12romanlab
- 25 Nov 2026ReviewReviewedqodo-code-review[bot] (automated)
No human review is recorded on GitHub for this upatch yet.
Evidence
On Gitea 1.27.0, the loaded upatch refused creating hooks/post-index-change during the second diffpatch request (HTTP 500) and stopped the Git hook from executing, while repository creation and the initial diffpatch succeeded.
- Tested
- 25 Nov 2026
- Target
- Gitea 1.27.0 (gitea-1.27.0-linux-amd64) on 127.0.0.1:3000
- Kernel
- 7.4-shirudo-ci-20261123
- Architecture
- x86_64
| State | Second diffpatch writes and runs hooks/post-index-change |
|---|---|
| Before loading | yes (HTTP 201) |
| Upatch loaded | no (HTTP 500) |
| After unloading | yes (HTTP 201) |
tools-test.log Output of tools/test --setup on Linux 7.4-shirudo-ci-20261123 showing reached before, blocked while loaded, and reached after.
tools/test --setup, 2026-11-25T10:30:22Z Target: shirudo test VM, Linux 7.4-shirudo-ci-20261123, x86_64, swtpm cve-2026-60004 setup done GITEA_URL=http://127.0.0.1:3000 GITEA_USER=probe GITEA_PASS=ProbePassword123! GITEA_TOP=/opt/upatch-payload/cve-2026-60004 before reached second diffpatch wrote and ran hooks/post-index-change (HTTP 201) loaded blocked second diffpatch refused hooks/post-index-change with HTTP 500 after reached second diffpatch wrote and ran hooks/post-index-change (HTTP 201) 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.
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-60004shirudo bpm push build/packages/cve-2026-60004-1.0.0.bee oci://<registry>/<namespace>/cve-2026-60004 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-60004-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>