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