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