[PATCH] core: fix possible race condition on downtime list lock, if

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[PATCH] core: fix possible race condition on downtime list lock, if

Post by Guest »

This is a multi-part message in MIME format.
--------------060206040808050503010208
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

recently in svn head, downtime lists got locked with a new mutex, but
the unlock on downtime delete could cause possible race conditions.
see the description on the git commit attached, applies against current
HEAD.
or fetch it from over here -
https://github.com/dnsmichi/nagios-fixe ... 2d87b5c8cc

kind regards,
michael

--
DI (FH) Michael Friedrich

Vienna University Computer Center
Universitaetsstrasse 7 A-1010 Vienna, Austria

email: [email protected]
phone: +43 1 4277 14359
mobile: +43 664 60277 14359
fax: +43 1 4277 14338
web: http://www.univie.ac.at/zid
http://www.aco.net

Icinga Core& IDOUtils Developer
http://www.icinga.org


--------------060206040808050503010208
Content-Type: text/x-diff;
name="0001-core-fix-possible-race-condition-on-downtime-list-lo.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0001-core-fix-possible-race-condition-on-downtime-list-lo.pa";
filename*1="tch"

From 8182d64cc2fffe4b87b0f894db49892d87b5c8cc Mon Sep 17 00:00:00 2001
From: Michael Friedrich
Date: Sat, 22 Oct 2011 15:38:21 +0200
Subject: [PATCH] core: fix possible race condition on downtime list lock, if
downtime already deleted

when deleting a downtime, the newly introduced
nagios_downtime_lock mutex gets locked to prevent
threads from fiddling in there.
after having fetched the downtime we want to delete
we try to delete only if !NULL and then releasing
the mutex.
if the possible case happens that an external module
already manipulated the list in memory and the downtime
was deleted before, the condition runs into the else-tree
returning an error. the mutex will be kept locked forever.

in order to fix that we move the unlocking outside the
if condition, let memory being free'd or result being an
error and then savely unlock the downtime list.

this will prevent us from running into a possible race
condition leaving the core idle wait for the mutex on
deleting a comment.
---
common/downtime.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/common/downtime.c b/common/downtime.c
index 6589bb2..48f58e9 100644
--- a/common/downtime.c
+++ b/common/downtime.c
@@ -796,9 +796,6 @@ int delete_downtime(int type, unsigned long downtime_id) {
else
last_downtime->next = next_downtime;

-#ifdef NSCORE
- pthread_mutex_unlock(&nagios_downtime_lock);
-#endif
/* free memory */
my_free(this_downtime->host_name);
my_free(this_downtime->service_description);
@@ -811,6 +808,10 @@ int delete_downtime(int type, unsigned long downtime_id) {
else
result = ERROR;

+#ifdef NSCORE
+ pthread_mutex_unlock(&nagios_downtime_lock);
+#endif
+
return result;
}

--
1.7.7


--------------060206040808050503010208--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked