Hi @tiann. Thanks for the great project, I had great fun playing around with it. This PR mainly tries to further minimize the possible delays caused by KernelSU hooking. There are 3 major changes: - Processes with 0 < UID < 2000 are blocked straight-up before going through the allow_list. I don't see any need for such processes to be interested in root, and this allows returning early before going through a more expensive lookup. If there's an expected breakage due to this change, I'll remove it. Let me know. - A page-sized (4K) bitmap is added. This allows O(1) lookup for UID <= 32767. This speeds up `ksu_is_allow_uid()` by about 4.8x by sacrificing a 4K memory. IMHO, a good trade-off. Most notably, this reduces the 99.999% result previously from worrying milliseconds scale to microseconds scale. For UID > 32767, another page-sized (4K) sequential array is used to cache allow_list. Compared to the previous PR #557, this new approach gives another nice 25% performance boost in average, 63-96% boost in worst cases. Benchmark results are available at https://docs.google.com/spreadsheets/d/1w_tO1zRLPNMFRer49pL1TQfL6ndEhilRrDU1XFIcWXY/edit?usp=sharing Thanks! --------- Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
34 lines
1.6 KiB
C
34 lines
1.6 KiB
C
#include "linux/kallsyms.h"
|
|
|
|
#define RE_EXPORT_SYMBOL1(ret, func, t1, v1) \
|
|
ret ksu_##func(t1 v1) \
|
|
{ \
|
|
return func(v1); \
|
|
} \
|
|
EXPORT_SYMBOL(ksu_##func);
|
|
|
|
#define RE_EXPORT_SYMBOL2(ret, func, t1, v1, t2, v2) \
|
|
ret ksu_##func(t1 v1, t2 v2) \
|
|
{ \
|
|
return func(v1, v2); \
|
|
} \
|
|
EXPORT_SYMBOL(ksu_##func);
|
|
|
|
RE_EXPORT_SYMBOL1(unsigned long, kallsyms_lookup_name, const char *, name)
|
|
|
|
// RE_EXPORT_SYMBOL2(int, register_kprobe, struct kprobe *, p)
|
|
// RE_EXPORT_SYMBOL2(void, unregister_kprobe, struct kprobe *, p)
|
|
|
|
// RE_EXPORT_SYMBOL2(int, register_kprobe, struct kprobe *, p)
|
|
// RE_EXPORT_SYMBOL2(void, unregister_kprobe, struct kprobe *, p)
|
|
|
|
// int ksu_register_kprobe(struct kprobe *p);
|
|
// void ksu_unregister_kprobe(struct kprobe *p);
|
|
// int ksu_register_kprobes(struct kprobe **kps, int num);
|
|
// void ksu_unregister_kprobes(struct kprobe **kps, int num);
|
|
|
|
// int ksu_register_kretprobe(struct kretprobe *rp);
|
|
// void unregister_kretprobe(struct kretprobe *rp);
|
|
// int register_kretprobes(struct kretprobe **rps, int num);
|
|
// void unregister_kretprobes(struct kretprobe **rps, int num);
|