401e1c
From 80d90c5c59e9477d8a0c9eb727a0fc1bec2b01ea Mon Sep 17 00:00:00 2001
401e1c
From: Andrei Vagin <avagin@gmail.com>
401e1c
Date: Sat, 4 May 2019 20:01:52 -0700
401e1c
Subject: [PATCH] lsm: don't reset socket contex if SELinux is disabled
401e1c
401e1c
Fixes #693
401e1c
---
401e1c
 criu/lsm.c | 16 ++++++++++++++--
401e1c
 1 file changed, 14 insertions(+), 2 deletions(-)
401e1c
401e1c
diff --git a/criu/lsm.c b/criu/lsm.c
401e1c
index 9c9ac7f80e..5921138392 100644
401e1c
--- a/criu/lsm.c
401e1c
+++ b/criu/lsm.c
401e1c
@@ -134,7 +134,15 @@ static int selinux_get_sockcreate_label(pid_t pid, char **output)
401e1c
 
401e1c
 int reset_setsockcreatecon()
401e1c
 {
401e1c
-	return setsockcreatecon_raw(NULL);
401e1c
+	/* Currently this only works for SELinux. */
401e1c
+	if (kdat.lsm != LSMTYPE__SELINUX)
401e1c
+		return 0;
401e1c
+
401e1c
+	if (setsockcreatecon_raw(NULL)) {
401e1c
+		pr_perror("Unable to reset socket SELinux context");
401e1c
+		return -1;
401e1c
+	}
401e1c
+	return 0;
401e1c
 }
401e1c
 
401e1c
 int run_setsockcreatecon(FdinfoEntry *e)
401e1c
@@ -147,7 +155,11 @@ int run_setsockcreatecon(FdinfoEntry *e)
401e1c
 
401e1c
 	ctx = e->xattr_security_selinux;
401e1c
 	/* Writing to the FD using fsetxattr() did not work for some reason. */
401e1c
-	return setsockcreatecon_raw(ctx);
401e1c
+	if (setsockcreatecon_raw(ctx)) {
401e1c
+		pr_perror("Unable to set the %s socket SELinux context", ctx);
401e1c
+		return -1;
401e1c
+	}
401e1c
+	return 0;
401e1c
 }
401e1c
 
401e1c
 int dump_xattr_security_selinux(int fd, FdinfoEntry *e)