@@ -42,13 +42,6 @@ void setup_selinux(const char *domain)
4242 pr_err ("transive domain failed.\n" );
4343 return ;
4444 }
45-
46- /* we didn't need this now, we have change selinux rules when boot!
47- if (!is_domain_permissive) {
48- if (set_domain_permissive() == 0) {
49- is_domain_permissive = true;
50- }
51- }*/
5245}
5346
5447void setenforce (bool enforce )
@@ -73,27 +66,28 @@ bool getenforce()
7366#endif
7467}
7568
76- #if (LINUX_VERSION_CODE < KERNEL_VERSION (5 , 10 , 0 )) && \
77- !defined(KSU_COMPAT_HAS_CURRENT_SID )
78- /*
79- * get the subjective security ID of the current task
80- */
81- static inline u32 current_sid (void )
82- {
83- const struct task_security_struct * tsec = current_security ();
69+ #if LINUX_VERSION_CODE < KERNEL_VERSION (6 , 14 , 0 )
70+ struct lsm_context {
71+ char * context ;
72+ u32 len ;
73+ };
8474
85- return tsec -> sid ;
75+ static int __security_secid_to_secctx (u32 secid , struct lsm_context * cp )
76+ {
77+ return security_secid_to_secctx (secid , & cp -> context , & cp -> len );
78+ }
79+ static void __security_release_secctx (struct lsm_context * cp )
80+ {
81+ return security_release_secctx (cp -> context , cp -> len );
8682}
83+ #else
84+ #define __security_secid_to_secctx security_secid_to_secctx
85+ #define __security_release_secctx security_release_secctx
8786#endif
8887
8988bool is_task_ksu_domain (const struct cred * cred )
9089{
91- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
92- struct lsm_context ctx ;
93- #else
94- char * domain ;
95- u32 seclen ;
96- #endif
90+ struct lsm_context ctx ;
9791 bool result ;
9892 if (!cred ) {
9993 return false;
@@ -102,21 +96,12 @@ bool is_task_ksu_domain(const struct cred* cred)
10296 if (!tsec ) {
10397 return false;
10498 }
105- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
106- int err = security_secid_to_secctx (tsec -> sid , & ctx );
107- #else
108- int err = security_secid_to_secctx (tsec -> sid , & domain , & seclen );
109- #endif
99+ int err = __security_secid_to_secctx (tsec -> sid , & ctx );
110100 if (err ) {
111101 return false;
112102 }
113- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
114- result = strncmp (KERNEL_SU_DOMAIN , ctx .context , ctx .len ) == 0 ;
115- security_release_secctx (& ctx );
116- #else
117- result = strncmp (KERNEL_SU_DOMAIN , domain , seclen ) == 0 ;
118- security_release_secctx (domain , seclen );
119- #endif
103+ result = strncmp (KERNEL_SU_DOMAIN , ctx .context , ctx .len ) == 0 ;
104+ __security_release_secctx (& ctx );
120105 return result ;
121106}
122107
@@ -135,28 +120,14 @@ bool is_zygote(const struct cred* cred)
135120 if (!tsec ) {
136121 return false;
137122 }
138- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
139- struct lsm_context ctx ;
140- #else
141- char * domain ;
142- u32 seclen ;
143- #endif
123+ struct lsm_context ctx ;
144124 bool result ;
145- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
146- int err = security_secid_to_secctx (tsec -> sid , & ctx );
147- #else
148- int err = security_secid_to_secctx (tsec -> sid , & domain , & seclen );
149- #endif
125+ int err = __security_secid_to_secctx (tsec -> sid , & ctx );
150126 if (err ) {
151127 return false;
152128 }
153- #if LINUX_VERSION_CODE >= KERNEL_VERSION (6 , 14 , 0 )
154- result = strncmp ("u:r:zygote:s0" , ctx .context , ctx .len ) == 0 ;
155- security_release_secctx (& ctx );
156- #else
157- result = strncmp ("u:r:zygote:s0" , domain , seclen ) == 0 ;
158- security_release_secctx (domain , seclen );
159- #endif
129+ result = strncmp ("u:r:zygote:s0" , ctx .context , ctx .len ) == 0 ;
130+ __security_release_secctx (& ctx );
160131 return result ;
161132}
162133
0 commit comments