@@ -29,7 +29,8 @@ static DEFINE_MUTEX(allowlist_mutex);
2929static struct root_profile default_root_profile ;
3030static struct non_root_profile default_non_root_profile ;
3131
32- static int allow_list_arr [PAGE_SIZE / sizeof (int )] __read_mostly __aligned (PAGE_SIZE );
32+ static int allow_list_arr [PAGE_SIZE / sizeof (int )] __read_mostly
33+ __aligned (PAGE_SIZE );
3334static int allow_list_pointer __read_mostly = 0 ;
3435
3536static void remove_uid_from_arr (uid_t uid )
@@ -70,7 +71,7 @@ static void init_default_profiles()
7071 default_root_profile .groups_count = 1 ;
7172 default_root_profile .groups [0 ] = 0 ;
7273 memcpy (& default_root_profile .capabilities .effective , & full_cap ,
73- sizeof (default_root_profile .capabilities .effective ));
74+ sizeof (default_root_profile .capabilities .effective ));
7475 default_root_profile .namespaces = 0 ;
7576 strcpy (default_root_profile .selinux_domain , KSU_DEFAULT_SELINUX_DOMAIN );
7677
@@ -100,7 +101,7 @@ void ksu_show_allow_list(void)
100101 list_for_each (pos , & allow_list ) {
101102 p = list_entry (pos , struct perm_data , list );
102103 pr_info ("uid :%d, allow: %d\n" , p -> profile .current_uid ,
103- p -> profile .allow_su );
104+ p -> profile .allow_su );
104105 }
105106}
106107
@@ -113,7 +114,8 @@ static void ksu_grant_root_to_shell()
113114 .current_uid = 2000 ,
114115 };
115116 strcpy (profile .key , "com.android.shell" );
116- strcpy (profile .rp_config .profile .selinux_domain , KSU_DEFAULT_SELINUX_DOMAIN );
117+ strcpy (profile .rp_config .profile .selinux_domain ,
118+ KSU_DEFAULT_SELINUX_DOMAIN );
117119 ksu_set_app_profile (& profile , false);
118120}
119121#endif
@@ -139,9 +141,10 @@ bool ksu_get_app_profile(struct app_profile *profile)
139141 return found ;
140142}
141143
142- static inline bool forbid_system_uid (uid_t uid ) {
143- #define SHELL_UID 2000
144- #define SYSTEM_UID 1000
144+ static inline bool forbid_system_uid (uid_t uid )
145+ {
146+ #define SHELL_UID 2000
147+ #define SYSTEM_UID 1000
145148 return uid < SHELL_UID && uid != SYSTEM_UID ;
146149}
147150
@@ -202,22 +205,24 @@ bool ksu_set_app_profile(struct app_profile *profile, bool persist)
202205 memcpy (& p -> profile , profile , sizeof (* profile ));
203206 if (profile -> allow_su ) {
204207 pr_info ("set root profile, key: %s, uid: %d, gid: %d, context: %s\n" ,
205- profile -> key , profile -> current_uid ,
206- profile -> rp_config .profile .gid ,
207- profile -> rp_config .profile .selinux_domain );
208+ profile -> key , profile -> current_uid ,
209+ profile -> rp_config .profile .gid ,
210+ profile -> rp_config .profile .selinux_domain );
208211 } else {
209212 pr_info ("set app profile, key: %s, uid: %d, umount modules: %d\n" ,
210- profile -> key , profile -> current_uid ,
211- profile -> nrp_config .profile .umount_modules );
213+ profile -> key , profile -> current_uid ,
214+ profile -> nrp_config .profile .umount_modules );
212215 }
213216 list_add_tail (& p -> list , & allow_list );
214217
215218out :
216219 if (profile -> current_uid <= BITMAP_UID_MAX ) {
217220 if (profile -> allow_su )
218- allow_list_bitmap [profile -> current_uid / BITS_PER_BYTE ] |= 1 << (profile -> current_uid % BITS_PER_BYTE );
221+ allow_list_bitmap [profile -> current_uid / BITS_PER_BYTE ] |=
222+ 1 << (profile -> current_uid % BITS_PER_BYTE );
219223 else
220- allow_list_bitmap [profile -> current_uid / BITS_PER_BYTE ] &= ~(1 << (profile -> current_uid % BITS_PER_BYTE ));
224+ allow_list_bitmap [profile -> current_uid / BITS_PER_BYTE ] &=
225+ ~(1 << (profile -> current_uid % BITS_PER_BYTE ));
221226 } else {
222227 if (profile -> allow_su ) {
223228 /*
@@ -264,13 +269,15 @@ bool __ksu_is_allow_uid(uid_t uid)
264269 return false;
265270 }
266271
267- if (likely (ksu_is_manager_uid_valid ()) && unlikely (ksu_get_manager_uid () == uid )) {
272+ if (likely (ksu_is_manager_uid_valid ()) &&
273+ unlikely (ksu_get_manager_uid () == uid )) {
268274 // manager is always allowed!
269275 return true;
270276 }
271277
272278 if (likely (uid <= BITMAP_UID_MAX )) {
273- return !!(allow_list_bitmap [uid / BITS_PER_BYTE ] & (1 << (uid % BITS_PER_BYTE )));
279+ return !!(allow_list_bitmap [uid / BITS_PER_BYTE ] &
280+ (1 << (uid % BITS_PER_BYTE )));
274281 } else {
275282 for (i = 0 ; i < allow_list_pointer ; i ++ ) {
276283 if (allow_list_arr [i ] == uid )
@@ -293,7 +300,8 @@ bool __ksu_is_allow_uid_for_current(uid_t uid)
293300bool ksu_uid_should_umount (uid_t uid )
294301{
295302 struct app_profile profile = { .current_uid = uid };
296- if (likely (ksu_is_manager_uid_valid ()) && unlikely (ksu_get_manager_uid () == uid )) {
303+ if (likely (ksu_is_manager_uid_valid ()) &&
304+ unlikely (ksu_get_manager_uid () == uid )) {
297305 // we should not umount on manager!
298306 return false;
299307 }
@@ -366,26 +374,22 @@ void persistent_allow_list()
366374 }
367375
368376 // store magic and version
369- if (ksu_kernel_write_compat (fp , & magic , sizeof (magic ), & off ) !=
370- sizeof (magic )) {
377+ if (kernel_write (fp , & magic , sizeof (magic ), & off ) != sizeof (magic )) {
371378 pr_err ("save_allow_list write magic failed.\n" );
372379 goto exit ;
373380 }
374381
375- if (ksu_kernel_write_compat (fp , & version , sizeof (version ), & off ) !=
376- sizeof (version )) {
382+ if (kernel_write (fp , & version , sizeof (version ), & off ) != sizeof (version )) {
377383 pr_err ("save_allow_list write version failed.\n" );
378384 goto exit ;
379385 }
380386
381387 list_for_each (pos , & allow_list ) {
382388 p = list_entry (pos , struct perm_data , list );
383389 pr_info ("save allow list, name: %s uid :%d, allow: %d\n" ,
384- p -> profile .key , p -> profile .current_uid ,
385- p -> profile .allow_su );
390+ p -> profile .key , p -> profile .current_uid , p -> profile .allow_su );
386391
387- ksu_kernel_write_compat (fp , & p -> profile , sizeof (p -> profile ),
388- & off );
392+ kernel_write (fp , & p -> profile , sizeof (p -> profile ), & off );
389393 }
390394
391395exit :
@@ -413,15 +417,13 @@ void ksu_load_allow_list()
413417 }
414418
415419 // verify magic
416- if (ksu_kernel_read_compat (fp , & magic , sizeof (magic ), & off ) !=
417- sizeof (magic ) ||
420+ if (kernel_read (fp , & magic , sizeof (magic ), & off ) != sizeof (magic ) ||
418421 magic != FILE_MAGIC ) {
419422 pr_err ("allowlist file invalid: %d!\n" , magic );
420423 goto exit ;
421424 }
422425
423- if (ksu_kernel_read_compat (fp , & version , sizeof (version ), & off ) !=
424- sizeof (version )) {
426+ if (kernel_read (fp , & version , sizeof (version ), & off ) != sizeof (version )) {
425427 pr_err ("allowlist read version: %d failed\n" , version );
426428 goto exit ;
427429 }
@@ -431,16 +433,15 @@ void ksu_load_allow_list()
431433 while (true) {
432434 struct app_profile profile ;
433435
434- ret = ksu_kernel_read_compat (fp , & profile , sizeof (profile ),
435- & off );
436+ ret = kernel_read (fp , & profile , sizeof (profile ), & off );
436437
437438 if (ret <= 0 ) {
438439 pr_info ("load_allow_list read err: %zd\n" , ret );
439440 break ;
440441 }
441442
442- pr_info ("load_allow_uid, name: %s, uid: %d, allow: %d\n" ,
443- profile . key , profile .current_uid , profile .allow_su );
443+ pr_info ("load_allow_uid, name: %s, uid: %d, allow: %d\n" , profile . key ,
444+ profile .current_uid , profile .allow_su );
444445 ksu_set_app_profile (& profile , false);
445446 }
446447
@@ -449,7 +450,8 @@ void ksu_load_allow_list()
449450 filp_close (fp , 0 );
450451}
451452
452- void ksu_prune_allowlist (bool (* is_uid_valid )(uid_t , char * , void * ), void * data )
453+ void ksu_prune_allowlist (bool (* is_uid_valid )(uid_t , char * , void * ),
454+ void * data )
453455{
454456 struct perm_data * np = NULL ;
455457 struct perm_data * n = NULL ;
@@ -467,7 +469,8 @@ void ksu_prune_allowlist(bool (*is_uid_valid)(uid_t, char *, void *), void *data
467469 pr_info ("prune uid: %d, package: %s\n" , uid , package );
468470 list_del (& np -> list );
469471 if (likely (uid <= BITMAP_UID_MAX )) {
470- allow_list_bitmap [uid / BITS_PER_BYTE ] &= ~(1 << (uid % BITS_PER_BYTE ));
472+ allow_list_bitmap [uid / BITS_PER_BYTE ] &=
473+ ~(1 << (uid % BITS_PER_BYTE ));
471474 }
472475 remove_uid_from_arr (uid );
473476 smp_mb ();
0 commit comments