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