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
41 changes: 39 additions & 2 deletions .github/workflows/build-ksu-lkm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
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}]
| {id, ksu_version, ksu_commit, lkm_sha256, lkm_size}]
| select(length > 0)
' targets.json)
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -71,15 +71,20 @@ jobs:
git -C "$RUNNER_TEMP/ksu-upstream" fetch --no-tags origin "$KSU_COMMIT"
git -C "$RUNNER_TEMP/ksu-upstream" checkout --detach "$KSU_COMMIT"
- name: Build and verify kernelsu.ko
id: build
shell: bash
env:
TARGET_ID: ${{ matrix.target.id }}
KSU_VERSION: ${{ matrix.target.ksu_version }}
LKM_SHA256: ${{ matrix.target.lkm_sha256 }}
REPO_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
set -euo pipefail
[[ "$TARGET_ID" =~ ^[a-z0-9][a-z0-9._-]*$ ]]
[[ "$KSU_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]
[[ "$REPO_SHA" =~ ^[0-9a-f]{40}$ ]]
short_sha=${REPO_SHA:0:12}
echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT"
bash build-target.sh "$TARGET_ID" "$RUNNER_TEMP/ksu-upstream" "$RUNNER_TEMP/ksu-work"
target="$RUNNER_TEMP/ksu-work/$TARGET_ID"
dist="$RUNNER_TEMP/ksu-dist"
Expand All @@ -88,17 +93,49 @@ jobs:
cp "$target/out/kernelsu.ko" "$dist/$ko_name"
cp "$target/target.env" "$dist/${TARGET_ID}.env"
(cd "$dist" && sha256sum "$ko_name" > SHA256SUMS.txt)
ko_size=$(stat -c %s "$dist/$ko_name")
ko_sha256=$(sha256sum "$dist/$ko_name")
ko_sha256=${ko_sha256%% *}
{
echo "### KernelSU LKM ($TARGET_ID)"
echo
echo "- Size: \`$ko_size\` bytes"
echo "- SHA-256: \`$ko_sha256\`"
echo "- Repository commit: \`$REPO_SHA\`"
echo
echo 'Values to pin in `targets.json` (and the ModAVDManager KernelSU profile) after device validation:'
echo
echo '~~~json'
printf '"lkm_sha256": "%s",\n"lkm_size": %s\n' "$ko_sha256" "$ko_size"
echo '~~~'
echo
echo '~~~text'
cat "$dist/SHA256SUMS.txt"
cat "$dist/${TARGET_ID}.env"
echo '~~~'
} >> "$GITHUB_STEP_SUMMARY"
if [[ -z "$LKM_SHA256" ]]; then
echo "::notice::This is a validation build. No LKM hash is pinned for publication."
# No pinned digest: hand out the build only under an unmistakable candidate name.
candidate_name="UNVERIFIED-candidate-${TARGET_ID}-${short_sha}"
candidate="$RUNNER_TEMP/ksu-candidate"
mkdir -p "$candidate"
cp "$dist/$ko_name" "$candidate/${candidate_name}_kernelsu.ko"
cp "$dist/${TARGET_ID}.env" "$candidate/${candidate_name}.env"
(cd "$candidate" && sha256sum "${candidate_name}_kernelsu.ko" > SHA256SUMS.txt)
{
echo
echo "No LKM digest is pinned. This build is uploaded only as the UNVERIFIED artifact \`$candidate_name\` (kept 5 days) for device testing. It is not a release asset."
} >> "$GITHUB_STEP_SUMMARY"
echo "::notice::Validation build: no LKM hash is pinned, so only the UNVERIFIED candidate artifact $candidate_name is uploaded."
fi
- name: Upload UNVERIFIED candidate LKM (device testing only)
if: matrix.target.lkm_sha256 == null
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: UNVERIFIED-candidate-${{ matrix.target.id }}-${{ steps.build.outputs.short_sha }}
path: ${{ runner.temp }}/ksu-candidate/*
if-no-files-found: error
retention-days: 5
- 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
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
23 changes: 21 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ Builds `kernelsu.ko` for ModAVD's Android 14 API 34 Google APIs x86_64 r14 image

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. Only a manual build on the official repository's `main` can publish an artifact, and only when its output matches the pinned SHA-256. After changing build inputs, maintainers should validate boot and live kernel status on a disposable r14 instance. Once independent builds produce the same digest, pin the matching digest and size in this repository and the ModAVDManager manifest. A maintainer attaches the verified module to this repository's Release as an optional download, for example under `v3.3.1-a14-6.1`. It is excluded from the installer. See [THIRD_PARTY.md](THIRD_PARTY.md) for corresponding source and licensing.
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.

Scripts and configuration are Apache-2.0. KernelSU patches are GPL-2.0-only. See [LICENSE](LICENSE) for the full terms. The x86_64 AVD build approach draws on [avd-kernelsu-x86_64-MultiSU](https://github.com/imkamaran/avd-kernelsu-x86_64-MultiSU).
## 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.

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

Follow these rules when changing the KernelSU version or adding a target, and update ModAVDManager's download URL to match.

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

## License and sources

Scripts and configuration are Apache-2.0. KernelSU patches are GPL-2.0-only. See [LICENSE](LICENSE) for the full terms. The x86_64 AVD build approach draws on [avd-kernelsu-x86_64-MultiSU](https://github.com/imkamaran/avd-kernelsu-x86_64-MultiSU). `x86_64-seccomp-skip.patch` and `x86_64-do_syscall_64-fallback.patch` are taken from the `patches/` directory of [avd-kernelsu-x86_64](https://github.com/leemikepop/avd-kernelsu-x86_64) at commit `d82e42733f08a03220dbbe72d7d998c162ca74d6` and are licensed GPL-2.0-only. avd-kernelsu-x86_64-MultiSU is a fork of it and has the same two files at commit `c4c5f421ba74b58b49d0a9f47fed2da97a836e8c`. Their content is unchanged; only a source note was added at the top of each file.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@

在 Linux x86_64 上使用 Docker、Python 3 和 Git。准备一份完整克隆,能解析配置中 `ksu_commit` 的 KernelSU Git 仓库,将目标 ID、该仓库路径和工作目录传给 `build-target.sh`。输出在工作目录的 `<目标 ID>/out`,日志包含模块的 SHA-256 和 vermagic。

PR 构建用于验证,制品只在官方仓库 `main` 的手动构建且输出 SHA-256 已固定并匹配时发布。修改构建输入后,维护者需要在 r14 测试实例上验证启动和内核状态,并在独立构建确认哈希一致后,把同一个模块哈希和大小填入本仓库和 ModAVDManager 的清单。维护者将核验后的模块作为本仓库 Release 的可选附件发布,例如标签 `v3.3.1-a14-6.1`。安装包不包含它。对应源码和许可证见 [THIRD_PARTY.md](THIRD_PARTY.md)。
PR 构建用于验证。`targets.json` 里还没钉模块的 `lkm_sha256` 和 `lkm_size` 时,构建会把产物上传成名为 `UNVERIFIED-candidate-<目标 ID>-<提交短哈希>` 的制品,保留 5 天,只供上机验证,不是正式版。ModAVDManager 不会下载候选制品,界面里也导入不了;要上机验证,用 `modavd components import-ksu <文件或文件夹> --lkm-sha256 <SHA-256>` 显式信任后导入。正式制品只在官方仓库 `main` 的手动构建、并且输出和钉住的大小、SHA-256 都一致时上传,名字是 `verified-ksu-lkm-<目标 ID>`。安装包不包含模块。对应源码和许可证见 [THIRD_PARTY.md](THIRD_PARTY.md)。

本目录脚本和配置按 Apache-2.0 发布。KernelSU 补丁按 GPL-2.0-only 发布。许可证全文见 [LICENSE](LICENSE)。x86_64 AVD 构建思路参考 [avd-kernelsu-x86_64-MultiSU](https://github.com/imkamaran/avd-kernelsu-x86_64-MultiSU)。
## 发布标签和文件名

这个目标的模块发布在本仓库的 Release `v3.3.1-a14-6.1`,附件名是 `a14-api34-6.1_kernelsu-v3.3.1_kernelsu.ko`。ModAVDManager 的下载地址写死了这个标签和文件名。

- 标签:`<ksu_version>-a<Android 版本>-<内核主次版本>`,也就是 `ksu_version` 接上 `kmi` 把 `android` 缩写成 `a` 以后的部分(`android14-6.1` → `a14-6.1`)。
- 文件名:`<目标 ID>_kernelsu-<ksu_version>_kernelsu.ko`,和 `verified-` 制品里的文件同名。

换 KernelSU 版本或者加目标时按这个规则起名,并同步改 ModAVDManager 的下载地址。

## 维护者怎么出一个新版本

1. 改构建输入(`targets.json`、补丁、脚本)时,把 `lkm_sha256`、`lkm_size` 改回 `null`,开 PR。PR 构建通过后,在这次运行的 Actions 页面下载 `UNVERIFIED-candidate-…` 制品;step summary 里有它的大小和 SHA-256。
2. 在一次性的 r14 测试实例上验证这份候选模块:用 `modavd components import-ksu <解压出的 .ko 或文件夹> --lkm-sha256 <step summary 里的 SHA-256>` 导入,然后确认能加载,vermagic 是完整的内核版本串,卸载返回 EBUSY,客体能正常开机和关机。
3. 验证通过后,把 step summary 里的大小和 SHA-256 填进 `targets.json` 的 `lkm_size`、`lkm_sha256`,开 PR。这次 PR 构建会同时比对大小和哈希,不一致就失败。有条件时另做一次独立构建,确认哈希一致。
4. 合并后,在 `main` 上手动触发这个工作流(Actions → Build KernelSU LKM → Run workflow),得到 `verified-ksu-lkm-<目标 ID>` 制品,保留 14 天。
5. 按上面的规则建标签和 Release,把 `verified-` 制品里的 `.ko`、`SHA256SUMS.txt` 和 `.env` 挂成附件,再把同一组大小和 SHA-256 填进 ModAVDManager 的 KernelSU 清单。

## 许可证和来源

本目录脚本和配置按 Apache-2.0 发布。KernelSU 补丁按 GPL-2.0-only 发布。许可证全文见 [LICENSE](LICENSE)。x86_64 AVD 构建思路参考 [avd-kernelsu-x86_64-MultiSU](https://github.com/imkamaran/avd-kernelsu-x86_64-MultiSU)。`x86_64-seccomp-skip.patch` 和 `x86_64-do_syscall_64-fallback.patch` 取自 [avd-kernelsu-x86_64](https://github.com/leemikepop/avd-kernelsu-x86_64) 提交 `d82e42733f08a03220dbbe72d7d998c162ca74d6` 的 `patches/` 目录,按 GPL-2.0-only 授权。avd-kernelsu-x86_64-MultiSU 是它的 fork,提交 `c4c5f421ba74b58b49d0a9f47fed2da97a836e8c` 里的这两个文件和它相同。补丁内容没有改动,只在文件开头加了来源说明。
1 change: 1 addition & 0 deletions THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| Artifact | License | Corresponding source |
|---|---|---|
| `a14-api34-6.1_kernelsu-v3.3.1_kernelsu.ko` | GPL-2.0-only | [KernelSU commit `0c0fdb960178fa12d80d6cbcfdcb6ad8be6a865d`](https://github.com/tiann/KernelSU/tree/0c0fdb960178fa12d80d6cbcfdcb6ad8be6a865d), [local patches](patches/) and [build scripts](README.en.md) |
| `patches/x86_64-seccomp-skip.patch`, `patches/x86_64-do_syscall_64-fallback.patch` | GPL-2.0-only | Taken unchanged from [avd-kernelsu-x86_64 commit `d82e42733f08a03220dbbe72d7d998c162ca74d6`](https://github.com/leemikepop/avd-kernelsu-x86_64/tree/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches) (`patches/`, licensed GPL-2.0-only by its [patches/LICENSE](https://github.com/leemikepop/avd-kernelsu-x86_64/blob/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches/LICENSE)); identical in its fork [avd-kernelsu-x86_64-MultiSU commit `c4c5f421ba74b58b49d0a9f47fed2da97a836e8c`](https://github.com/imkamaran/avd-kernelsu-x86_64-MultiSU/tree/c4c5f421ba74b58b49d0a9f47fed2da97a836e8c/patches). A source note was added at the top of each file |
| Android r14 kernel build input | See the pinned Android source tree | [Android kernel/common commit `7e35917775b8b3e3346a87f294e334e258bf15e6`](https://android.googlesource.com/kernel/common/+/7e35917775b8b3e3346a87f294e334e258bf15e6), with the configuration extracted from the r14 `kernel-ranchu` pinned in [targets.json](targets.json) |

Publish the matching repository commit and the source references alongside the verified Release asset. The build summary and target environment record the exact locked inputs and output digest.
6 changes: 6 additions & 0 deletions build-target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ docker run --rm --platform linux/amd64 --network none \

actual=$(sha256sum "$TDIR/out/kernelsu.ko")
actual=${actual%% *}
actual_size=$(stat -c %s "$TDIR/out/kernelsu.ko")
echo "LKM size: $actual_size bytes"
echo "LKM SHA-256: $actual"
if [[ -n "$LKM_SIZE" && "$actual_size" != "$LKM_SIZE" ]]; then
echo "Expected LKM size: $LKM_SIZE bytes" >&2
exit 1
fi
if [[ -n "$LKM_SHA256" && "$actual" != "$LKM_SHA256" ]]; then
echo "Expected LKM SHA-256: $LKM_SHA256" >&2
exit 1
Expand Down
8 changes: 8 additions & 0 deletions fetch_kernel_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ def main():
"KSU_COMMIT": t["ksu_commit"],
"KSU_COMMIT_COUNT": str(t["ksu_commit_count"]),
"LKM_SHA256": t["lkm_sha256"] or "",
"LKM_SIZE": "",
"PATCHES": " ".join(t.get("patches", [])),
}
if env["LKM_SHA256"] and not re.fullmatch(r"[0-9a-f]{64}", env["LKM_SHA256"]):
sys.exit("invalid expected LKM SHA-256")
lkm_size = t.get("lkm_size")
if lkm_size is not None:
if type(lkm_size) is not int or lkm_size <= 0:
sys.exit("invalid expected LKM size")
env["LKM_SIZE"] = str(lkm_size)
if bool(env["LKM_SHA256"]) != bool(env["LKM_SIZE"]):
sys.exit("lkm_sha256 and lkm_size must be pinned together")
(a.out / "target.env").write_text(
"".join(f"{k}={shlex.quote(v)}\n" for k, v in env.items()), encoding="utf-8"
)
Expand Down
7 changes: 7 additions & 0 deletions patches/x86_64-do_syscall_64-fallback.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Source: https://github.com/leemikepop/avd-kernelsu-x86_64/blob/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches/x86_64-do_syscall_64-fallback.patch
Taken unchanged from avd-kernelsu-x86_64 at commit d82e42733f08a03220dbbe72d7d998c162ca74d6.
The same file is in its fork avd-kernelsu-x86_64-MultiSU at commit c4c5f421ba74b58b49d0a9f47fed2da97a836e8c.
License: GPL-2.0-only, as stated by https://github.com/leemikepop/avd-kernelsu-x86_64/blob/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches/LICENSE
(full text in LICENSES/GPL-2.0-only.txt of this repository).
SPDX-License-Identifier: GPL-2.0-only

--- a/kernel/hook/x86_64/syscall_hook.c
+++ b/kernel/hook/x86_64/syscall_hook.c
@@ -215,10 +215,15 @@ static long my_x64_sys_call(const struct pt_regs *regs, unsigned int nr)
Expand Down
7 changes: 7 additions & 0 deletions patches/x86_64-seccomp-skip.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Source: https://github.com/leemikepop/avd-kernelsu-x86_64/blob/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches/x86_64-seccomp-skip.patch
Taken unchanged from avd-kernelsu-x86_64 at commit d82e42733f08a03220dbbe72d7d998c162ca74d6.
The same file is in its fork avd-kernelsu-x86_64-MultiSU at commit c4c5f421ba74b58b49d0a9f47fed2da97a836e8c.
License: GPL-2.0-only, as stated by https://github.com/leemikepop/avd-kernelsu-x86_64/blob/d82e42733f08a03220dbbe72d7d998c162ca74d6/patches/LICENSE
(full text in LICENSES/GPL-2.0-only.txt of this repository).
SPDX-License-Identifier: GPL-2.0-only

--- a/kernel/hook/x86_64/syscall_hook.c
+++ b/kernel/hook/x86_64/syscall_hook.c
@@ -244,7 +244,9 @@
Expand Down
1 change: 1 addition & 0 deletions targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ksu_commit": "0c0fdb960178fa12d80d6cbcfdcb6ad8be6a865d",
"ddk_image": "ghcr.io/ylarod/ddk-min@sha256:1dd6ac340b627a90a4031d6d0df6b129d8cc949b139fb56032c898f023d3d5d3",
"lkm_sha256": null,
"lkm_size": null,
"ksu_commit_count": 2680
}
]
Expand Down
Loading