!104 fix log_keep_err signal deadlock

From: @maskinghk 
Reviewed-by: @chenwei_kernel 
Signed-off-by: @chenwei_kernel
This commit is contained in:
openeuler-ci-bot 2025-04-21 01:39:52 +00:00 committed by Gitee
commit 0d6b730395
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,66 @@
From bc1415317379c45b08ac6f8eb98698ca2df9b78c Mon Sep 17 00:00:00 2001
From: Ivan Pravdin <ipravdin.official@gmail.com>
Date: Sat, 22 Mar 2025 19:31:02 -0400
Subject: [PATCH] criu: fix log_keep_err signal deadlock
When using pr_err in signal handler, locking is used
in an unsafe manner. If another signal happens while holding the
lock, deadlock can happen.
To fix this, we can introduce mutex_trylock similar to
pthread_mutex_trylock that returns immediately. Due to the fact
that lock is used only for writing first_err, this change garantees
that deadlock cannot happen.
Fixes: #358
Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
---
criu/log.c | 9 +++++----
include/common/lock.h | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/criu/log.c b/criu/log.c
index 89ae8f8205..70e267fd65 100644
--- a/criu/log.c
+++ b/criu/log.c
@@ -132,10 +132,11 @@ static void log_note_err(char *msg)
* anyway, so it doesn't make much sense to try hard
* and optimize this out.
*/
- mutex_lock(&first_err->l);
- if (first_err->s[0] == '\0')
- __strlcpy(first_err->s, msg, sizeof(first_err->s));
- mutex_unlock(&first_err->l);
+ if (mutex_trylock(&first_err->l)) {
+ if (first_err->s[0] == '\0')
+ __strlcpy(first_err->s, msg, sizeof(first_err->s));
+ mutex_unlock(&first_err->l);
+ }
}
}
diff --git a/include/common/lock.h b/include/common/lock.h
index ccfa468b83..4733d72870 100644
--- a/include/common/lock.h
+++ b/include/common/lock.h
@@ -2,6 +2,7 @@
#define __CR_COMMON_LOCK_H__
#include <stdint.h>
+#include <stdbool.h>
#include <linux/futex.h>
#include <sys/time.h>
#include <limits.h>
@@ -162,6 +163,11 @@ static inline void mutex_lock(mutex_t *m)
}
}
+static inline bool mutex_trylock(mutex_t *m)
+{
+ return atomic_inc_return(&m->raw) == 1;
+}
+
static inline void mutex_unlock(mutex_t *m)
{
uint32_t c = 0;

View File

@ -1,6 +1,6 @@
Name: criu
Version: 3.19
Release: 4
Release: 5
Provides: crtools = %{version}-%{release}
Obsoletes: crtools <= 1.0-2
Summary: A tool of Checkpoint/Restore in User-space
@ -19,6 +19,7 @@ Obsoletes: %{name}-libs < %{version}-%{release}
Patch1: 0001-criu-dump-and-restore-cpu-affinity-of-each-thread.patch
Patch2: 0002-Add-sys_sched_setaffinity-define-for-loongarch64.patch
Patch3: 0003-chore-support-building-without-network.patch
Patch4: 0004-criu-fix-log_keep_err-signal-deadlock.patch
%description
Checkpoint/Restore in Userspace(CRIU),is a software tool for the linux operating system.
@ -104,6 +105,9 @@ chmod 0755 %{buildroot}/run/%{name}/
%doc %{_mandir}/man1/{compel.1*,crit.1*,criu-ns.1*,criu-amdgpu-plugin.1*}
%changelog
* Fri Apr 18 2025 maxin <maxin@xfusion.com> - 3.19-5
- fix log_keep_err signal deadlock
* Thu Dec 12 2024 Wenlong Zhang <zhangwenlong@loongson.cn> - 3.19-4
- add sys_sched_setaffinity for loongarch64
- delete 0002-mm-add-pin-memory-method-for-criu.patch