multipath-tools: coverity defect fixes
cover multipath-tools: coverity defect fixes
From: Martin Wilck <[email protected]>
Fixes for defects reported by coverity (new defects in old code). So far I haven't had time to test them thoroughly.
Martin Wilck (3):
multipathd: init_unwinder: protect pthread_cond_wait() call with a
loop
libmultipath: is_uevent_busy(): check servicing_uev under lock
libmultipath: tur: protect pthread_cond_timedwait with a loop
libmultipath/checkers/tur.c | 9 ++++++--- libmultipath/uevent.c | 5 +++-- multipathd/init_unwinder.c | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 multipathd: init_unwinder: protect pthread_cond_wait() call with a loop
From: Martin Wilck <[email protected]>
This fixes a coverity-reported defect (413387 Indefinite wait).
--- multipathd/init_unwinder.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
multipathd/init_unwinder.c +5 -1
@@ -4,10 +4,12 @@static pthread_mutex_t dummy_mtx =PTHREAD_MUTEX_INITIALIZER ;static pthread_cond_t dummy_cond =PTHREAD_COND_INITIALIZER ; +static int dummy_started;static void *dummy_thread (void *arg __attribute__((unused))) {pthread_mutex_lock (&dummy_mtx); + dummy_started =1 ;pthread_cond_broadcast (&dummy_cond);pthread_mutex_unlock (&dummy_mtx);pause ();
@@ -27,7 +29,9 @@ int init_unwinder(void)return rc; } -pthread_cond_wait (&dummy_cond, &dummy_mtx); +while (!dummy_started) +pthread_cond_wait (&dummy_cond, &dummy_mtx); +pthread_mutex_unlock (&dummy_mtx);return pthread_cancel (dummy);
Signature · 1 line
2.43.0
PATCH 2/3 libmultipath: is_uevent_busy(): check servicing_uev under lock
In reply to [email protected]From: Martin Wilck <[email protected]>
This fixes a coverity-reported defect (413384 Data race condition). Indeed, we always set servicing_uev with the lock held, so it makes sense to read it with the lock held, too.
--- libmultipath/uevent.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/uevent.c +3 -2
@@ -82,12 +82,13 @@ static void reset_filter_state(struct uevent_filter_state *st)int is_uevent_busy (void ) { -int empty; +int empty, servicing;pthread_mutex_lock (uevq_lockp); empty =list_empty (&uevq); + servicing = servicing_uev;pthread_mutex_unlock (uevq_lockp); -return (!empty || servicing_uev); +return (!empty || servicing); }struct uevent *alloc_uevent (void )
Signature · 1 line
2.43.0
PATCH 3/3 libmultipath: tur: protect pthread_cond_timedwait with a loop
In reply to [email protected]From: Martin Wilck <[email protected]>
Defect reported by coverity (413383 Data race condition)
--- libmultipath/checkers/tur.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
libmultipath/checkers/tur.c +6 -3
@@ -438,9 +438,12 @@ int libcheck_check(struct checker * c) }tur_timeout (&tsp);pthread_mutex_lock (&ct->lock); -if (ct->state ==PATH_PENDING && ct->msgid ==MSG_TUR_RUNNING ) - r =pthread_cond_timedwait (&ct->active, &ct->lock, - &tsp); + +for (r =0 ; + r ==0 && ct->state ==PATH_PENDING && + ct->msgid ==MSG_TUR_RUNNING ; + r =pthread_cond_timedwait (&ct->active, &ct->lock, &tsp)); +if (!r) { tur_status = ct->state; c->msgid = ct->msgid;
Signature · 1 line
2.43.0
Quoted 4 lines · On Fri, Jan 05, 2024 at 07:40:33PM +0100, [email protected] wrote:
From: Martin Wilck <[email protected]>
Fixes for defects reported by coverity (new defects in old code). So far I haven't had time to test them thoroughly.
For the set:
Quoted 14 lines
Martin Wilck (3):
multipathd:init_unwinder: protectpthread_cond_wait()call with a
loop
libmultipath:is_uevent_busy(): checkservicing_uevunder lock
libmultipath: tur: protectpthread_cond_timedwaitwith a looplibmultipath/checkers/tur.c | 9 ++++++--- libmultipath/uevent.c | 5 +++-- multipathd/init_unwinder.c | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-)Signature · 1 line
2.43.0