Skip to content

Commit dfb29f9

Browse files
author
git-core
committed
Don't touch su context in children
It's too high on the stack
1 parent 6799779 commit dfb29f9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

activity.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,37 @@
2626

2727
int send_intent(struct su_context *ctx, allow_t allow, const char *action)
2828
{
29+
const char *socket_path;
30+
unsigned int uid = ctx->from.uid;
31+
2932
if (ctx->child) {
3033
LOGE("child %d already running", ctx->child);
3134
return -1;
3235
}
36+
if (allow == INTERACTIVE) {
37+
socket_path = ctx->sock_path;
38+
} else {
39+
socket_path = "";
40+
}
3341

3442
pid_t pid = fork();
3543
/* Child */
3644
if (!pid) {
37-
const char *socket_path = (allow == INTERACTIVE) ? ctx->sock_path : "";
3845
char command[ARG_MAX];
3946

4047
snprintf(command, sizeof(command),
4148
"exec /system/bin/am broadcast -a %s --es socket '%s' "
4249
"--ei caller_uid %d --ei allow %d "
4350
"--ei version_code %d",
44-
action, socket_path, ctx->from.uid, allow, VERSION_CODE);
51+
action, socket_path, uid, allow, VERSION_CODE);
4552
char *args[] = { "sh", "-c", command, NULL, };
4653

4754
/*
4855
* before sending the intent, make sure the effective uid/gid match
4956
* the real uid/gid, otherwise LD_LIBRARY_PATH is wiped
5057
* in Android 4.0+.
5158
*/
52-
set_identity(ctx->from.uid);
59+
set_identity(uid);
5360
int zero = open("/dev/zero", O_RDONLY | O_CLOEXEC);
5461
dup2(zero, 0);
5562
int null = open("/dev/null", O_WRONLY | O_CLOEXEC);

0 commit comments

Comments
 (0)