# CVE-2026-60004: Gitea before 1.27.1 allows remote code execution via the diffpatch API through Git hook installation.

The Markdown version of <https://upatch.dev/cve/CVE-2026-60004>. Last updated 25 Nov 2026.

## At a glance

CVE-2026-60004 is rated Critical 9.8 (CVSS 3.1, CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H). It affects Gitea and was published on 26 Aug 2026. It is known exploited: CISA added it to its Known Exploited Vulnerabilities catalog on 25 Aug 2026. Its EPSS score is 24%: the estimated chance it is exploited in the next 30 days, as of 24 Nov 2026. The upatch `cve-2026-60004-hook-block` mitigates it, and is vetted (merged into the registry).

A upatch is a signed BPF program that shirudo loads into a running Linux kernel to block the code path this CVE's exploit takes. It holds the line until the fix ships; it does not replace patching.

## The vulnerability

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.

## What the upatch does

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`).

The policy: [`cve-2026-60004-hook-block.bpf.c`](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-60004), 139 lines of BPF C attached at `lsm/inode_create` and `lsm/bprm_check_security`, licensed GPL-2.0 OR BSD-2-Clause.

## Side effects

- Any `diffpatch` request to a vulnerable Gitea instance that attempts to check out `hooks/post-index-change` into the temporary bare clone fails at `git apply` with `Permission denied` (HTTP 500), and any pre-existing `hooks/post-index-change` cannot be executed by Gitea's `git` subprocesses.
- Gitea itself only installs and manages `pre-receive`, `update`, `post-receive` and `proc-receive` hooks in repositories; it never uses `post-index-change`. Normal repository creation, commits, pushes, pulls and `diffpatch` requests 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.

## 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`.

## How it was tested

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

### Results

| 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)                                           |

## How to apply

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:

```sh
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-60004
```

Publish and roll out:

```sh
shirudo 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>
```

## Review

- Contributors: romanlab.
- Reviewers: none recorded yet.

## Sources and links

- [GHSA-rcr6-4jqh-j84m advisory](https://github.com/go-gitea/gitea/security/advisories/GHSA-rcr6-4jqh-j84m)
- [Gitea 1.27.1 release announcement](https://blog.gitea.com/release-of-1.27.1/)
- [Fix pull request #38637 (`470d34b1de87d901bd9135564d5ee18c0d339e82`)](https://github.com/go-gitea/gitea/commit/470d34b1de87d901bd9135564d5ee18c0d339e82) and [backport pull request #38638 (`d7bc52beeadff4be5f5690de4d5de42abd10affe`)](https://github.com/go-gitea/gitea/pull/38638)
- [Public PoC reference (`0xBlackash/CVE-2026-60004`)](https://github.com/0xBlackash/CVE-2026-60004)
- [runZero analysis of CVE-2026-60004](https://www.runzero.com/blog/gitea/)

### Links

- [CVE-2026-60004 on upatch.dev](https://upatch.dev/cve/CVE-2026-60004) (this page, as HTML)
- [NVD](https://nvd.nist.gov/vuln/detail/CVE-2026-60004)
- [CVE.org](https://www.cve.org/CVERecord?id=CVE-2026-60004)
- [CWE-94](https://cwe.mitre.org/data/definitions/94.html)
- Upatch source: [upatches/cve-2026-60004](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-60004)

### More references from NVD (3)

- [blog.gitea.com](https://blog.gitea.com/release-of-1.27.1/) (Release Notes)
- [runzero.com](https://www.runzero.com/blog/gitea/) (Third Party Advisory)
- [cisa.gov](https://www.cisa.gov/known-exploited-vulnerabilities-catalog?field_cve=CVE-2026-60004) (US Government Resource)
