@@ -71,6 +71,7 @@ static int from_init(struct su_initiator *from)
71
71
int fd ;
72
72
ssize_t len ;
73
73
int i ;
74
+ int err ;
74
75
75
76
from -> uid = getuid ();
76
77
from -> pid = getppid ();
@@ -83,9 +84,10 @@ static int from_init(struct su_initiator *from)
83
84
return -1 ;
84
85
}
85
86
len = read (fd , args , sizeof (args ));
87
+ err = errno ;
86
88
close (fd );
87
89
if (len < 0 || len == sizeof (args )) {
88
- PLOGE ("Reading command line" );
90
+ PLOGEV ("Reading command line" , err );
89
91
return -1 ;
90
92
}
91
93
@@ -144,10 +146,10 @@ static void cleanup_signal(int sig)
144
146
exit (sig );
145
147
}
146
148
147
- static int socket_create_temp (unsigned req_uid )
149
+ static int socket_create_temp (void )
148
150
{
149
151
static char buf [PATH_MAX ];
150
- int fd , err ;
152
+ int fd ;
151
153
152
154
struct sockaddr_un sun ;
153
155
@@ -174,18 +176,6 @@ static int socket_create_temp(unsigned req_uid)
174
176
}
175
177
}
176
178
177
- if (chmod (sun .sun_path , 0600 ) < 0 ) {
178
- PLOGE ("chmod(socket)" );
179
- unlink (sun .sun_path );
180
- return -1 ;
181
- }
182
-
183
- if (chown (sun .sun_path , req_uid , req_uid ) < 0 ) {
184
- PLOGE ("chown(socket)" );
185
- unlink (sun .sun_path );
186
- return -1 ;
187
- }
188
-
189
179
if (listen (fd , 1 ) < 0 ) {
190
180
PLOGE ("listen" );
191
181
return -1 ;
@@ -222,7 +212,6 @@ static int socket_accept(int serv_fd)
222
212
static int socket_receive_result (int serv_fd , char * result , ssize_t result_len )
223
213
{
224
214
ssize_t len ;
225
- char buf [64 ];
226
215
227
216
for (;;) {
228
217
int fd = socket_accept (serv_fd );
@@ -275,19 +264,19 @@ static void deny(void)
275
264
exit (EXIT_FAILURE );
276
265
}
277
266
278
- static void allow (char * shell )
267
+ static void allow (char * shell , mode_t mask )
279
268
{
280
269
struct su_initiator * from = & su_from ;
281
270
struct su_request * to = & su_to ;
282
271
char * exe = NULL ;
283
272
273
+ umask (mask );
284
274
send_intent (& su_from , & su_to , "" , 1 , 1 );
285
275
286
276
if (!strcmp (shell , "" )) {
287
277
strcpy (shell , "/system/bin/sh" );
288
278
}
289
279
exe = strrchr (shell , '/' ) + 1 ;
290
- setgroups (0 , NULL );
291
280
setresgid (to -> uid , to -> uid , to -> uid );
292
281
setresuid (to -> uid , to -> uid , to -> uid );
293
282
LOGD ("%u %s executing %u %s using shell %s : %s" , from -> uid , from -> bin ,
@@ -307,7 +296,7 @@ int main(int argc, char *argv[])
307
296
static int socket_serv_fd = -1 ;
308
297
char buf [64 ], shell [PATH_MAX ], * result ;
309
298
int i , dballow ;
310
- unsigned req_uid ;
299
+ mode_t orig_umask ;
311
300
312
301
for (i = 1 ; i < argc ; i ++ ) {
313
302
if (!strcmp (argv [i ], "-c" ) || !strcmp (argv [i ], "--command" )) {
@@ -356,8 +345,10 @@ int main(int argc, char *argv[])
356
345
deny ();
357
346
}
358
347
348
+ orig_umask = umask (027 );
349
+
359
350
if (su_from .uid == AID_ROOT || su_from .uid == AID_SHELL )
360
- allow (shell );
351
+ allow (shell , orig_umask );
361
352
362
353
if (stat (REQUESTOR_DATA_PATH , & st ) < 0 ) {
363
354
PLOGE ("stat" );
@@ -371,10 +362,8 @@ int main(int argc, char *argv[])
371
362
deny ();
372
363
}
373
364
374
- req_uid = st .st_uid ;
375
-
376
- if (mkdir (REQUESTOR_CACHE_PATH , 0771 ) >= 0 ) {
377
- chown (REQUESTOR_CACHE_PATH , req_uid , req_uid );
365
+ if (mkdir (REQUESTOR_CACHE_PATH , 0770 ) >= 0 ) {
366
+ chown (REQUESTOR_CACHE_PATH , st .st_uid , st .st_gid );
378
367
}
379
368
380
369
setgroups (0 , NULL );
@@ -400,12 +389,12 @@ int main(int argc, char *argv[])
400
389
401
390
switch (dballow ) {
402
391
case DB_DENY : deny ();
403
- case DB_ALLOW : allow (shell );
392
+ case DB_ALLOW : allow (shell , orig_umask );
404
393
case DB_INTERACTIVE : break ;
405
394
default : deny ();
406
395
}
407
396
408
- socket_serv_fd = socket_create_temp (req_uid );
397
+ socket_serv_fd = socket_create_temp ();
409
398
if (socket_serv_fd < 0 ) {
410
399
deny ();
411
400
}
@@ -432,7 +421,7 @@ int main(int argc, char *argv[])
432
421
if (!strcmp (result , "DENY" )) {
433
422
deny ();
434
423
} else if (!strcmp (result , "ALLOW" )) {
435
- allow (shell );
424
+ allow (shell , orig_umask );
436
425
} else {
437
426
LOGE ("unknown response from Superuser Requestor: %s" , result );
438
427
deny ();
0 commit comments