i386, x86_64, x32, and powerpc all use TLS for stack protector canary
values in the default stack protector ABI, but the location only
matched the ABI on i386 and x86_64. on x32, the expected location for
the canary contained the tid, thus producing spurious mismatches
(resulting in process termination) upon fork. on powerpc, the expected
location contained the stdio_locks list head, so returning from a
function after calling flockfile produced spurious mismatches. in both
cases, the random canary was not present, and a predictable value was
used instead, making the stack protector hardening much less effective
than it should be.
in the current fix, the thread structure has been expanded to have
canary fields at all three possible locations, and archs that use a
non-default location must define a macro in pthread_arch.h to choose
which location is used. for most archs (which lack TLS canary ABI) the
choice does not matter.
// GPRs.
#define CANCEL_REG_IP 32
+#define CANARY canary_at_end
#define TP_ADJ(p) (p)
#define CANCEL_REG_IP 32
+
+#define CANARY canary2
if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
- __pthread_self()->canary = __stack_chk_guard;
+ __pthread_self()->CANARY = __stack_chk_guard;
}
void __stack_chk_fail(void)
struct pthread *self;
void **dtv, *unused1, *unused2;
uintptr_t sysinfo;
- uintptr_t canary;
+ uintptr_t canary, canary2;
pid_t tid, pid;
int tsd_used, errno_val;
volatile int cancel, canceldisable, cancelasync;
char *dlerror_buf;
int dlerror_flag;
void *stdio_locks;
+ uintptr_t canary_at_end;
void **dtv_copy;
};
#include "pthread_arch.h"
+#ifndef CANARY
+#define CANARY canary
+#endif
+
#define SIGTIMER 32
#define SIGCANCEL 33
#define SIGSYNCCALL 34
}
new->robust_list.head = &new->robust_list.head;
new->unblock_cancel = self->cancel;
- new->canary = self->canary;
+ new->CANARY = self->CANARY;
a_inc(&libc.threads_minus_1);
ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->tid);