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