[CRIU] [PATCH] Guard against empty file lock status

Nicolas Viennot Nicolas.Viennot at twosigma.com
Tue Oct 1 23:56:26 MSK 2019


The lock status string may be empty. This can happen when the owner of
the lock is invisible from our PID namespace. This unfortunate behavior
is fixed in kernels v4.19 and up (see commit 1cf8e5de40)

Signed-off-by: Nicolas Viennot <Nicolas.Viennot at twosigma.com>
---
 criu/proc_parse.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 97f82ee0..d67392a1 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1669,17 +1669,27 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg)
 		if (fdinfo_field(str, "lock")) {
 			struct file_lock *fl;
 			struct fdinfo_common *fdinfo = arg;
+			char *flock_status = str+sizeof("lock:\t")-1;
 
 			if (type != FD_TYPES__UND)
 				continue;
 
+			/*
+			 * The lock status can be empty when the owner of the
+			 * lock is invisible from our PID namespace.
+			 * This unfortunate behavior is fixed in kernels v4.19
+			 * and up (see commit 1cf8e5de40).
+			 */
+			if (flock_status[0] == '\0')
+				continue;
+
 			fl = alloc_file_lock();
 			if (!fl) {
 				pr_perror("Alloc file lock failed!");
 				goto out;
 			}
 
-			if (parse_file_lock_buf(str + 6, fl, 0)) {
+			if (parse_file_lock_buf(flock_status, fl, 0)) {
 				xfree(fl);
 				goto parse_err;
 			}
-- 
2.19.1




More information about the CRIU mailing list