Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions .github/workflows/build-ksu-lkm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ on:
description: Target id from targets.json (or "all")
default: a14-api34-6.1
type: string
# release.yml calls this with release: true to build every pinned target for a tag.
workflow_call:
inputs:
target:
description: Target id from targets.json (or "all")
default: all
type: string
release:
description: Build only targets with pinned digests and upload them as verified artifacts
default: false
type: boolean
pull_request:
paths:
- build-lkm.sh
Expand Down Expand Up @@ -35,14 +46,35 @@ jobs:
shell: bash
env:
INPUT_TARGET: ${{ inputs.target }}
INPUT_RELEASE: ${{ inputs.release == true }}
run: |
set -euo pipefail
target="${INPUT_TARGET:-a14-api34-6.1}"
matrix=$(jq -ce --arg t "$target" '
[.targets[] | select($t == "all" or .id == $t)
| {id, ksu_version, ksu_commit, lkm_sha256, lkm_size}]
| select(length > 0)
' targets.json)
if [[ "$INPUT_RELEASE" == "true" ]]; then
# A null pin means the module has not passed device validation: skip it, never release it.
skipped=$(jq -r --arg t "$target" '
[.targets[] | select($t == "all" or .id == $t)
| select(.lkm_sha256 == null or .lkm_size == null) | .id] | join(" ")
' targets.json)
if [[ -n "$skipped" ]]; then
echo "::notice::Not released (no pinned LKM digest): $skipped"
fi
if ! matrix=$(jq -ce --arg t "$target" '
[.targets[] | select($t == "all" or .id == $t)
| select(.lkm_sha256 != null and .lkm_size != null)
| {id, ksu_version, ksu_commit, lkm_sha256, lkm_size}]
| select(length > 0)
' targets.json); then
echo "::error::No selected target has a pinned lkm_sha256 and lkm_size; nothing to release"
exit 1
fi
else
matrix=$(jq -ce --arg t "$target" '
[.targets[] | select($t == "all" or .id == $t)
| {id, ksu_version, ksu_commit, lkm_sha256, lkm_size}]
| select(length > 0)
' targets.json)
fi
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"

build:
Expand Down Expand Up @@ -136,8 +168,12 @@ jobs:
path: ${{ runner.temp }}/ksu-candidate/*
if-no-files-found: error
retention-days: 5
# Manual runs on main, or release.yml on a v0.N.P tag (it checks that the tag is on main).
- name: Upload verified LKM from upstream main
if: github.event_name == 'workflow_dispatch' && github.repository == 'ModAVD/ModAVDKernelSU' && github.ref == 'refs/heads/main' && matrix.target.lkm_sha256 != null
if: >-
github.repository == 'ModAVD/ModAVDKernelSU' && matrix.target.lkm_sha256 != null &&
((github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
(inputs.release == true && startsWith(github.ref, 'refs/tags/v0.')))
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: verified-ksu-lkm-${{ matrix.target.id }}
Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Release

# Pushing a v0.N.P tag (the ModAVD package version this module ships with) builds every
# target whose lkm_sha256 / lkm_size are pinned in targets.json, checks the output against
# those pins, and creates a draft Release. The ModAVD release script publishes the draft
# after the package release is approved.

on:
push:
tags: ["v*"]

permissions: {}

concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false

jobs:
check:
if: github.repository == 'ModAVD/ModAVDKernelSU'
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Verify tag name and that it is on main
shell: bash
env:
TAG: ${{ github.ref_name }}
SHA: ${{ github.sha }}
run: |
set -euo pipefail
# Only package versions. Tags in the old style (v3.3.1-a14-6.1) are not released by this workflow.
if [[ ! "$TAG" =~ ^v0\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::Tag $TAG is not v0.N.P; not releasing"
exit 1
fi
[[ "$SHA" =~ ^[0-9a-f]{40}$ ]]
# Full ref name: a tag called origin/main would otherwise win over the branch.
if ! git merge-base --is-ancestor "$SHA" refs/remotes/origin/main; then
echo "::error::$TAG ($SHA) is not on main"
exit 1
fi

build:
needs: check
permissions:
contents: read
uses: ./.github/workflows/build-ksu-lkm.yml
with:
target: all
release: true

draft:
needs: build
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: verified-ksu-lkm-*
path: ${{ runner.temp }}/verified
- name: Check modules against targets.json
shell: bash
env:
VERIFIED: ${{ runner.temp }}/verified
DIST: ${{ runner.temp }}/dist
run: |
set -euo pipefail
mkdir -p "$DIST"
# Exactly the pinned targets, checked against the tag's own targets.json.
mapfile -t pinned < <(jq -r '.targets[] | select(.lkm_sha256 != null and .lkm_size != null) | .id' targets.json)
if (( ${#pinned[@]} == 0 )); then
echo "::error::No target has a pinned LKM digest"
exit 1
fi
have=$(cd "$VERIFIED" && ls -1 | sort | tr '\n' ' ')
want=$(printf 'verified-ksu-lkm-%s\n' "${pinned[@]}" | sort | tr '\n' ' ')
if [[ "$have" != "$want" ]]; then
echo "::error::Artifacts [$have] do not match pinned targets [$want]"
exit 1
fi
for id in "${pinned[@]}"; do
[[ "$id" =~ ^[a-z0-9][a-z0-9._-]*$ ]]
ksu_version=$(jq -r --arg id "$id" '.targets[] | select(.id == $id) | .ksu_version' targets.json)
want_sha=$(jq -r --arg id "$id" '.targets[] | select(.id == $id) | .lkm_sha256' targets.json)
want_size=$(jq -r --arg id "$id" '.targets[] | select(.id == $id) | .lkm_size' targets.json)
[[ "$ksu_version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]
[[ "$want_sha" =~ ^[0-9a-f]{64}$ ]]
[[ "$want_size" =~ ^[1-9][0-9]*$ ]]
ko="${id}_kernelsu-${ksu_version}_kernelsu.ko"
src="$VERIFIED/verified-ksu-lkm-$id"
got_sha=$(sha256sum "$src/$ko")
got_sha=${got_sha%% *}
got_size=$(stat -c %s "$src/$ko")
if [[ "$got_sha" != "$want_sha" || "$got_size" != "$want_size" ]]; then
echo "::error::$ko is $got_size bytes, $got_sha; targets.json pins $want_size bytes, $want_sha"
exit 1
fi
cp "$src/$ko" "$DIST/$ko"
cp "$src/$id.env" "$DIST/$id.env"
done
# One SHA256SUMS.txt over the modules, the same form as the earlier releases.
(cd "$DIST" && sha256sum -- *_kernelsu.ko > SHA256SUMS.txt)
cat "$DIST/SHA256SUMS.txt"
- name: Create draft release
shell: bash
env:
TAG: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
DIST: ${{ runner.temp }}/dist
run: |
set -euo pipefail
[[ "$TAG" =~ ^v0\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]
version=${TAG#v}
# Drafts are not bound to their tag, so list every release, drafts included.
tags=$(gh api "repos/$GH_REPO/releases?per_page=100" --paginate --jq '.[].tag_name')
if grep -Fxq -- "$TAG" <<< "$tags"; then
echo "::error::A release for $TAG already exists (draft or published); not overwriting"
exit 1
fi
notes="$RUNNER_TEMP/notes.md"
if [[ -f "release/$version.md" ]]; then
cp "release/$version.md" "$notes"
else
{
echo "随 ModAVD $version 发布。"
echo
echo "Released with ModAVD $version."
echo
echo '```text'
cat "$DIST/SHA256SUMS.txt"
echo '```'
} > "$notes"
fi
gh release create "$TAG" --draft --verify-tag --title "$TAG" --notes-file "$notes" "$DIST"/*
23 changes: 16 additions & 7 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,36 @@ Builds `kernelsu.ko` for ModAVD's Android 14 API 34 Google APIs x86_64 r14 image
- `x86_64-seccomp-skip.patch` preserves the kernel's decision to skip a system call when the call number is read again.
- `x86_64-do_syscall_64-fallback.patch` selects the compatibility entry when r14 lacks `x64_sys_call`. It applies after the first patch.
- `disable-module-unload.patch` disables live unloading. In-flight system calls may return to module code. Shut down the guest normally to remove the module.
- `observer-release-mount-reference.patch` stops the package observer from pinning the `/data` mount. KernelSU watches `/data/system` to update its package list. It used to hold a path reference to that directory for as long as the watch existed, so `/data` could not be unmounted at shutdown: shutdown waited for the unmount timeout and was slower, and the next boot replayed the ext4 journal and ran a full check (ModAVD/ModAVD#309). The patch keeps the watch but releases the path reference right after registering it; the `fsnotify` mark holds the inode.

Use Docker, Python 3, and Git on Linux x86_64. Prepare a full KernelSU clone containing the configured `ksu_commit` and pass the target ID, checkout path, and working directory to `build-target.sh`. Outputs are in `<target ID>/out` under that directory. The log includes the module SHA-256 and vermagic.

PR builds validate changes. While `lkm_sha256` and `lkm_size` are not pinned in `targets.json`, the build uploads its output as an artifact named `UNVERIFIED-candidate-<target ID>-<short commit hash>`, kept for 5 days, for device testing only. It is not a release. ModAVDManager never downloads a candidate, and its UI cannot import one. For device testing, import it with `modavd components import-ksu <file or folder> --lkm-sha256 <SHA-256>`, which explicitly trusts that digest. The release artifact, `verified-ksu-lkm-<target ID>`, is uploaded only by a manual build on the official repository's `main`, and only when the output matches both the pinned size and SHA-256. The module is excluded from the installer. See [THIRD_PARTY.md](THIRD_PARTY.md) for corresponding source and licensing.

## Release tag and file name

This target's module is published in this repository's Release `v3.3.1-a14-6.1` as `a14-api34-6.1_kernelsu-v3.3.1_kernelsu.ko`. ModAVDManager's download URL hard-codes this tag and file name.
The module is released together with the ModAVD package, and its tag follows the package.

- Tag: `<ksu_version>-a<Android version>-<kernel major.minor>`, that is `ksu_version` followed by `kmi` with `android` shortened to `a` (`android14-6.1` → `a14-6.1`).
- File name: `<target ID>_kernelsu-<ksu_version>_kernelsu.ko`, the same name as the file in the `verified-` artifact.
- Tag: `v0.N.P`, the version of the ModAVD package that ships this module. A tag is made only in a release where `main` has new commits since the last release and `targets.json` on `main` pins the module (`tools/pubrel/chain-components.ps1` in ModAVD decides this at freeze); otherwise the package keeps the previous tag and nothing is released again.
- File name, unchanged: `<target ID>_kernelsu-<ksu_version>_kernelsu.ko`, the same name as the file in the `verified-` artifact, for example `a14-api34-6.1_kernelsu-v3.3.1_kernelsu.ko`. The upstream KernelSU version stays in the file name. Each target also has `<target ID>.env` (its build inputs), and one `SHA256SUMS.txt` covers all `.ko` files.
- The existing `v3.3.1-a14-6.1` was released under the old rule (`<ksu_version>-a<Android version>-<kernel major.minor>`) and stays as it is. The old rule gives the same tag when only the patches change and the KernelSU version does not, and Release assets cannot be replaced, so the rule was changed.

Follow these rules when changing the KernelSU version or adding a target, and update ModAVDManager's download URL to match.
The tag, file name, size, and SHA-256 that ModAVDManager downloads are pinned in the manager's `internal/kernelsu/profile.go`: a new tag means changing them on the manager's release branch for that version (in the same step as its version number), and they ship with the package.

## How maintainers publish a new version

1. When changing build inputs (`targets.json`, patches, scripts), reset `lkm_sha256` and `lkm_size` to `null` and open a PR. Once the PR build passes, download the `UNVERIFIED-candidate-…` artifact from that run's Actions page. The step summary shows its size and SHA-256.
1. When changing build inputs (`targets.json`, patches, scripts), reset `lkm_sha256` and `lkm_size` to `null` and open a PR. Once the PR build passes, download the `UNVERIFIED-candidate-…` artifact from that run's Actions page. The step summary shows its size and SHA-256. A change users can see also adds a [`changelog.d`](changelog.d/README.md) file in the same PR.
2. Validate the candidate on a disposable r14 test instance. Import it with `modavd components import-ksu <extracted .ko or folder> --lkm-sha256 <SHA-256 from the step summary>`, then check that it loads, its vermagic is the full kernel release, unloading returns EBUSY, and the guest boots and shuts down normally.
3. Once it passes, copy the size and SHA-256 from the step summary into `lkm_size` and `lkm_sha256` in `targets.json` and open a PR. That PR build checks both the size and the digest and fails on a mismatch. When possible, confirm the digest with an independent build.
4. After merging, run this workflow manually on `main` (Actions → Build KernelSU LKM → Run workflow) to get the `verified-ksu-lkm-<target ID>` artifact, kept for 14 days.
5. Create the tag and Release named by the rules above, attach the `.ko`, `SHA256SUMS.txt`, and `.env` from the `verified-` artifact, and pin the same size and SHA-256 in ModAVDManager's KernelSU manifest.
4. After merging, wait for the package release; the module is not released on its own. **Only targets whose pins are not `null` and are merged into `main` count as validated and can be released.** Targets still pinned to `null` are not released, and the package keeps the previous tag.

The ModAVD release script releases the module as part of the package release; Releases are not created by hand:

1. The script tags the `main` commit `v0.N.P`.
2. The tag triggers [`release.yml`](.github/workflows/release.yml). It checks that the tag is `v0.N.P` and the commit is on `main`; skips targets pinned to `null` (and fails if all are); builds the modules with the same build workflow as above and compares them with the size and SHA-256 in `targets.json`; writes `SHA256SUMS.txt`; and creates a **draft** Release. If the tag already has a Release (draft or published), it fails instead of overwriting it.
3. After the maintainer approves the package release, the script publishes the draft, then the package.

For a standalone release artifact (for example to recheck on a device), you can still run the build manually on `main` (Actions → Build KernelSU LKM → Run workflow) to get the `verified-ksu-lkm-<target ID>` artifact, kept for 14 days.

## License and sources

Expand Down
Loading