summaryrefslogtreecommitdiff
path: root/nptl/allocatestack.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2014-07-10 17:34:46 +0200
committerFlorian Weimer <fweimer@redhat.com>2014-07-11 12:30:53 +0200
commit771eb1415fde935e377111f69364a5d92a29e67d (patch)
tree1e9dd40b64e87fe715c4bc7ccee7487c6e500a8a /nptl/allocatestack.c
parentbc1da1765e901a9a9f532f91d09f5237655e01fd (diff)
nptl: Fix abort in case of set*id failure [BZ #17135]
If a call to the set*id functions fails in a multi-threaded program, the abort introduced in commit 13f7fe35ae2b0ea55dc4b9628763aafdc8bdc30c was triggered. We address by checking that all calls to set*id on all threads give the same result, and only abort if we see success followed by failure (or vice versa).
Diffstat (limited to 'nptl/allocatestack.c')
-rw-r--r--nptl/allocatestack.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 9095ef430d..d95ffe9d36 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -1059,6 +1059,25 @@ setxid_signal_thread (struct xid_command *cmdp, struct pthread *t)
return 0;
}
+/* Check for consistency across set*id system call results. The abort
+ should not happen as long as all privileges changes happen through
+ the glibc wrappers. ERROR must be 0 (no error) or an errno
+ code. */
+void
+attribute_hidden
+__nptl_setxid_error (struct xid_command *cmdp, int error)
+{
+ do
+ {
+ int olderror = cmdp->error;
+ if (olderror == error)
+ break;
+ if (olderror != -1)
+ /* Mismatch between current and previous results. */
+ abort ();
+ }
+ while (atomic_compare_and_exchange_bool_acq (&cmdp->error, error, -1));
+}
int
attribute_hidden
@@ -1070,6 +1089,7 @@ __nptl_setxid (struct xid_command *cmdp)
__xidcmd = cmdp;
cmdp->cntr = 0;
+ cmdp->error = -1;
struct pthread *self = THREAD_SELF;
@@ -1153,11 +1173,14 @@ __nptl_setxid (struct xid_command *cmdp)
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, err, 3,
cmdp->id[0], cmdp->id[1], cmdp->id[2]);
- if (INTERNAL_SYSCALL_ERROR_P (result, err))
+ int error = 0;
+ if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
{
- __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
+ error = INTERNAL_SYSCALL_ERRNO (result, err);
+ __set_errno (error);
result = -1;
}
+ __nptl_setxid_error (cmdp, error);
lll_unlock (stack_cache_lock, LLL_PRIVATE);
return result;