|
| 1 | +#include <linux/mutex.h> |
| 2 | +#include <linux/task_work.h> |
1 | 3 | #include <linux/capability.h> |
2 | 4 | #include <linux/compiler.h> |
3 | 5 | #include <linux/fs.h> |
@@ -357,14 +359,15 @@ bool ksu_get_allow_list(int *array, int *length, bool allow) |
357 | 359 | return true; |
358 | 360 | } |
359 | 361 |
|
360 | | -void persistent_allow_list() |
| 362 | +static void do_persistent_allow_list(struct callback_head *_cb) |
361 | 363 | { |
362 | 364 | u32 magic = FILE_MAGIC; |
363 | 365 | u32 version = FILE_FORMAT_VERSION; |
364 | 366 | struct perm_data *p = NULL; |
365 | 367 | struct list_head *pos = NULL; |
366 | 368 | loff_t off = 0; |
367 | 369 |
|
| 370 | + mutex_lock(&allowlist_mutex); |
368 | 371 | struct file *fp = |
369 | 372 | filp_open(KERNEL_SU_ALLOWLIST, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
370 | 373 | if (IS_ERR(fp)) { |
@@ -393,6 +396,29 @@ void persistent_allow_list() |
393 | 396 |
|
394 | 397 | exit: |
395 | 398 | filp_close(fp, 0); |
| 399 | + mutex_unlock(&allowlist_mutex); |
| 400 | +} |
| 401 | + |
| 402 | +void persistent_allow_list() |
| 403 | +{ |
| 404 | + struct task_struct *tsk; |
| 405 | + |
| 406 | + tsk = get_pid_task(find_vpid(1), PIDTYPE_PID); |
| 407 | + if (!tsk) { |
| 408 | + pr_err("save_allow_list find init task err\n"); |
| 409 | + return; |
| 410 | + } |
| 411 | + |
| 412 | + struct callback_head *cb = |
| 413 | + kzalloc(sizeof(struct callback_head), GFP_KERNEL); |
| 414 | + if (!cb) { |
| 415 | + pr_err("save_allow_list alloc cb err\b"); |
| 416 | + return; |
| 417 | + } |
| 418 | + cb->func = do_persistent_allow_list; |
| 419 | + task_work_add(tsk, cb, TWA_RESUME); |
| 420 | + |
| 421 | + put_task_struct(tsk); |
396 | 422 | } |
397 | 423 |
|
398 | 424 | void ksu_load_allow_list() |
|
0 commit comments