Skip to content

Commit dc74b79

Browse files
pershootTashar02
authored andcommitted
kernel: selinux: rules: Micro-optimize get_policydb() and fix illegal RCU lock usage in handle_sepolicy() (tiann/KernelSU#2695) (KernelSU-Next#721)
Signed-off-by: Tashfin Shakeer Rhythm <[email protected]> -Update the other side of the conditional. KernelSU-Next#721 (comment) Atom-X-Devs/scarlet_xiaomi_sm7325@06ac6d6#diff-8cea866f9b1ae8607ee66566fc7a63c950c64952a753e3691edc2b69622a7d86 Co-authored-by: Tashfin Shakeer Rhythm <[email protected]>
1 parent 34d5e6e commit dc74b79

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernel/selinux/rules.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ static struct policydb *get_policydb(void)
2424
// selinux_state does not exists before 4.19
2525
#ifdef KSU_COMPAT_USE_SELINUX_STATE
2626
#ifdef SELINUX_POLICY_INSTEAD_SELINUX_SS
27-
struct selinux_policy *policy = rcu_dereference(selinux_state.policy);
27+
struct selinux_policy *policy = selinux_state.policy;
2828
db = &policy->policydb;
2929
#else
30-
struct selinux_ss *ss = rcu_dereference(selinux_state.ss);
30+
struct selinux_ss *ss = selinux_state.ss;
3131
db = &ss->policydb;
3232
#endif
3333
#else
@@ -230,6 +230,8 @@ static void reset_avc_cache()
230230

231231
int handle_sepolicy(unsigned long arg3, void __user *arg4)
232232
{
233+
struct policydb *db;
234+
233235
if (!arg4) {
234236
return -1;
235237
}
@@ -291,9 +293,9 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
291293
subcmd = data.subcmd;
292294
#endif
293295

294-
rcu_read_lock();
296+
mutex_lock(&ksu_rules);
295297

296-
struct policydb *db = get_policydb();
298+
db = get_policydb();
297299

298300
int ret = -1;
299301
if (cmd == CMD_NORMAL_PERM) {
@@ -543,7 +545,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
543545
}
544546

545547
exit:
546-
rcu_read_unlock();
548+
mutex_unlock(&ksu_rules);
547549

548550
// only allow and xallow needs to reset avc cache, but we cannot do that because
549551
// we are in atomic context. so we just reset it every time.

0 commit comments

Comments
 (0)