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

throne_tracker.c 中部分功能会导致低版本内核/系统无法启动(卡第一屏) #1675

Closed
3 tasks done
Seshiria opened this issue Apr 28, 2024 · 13 comments
Closed
3 tasks done

Comments

@Seshiria
Copy link

Please check before submitting an issue

  • I have searched the issues and haven't found anything relevant
  • I will upload bugreport file in KernelSU Manager - Settings - Report log
  • I know how to reproduce the issue which may not be specific to my device

Describe the bug

你好,我在维护一个4.4.302的内核,为其添加了ksu的支持,具体信息:
设备:oneplus 5
系统:LineageOS 21(android14)
官方的内核:https://github.com/LineageOS/android_kernel_oneplus_msm8998
内核版本:4.4.302
我使用的是手动集成,修改内核的内容:https://github.com/Seshiria/op5dc/blob/master/ksu_patch/ksu_patch.diff

最近一个正常使用的ksu tag为v0.9.2.

在合并v0.9.3后发现系统开机会卡在第一屏,经过排查发现在 9a04211 的提交后,所有构建的内核均无法正常启动(卡第一屏),此提交的前一个提交 9403c8f 构建出来的内核是可以正常启动的。

我尝试定位到tag v0.9.3、删除了在 9a04211 中 throne_tracker.c 添加的验证代码、然后重新构建了内核,此时正常进入系统,但是ksu管理器(11807)提示不支持的内核,以下为从 /data/adb/ksu/log 中获取的日志文件:
dmesg (2).log

这是我修改ksu的内容: e538f8f 分支在:https://github.com/Seshiria/KernelSU/commits/beta/

To Reproduce

No response

Expected behavior

No response

Screenshots

这是我修改ksu后构建的内核:此时正常进入系统但是管理器不能识别内核:
image

Logs

No response

Device info

  • Device: oneplus 5
  • OS Version: LineageOS 21(android14)
  • KernelSU Version: v0.9.3
  • Kernel Version: 4.4.302

Additional context

No response

@tiann
Copy link
Owner

tiann commented Apr 29, 2024

两个选择:

  1. 提供开机卡第一屏的 pstore 日志
  2. 用最新的代码二分查找具体是哪一行或者哪个部分导致

@Seshiria
Copy link
Author

两个选择:

  1. 提供开机卡第一屏的 pstore 日志
  2. 用最新的代码二分查找具体是哪一行或者哪个部分导致

这是使用 efbc07f 构建的内核,开机卡第一屏幕时候的logcat:
logfile.txt

@tiann
Copy link
Owner

tiann commented Apr 29, 2024

用这个 646b6f7 再试下,顺便把你那堆插件关掉

@Seshiria
Copy link
Author

用这个 646b6f7 再试下,顺便把你那堆插件关掉

同样卡在第一屏,已移除全部模块,log:logfile2.txt

@tiann
Copy link
Owner

tiann commented Apr 29, 2024

iterate_dir 死锁了,你可以尝试把高版本内核的移植过去,比如 https://elixir.bootlin.com/linux/v4.9.337/source/fs/readdir.c#L24

@Seshiria
Copy link
Author

iterate_dir 死锁了,你可以尝试把高版本内核的移植过去,比如 https://elixir.bootlin.com/linux/v4.9.337/source/fs/readdir.c#L24

我看了一下4.14与4.4内核的iterate_dir逻辑好像都是一样的,缺少功能iterate_shared

而且对比最后一个正常启动 9403c8f 和第一个不能正常启动 9a04211 的提交,do_update_uid 方法并没有发生改变

@tiann
Copy link
Owner

tiann commented Apr 29, 2024

改了那么多还叫没改变…

@twu2
Copy link

twu2 commented Apr 30, 2024

你 0.9.3 提示不支援時, 可以安裝 0.9.2 的 Manager 試試. 我同樣 4.4 的 kernel, 直接裝 0.9.3 的 Manager 會不支援, 換成 0.9.2 的就可以 (再升級到 0.9.3 一樣可以)
#1683

@tiann
Copy link
Owner

tiann commented Apr 30, 2024

如果改动比较麻烦,你可以尝试在 search_manager 前禁用抢占

@tiann
Copy link
Owner

tiann commented Apr 30, 2024

diff --git a/kernel/throne_tracker.c b/kernel/throne_tracker.c
index b931b60..cf198ef 100644
--- a/kernel/throne_tracker.c
+++ b/kernel/throne_tracker.c
@@ -1,3 +1,4 @@
+#include "linux/preempt.h"
 #include <linux/err.h>
 #include <linux/fs.h>
 #include <linux/list.h>
@@ -189,8 +190,10 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
                return;
        }

+       preempt_disable();
        iterate_dir(file, &ctx.ctx);
        filp_close(file, NULL);
+       preempt_enable();
 }

 static bool is_uid_exist(uid_t uid, char *package, void *data)

可以这么试试

@Seshiria
Copy link
Author

diff --git a/kernel/throne_tracker.c b/kernel/throne_tracker.c
index b931b60..cf198ef 100644
--- a/kernel/throne_tracker.c
+++ b/kernel/throne_tracker.c
@@ -1,3 +1,4 @@
+#include "linux/preempt.h"
 #include <linux/err.h>
 #include <linux/fs.h>
 #include <linux/list.h>
@@ -189,8 +190,10 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
                return;
        }

+       preempt_disable();
        iterate_dir(file, &ctx.ctx);
        filp_close(file, NULL);
+       preempt_enable();
 }

 static bool is_uid_exist(uid_t uid, char *package, void *data)

可以这么试试

合并于 351f5c8 日志是 :logfile10.txt

同样还是卡第一屏

@tiann
Copy link
Owner

tiann commented May 7, 2024

同样是 4.4 的内核,有的设备是可以正常工作的,所以这是你这个内核的问题;它调用 iterate_dir 可能会死锁;建议你换内核或者用0.9.0 版本。

@tiann tiann closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@Sinclair19
Copy link

我这边相同的设备,相同的lineage内核用kprobe集成工作是正常的,包括最新的0.9.4
https://github.com/Sinclair19/android_kernel_oneplus_msm8998/tree/lineage-21-f2fs

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