Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting KernelSU to android kernel3.18 failed #539

Closed
dabao1955 opened this issue May 21, 2023 · 4 comments
Closed

porting KernelSU to android kernel3.18 failed #539

dabao1955 opened this issue May 21, 2023 · 4 comments

Comments

@dabao1955
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.
porting KernelSU to android kernel3.18 failed
To Reproduce
Steps to reproduce the behavior:make ARCH=arm64
O=../out
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=$HOME/aarch64-linux-android-4.9>
CROSS_COMPILE_ARM32=$HOME/arm-linux-androidea>

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.
build complete
Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: OPPO R9S
  • OS: lineageos
  • Version 14
  • kernel version:3.18

Additional context
Add any other context about the problem here.

CC drivers/input/touchscreen/of_touchscreen.o
/home/synaptic/linux-3.18/drivers/kernelsu/ksu.c: In function 'kernelsu_init':
/home/synaptic/linux-3.18/drivers/kernelsu/ksu.c:60:2: warning: #warning ("KPROBES is disabled, KernelSU may not work, please check https://kernelsu.org/guide/how-to-integrate-for-non-gki.html") [-Wcpp]
error, forbidden warning: ksu.c:60
make[3]: *** [/home/synaptic/linux-3.18/scripts/Makefile.build:257: drivers/kernelsu/ksu.o] エラー 1
make[2]: *** [/home/synaptic/linux-3.18/scripts/Makefile.build:402: drivers/kernelsu] エラー 2
make[2]: *** 未完了のジョブを待っています....

CC drivers/irqchip/irq-gic-common.o
/home/synaptic/linux-3.18/drivers/kernelsu/allowlist.c: In function 'do_load_allow_list':
/home/synaptic/linux-3.18/drivers/kernelsu/allowlist.c:175:3: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
error, forbidden warning: allowlist.c:175
make[3]: *** [/home/synaptic/linux-3.18/scripts/Makefile.build:257: drivers/kernelsu/allowlist.o] エラー 1
make[2]: *** [/home/synaptic/linux-3.18/scripts/Makefile.build:402: drivers/kernelsu] エラー 2
make[2]: *** 未完了のジョブを待っています....
CC drivers/iommu/iommu-sysfs.o

@tiann
Copy link
Owner

tiann commented May 22, 2023

KernelSU does not support kernels below version 4.4. If you are interested, you can try it on your own, but this requires some kernel-related knowledge, as some features may not be available on lower versions of the kernel. It is not as simple as compiling the source code.

@tiann tiann closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2023
@ananjaser1211
Copy link

ananjaser1211 commented Oct 15, 2023

If anyone in the future is searching for 3.18, i have managed to get it working on my samsung galaxy S7 with 3.18.140

Notes : This only compiles with Werror disabled, there are few casting errors in ksu_handle_prctl , apk_sign check_block and few others i did not have the urge to fix, but i assume they will cause errors later on. Also it works while having Selinux enforcing so thats nice.

I also tested some modules like Zygisk on kernelSU and youtube-revanced-magisk

Thanks @tiann for kernelSU, it is amazing and i have been using it on pretty much all my phones.

EDIT : To be able to use Zygisk / LSPOSED and co, you need to upstream OverlayFS and related vfs/fs : Here

For easier reading, look in this commit range : Here

You mainly need :
kernel: groups: expose groups_sort
configs: exynos8890: Enable overlayfs
syscalls: implement execveat() system call
VFS: Split DCACHE_FILE_TYPE into regular and special types

VFS and friends :

VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(de…
VFS: Fix up debugfs to use d_is_dir() in place of S_ISDIR()

The most difficult however is you need LSM_HOOKS which was not in my 3.18 kernel, i was able to pick it from 4.4 kernel source, but it needed some work
You can start at [LSM: Split security.h] (ananjaser1211/Cronos_8890@af0db6c) and go up

From how to implement on non GKI
fs: Add KernelSU calls manually
selinux: Allow init exec ksud under nosuid

FInally i need to edit the fetcher because 3.18 has different headers for input (we dont split input codes) we also needed uaccess header and AIO header for kiocb

# 3.18 Kernel Patches

# Fix pointer error
sed -i 's/PTR_ERR(fp));/ (int)PTR_ERR(fp));/' uid_observer.c

# Add uaccess Header
sed -i '/#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)/i #include "linux/uaccess.h"' kernel_compat.c

# Add AIO Header To address kiocb on 3.18
sed -i '/#include "allowlist.h"/i #include "linux/aio.h"' ksud.c

# Use input.h Header instead of input-event-codes.h
sed -i 's/#include "linux\/input-event-codes.h"/#include "linux\/input.h"/' ksud.c

# Remove unsupported cflags
sed -i 's/ccflags-y += -Wno-implicit-function-declaration -Wno-strict-prototypes -Wno-int-conversion -Wno-gcc-compat/ccflags-y += -Wno-implicit-function-declaration -Wno-strict-prototypes/' Makefile

ROOT test

photo_2023-10-15_17-52-56
photo_2023-10-15_17-53-02
Screenshot_2

Module

photo_2023-10-15_17-59-05
photo_2023-10-15_17-59-00

Module after OverlayFS update

photo_2023-10-18_13-33-54

@ananjaser1211
Copy link

Update, For module support to work on 3.18 (Zygisk for example) it wont initialize properly and would not mount, the solution in my case was upstreaming ovl (overlayfs) and whatever dependencies it needed in FS, i found it easy to cherry-pick directly from 4.4 kernel source.

Range i picked : https://github.com/ananjaser1211/Cronos_8890//compare/3b260b125e3eb9508e9110043d795554215ec8cf...cab7f2b816073fcfe64543b21a44253a1697b7c6

This made zygisk work and made modules like LSposed work, i do notice in log when using Zygisk there is a CMD 12/13 error

<3>[  261.868202]  [3:      zygiskd64:21510] KernelSU: prctl reply error, cmd: 12
<3>[  261.868229]  [3:      zygiskd64:21510] KernelSU: prctl reply error, cmd: 13

I think its something in the REGS but i dont know how to read them yet, works otherwise.

@backslashxx
Copy link
Contributor

@ananjaser1211 sorry to hijack but does #1464 work on 3.18?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants