Skip to content

Commit

Permalink
unshare on parent Zygote only
Browse files Browse the repository at this point in the history
Calling unshare on child Zygotes crash at a sanity check but they end up inheriting the namespace either way.

closes #1
  • Loading branch information
snake-4 committed Mar 26, 2024
1 parent 72afc9e commit 58782b2
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions module/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ class ZygiskModule : public zygisk::ModuleBase
{
LOGD("Creating new mount namespace for parent pid=%d uid=%d", getpid(), args->uid);

/*
* Mount the pseudo app mount namespace's root as MS_SLAVE, so every mount/umount from
* Zygote shared pre-specialization mountspace is propagated to this one.
*/
if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1)
{
LOGE("mount(\"rootfs\", \"/\", NULL, (MS_SLAVE | MS_REC), NULL) returned -1");
/*
* preAppSpecialize is before ensureInAppMountNamespace.
* postAppSpecialize is after seccomp setup.
* So we unshare here to create a pseudo app mount namespace
*/
if (unshare(CLONE_NEWNS) == -1)
{
LOGE("unshare(CLONE_NEWNS) returned -1: %d (%s)", errno, strerror(errno));
// Don't unmount anything in global namespace
return;
}

/*
* Mount the pseudo app mount namespace's root as MS_SLAVE, so every mount/umount from
* Zygote shared pre-specialization mountspace is propagated to this one.
*/
if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1)
{
LOGE("mount(\"rootfs\", \"/\", NULL, (MS_SLAVE | MS_REC), NULL) returned -1");
}
}

do_unmount();
Expand Down

0 comments on commit 58782b2

Please sign in to comment.