Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone(2): fix check for attempts to create new process #1733

Merged
merged 1 commit into from
Jun 3, 2022

Conversation

francescolavra
Copy link
Member

The existing clone(2) syscall implementation was detecting whether the user program is trying to create a new process by checking the child_stack argument against a null value. This logic is based on the fact that the glibc fork() wrapper that is provided as part of the NPTL threading implementation invokes clone(2) with child_stack set to 0. However, it is possible to create a new process even if child_stack is non-zero: notably, the posix_spawn() implementation in glibc invokes clone() with a valid stack pointer, which is later unmapped by the parent process after the child starts executing the newly created process. The correct way for clone(2) to detect an attempt to create a new process is by checking for the CLONE_THREAD flag.

The existing clone(2) syscall implementation was detecting whether
the user program is trying to create a new process by checking the
child_stack argument against a null value. This logic is based on
the fact that the glibc fork() wrapper that is provided as part of
the NPTL threading implementation invokes clone(2) with child_stack
set to 0. However, it is possible to create a new process even if
child_stack is non-zero: notably, the posix_spawn() implementation
in glibc invokes clone() with a valid stack pointer, which is
later unmapped by the parent process after the child starts
executing the newly created process. The correct way for clone(2)
to detect an attempt to create a new process is by checking for the
CLONE_THREAD flag.
Copy link
Contributor

@wjhun wjhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@francescolavra francescolavra merged commit ebb9df4 into master Jun 3, 2022
@francescolavra francescolavra deleted the fix/clone branch June 3, 2022 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants