Repository navigation
Process start OSAL abstraction using posix_spawn for QNX - Part 1 - #1023
Conversation
dc02d3f to
90756ec
Compare
|
Documentation preview for this pull request is available at: |
|
Move "Detailed comparison of fork()+execve() vs posix_spawn (QNX-only)" from PR description to a markdown file in the osal folder. |
| common:codeql --noremote_accept_cached | ||
| common:codeql --noremote_upload_local_results | ||
| common:codeql --disk_cache= | ||
| common:codeql --skip_incompatible_explicit_targets |
There was a problem hiding this comment.
Seems like QNX code might be missing from our CodeQL report?
There was a problem hiding this comment.
yeah we'll need another codeql target for QNX eventually. But it seems at the moment it is accepted to run CodeQL only for Linux
I know added a design decision that also links to this comparison table. Later, we would pull them down to the component level |
SimonKozik
left a comment
There was a problem hiding this comment.
Looks good enough for first step
2e23040
Using posix_spawn on QNX yields much better performance compared to fork()+execve().
Therefore, we want to use posix_spawn on QNX and fork()+execve() on Linux.
This PR adds a OSAL function to start a process, which can have different implementations for QNX and Linux.
This PR provides the QNX-based implementation. The code is not actually used yet and will be wired in with a follow up PR.
Follow Up PRs:
Detailed comparison of fork()+execve() vs posix_spawn (QNX-only)
process_command)access(X_OK)in the parent, thenexecve(executablePath, argv, envp)in the childposix_spawn(argv[0], …, argv, envp)(argv[0]is the executable path), no PATH lookupENOENT,EACCES, …) are returned byposix_spawn()→kFail, instead of making the child exit withEXIT_FAILUREenvironmental_variables)envppassed toexecve()envppassed toposix_spawn()application_type≠ Native)dup2(fd, 111)+fcntl(F_SETFD, 0)to clearFD_CLOEXECposix_spawn_file_actions_adddup2(fd, 111). The dup'ed fd is notFD_CLOEXECsetpgid(0, getpid())posix_spawnattr_setpgroup(0)+POSIX_SPAWN_SETPGROUPsigaction(SIG_DFL)for every signal except KILL/STOP, thenpthread_sigmask(empty)posix_spawnattr_setsigdefault(all)+setsigmask(empty)(POSIX_SPAWN_SETSIGDEF | SETSIGMASK)sandbox.uid,sandbox.gid)setgid()→setgroups()→setuid()posix_spawnattr_setcred(uid, gid)+POSIX_SPAWN_SETCREDposix_spawn()fail →kFail, no process is createdsandbox.supplementary_group_ids)setgroups(n, list)beforesetuid(). Always called, so an empty list clears Launch Manager's groupssetgroupspid(n, list, pid)on the held process. Always calledsandbox.scheduling_policy,sandbox.scheduling_priority)sched_setscheduler(0, …)sched_setscheduler(pid, …)on the held process. The spawn attribute is deliberately not used, to avoid priority inversion whileposix_spawn()waits for the child to initializesched_get_priority_min/max(policy)once at configuration load (with a warning) instead of in the forked childsandbox.affinity_mask, optional)ThreadCtl(_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT)with runmask = inherit mask = configured mask (up to 64 CPUs)pthread_spawnattr_setrunmask_np(mask)(64 bit) +POSIX_SPAWN_EXPLICIT_CPUsandbox.rlimits)setrlimit()for each limit, before dropping privilegesprlimit(pid, …)for each limit on the held processsandbox.rlimits)setrlimit()beforeexecve(). The new image's main thread stack follows the limitposix_spawnattr_setstackmax(soft limit)+POSIX_SPAWN_SETSTACKMAX, because the main thread stack already exists while the process is heldRLIM_INFINITYor > 4 GiB, a warning is logged and the main thread gets the default stack size. The rlimit itself is still applied withprlimit()working_dir)chdir(working_dir)aftersetuid(), so access is checked as the target uidO_RDONLY | O_DIRECTORY | O_CLOEXEC) and passes the fd viaposix_spawnattr_setcwd_np()+POSIX_SPAWN_SETCWD, so access is checked as Launch Manager's uidsandbox.security_policy, optional)secpol_transition_type(nullptr, name, 1)aftersetuid()/chdir(), just beforeexecve().ENOTSUPis ignoredsecpol_posix_spawnattr_settypeid(name, SECPOL_TYPE_NAME)(setsPOSIX_SPAWN_SETTYPEID).kOperationNotSupportedis ignoredError handling and observable behavior
open(working_dir),posix_spawn()itself)EXIT_FAILURE.startProcess()already returnedkSuccessstartProcess()returnskFail,pid = -1, no process is createdSIGKILLsent to the held process,startProcess()returnskSuccess. Termination is reported through the normal pathWIFEXITED, exit code1WIFSIGNALED,SIGKILLsetSchedulingAndSecurity()tries all settings and logs every failure, then exitssignal_safe_logfrom the forked child (async-signal-safe only)LM_LOG_*from Launch Manager, with the executable and pidSIGCONTfailsSIGKILLsentfflush(stdout)before startSIGCONT