@@ -136,17 +136,20 @@ int ksu_getname_flags_user(const char __user **filename_user, int flags)
136
136
return ksu_sucompat_user_common (filename_user , "getname_flags" , !!!flags );
137
137
}
138
138
139
- static int ksu_do_execveat_common (void * filename_ptr , const char * function_name )
139
+ static int ksu_sucompat_kernel_common (void * filename_ptr , const char * function_name , bool escalate )
140
140
{
141
- const char sh [] = KSUD_PATH ;
142
- const char su [] = SU_PATH ;
143
141
144
- if (likely (memcmp (filename_ptr , su , sizeof (su ))))
142
+ if (likely (memcmp (filename_ptr , SU_PATH , sizeof (SU_PATH ))))
145
143
return 0 ;
146
144
147
- pr_info ("%s su found\n" , function_name );
148
- memcpy (filename_ptr , sh , sizeof (sh ));
149
- escape_to_root ();
145
+ if (escalate ) {
146
+ pr_info ("%s su found\n" , function_name );
147
+ memcpy (filename_ptr , KSUD_PATH , sizeof (KSUD_PATH ));
148
+ escape_to_root ();
149
+ } else {
150
+ pr_info ("%s su->sh\n" , function_name );
151
+ memcpy (filename_ptr , SH_PATH , sizeof (SH_PATH ));
152
+ }
150
153
return 0 ;
151
154
}
152
155
@@ -164,7 +167,7 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
164
167
// return ksu_do_execveat_common((void *)filename->name, "do_execveat_common");
165
168
// nvm this, just inline
166
169
167
- return ksu_do_execveat_common ((void * )(* filename_ptr )-> name , "do_execveat_common" );
170
+ return ksu_sucompat_kernel_common ((void * )(* filename_ptr )-> name , "do_execveat_common" , true );
168
171
}
169
172
170
173
int ksu_handle_execveat (int * fd , struct filename * * filename_ptr , void * argv ,
@@ -182,10 +185,21 @@ int ksu_legacy_execve_sucompat(const char **filename_ptr,
182
185
if (!is_su_allowed ((const void * )filename_ptr ))
183
186
return 0 ;
184
187
185
- return ksu_do_execveat_common ((void * )* filename_ptr , "do_execve_common" );
188
+ return ksu_sucompat_kernel_common ((void * )* filename_ptr , "do_execve_common" , true );
186
189
}
187
190
#endif
188
191
192
+ // getname_flags on fs/namei.c, this hooks ALL fs-related syscalls.
193
+ // put the hook right after usercopy
194
+ // NOT RECOMMENDED for daily use. mostly for debugging purposes.
195
+ int ksu_getname_flags_kernel (char * * kname , int flags )
196
+ {
197
+ if (!is_su_allowed ((const void * )kname ))
198
+ return 0 ;
199
+
200
+ return ksu_sucompat_kernel_common ((void * )* kname , "getname_flags" , !!!flags );
201
+ }
202
+
189
203
// dummified
190
204
int ksu_handle_devpts (struct inode * inode )
191
205
{
0 commit comments