@@ -49,6 +49,10 @@ static bool ksu_module_mounted = false;
4949
5050extern int handle_sepolicy (unsigned long arg3 , void __user * arg4 );
5151
52+ static bool ksu_su_compat_enabled = true;
53+ extern void ksu_sucompat_init ();
54+ extern void ksu_sucompat_exit ();
55+
5256static inline bool is_allow_su ()
5357{
5458 if (is_manager ()) {
@@ -278,12 +282,12 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
278282 if (copy_to_user (arg3 , & version , sizeof (version ))) {
279283 pr_err ("prctl reply error, cmd: %lu\n" , arg2 );
280284 }
285+ u32 version_flags = 0 ;
281286#ifdef MODULE
282- u32 is_lkm = 0x1 ;
283- #else
284- u32 is_lkm = 0x0 ;
287+ version_flags |= 0x1 ;
285288#endif
286- if (arg4 && copy_to_user (arg4 , & is_lkm , sizeof (is_lkm ))) {
289+ if (arg4 &&
290+ copy_to_user (arg4 , & version_flags , sizeof (version_flags ))) {
287291 pr_err ("prctl reply error, cmd: %lu\n" , arg2 );
288292 }
289293 return 0 ;
@@ -429,6 +433,39 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
429433 return 0 ;
430434 }
431435
436+ if (arg2 == CMD_IS_SU_ENABLED ) {
437+ if (copy_to_user (arg3 , & ksu_su_compat_enabled ,
438+ sizeof (ksu_su_compat_enabled ))) {
439+ pr_err ("copy su compat failed\n" );
440+ return 0 ;
441+ }
442+ if (copy_to_user (result , & reply_ok , sizeof (reply_ok ))) {
443+ pr_err ("prctl reply error, cmd: %lu\n" , arg2 );
444+ }
445+ return 0 ;
446+ }
447+
448+ if (arg2 == CMD_ENABLE_SU ) {
449+ bool enabled = (arg3 != 0 );
450+ if (enabled == ksu_su_compat_enabled ) {
451+ pr_info ("cmd enable su but no need to change.\n" );
452+ return 0 ;
453+ }
454+
455+ if (enabled ) {
456+ ksu_sucompat_init ();
457+ } else {
458+ ksu_sucompat_exit ();
459+ }
460+ ksu_su_compat_enabled = enabled ;
461+
462+ if (copy_to_user (result , & reply_ok , sizeof (reply_ok ))) {
463+ pr_err ("prctl reply error, cmd: %lu\n" , arg2 );
464+ }
465+
466+ return 0 ;
467+ }
468+
432469 return 0 ;
433470}
434471
0 commit comments