Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: sandbox/linux/services/credentials.cc

Issue 1248673004: Set a new TLS when using CLONE_VM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sandbox/linux/services/credentials_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/credentials.cc
diff --git a/sandbox/linux/services/credentials.cc b/sandbox/linux/services/credentials.cc
index dc62f1b21392b05012a6dda3a24b50be97bacf91..014ae134404326324ca047468535c86ab11e784f 100644
--- a/sandbox/linux/services/credentials.cc
+++ b/sandbox/linux/services/credentials.cc
@@ -54,6 +54,9 @@ bool GetRESIds(uid_t* resuid, gid_t* resgid) {
const int kExitSuccess = 0;
int ChrootToSelfFdinfo(void*) {
+ // This function can be run from a vforked child, so it should not write to
+ // any memory other than the stack or errno. Reads from TLS may be different
+ // from in the parent process.
RAW_CHECK(sys_chroot("/proc/self/fdinfo/") == 0);
// CWD is essentially an implicit file descriptor, so be careful to not
@@ -91,9 +94,22 @@ bool ChrootToSafeEmptyDir() {
#error "Unsupported architecture"
#endif
- pid = clone(ChrootToSelfFdinfo, stack,
- CLONE_VM | CLONE_VFORK | CLONE_FS | LINUX_SIGCHLD, nullptr,
- nullptr, nullptr, nullptr);
+ int clone_flags = CLONE_FS | LINUX_SIGCHLD;
+ void* tls = nullptr;
+#if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM_FAMILY)
+ // Use CLONE_VM | CLONE_VFORK as an optimization to avoid copying page tables.
+ // Since clone writes to the new child's TLS before returning, we must set a
+ // new TLS to avoid corrupting the current process's TLS. On ARCH_CPU_X86,
+ // glibc performs syscalls by calling a function pointer in TLS, so we do not
+ // attempt this optimization.
+ clone_flags |= CLONE_VM | CLONE_VFORK | CLONE_SETTLS;
+
+ char tls_buf[PTHREAD_STACK_MIN] = {0};
+ tls = tls_buf;
+#endif
+
+ pid = clone(ChrootToSelfFdinfo, stack, clone_flags, nullptr, nullptr, tls,
+ nullptr);
PCHECK(pid != -1);
int status = -1;
« no previous file with comments | « no previous file | sandbox/linux/services/credentials_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698