Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
14 changes: 9 additions & 5 deletions kernel/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ mkdir -p output

KMIS="android12-5.10 android13-5.10 android13-5.15 android14-5.15 android14-6.1 android15-6.6 android16-6.12"

mv .ddk-version .ddk-version.bak || true
cd ..

for kmi in $KMIS; do
Comment thread
AlexLiuDev233 marked this conversation as resolved.
echo "========== Building $kmi =========="
export DDK_TARGET=$kmi
if ddk build -e CONFIG_KSU=m; then
if ddk build \
-e CONFIG_KSU=m \
-- -C kernel; then
cd kernel/
if [ -f kernelsu.ko ]; then
cp kernelsu.ko "kernelsu-${kmi}.ko"
llvm-objcopy --strip-unneeded --discard-locals "kernelsu-${kmi}.ko"
llvm-objcopy --strip-unneeded "kernelsu-${kmi}.ko"
echo "✓ Built kernelsu-${kmi}.ko"
fi
cd ..
else
echo "✗ Build failed for $kmi"
fi
echo ""
unset DDK_TARGET
done

mv .ddk-version.bak .ddk-version || true
cd kernel

echo "========== Final output =========="
ls -la
ls -la
1 change: 1 addition & 0 deletions kernel/supercall/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static int do_get_info(void __user *arg)
cmd.flags |= KSU_GET_INFO_FLAG_PR_BUILD;
#endif
cmd.features = KSU_FEATURE_MAX;
cmd.uapi_version = KERNEL_SU_UAPI_VERSION;

if (copy_to_user(arg, &cmd, sizeof(cmd))) {
pr_err("get_version: copy_to_user failed\n");
Comment thread
AlexLiuDev233 marked this conversation as resolved.
Expand Down
6 changes: 6 additions & 0 deletions manager/app/src/main/cpp/jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Java_me_weishu_kernelsu_Natives_getVersion(JNIEnv *env, jobject) {
return legacy_get_info().first;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_me_weishu_kernelsu_Natives_checkUAPIMismatch(JNIEnv *env, jobject) {
return is_uapi_version_mismatch();
}

extern "C"
JNIEXPORT jint JNICALL
Java_me_weishu_kernelsu_Natives_getSuperuserCount(JNIEnv *env, jobject) {
Expand Down
5 changes: 5 additions & 0 deletions manager/app/src/main/cpp/ksu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ struct ksu_get_info_cmd get_info() {
return g_version;
}

bool is_uapi_version_mismatch() {
auto info = get_info();
return info.uapi_version != KERNEL_SU_UAPI_VERSION;
}

uint32_t get_version() {
auto info = get_info();
return info.version;
Expand Down
2 changes: 2 additions & 0 deletions manager/app/src/main/cpp/ksu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "uapi/ksu.h"

bool is_uapi_version_mismatch();

uint32_t get_version();

bool uid_should_umount(int uid);
Expand Down
7 changes: 5 additions & 2 deletions manager/app/src/main/java/me/weishu/kernelsu/Natives.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ object Natives {
// 32310: new get_allow_list ioctl
// 32336: new set_sepolicy ioctl
// 32377: add set_init_pgrp ioctl
const val MINIMAL_SUPPORTED_KERNEL = 32377
// 32483: add uapi version
const val MINIMAL_SUPPORTED_KERNEL = 32483

const val KERNEL_SU_DOMAIN = "u:r:ksu:s0"

Expand Down Expand Up @@ -105,8 +106,10 @@ object Natives {
}
}

external fun checkUAPIMismatch(): Boolean

fun requireNewKernel(): Boolean {
return version != -1 && version < MINIMAL_SUPPORTED_KERNEL
return (version != -1 && version < MINIMAL_SUPPORTED_KERNEL) || checkUAPIMismatch()
}

@Keep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,23 @@ fun HomePagerMaterial(
WarningCard(stringResource(id = R.string.home_gki_warning))
}
if (state.showRequireKernelWarning) {
WarningCard(
stringResource(id = R.string.require_kernel_version,
state.ksuVersion ?: 0,
me.weishu.kernelsu.Natives.MINIMAL_SUPPORTED_KERNEL
if (state.currentManagerVersionCode < (state.ksuVersion ?: 0)) {
Comment thread
AlexLiuDev233 marked this conversation as resolved.
WarningCard(
stringResource(
id = R.string.require_manager_version,
state.currentManagerVersionCode,
state.ksuVersion ?: 0,
)
)
)
} else {
WarningCard(
stringResource(
id = R.string.require_kernel_version,
state.ksuVersion ?: 0,
me.weishu.kernelsu.Natives.MINIMAL_SUPPORTED_KERNEL
)
)
}
}
if (state.showRootWarning) {
WarningCard(stringResource(id = R.string.grant_root_failed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,23 @@ fun HomePagerMiuix(
WarningCard(stringResource(id = R.string.home_gki_warning))
}
if (state.showRequireKernelWarning) {
WarningCard(
stringResource(
id = R.string.require_kernel_version,
state.ksuVersion ?: 0, me.weishu.kernelsu.Natives.MINIMAL_SUPPORTED_KERNEL
),
)
if (state.currentManagerVersionCode < (state.ksuVersion ?: 0)) {
Comment thread
AlexLiuDev233 marked this conversation as resolved.
WarningCard(
stringResource(
id = R.string.require_manager_version,
state.currentManagerVersionCode,
state.ksuVersion ?: 0,
)
)
} else {
WarningCard(
stringResource(
id = R.string.require_kernel_version,
state.ksuVersion ?: 0,
me.weishu.kernelsu.Natives.MINIMAL_SUPPORTED_KERNEL
)
)
}
}
if (state.showRootWarning) {
WarningCard(stringResource(id = R.string.grant_root_failed))
Expand Down
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<string name="profile_selinux_context">SELinux</string>
<string name="profile_umount_modules">卸载模块</string>
<string name="failed_to_update_app_profile">为 %s 更新 App Profile 失败</string>
<string name="require_manager_version">当前 KernelSU 管理器版本 %1$d 过低,KernelSU 无法正常工作. 请将 KernelSU 管理器版本升级至 %2$d 或以上!</string>
<string name="require_kernel_version">当前 KernelSU 版本 %1$d 过低,管理器无法正常工作,请将内核 KernelSU 版本升级至 %2$d 或以上!</string>
<string name="settings_umount_modules_default">默认卸载模块</string>
<string name="settings_umount_modules_default_summary">App Profile 中「卸载模块」的全局默认值,如果启用,会将未自定义 Profile 的应用移除所有模块针对系统的修改</string>
Expand Down
1 change: 1 addition & 0 deletions manager/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<string name="profile_selinux_context">SELinux context</string>
<string name="profile_umount_modules">Umount modules</string>
<string name="failed_to_update_app_profile">Failed to update App Profile for %s</string>
<string name="require_manager_version">The current KernelSU manager version %1$d is too low for KernelSU to work properly. Please upgrade manager to version %2$d or higher!</string>
<string name="require_kernel_version">The current KernelSU version %1$d is too low for the manager to work properly. Please upgrade to version %2$d or higher!</string>
<string name="settings_umount_modules_default">Umount modules by default</string>
<string name="settings_umount_modules_default_summary">The global default value for \"Umount modules\" in App Profile. If enabled, it will remove all module modifications to the system for apps that don\'t have a profile set.</string>
Expand Down
5 changes: 5 additions & 0 deletions uapi/supercall.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "uapi/app_profile.h"

// use __u32 to avoid we maybe have version more than 255
// yep, it's possible it will never be exceeded, just to prevent the possibility
static const __u32 KERNEL_SU_UAPI_VERSION = 1;

/* Magic numbers for reboot hook to install fd */
static const __u32 KSU_INSTALL_MAGIC1 = 0xDEADBEEF;
static const __u32 KSU_INSTALL_MAGIC2 = 0xCAFEBABE;
Expand All @@ -27,6 +31,7 @@ struct ksu_get_info_cmd {
__u32 version; /* Output: KERNEL_SU_VERSION */
__u32 flags; /* Output: KSU_GET_INFO_FLAG_* bits */
__u32 features; /* Output: max feature ID supported */
__u32 uapi_version; /* Output: KERNEL_SU_UAPI_VERSION */
};
Comment thread
AlexLiuDev233 marked this conversation as resolved.

struct ksu_report_event_cmd {
Expand Down
23 changes: 22 additions & 1 deletion userspace/ksud/src/init_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ use crate::{
};
use anyhow::{Context, Result};
use libc::_exit;
use log::{info, warn};
use log::{error, info, warn};
use prop_rs_android::resetprop::ResetProp;
use prop_rs_android::sys_prop;
use rustix::process::chdir;
use std::path::Path;
use std::process::Command;

pub fn on_post_data_fs() -> Result<()> {
if ksucalls::is_uapi_version_mismatch() {
error!("Kernel and userspace uapi version mismatch! skip on_post_fs_data");
return Ok(());
}

ksucalls::report_post_fs_data();

utils::umask(0);
Expand Down Expand Up @@ -144,11 +149,21 @@ pub fn run_stage(stage: &str, block: bool) {
}

pub fn on_services() {
if ksucalls::is_uapi_version_mismatch() {
error!("Kernel and userspace uapi version mismatch! skip on_services");
return;
}
Comment thread
AlexLiuDev233 marked this conversation as resolved.

info!("on_services triggered!");
run_stage("service", false);
}

pub fn on_boot_completed() {
if ksucalls::is_uapi_version_mismatch() {
error!("Kernel and userspace uapi version mismatch! skip on_boot_completed");
return;
}
Comment thread
AlexLiuDev233 marked this conversation as resolved.

ksucalls::report_boot_complete();
info!("on_boot_completed triggered!");

Expand Down Expand Up @@ -223,6 +238,12 @@ fn catch_bootlog(logname: &str, command: &[&str]) -> Result<()> {
}

pub fn soft_reboot() -> Result<()> {
// check it avoid user click "soft_reboot" in manager when version mismatch
if ksucalls::is_uapi_version_mismatch() {
error!("Kernel and userspace uapi version mismatch! skip soft_reboot");
return Ok(());
}

utils::daemonize_with(true, || -> Result<()> {
switch_mnt_ns(1)?;
chdir("/")?;
Expand Down
5 changes: 5 additions & 0 deletions userspace/ksud/src/ksucalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn get_info() -> ksu_uapi::ksu_get_info_cmd {
version: 0,
flags: 0,
features: 0,
uapi_version: 0,
};
let _ = ksuctl(ksu_uapi::KSU_IOCTL_GET_INFO, &raw mut cmd);
cmd
Expand All @@ -82,6 +83,10 @@ pub fn is_late_load() -> bool {
get_info().flags & ksu_uapi::KSU_GET_INFO_FLAG_LATE_LOAD != 0
}

pub fn is_uapi_version_mismatch() -> bool {
get_info().uapi_version != ksu_uapi::KERNEL_SU_UAPI_VERSION
}

pub fn grant_root() -> std::io::Result<()> {
ksuctl(ksu_uapi::KSU_IOCTL_GRANT_ROOT, std::ptr::null_mut::<u8>())?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions userspace/ksuinit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn has_kernelsu_v2() -> bool {
version: u32,
flags: u32,
features: u32,
uapi_version: u32,
}

// Try new method: get driver fd using reboot syscall with magic numbers
Expand Down