forked from WildPlusKernel/kernel_patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch
1569 lines (1472 loc) · 51.7 KB
/
KernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From f5640e27bfbd3ba85fa05286a85f7287488a8f3e Mon Sep 17 00:00:00 2001
From: sidex15 <24408329+sidex15@users.noreply.github.com>
Date: Tue, 4 Feb 2025 12:03:30 +0800
Subject: [PATCH 1/1] Kernel: Implement SUSFS v1.5.5
---
.gitignore | 3 +
kernel/Kconfig | 144 +++++++++++
kernel/Makefile | 79 +++++-
kernel/allowlist.c | 10 +-
kernel/apk_sign.c | 2 +-
kernel/apk_sign.h | 2 +-
kernel/core_hook.c | 515 +++++++++++++++++++++++++++++++++++++--
kernel/kernel_compat.c | 10 +
kernel/kernel_compat.h | 1 +
kernel/ksu.c | 16 +-
kernel/ksud.c | 23 +-
kernel/ksud.h | 2 +-
kernel/manager.h | 2 +-
kernel/selinux/rules.c | 16 +-
kernel/selinux/selinux.c | 95 +++++++-
kernel/selinux/selinux.h | 24 +-
kernel/sucompat.c | 52 +++-
kernel/throne_tracker.c | 4 +-
kernel/throne_tracker.h | 2 +-
19 files changed, 936 insertions(+), 66 deletions(-)
diff --git a/.gitignore b/.gitignore
index 706fd07f..0e6a2c9b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
.idea
.vscode
+*.patch
+*.rej
+*.orig
\ No newline at end of file
diff --git a/kernel/Kconfig b/kernel/Kconfig
index 1f3802f6..c16b2e30 100644
--- a/kernel/Kconfig
+++ b/kernel/Kconfig
@@ -24,4 +24,148 @@ config KSU_ALLOWLIST_WORKAROUND
Enable session keyring init workaround for problematic devices.
Useful for situations where the SU allowlist is not kept after a reboot.
+menu "KernelSU - SUSFS"
+config KSU_SUSFS
+ bool "KernelSU addon - SUSFS"
+ depends on KSU
+ default y
+ help
+ Patch and Enable SUSFS to kernel with KernelSU.
+
+config KSU_SUSFS_HAS_MAGIC_MOUNT
+ bool "Say yes if the current KernelSU repo has magic mount implemented (default n)"
+ depends on KSU
+ default y
+ help
+ - Enable to indicate that the current SUSFS kernel supports the auto hide features for 5ec1cff's Magic Mount KernelSU
+ - Every mounts from /debug_ramdisk/workdir will be treated as magic mount and processed differently by susfs
+
+config KSU_SUSFS_SUS_PATH
+ bool "Enable to hide suspicious path (NOT recommended)"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow hiding the user-defined path and all its sub-paths from various system calls.
+ - tmpfs filesystem is not allowed to be added.
+ - Effective only on zygote spawned user app process.
+ - Use with cautious as it may cause performance loss and will be vulnerable to side channel attacks,
+ just disable this feature if it doesn't work for you or you don't need it at all.
+
+config KSU_SUSFS_SUS_MOUNT
+ bool "Enable to hide suspicious mounts"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow hiding the user-defined mount paths from /proc/self/[mounts|mountinfo|mountstat].
+ - Effective on all processes for hiding mount entries.
+ - Mounts mounted by process with ksu domain will be forced to be assigned the dev name "KSU".
+ - mnt_id and mnt_group_id of the sus mount will be assigned to a much bigger number to solve the issue of id not being contiguous.
+
+config KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+ bool "Enable to hide KSU's default mounts automatically (experimental)"
+ depends on KSU_SUSFS_SUS_MOUNT
+ default y
+ help
+ - Automatically add KSU's default mounts to sus_mount.
+ - No susfs command is needed in userspace.
+ - Only mount operation from process with ksu domain will be checked.
+
+config KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+ bool "Enable to hide suspicious bind mounts automatically (experimental)"
+ depends on KSU_SUSFS_SUS_MOUNT
+ default y
+ help
+ - Automatically add binded mounts to sus_mount.
+ - No susfs command is needed in userspace.
+ - Only mount operation from process with ksu domain will be checked.
+
+config KSU_SUSFS_SUS_KSTAT
+ bool "Enable to spoof suspicious kstat"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow spoofing the kstat of user-defined file/directory.
+ - Effective only on zygote spawned user app process.
+
+config KSU_SUSFS_SUS_OVERLAYFS
+ bool "Enable to automatically spoof kstat and kstatfs for overlayed files/directories"
+ depends on KSU_SUSFS
+ default n
+ help
+ - Automatically spoof the kstat and kstatfs for overlayed files/directories.
+ - Enable it if you are using legacy KernelSU and dont have auto hide features enabled.
+ - No susfs command is needed in userspace.
+ - Effective on all processes.
+
+config KSU_SUSFS_TRY_UMOUNT
+ bool "Enable to use ksu's ksu_try_umount"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow using ksu_try_umount to umount other user-defined mount paths prior to ksu's default umount paths.
+ - Effective on all NO-root-access-granted processes.
+
+config KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+ bool "Enable to add bind mounts to ksu's ksu_try_umount automatically (experimental)"
+ depends on KSU_SUSFS_TRY_UMOUNT
+ default y
+ help
+ - Automatically add binded mounts to ksu's ksu_try_umount.
+ - No susfs command is needed in userspace.
+ - Only mount operation from process with ksu domain will be checked.
+
+config KSU_SUSFS_SPOOF_UNAME
+ bool "Enable to spoof uname"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow spoofing the string returned by uname syscall to user-defined string.
+ - Effective on all processes.
+
+config KSU_SUSFS_ENABLE_LOG
+ bool "Enable logging susfs log to kernel"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow logging susfs log to kernel, uncheck it to completely disable all susfs log.
+
+config KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS
+ bool "Enable to automatically hide ksu and susfs symbols from /proc/kallsyms"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Automatically hide ksu and susfs symbols from '/proc/kallsyms'.
+ - Effective on all processes.
+
+config KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
+ bool "Enable to spoof /proc/bootconfig (gki) or /proc/cmdline (non-gki)"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Spoof the output of /proc/bootconfig (gki) or /proc/cmdline (non-gki) with a user-defined file.
+ - Effective on all processes.
+
+config KSU_SUSFS_OPEN_REDIRECT
+ bool "Enable to redirect a path to be opened with another path (experimental)"
+ depends on KSU_SUSFS
+ default y
+ help
+ - Allow redirecting a target path to be opened with another user-defined path.
+ - Effective only on processes with uid < 2000.
+ - Please be reminded that process with open access to the target and redirected path can be detected.
+
+config KSU_SUSFS_SUS_SU
+ bool "Enable SUS-SU in runtime temporarily"
+ depends on KSU_SUSFS && KPROBES && HAVE_KPROBES && KPROBE_EVENTS
+ default y
+ help
+ - Allow user to enable or disable core ksu kprobes hooks temporarily in runtime. There are 2 working modes for sus_su.
+ - Mode 0 (default): Disable sus_su, and enable ksu kprobe hooks for su instead.
+ - Mode 1 (deprecated):
+ - Mode 2: Enable sus_su, and disable ksu kprobe hooks for su, which means the kernel inline hooks are enabled,
+ the same as the su implementaion of non-gki kernel without kprobe supported.
+ - Only apps with root access granted by ksu manager are allowed to get root.
+
+endmenu
+
endmenu
diff --git a/kernel/Makefile b/kernel/Makefile
index 33b204e3..e07aa99b 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -150,4 +150,81 @@ endif
ccflags-y += -Wno-implicit-function-declaration -Wno-strict-prototypes -Wno-int-conversion -Wno-gcc-compat
ccflags-y += -Wno-declaration-after-statement -Wno-unused-function
-# Keep a new line here!! Because someone may append config
+## For non-gki compatiblity ##
+ifeq ($(shell grep -q " current_sid(void)" $(srctree)/security/selinux/include/objsec.h; echo $$?),0)
+ccflags-y += -DKSU_COMPAT_HAS_CURRENT_SID
+endif
+
+ifeq ($(shell grep -q "struct selinux_state " $(srctree)/security/selinux/include/security.h; echo $$?),0)
+ccflags-y += -DKSU_COMPAT_HAS_SELINUX_STATE
+endif
+
+ccflags-y += -DKSU_UMOUNT
+ifneq ($(shell grep -Eq "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0)
+$(info -- KSU_SUSFS: adding function 'static inline const struct cred *get_cred_rcu();' to $(srctree)/include/linux/cred.h)
+GET_CRED_RCU = static inline const struct cred *get_cred_rcu(const struct cred *cred)\n\
+{\n\t\
+ struct cred *nonconst_cred = (struct cred *) cred;\n\t\
+ if (!cred)\n\t\t\
+ return NULL;\n\t\
+ if (!atomic_inc_not_zero(&nonconst_cred->usage))\n\t\t\
+ return NULL;\n\t\
+ validate_creds(cred);\n\t\
+ return cred;\n\
+}\n
+$(shell sed -i '/^static inline void put_cred/i $(GET_CRED_RCU)' $(srctree)/include/linux/cred.h;)
+endif
+
+ifneq ($(shell grep -Eq "^static int can_umount" $(srctree)/fs/namespace.c; echo $$?),0)
+$(info -- KSU_SUSFS: adding function 'static int can_umount(const struct path *path, int flags);' to $(srctree)/fs/namespace.c)
+CAN_UMOUNT = static int can_umount(const struct path *path, int flags)\n\
+{\n\t\
+ struct mount *mnt = real_mount(path->mnt);\n\t\
+ if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))\n\t\t\
+ return -EINVAL;\n\t\
+ if (!may_mount())\n\t\t\
+ return -EPERM;\n\t\
+ if (path->dentry != path->mnt->mnt_root)\n\t\t\
+ return -EINVAL;\n\t\
+ if (!check_mnt(mnt))\n\t\t\
+ return -EINVAL;\n\t\
+ if (mnt->mnt.mnt_flags & MNT_LOCKED)\n\t\t\
+ return -EINVAL;\n\t\
+ if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))\n\t\t\
+ return -EPERM;\n\t\
+ return 0;\n\
+}\n
+$(shell sed -i '/^static bool is_mnt_ns_file/i $(CAN_UMOUNT)' $(srctree)/fs/namespace.c;)
+endif
+
+ifneq ($(shell grep -Eq "^int path_umount" $(srctree)/fs/namespace.c; echo $$?),0)
+$(info -- KSU_SUSFS: adding function 'int path_umount(struct path *path, int flags);' to $(srctree)/fs/namespace.c)
+PATH_UMOUNT = int path_umount(struct path *path, int flags)\n\
+{\n\t\
+ struct mount *mnt = real_mount(path->mnt);\n\t\
+ int ret;\n\t\
+ ret = can_umount(path, flags);\n\t\
+ if (!ret)\n\t\t\
+ ret = do_umount(mnt, flags);\n\t\
+ dput(path->dentry);\n\t\
+ mntput_no_expire(mnt);\n\t\
+ return ret;\n\
+}\n
+$(shell sed -i '/^static bool is_mnt_ns_file/i $(PATH_UMOUNT)' $(srctree)/fs/namespace.c;)
+endif
+
+ifneq ($(shell grep -Eq "^int path_umount" $(srctree)/fs/internal.h; echo $$?),0)
+$(shell sed -i '/^extern void __init mnt_init/a int path_umount(struct path *path, int flags);' $(srctree)/fs/internal.h;)
+$(info -- KSU_SUSFS: adding 'int path_umount(struct path *path, int flags);' to $(srctree)/fs/internal.h)
+endif
+
+## For susfs stuff ##
+ifeq ($(shell test -e $(srctree)/fs/susfs.c; echo $$?),0)
+$(eval SUSFS_VERSION=$(shell cat $(srctree)/include/linux/susfs.h | grep -E '^#define SUSFS_VERSION' | cut -d' ' -f3 | sed 's/"//g'))
+$(info )
+$(info -- SUSFS_VERSION: $(SUSFS_VERSION))
+else
+$(info -- You have not integrate susfs in your kernel.)
+$(info -- Read: https://gitlab.com/simonpunk/susfs4ksu)
+endif
+# Keep a new line here!! Because someone may append config
\ No newline at end of file
diff --git a/kernel/allowlist.c b/kernel/allowlist.c
index 443ce430..42c44f64 100644
--- a/kernel/allowlist.c
+++ b/kernel/allowlist.c
@@ -95,7 +95,7 @@ static uint8_t allow_list_bitmap[PAGE_SIZE] __read_mostly __aligned(PAGE_SIZE);
static struct work_struct ksu_save_work;
static struct work_struct ksu_load_work;
-bool persistent_allow_list(void);
+static bool persistent_allow_list(void);
void ksu_show_allow_list(void)
{
@@ -270,7 +270,7 @@ bool __ksu_is_allow_uid(uid_t uid)
if (unlikely(uid == 0)) {
// already root, but only allow our domain.
- return is_ksu_domain();
+ return ksu_is_ksu_domain();
}
if (forbid_system_uid(uid)) {
@@ -355,7 +355,7 @@ bool ksu_get_allow_list(int *array, int *length, bool allow)
return true;
}
-void do_save_allow_list(struct work_struct *work)
+static void do_save_allow_list(struct work_struct *work)
{
u32 magic = FILE_MAGIC;
u32 version = FILE_FORMAT_VERSION;
@@ -397,7 +397,7 @@ exit:
filp_close(fp, 0);
}
-void do_load_allow_list(struct work_struct *work)
+static void do_load_allow_list(struct work_struct *work)
{
loff_t off = 0;
ssize_t ret = 0;
@@ -487,7 +487,7 @@ void ksu_prune_allowlist(bool (*is_uid_valid)(uid_t, char *, void *), void *data
}
// make sure allow list works cross boot
-bool persistent_allow_list(void)
+static bool persistent_allow_list(void)
{
return ksu_queue_work(&ksu_save_work);
}
diff --git a/kernel/apk_sign.c b/kernel/apk_sign.c
index 384bb1c5..87401814 100644
--- a/kernel/apk_sign.c
+++ b/kernel/apk_sign.c
@@ -314,7 +314,7 @@ module_param_cb(ksu_debug_manager_uid, &expected_size_ops,
#endif
-bool is_manager_apk(char *path)
+bool ksu_is_manager_apk(char *path)
{
return check_v2_signature(path, EXPECTED_NEXT_SIZE, EXPECTED_NEXT_HASH);
}
\ No newline at end of file
diff --git a/kernel/apk_sign.h b/kernel/apk_sign.h
index bed501c4..e02aa514 100644
--- a/kernel/apk_sign.h
+++ b/kernel/apk_sign.h
@@ -3,6 +3,6 @@
#include <linux/types.h>
-bool is_manager_apk(char *path);
+bool ksu_is_manager_apk(char *path);
#endif
diff --git a/kernel/core_hook.c b/kernel/core_hook.c
index 16a6a135..18f82a46 100644
--- a/kernel/core_hook.c
+++ b/kernel/core_hook.c
@@ -33,6 +33,10 @@
#include <linux/vmalloc.h>
#endif
+#ifdef CONFIG_KSU_SUSFS
+#include <linux/susfs.h>
+#endif // #ifdef CONFIG_KSU_SUSFS
+
#include "allowlist.h"
#include "arch.h"
#include "core_hook.h"
@@ -49,13 +53,80 @@
#define KSU_GET_CRED_RCU
#endif
+#ifdef CONFIG_KSU_SUSFS
+bool susfs_is_allow_su(void)
+{
+ if (ksu_is_manager()) {
+ // we are manager, allow!
+ return true;
+ }
+ return ksu_is_allow_uid(current_uid().val);
+}
+
+extern u32 susfs_zygote_sid;
+extern bool susfs_is_mnt_devname_ksu(struct path *path);
+extern bool susfs_is_log_enabled __read_mostly;
+
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+extern void susfs_run_try_umount_for_current_mnt_ns(void);
+#endif // #ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+static bool susfs_is_umount_for_zygote_system_process_enabled = false;
+#endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+extern bool susfs_is_auto_add_sus_bind_mount_enabled;
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+extern bool susfs_is_auto_add_sus_ksu_default_mount_enabled;
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+extern bool susfs_is_auto_add_try_umount_for_bind_mount_enabled;
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+
+static inline void susfs_on_post_fs_data(void) {
+ struct path path;
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+ if (!kern_path(DATA_ADB_UMOUNT_FOR_ZYGOTE_SYSTEM_PROCESS, 0, &path)) {
+ susfs_is_umount_for_zygote_system_process_enabled = true;
+ path_put(&path);
+ }
+ pr_info("susfs_is_umount_for_zygote_system_process_enabled: %d\n", susfs_is_umount_for_zygote_system_process_enabled);
+#endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+ if (!kern_path(DATA_ADB_NO_AUTO_ADD_SUS_BIND_MOUNT, 0, &path)) {
+ susfs_is_auto_add_sus_bind_mount_enabled = false;
+ path_put(&path);
+ }
+ pr_info("susfs_is_auto_add_sus_bind_mount_enabled: %d\n", susfs_is_auto_add_sus_bind_mount_enabled);
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+ if (!kern_path(DATA_ADB_NO_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT, 0, &path)) {
+ susfs_is_auto_add_sus_ksu_default_mount_enabled = false;
+ path_put(&path);
+ }
+ pr_info("susfs_is_auto_add_sus_ksu_default_mount_enabled: %d\n", susfs_is_auto_add_sus_ksu_default_mount_enabled);
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+ if (!kern_path(DATA_ADB_NO_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT, 0, &path)) {
+ susfs_is_auto_add_try_umount_for_bind_mount_enabled = false;
+ path_put(&path);
+ }
+ pr_info("susfs_is_auto_add_try_umount_for_bind_mount_enabled: %d\n", susfs_is_auto_add_try_umount_for_bind_mount_enabled);
+#endif // #ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+}
+#endif // #ifdef CONFIG_KSU_SUSFS
+
+#ifdef CONFIG_KSU_SUSFS_SUS_SU
+extern bool susfs_is_sus_su_ready;
+#endif // #ifdef CONFIG_KSU_SUSFS_SUS_SU
+
static bool ksu_module_mounted = false;
-extern int handle_sepolicy(unsigned long arg3, void __user *arg4);
+extern int ksu_handle_sepolicy(unsigned long arg3, void __user *arg4);
static inline bool is_allow_su()
{
- if (is_manager()) {
+ if (ksu_is_manager()) {
// we are manager, allow!
return true;
}
@@ -132,7 +203,7 @@ static void disable_seccomp(void)
#endif
}
-void escape_to_root(void)
+void ksu_escape_to_root(void)
{
struct cred *cred;
@@ -202,7 +273,7 @@ void escape_to_root(void)
disable_seccomp();
spin_unlock_irq(¤t->sighand->siglock);
- setup_selinux(profile->selinux_domain);
+ ksu_setup_selinux(profile->selinux_domain);
}
int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)
@@ -239,7 +310,7 @@ int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)
pr_info("renameat: %s -> %s, new path: %s\n", old_dentry->d_iname,
new_dentry->d_iname, buf);
- track_throne();
+ ksu_track_throne();
return 0;
}
@@ -264,7 +335,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
}
bool from_root = 0 == current_uid().val;
- bool from_manager = is_manager();
+ bool from_manager = ksu_is_manager();
if (!from_root && !from_manager) {
// only root or manager can access this interface
@@ -288,7 +359,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
if (arg2 == CMD_GRANT_ROOT) {
if (is_allow_su()) {
pr_info("allow root for: %d\n", current_uid().val);
- escape_to_root();
+ ksu_escape_to_root();
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("grant_root: prctl reply error\n");
}
@@ -320,10 +391,13 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
switch (arg3) {
case EVENT_POST_FS_DATA: {
static bool post_fs_data_lock = false;
+#ifdef CONFIG_KSU_SUSFS
+ susfs_on_post_fs_data();
+#endif
if (!post_fs_data_lock) {
post_fs_data_lock = true;
pr_info("post-fs-data triggered\n");
- on_post_fs_data();
+ ksu_on_post_fs_data();
}
break;
}
@@ -350,7 +424,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
if (!from_root) {
return 0;
}
- if (!handle_sepolicy(arg3, arg4)) {
+ if (!ksu_handle_sepolicy(arg3, arg4)) {
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("sepolicy: prctl reply error\n");
}
@@ -411,6 +485,338 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
return 0;
}
+#ifdef CONFIG_KSU_SUSFS
+ if (current_uid_val == 0) {
+#ifdef CONFIG_KSU_SUSFS_SUS_PATH
+ if (arg2 == CMD_SUSFS_ADD_SUS_PATH) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_sus_path))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_PATH -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_PATH -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_sus_path((struct st_susfs_sus_path __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_SUS_PATH -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SUS_PATH
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+ if (arg2 == CMD_SUSFS_ADD_SUS_MOUNT) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_sus_mount))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_MOUNT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_MOUNT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_sus_mount((struct st_susfs_sus_mount __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_SUS_MOUNT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+#ifdef CONFIG_KSU_SUSFS_SUS_KSTAT
+ if (arg2 == CMD_SUSFS_ADD_SUS_KSTAT) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_sus_kstat))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_KSTAT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_KSTAT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_sus_kstat((struct st_susfs_sus_kstat __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_SUS_KSTAT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_UPDATE_SUS_KSTAT) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_sus_kstat))) {
+ pr_err("susfs: CMD_SUSFS_UPDATE_SUS_KSTAT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_UPDATE_SUS_KSTAT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_update_sus_kstat((struct st_susfs_sus_kstat __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_UPDATE_SUS_KSTAT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_ADD_SUS_KSTAT_STATICALLY) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_sus_kstat))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_KSTAT_STATICALLY -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_SUS_KSTAT_STATICALLY -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_sus_kstat((struct st_susfs_sus_kstat __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_SUS_KSTAT_STATICALLY -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SUS_KSTAT
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+ if (arg2 == CMD_SUSFS_ADD_TRY_UMOUNT) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_try_umount))) {
+ pr_err("susfs: CMD_SUSFS_ADD_TRY_UMOUNT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_TRY_UMOUNT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_try_umount((struct st_susfs_try_umount __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_TRY_UMOUNT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_RUN_UMOUNT_FOR_CURRENT_MNT_NS) {
+ int error = 0;
+ susfs_run_try_umount_for_current_mnt_ns();
+ pr_info("susfs: CMD_SUSFS_RUN_UMOUNT_FOR_CURRENT_MNT_NS -> ret: %d\n", error);
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+#ifdef CONFIG_KSU_SUSFS_SPOOF_UNAME
+ if (arg2 == CMD_SUSFS_SET_UNAME) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_uname))) {
+ pr_err("susfs: CMD_SUSFS_SET_UNAME -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SET_UNAME -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_set_uname((struct st_susfs_uname __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_SET_UNAME -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SPOOF_UNAME
+#ifdef CONFIG_KSU_SUSFS_ENABLE_LOG
+ if (arg2 == CMD_SUSFS_ENABLE_LOG) {
+ int error = 0;
+ if (arg3 != 0 && arg3 != 1) {
+ pr_err("susfs: CMD_SUSFS_ENABLE_LOG -> arg3 can only be 0 or 1\n");
+ return 0;
+ }
+ susfs_set_log(arg3);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_ENABLE_LOG
+#ifdef CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
+ if (arg2 == CMD_SUSFS_SET_CMDLINE_OR_BOOTCONFIG) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, SUSFS_FAKE_CMDLINE_OR_BOOTCONFIG_SIZE)) {
+ pr_err("susfs: CMD_SUSFS_SET_CMDLINE_OR_BOOTCONFIG -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SET_CMDLINE_OR_BOOTCONFIG -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_set_cmdline_or_bootconfig((char __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_SET_CMDLINE_OR_BOOTCONFIG -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
+#ifdef CONFIG_KSU_SUSFS_OPEN_REDIRECT
+ if (arg2 == CMD_SUSFS_ADD_OPEN_REDIRECT) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_susfs_open_redirect))) {
+ pr_err("susfs: CMD_SUSFS_ADD_OPEN_REDIRECT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_ADD_OPEN_REDIRECT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_add_open_redirect((struct st_susfs_open_redirect __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_ADD_OPEN_REDIRECT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_OPEN_REDIRECT
+#ifdef CONFIG_KSU_SUSFS_SUS_SU
+ if (arg2 == CMD_SUSFS_SUS_SU) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(struct st_sus_su))) {
+ pr_err("susfs: CMD_SUSFS_SUS_SU -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SUS_SU -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = susfs_sus_su((struct st_sus_su __user*)arg3);
+ pr_info("susfs: CMD_SUSFS_SUS_SU -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS_SUS_SU
+ if (arg2 == CMD_SUSFS_SHOW_VERSION) {
+ int error = 0;
+ int len_of_susfs_version = strlen(SUSFS_VERSION);
+ char *susfs_version = SUSFS_VERSION;
+ if (!ksu_access_ok((void __user*)arg3, len_of_susfs_version+1)) {
+ pr_err("susfs: CMD_SUSFS_SHOW_VERSION -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_VERSION -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = copy_to_user((void __user*)arg3, (void*)susfs_version, len_of_susfs_version+1);
+ pr_info("susfs: CMD_SUSFS_SHOW_VERSION -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_SHOW_ENABLED_FEATURES) {
+ int error = 0;
+ u64 enabled_features = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(u64))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg5 is not accessible\n");
+ return 0;
+ }
+#ifdef CONFIG_KSU_SUSFS_SUS_PATH
+ enabled_features |= (1 << 0);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+ enabled_features |= (1 << 1);
+#endif
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
+ enabled_features |= (1 << 2);
+#endif
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
+ enabled_features |= (1 << 3);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SUS_KSTAT
+ enabled_features |= (1 << 4);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SUS_OVERLAYFS
+ enabled_features |= (1 << 5);
+#endif
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+ enabled_features |= (1 << 6);
+#endif
+#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
+ enabled_features |= (1 << 7);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SPOOF_UNAME
+ enabled_features |= (1 << 8);
+#endif
+#ifdef CONFIG_KSU_SUSFS_ENABLE_LOG
+ enabled_features |= (1 << 9);
+#endif
+#ifdef CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS
+ enabled_features |= (1 << 10);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
+ enabled_features |= (1 << 11);
+#endif
+#ifdef CONFIG_KSU_SUSFS_OPEN_REDIRECT
+ enabled_features |= (1 << 12);
+#endif
+#ifdef CONFIG_KSU_SUSFS_SUS_SU
+ enabled_features |= (1 << 13);
+#endif
+#ifdef CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT
+ enabled_features |= (1 << 14);
+#endif
+ error = copy_to_user((void __user*)arg3, (void*)&enabled_features, sizeof(enabled_features));
+ pr_info("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_SHOW_VARIANT) {
+ int error = 0;
+ int len_of_variant = strlen(SUSFS_VARIANT);
+ char *susfs_variant = SUSFS_VARIANT;
+ if (!ksu_access_ok((void __user*)arg3, len_of_variant+1)) {
+ pr_err("susfs: CMD_SUSFS_SHOW_VARIANT -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_VARIANT -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = copy_to_user((void __user*)arg3, (void*)susfs_variant, len_of_variant+1);
+ pr_info("susfs: CMD_SUSFS_SHOW_VARIANT -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#ifdef CONFIG_KSU_SUSFS_SUS_SU
+ if (arg2 == CMD_SUSFS_IS_SUS_SU_READY) {
+ int error = 0;
+ if (!ksu_access_ok((void __user*)arg3, sizeof(susfs_is_sus_su_ready))) {
+ pr_err("susfs: CMD_SUSFS_IS_SUS_SU_READY -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_IS_SUS_SU_READY -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = copy_to_user((void __user*)arg3, (void*)&susfs_is_sus_su_ready, sizeof(susfs_is_sus_su_ready));
+ pr_info("susfs: CMD_SUSFS_IS_SUS_SU_READY -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+ if (arg2 == CMD_SUSFS_SHOW_SUS_SU_WORKING_MODE) {
+ int error = 0;
+ int working_mode = susfs_get_sus_su_working_mode();
+ if (!ksu_access_ok((void __user*)arg3, sizeof(working_mode))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_SUS_SU_WORKING_MODE -> arg3 is not accessible\n");
+ return 0;
+ }
+ if (!ksu_access_ok((void __user*)arg5, sizeof(error))) {
+ pr_err("susfs: CMD_SUSFS_SHOW_SUS_SU_WORKING_MODE -> arg5 is not accessible\n");
+ return 0;
+ }
+ error = copy_to_user((void __user*)arg3, (void*)&working_mode, sizeof(working_mode));
+ pr_info("susfs: CMD_SUSFS_SHOW_SUS_SU_WORKING_MODE -> ret: %d\n", error);
+ if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
+ pr_info("susfs: copy_to_user() failed\n");
+ return 0;
+ }
+#endif // #ifdef CONFIG_KSU_SUSFS_SUS_SU
+ }
+#endif //#ifdef CONFIG_KSU_SUSFS
+
// all other cmds are for 'root manager'
if (!from_manager) {
return 0;
@@ -478,11 +884,15 @@ static bool should_umount(struct path *path)
return false;
}
+#ifdef CONFIG_KSU_SUSFS
+ return susfs_is_mnt_devname_ksu(path);
+#else
if (path->mnt && path->mnt->mnt_sb && path->mnt->mnt_sb->s_type) {
const char *fstype = path->mnt->mnt_sb->s_type->name;
return strcmp(fstype, "overlay") == 0;
}
return false;
+#endif
}
static int ksu_umount_mnt(struct path *path, int flags)
@@ -495,7 +905,11 @@ static int ksu_umount_mnt(struct path *path, int flags)
#endif
}
-static void try_umount(const char *mnt, bool check_mnt, int flags)
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+void ksu_try_umount(const char *mnt, bool check_mnt, int flags, uid_t uid)
+#else
+static void ksu_try_umount(const char *mnt, bool check_mnt, int flags)
+#endif
{
struct path path;
int err = kern_path(mnt, 0, &path);
@@ -513,12 +927,35 @@ static void try_umount(const char *mnt, bool check_mnt, int flags)
return;
}
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+ if (susfs_is_log_enabled) {
+ pr_info("susfs: umounting '%s' for uid: %d\n", mnt, uid);
+ }
+#endif
+
err = ksu_umount_mnt(&path, flags);
if (err) {
pr_warn("umount %s failed: %d\n", mnt, err);
}
}
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+void susfs_try_umount_all(uid_t uid) {
+ susfs_try_umount(uid);
+ /* For Legacy KSU only */
+ ksu_try_umount("/system", true, 0, uid);
+ ksu_try_umount("/system_ext", true, 0, uid);
+ ksu_try_umount("/vendor", true, 0, uid);
+ ksu_try_umount("/product", true, 0, uid);
+ ksu_try_umount("/odm", true, 0, uid);
+ // - For '/data/adb/modules' we pass 'false' here because it is a loop device that we can't determine whether
+ // its dev_name is KSU or not, and it is safe to just umount it if it is really a mountpoint
+ ksu_try_umount("/data/adb/modules", false, MNT_DETACH, uid);
+ /* For both Legacy KSU and Magic Mount KSU */
+ ksu_try_umount("/debug_ramdisk", true, MNT_DETACH, uid);
+}
+#endif
+
int ksu_handle_setuid(struct cred *new, const struct cred *old)
{
// this hook is used for umounting overlayfs for some uid, if there isn't any module mounted, just ignore it!
@@ -538,6 +975,20 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
return 0;
}
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+ // check if current process is zygote
+ bool is_zygote_child = susfs_is_sid_equal(old->security, susfs_zygote_sid);
+ if (likely(is_zygote_child)) {
+ // if spawned process is non user app process
+ if (unlikely(new_uid.val < 10000 && new_uid.val >= 1000)) {
+ // umount for the system process if path DATA_ADB_UMOUNT_FOR_ZYGOTE_SYSTEM_PROCESS exists
+ if (susfs_is_umount_for_zygote_system_process_enabled) {
+ goto out_ksu_try_umount;
+ }
+ }
+ }
+#endif
+
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
return 0;
@@ -547,7 +998,17 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
return 0;
}
+#ifdef CONFIG_KSU_SUSFS
+ else {
+ task_lock(current);
+ current->susfs_task_state |= TASK_STRUCT_NON_ROOT_USER_APP_PROC;
+ task_unlock(current);
+ }
+#endif
+#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
+out_ksu_try_umount:
+#endif
if (!ksu_uid_should_umount(new_uid.val)) {
return 0;
} else {
@@ -555,11 +1016,12 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
pr_info("uid: %d should not umount!\n", current_uid().val);
#endif
}
-
- // check old process's selinux context, if it is not zygote, ignore it!
- // because some su apps may setuid to untrusted_app but they are in global mount namespace
- // when we umount for such process, that is a disaster!
- bool is_zygote_child = is_zygote(old->security);
+#ifndef CONFIG_KSU_SUSFS_SUS_MOUNT
+ // check old process's selinux context, if it is not zygote, ignore it!
+ // because some su apps may setuid to untrusted_app but they are in global mount namespace
+ // when we umount for such process, that is a disaster!
+ bool is_zygote_child = ksu_is_zygote(old->security);
+#endif
if (!is_zygote_child) {
pr_info("handle umount ignore non zygote child: %d\n",
current->pid);
@@ -571,21 +1033,26 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
current->pid);
#endif
+#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
+ // susfs come first, and lastly umount by ksu, make sure umount in reversed order
+ susfs_try_umount_all(new_uid.val);
+#else
+
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
// filter the mountpoint whose target is `/data/adb`
- try_umount("/system", true, 0);
- try_umount("/system_ext", true, 0);
- try_umount("/vendor", true, 0);
- try_umount("/product", true, 0);
- try_umount("/data/adb/modules", false, MNT_DETACH);
+ ksu_try_umount("/system", true, 0);
+ ksu_try_umount("/system_ext", true, 0);