summaryrefslogtreecommitdiff
path: root/src/internal/libc.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-07-29 22:59:44 -0400
committerRich Felker <dalias@aerifal.cx>2011-07-29 22:59:44 -0400
commitacb04806628990ad2430e04261dd20f23babde5e (patch)
tree90e734333eee81878a920bfd32277bc96aa46402 /src/internal/libc.h
parentaed707f679cce80afd929f0efaf080f1e8481330 (diff)
downloadmusl-acb04806628990ad2430e04261dd20f23babde5e.tar.gz
new attempt at making set*id() safe and robust
changing credentials in a multi-threaded program is extremely difficult on linux because it requires synchronizing the change between all threads, which have their own thread-local credentials on the kernel side. this is further complicated by the fact that changing the real uid can fail due to exceeding RLIMIT_NPROC, making it possible that the syscall will succeed in some threads but fail in others. the old __rsyscall approach being replaced was robust in that it would report failure if any one thread failed, but in this case, the program would be left in an inconsistent state where individual threads might have different uid. (this was not as bad as glibc, which would sometimes even fail to report the failure entirely!) the new approach being committed refuses to change real user id when it cannot temporarily set the rlimit to infinity. this is completely POSIX conformant since POSIX does not require an implementation to allow real-user-id changes for non-privileged processes whatsoever. still, setting the real uid can fail due to memory allocation in the kernel, but this can only happen if there is not already a cached object for the target user. thus, we forcibly serialize the syscalls attempts, and fail the entire operation on the first failure. this *should* lead to an all-or-nothing success/failure result, but it's still fragile and highly dependent on kernel developers not breaking things worse than they're already broken. ideally linux will eventually add a CLONE_USERCRED flag that would give POSIX conformant credential changes without any hacks from userspace, and all of this code would become redundant and could be removed ~10 years down the line when everyone has abandoned the old broken kernels. i'm not holding my breath...
Diffstat (limited to 'src/internal/libc.h')
-rw-r--r--src/internal/libc.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/internal/libc.h b/src/internal/libc.h
index 638ea527..906de2ca 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -42,7 +42,8 @@ void __lockfile(FILE *);
#define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
#define UNLOCK(x) (*(volatile int *)(x)=0)
-int __rsyscall(int, long, long, long, long, long, long);
+void __synccall(void (*)(void *), void *);
+int __setxid(int, int, int, int);
extern char **__environ;
#define environ __environ