diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2017-07-29 08:36:24 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2017-07-29 08:36:24 +0000 |
commit | 9f99f32a08a1ad4aed76c2c8c18102e235aa681e (patch) | |
tree | 7a63512df1b9bc4dbc85ddd3b583c16f13954881 /lib/librthread | |
parent | fa5adad6e0ca0c2ffcd4bfcd28753788049b59b0 (diff) |
Use memory barriers to prevent pointer use before initialization.
This work was sparked by the topic posted on hn by wuch. I am still not
sure that this fixes the defect he claims to have observed because I was
not able to create a proper regress test for it to manifest.
To that end, a proof of concept is more than welcomed!
Thank you for the report!
Discussed with and OK kettenis@, tedu@.
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread_cond.c | 4 | ||||
-rw-r--r-- | lib/librthread/rthread_mutex.c | 4 | ||||
-rw-r--r-- | lib/librthread/rthread_rwlock.c | 5 | ||||
-rw-r--r-- | lib/librthread/rthread_sync.c | 4 |
4 files changed, 13 insertions, 4 deletions
diff --git a/lib/librthread/rthread_cond.c b/lib/librthread/rthread_cond.c index 3a484b04d06..184d533235f 100644 --- a/lib/librthread/rthread_cond.c +++ b/lib/librthread/rthread_cond.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_cond.c,v 1.1 2017/05/27 14:20:39 mpi Exp $ */ +/* $OpenBSD: rthread_cond.c,v 1.2 2017/07/29 08:36:23 pirofti Exp $ */ /* * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -42,6 +42,8 @@ pthread_cond_init(pthread_cond_t *condp, const pthread_condattr_t *attr) cond->clock = CLOCK_REALTIME; else cond->clock = (*attr)->ca_clock; + + membar_producer(); *condp = cond; return (0); diff --git a/lib/librthread/rthread_mutex.c b/lib/librthread/rthread_mutex.c index ea2db8131b3..cb4b2f0a0b0 100644 --- a/lib/librthread/rthread_mutex.c +++ b/lib/librthread/rthread_mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_mutex.c,v 1.3 2017/05/29 14:47:54 mpi Exp $ */ +/* $OpenBSD: rthread_mutex.c,v 1.4 2017/07/29 08:36:23 pirofti Exp $ */ /* * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -64,6 +64,8 @@ pthread_mutex_init(pthread_mutex_t *mutexp, const pthread_mutexattr_t *attr) mutex->prioceiling = (*attr)->ma_protocol == PTHREAD_PRIO_PROTECT ? (*attr)->ma_prioceiling : -1; } + + membar_producer(); *mutexp = mutex; return (0); diff --git a/lib/librthread/rthread_rwlock.c b/lib/librthread/rthread_rwlock.c index 4faeb92372a..8bceba3b6a2 100644 --- a/lib/librthread/rthread_rwlock.c +++ b/lib/librthread/rthread_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_rwlock.c,v 1.8 2016/09/04 10:13:35 akfaew Exp $ */ +/* $OpenBSD: rthread_rwlock.c,v 1.9 2017/07/29 08:36:23 pirofti Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -27,6 +27,8 @@ #include <pthread.h> +#include <sys/atomic.h> + #include "rthread.h" static _atomic_lock_t rwlock_init_lock = _SPINLOCK_UNLOCKED; @@ -43,6 +45,7 @@ pthread_rwlock_init(pthread_rwlock_t *lockp, lock->lock = _SPINLOCK_UNLOCKED; TAILQ_INIT(&lock->writers); + membar_producer(); *lockp = lock; return (0); diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index a9b490d5410..432469fa522 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.44 2016/09/04 10:13:35 akfaew Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.45 2017/07/29 08:36:23 pirofti Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -54,6 +54,8 @@ pthread_mutex_init(pthread_mutex_t *mutexp, const pthread_mutexattr_t *attr) mutex->prioceiling = (*attr)->ma_protocol == PTHREAD_PRIO_PROTECT ? (*attr)->ma_prioceiling : -1; } + + membar_producer(); *mutexp = mutex; return (0); |