|
13 | 13 | #include "throne_tracker.h" |
14 | 14 | #include "kernel_compat.h" |
15 | 15 |
|
| 16 | +#include <linux/kthread.h> |
| 17 | +#include <linux/sched.h> |
| 18 | + |
16 | 19 | uid_t ksu_manager_uid = KSU_INVALID_UID; |
17 | 20 |
|
18 | | -#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list.tmp" |
| 21 | +static struct task_struct *throne_thread; |
| 22 | +#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list" |
19 | 23 |
|
20 | 24 | struct uid_data { |
21 | 25 | struct list_head list; |
@@ -241,6 +245,17 @@ void search_manager(const char *path, int depth, struct list_head *uid_data) |
241 | 245 | .depth = pos->depth, |
242 | 246 | .stop = &stop }; |
243 | 247 | struct file *file; |
| 248 | + struct path kpath; |
| 249 | + |
| 250 | + if (kern_path(path, 0, &kpath)) |
| 251 | + goto skip_iterate; |
| 252 | + |
| 253 | + if (!spin_trylock(&kpath.dentry->d_lock)) { |
| 254 | + path_put(&kpath); |
| 255 | + goto skip_iterate; |
| 256 | + } |
| 257 | + spin_unlock(&kpath.dentry->d_lock); |
| 258 | + path_put(&kpath); |
244 | 259 |
|
245 | 260 | if (!stop) { |
246 | 261 | file = ksu_filp_open_compat(pos->dirpath, O_RDONLY | O_NOFOLLOW, 0); |
@@ -284,7 +299,7 @@ static bool is_uid_exist(uid_t uid, char *package, void *data) |
284 | 299 | return exist; |
285 | 300 | } |
286 | 301 |
|
287 | | -void track_throne() |
| 302 | +static void track_throne_function() |
288 | 303 | { |
289 | 304 | struct file *fp = |
290 | 305 | ksu_filp_open_compat(SYSTEM_PACKAGES_LIST_PATH, O_RDONLY, 0); |
@@ -379,6 +394,35 @@ void track_throne() |
379 | 394 | } |
380 | 395 | } |
381 | 396 |
|
| 397 | +static int throne_tracker_thread(void *data) |
| 398 | +{ |
| 399 | + pr_info("%s: pid: %d started\n", __func__, current->pid); |
| 400 | + track_throne_function(); |
| 401 | + throne_thread = NULL; |
| 402 | + pr_info("%s: pid: %d exit!\n", __func__, current->pid); |
| 403 | + return 0; |
| 404 | +} |
| 405 | + |
| 406 | +void track_throne() |
| 407 | +{ |
| 408 | + static bool throne_tracker_first_run = true; |
| 409 | + if (throne_tracker_first_run) { |
| 410 | + // be locking on first run, workaround for some kernels |
| 411 | + track_throne_function(); |
| 412 | + throne_tracker_first_run = false; |
| 413 | + return; |
| 414 | + } |
| 415 | + |
| 416 | + if (throne_thread != NULL) // single instance lock |
| 417 | + return; |
| 418 | + |
| 419 | + throne_thread = kthread_run(throne_tracker_thread, NULL, "throne_tracker"); |
| 420 | + if (IS_ERR(throne_thread)) { |
| 421 | + throne_thread = NULL; |
| 422 | + return; |
| 423 | + } |
| 424 | +} |
| 425 | + |
382 | 426 | void ksu_throne_tracker_init() |
383 | 427 | { |
384 | 428 | // nothing to do |
|
0 commit comments