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

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: Add test 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
Index: sandbox/linux/services/credentials.cc
diff --git a/sandbox/linux/services/credentials.cc b/sandbox/linux/services/credentials.cc
index dc62f1b21392b05012a6dda3a24b50be97bacf91..d5f10233bc9649e22d69d4418de95a8234d23315 100644
--- a/sandbox/linux/services/credentials.cc
+++ b/sandbox/linux/services/credentials.cc
@@ -91,9 +91,24 @@ 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_MIPS64_FAMILY) || \
+ defined(ARCH_CPU_MIPS_FAMILY)
jln (very slow on Chromium) 2015/07/22 00:04:20 Let's just exclude MIPS here. We've not tested the
rickyz (no longer on Chrome) 2015/07/22 04:00:32 Done - also noticed that I forgot to add ARM in th
+ // 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;
+
+ // The stack grows down on these architectures. Place the TLS at the bottom of
jln (very slow on Chromium) 2015/07/21 23:39:17 "bottom of the stack" is very confusing here. I wo
rickyz (no longer on Chrome) 2015/07/22 04:00:32 Yeah, I ended up switching this to a zero-initiali
+ // the stack.
+ tls = stack_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') | sandbox/linux/services/credentials_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698