kernel: selinux: replace rcu_read_{lock, unlock} to mutex_{lock, unlock}

* We got a splat related to atomic sleep.
* The trace is from strncpy_from_user and might_fault

Same case:
e47115e009

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
This commit is contained in:
rsuntk
2025-07-28 22:31:16 +07:00
committed by ShirkNeko
parent da89b00d06
commit 71f8944ffb

View File

@@ -36,7 +36,7 @@ static struct policydb *get_policydb(void)
return db; return db;
} }
static DEFINE_MUTEX(ksu_rules); static DEFINE_MUTEX(apply_ksu_rules_mutex);
void ksu_apply_kernelsu_rules() void ksu_apply_kernelsu_rules()
{ {
@@ -46,7 +46,7 @@ void ksu_apply_kernelsu_rules()
pr_info("SELinux permissive or disabled, apply rules!\n"); pr_info("SELinux permissive or disabled, apply rules!\n");
} }
mutex_lock(&ksu_rules); mutex_lock(&apply_ksu_rules_mutex);
db = get_policydb(); db = get_policydb();
@@ -149,7 +149,7 @@ void ksu_apply_kernelsu_rules()
susfs_set_zygote_sid(); susfs_set_zygote_sid();
#endif #endif
mutex_unlock(&ksu_rules); mutex_unlock(&apply_ksu_rules_mutex);
} }
#define MAX_SEPOL_LEN 128 #define MAX_SEPOL_LEN 128
@@ -233,6 +233,7 @@ static void reset_avc_cache()
selinux_xfrm_notify_policyload(); selinux_xfrm_notify_policyload();
} }
static DEFINE_MUTEX(ksu_handle_sepolicy_mutex);
int ksu_handle_sepolicy(unsigned long arg3, void __user *arg4) int ksu_handle_sepolicy(unsigned long arg3, void __user *arg4)
{ {
if (!arg4) { if (!arg4) {
@@ -279,9 +280,11 @@ int ksu_handle_sepolicy(unsigned long arg3, void __user *arg4)
subcmd = data.subcmd; subcmd = data.subcmd;
} }
rcu_read_lock(); struct policydb *db;
struct policydb *db = get_policydb(); mutex_lock(&ksu_handle_sepolicy_mutex);
db = get_policydb();
int ret = -1; int ret = -1;
if (cmd == CMD_NORMAL_PERM) { if (cmd == CMD_NORMAL_PERM) {
@@ -531,7 +534,7 @@ int ksu_handle_sepolicy(unsigned long arg3, void __user *arg4)
} }
exit: exit:
rcu_read_unlock(); mutex_unlock(&ksu_handle_sepolicy_mutex);
// only allow and xallow needs to reset avc cache, but we cannot do that because // only allow and xallow needs to reset avc cache, but we cannot do that because
// we are in atomic context. so we just reset it every time. // we are in atomic context. so we just reset it every time.