File 0051-libcharon-fixed-strongswan-crash-in-packet-sender.patch of Package strongswan.28851

From 4739bb36513f8f44df6e2a04834236948475652f Mon Sep 17 00:00:00 2001
From: Bhushan Narkhede <bnarkhede@marvell.com>
Date: Tue, 2 Aug 2022 01:12:40 -0700
References: bsc#1199205
Upstream: no
Subject: [PATCH] libcharon: fixed strongswan crash in packet sender

Mutex of sender wakeup thread is unlocked without
locking it before in libcharon.
This cause strongswan crash when strongswan is idle
and no packets are available to send across.

Fixed crash by ensuring mutex is locked before releasing
it in sender thread. Also prevent multiple unlock of mutex.

Signed-off-by: Bhushan Narkhede <bnarkhede@marvell.com>
---
 src/libcharon/network/sender.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/libcharon/network/sender.c b/src/libcharon/network/sender.c
index 89c99dda6..1bb323639 100644
--- a/src/libcharon/network/sender.c
+++ b/src/libcharon/network/sender.c
@@ -145,6 +145,7 @@ static job_requeue_t send_packets(private_sender_t *this)
 {
 	packet_t *packet;
 	bool oldstate;
+	bool got_wakeup_mutex = false;
 
 	this->mutex->lock(this->mutex);
 	while (this->list->get_count(this->list) == 0)
@@ -155,6 +156,7 @@ static job_requeue_t send_packets(private_sender_t *this)
 
 		this->got->wait(this->got, this->mutex);
 		this->wakeup_mutex->lock (this->wakeup_mutex);
+		got_wakeup_mutex = true;
 
 		thread_cancelability(oldstate);
 		thread_cleanup_pop(FALSE);
@@ -165,13 +167,15 @@ static job_requeue_t send_packets(private_sender_t *this)
 		if (this->list->get_count(this->list) == 0)
 		{
 			this->wakeup_mutex->unlock (this->wakeup_mutex);
-			this->mutex->unlock(this->mutex);
-			continue;
+			got_wakeup_mutex = false;
 		}
 	}
 	this->list->remove_first(this->list, (void**)&packet);
 	this->sent->signal(this->sent);
-	this->wakeup_mutex->unlock (this->wakeup_mutex);
+	if (got_wakeup_mutex)
+	{
+	   this->wakeup_mutex->unlock (this->wakeup_mutex);
+	}
 	this->mutex->unlock(this->mutex);
 
 	charon->socket->send(charon->socket, packet);
-- 
2.31.1.windows.1

openSUSE Build Service is sponsored by