-
An addon root hiding kernel patches and userspace module for KernelSU.
-
The userspace tool
ksu_susfs, as well as the ksu module, require a susfs patched kernel to work.
- This is only experimental code, that said it can harm your system or cause performance hit, YOU ARE !! W A R N E D !! already
- The susfs kernel patches may differ for different kernel version or even on the same kernel version, you may need to create your own patches for your kernel.
- Prerequisite -
- All susfs patches are mainly based on the original official KernelSU (the one from weishu), since KernelSU updates frequently and susfs needs to sync up with it, so it is now suggested to just clone the KernelSU and susfs repo without tag/release tag. If the applied susfs patches fails on KernelSU, you need to rollback KernelSU version to a specific commit and apply the patches again.
- Since v2.0.0, SUSFS does not rely on kernel features like KPROBES, KRETPROBES and HAVE_SYSCALL_TRACEPOINTS, which means it will patch all the sucompat code in KernelSU, fs/exec.c, fs/open.c, and fs/stat.c.
- Do NOT apply custom manual hooks for sucompat unless you implement your own one instead of the susfs one.
- Apply SUSFS patches -
- Make sure you follow the offical KSU guild here to clone and build the kernel with KSU:
https://kernelsu.org/guide/how-to-build.html, the kernel root directory should be$KERNEL_REPO/common, you should run script to clone KernelSU in$KERNEL_REPO, make sure you clone with a tag version. - Clone this susfs branch with a tag / release tag or up to a commit message containing "Bump version to vX.X.X", as they are more stable in general.
- Run
cp ./kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch $KERNEL_REPO/KernelSU/ - Run
cp ./kernel_patches/50_add_susfs_in_kernel-<kernel_version>.patch $KERNEL_REPO/common/ - Run
cp ./kernel_patches/fs/* $KERNEL_REPO/common/fs/ - Run
cp ./kernel_patches/include/linux/* $KERNEL_REPO/common/include/linux/ - Run
cd $KERNEL_REPO/KernelSUand thenpatch -p1 < 10_enable_susfs_for_ksu.patch - Run
cd $KERNEL_REPO/commonand thenpatch -p1 < 50_add_susfs_in_kernel.patch, if there are failed patches, you may try to patch them manually by yourself. - If you want to make your kernel support other KSU manager variant, you can add its own hash size and hash in
ksu_is_manager_apk()function inKernelSU/kernel/apk_sign.c - Make sure again to have
CONFIG_KSUandCONFIG_KSU_SUSFSenabled before building the kernel, some other SUSFS feature may be disabled by default, you may enable/disable them viamenuconfig,kernel defconfig, or change thedefault [y|n]option under eachconfig KSU_SUSFS_option in$KernelSU_repo/kernel/Kconfigif you build with a new defconfig every time. - For
gki kernel android14or above, if you are building from google artifacts, it is necessary to delete the file$KERNEL_REPO/common/android/abi_gki_protected_exports_aarch64and$KERNEL_REPO/common/android/abi_gki_protected_exports_x86_64, otherwise some modules like WiFi will not work. Or you can just remove those files whenever they exist in your kernel repo. - If you want to flash the fresh built gki boot.img, then before you build the kernel, first you need to fix or hardcode the
local spl_datein functionbuild_gki_boot_images()in$KERNEL_REPO/build/kernel/build_utils.shto match the current boot security patch level of your phone. Or you can just use magiskboot to unpack and repack the built kernel for your stock boot.img. - Build and flash the kernel.
- For other building tips, please refer to the section [Other Building Tips] below.
- Run
./build_ksu_susfs_tool.shto build the userspace toolksu_susfs, and the arm64 and arm binary will be copied toksu_module_susfs/tools/as well. - Now you can also push the compiled
ksu_susfstool to/data/adb/ksu/bin/so that you can run it directly in adb root shell or termux root shell, as well as in your own ksu modules.
- The ksu module here is just a demo to show how to use it.
- It will also copy the
ksu_susfstool to/data/adb/ksu/bin/as well when installing the module.
- ksu_susfs tool can be run in any stage scripts, post-fs-data.sh, services.sh, boot-completed.sh according to your own need.
- Run
./build_ksu_module.shto build the susfs KSU module.
- Run
ksu_susfsin root shell for detailed usages. - See
$KernelSU_repo/kernel/Kconfigfor supported features after applying the susfs patches.
-
To only remove the
-dirtystring from kernel release string, open file$KERNEL_ROOT/scripts/setlocalversion, then look for all the lines that containingprintf '%s' -dirty, and replace it withprintf '%s' '' -
Alternatively, If you want to directly hardcode the whole kernel release string, then open file
$KERNEL_ROOT/scripts/setlocalversion, look for the last lineecho "$res", and for example, replace it withecho "-android13-01-gb123456789012-ab12345678" -
To hardcode your kernel version string, open
$KERNEL_ROOT/scripts/mkcompile_h, and look for lineUTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)", then for example, replace it withUTS_VERSION="#1 SMP PREEMPT Mon Jan 1 18:00:00 UTC 2024". But for kernel 6.1+, you need to edit${KERNEL_ROOT}/init/Makefile, and look for linebuild-timestamp = $(or $(KBUILD_BUILD_TIMESTAMP), $(build-timestamp-auto)), replace it with your own timestamp, likebuild-timestamp = "Wed Jan 30 12:00:00 UTC 2025" -
To hardcode your kernel version string which can be seen from /proc/version, open
$KERNEL_ROOT/scripts/mkcompile_h, then search for variable nameLINUX_COMPILE_BYandLINUX_COMPILE_HOST, then for example, appendLINUX_COMPILE_BY=build-userandLINUX_COMPILE_HOST=build-hostafter lineUTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" -
To spoof the
/proc/config.gzwith the stock config,- Make sure you are on the stock ROM and using stock kernel.
- Use adb shell or root shell to pull your stock
/proc/config.gzfrom your device to PC. - Decompress it using
gunzipor whatever tools, then copy it to$KERNEL_ROOT/arch/arm64/configs/stock_defconfig - Open file
$KERNEL_ROOT/kernel/Makefile. - Look for line
$(obj)/config_data: $(KCONFIG_CONFIG) FORCE, and replace it with$(obj)/config_data: arch/arm64/configs/stock_defconfig FORCE
- KernelSU: https://github.com/tiann/KernelSU
- KernelSU fork: https://github.com/5ec1cff/KernelSU
- @Kartatz: for ideas and original commit from https://github.com/Dominium-Apum/kernel_xiaomi_chime/pull/1/commits/74f8d4ecacd343432bb8137b7e7fbe3fd9fef189
- @simonpunk