You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
On plain ARMv8.0 devices (A53,A57,A73), strncpy_from_user_nofault() sometimes
fails to copy `filename_user` string correctly. This breaks su ofc, breaking
some apps like Termux (Play Store ver), ZArchiver and Root Explorer.
This does NOT seem to affect newer ARMv8.2+ CPUs (A75/A76 and newer)
My speculation? ARMv8.0 has weak speculation :)
here we replace `ksu_strncpy_from_user_nofault` with ksu_strncpy_from_user_retry:
- ksu_strncpy_from_user_nofault as fast-path copy
- fallback to access_ok to validate the pointer + strncpy_from_user
- manual null-termination just in case, as strncpy_from_user_nofault also does it
- remove that memset, seems useless as it is an strncpy, not strncat
basically, we retry on pagefualt
for usercopies, its not like were doing
memset(dest, 0, sizeof(dest));
strncat(dest, var, bytes);
that memset seems unneeded. instead we use strncpy itself to do proper
error and oob check and null term it after.
as for optimizations
- just return early if unauthorized
- commonized logic
- reduced duplication
Tested on:
- ARMv8.0 A73.a53, A57.a53, A53.a53
- ARMv8.2 A76.a55
Stale: tiann#2656
Signed-off-by: backslashxx <[email protected]>
// the call from execve_handler_pre won't provided correct value for __never_use_argument, use them after fix execve_handler_pre, keeping them for consistence for manually patched code
@@ -103,7 +144,7 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
103
144
constcharsh[] =KSUD_PATH;
104
145
constcharsu[] =SU_PATH;
105
146
106
-
if (unlikely(!filename_ptr))
147
+
if (!is_su_allowed((constvoid*)filename_ptr))
107
148
return0;
108
149
109
150
filename=*filename_ptr;
@@ -114,9 +155,6 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
114
155
if (likely(memcmp(filename->name, su, sizeof(su))))
115
156
return0;
116
157
117
-
if (!ksu_is_allow_uid(current_uid().val))
118
-
return0;
119
-
120
158
pr_info("do_execveat_common su found\n");
121
159
memcpy((void*)filename->name, sh, sizeof(sh));
122
160
@@ -125,35 +163,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
0 commit comments