Skip to content

Commit 5592dc0

Browse files
committed
kernel: fix save allowlist
1 parent b161b82 commit 5592dc0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

kernel/allowlist.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <linux/mutex.h>
2+
#include <linux/task_work.h>
13
#include <linux/capability.h>
24
#include <linux/compiler.h>
35
#include <linux/fs.h>
@@ -357,14 +359,15 @@ bool ksu_get_allow_list(int *array, int *length, bool allow)
357359
return true;
358360
}
359361

360-
void persistent_allow_list()
362+
static void do_persistent_allow_list(struct callback_head *_cb)
361363
{
362364
u32 magic = FILE_MAGIC;
363365
u32 version = FILE_FORMAT_VERSION;
364366
struct perm_data *p = NULL;
365367
struct list_head *pos = NULL;
366368
loff_t off = 0;
367369

370+
mutex_lock(&allowlist_mutex);
368371
struct file *fp =
369372
filp_open(KERNEL_SU_ALLOWLIST, O_WRONLY | O_CREAT | O_TRUNC, 0644);
370373
if (IS_ERR(fp)) {
@@ -393,6 +396,29 @@ void persistent_allow_list()
393396

394397
exit:
395398
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);
396422
}
397423

398424
void ksu_load_allow_list()

0 commit comments

Comments
 (0)