Skip to contentSkip to conversation

Currently we can end up with different permissions on the compiled file_context regex files than the original.

PATCH Daniel J Walsh 2 participants 3 messages Aug 20, 2014 – Aug 26, 2014 SELinux security module

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

From dc822395634647dfc25c611261fd74f30962e668 Mon Sep 17 00:00:00 2001

From: Dan Walsh <[email protected]>
Date: Sat, 16 Aug 2014 07:37:42 -0400
Subject: [PATCH] Compiled file context files and the original should have the
same permissions

Currently the compiled file context files can end up with different permissions then the original. This can lead to non priv users not being able to read the compiled versions.

---
 libselinux/utils/sefcontext_compile.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
libselinux/utils/sefcontext_compile.c +15 -0
index 0adc968..9618989 100644
@@ -4,6 +4,9 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include <linux/limits.h>
 
@@ -323,6 +326,7 @@ int main(int argc, char *argv[])
 	int rc;
 	char *tmp= NULL;
 	int fd;
+	struct stat buf;
 
 	if (argc != 2) {
 		fprintf(stderr, "usage: %s input_file\n", argv[0]);
@@ -333,6 +337,11 @@ int main(int argc, char *argv[])
 
 	path = argv[1];
 
+	if (stat(path, &buf) < 0) {
+		fprintf(stderr, "Can not stat: %s: %m\n", argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
 	rc = process_file(&data, path);
 	if (rc < 0)
 		return rc;
@@ -352,6 +361,12 @@ int main(int argc, char *argv[])
 	if (fd < 0)
 		goto err;
 
+	rc = fchmod(fd, buf.st_mode);
+	if (rc < 0) {
+		perror("fchmod failed to set permission on compiled regexs");
+		goto err;
+	}
+
 	rc = write_binary_file(&data, fd);
 
 	if (rc < 0)
Signature · 1 line
2.0.4
#1 lore raw

libselinux/utils/sefcontext_compile.c int main(int argc, char *argv[]) · line 341

Quoted 2 lines
libselinux/utils/sefcontext_compile.c +2 -0
+	if (stat(path, &buf) < 0) {
+		fprintf(stderr, "Can not stat: %s: %m\n", argv[0]);

Should the fprintf print path instead of argv[0]?

libselinux/utils/sefcontext_compile.c int main(int argc, char *argv[]) · line 344

Quoted 3 lines
libselinux/utils/sefcontext_compile.c +3 -0
+		exit(EXIT_FAILURE);
+	}
+

Looks good otherwise. I'll add to the repo with that change if that's okay.

- Steve

#2 lore raw
Quoted 3 lines · Steve Lawrence

libselinux/utils/sefcontext_compile.c int main(int argc, char *argv[]) · line 341

Quoted 2 lines
libselinux/utils/sefcontext_compile.c +2 -0
+	if (stat(path, &buf) < 0) {
+		fprintf(stderr, "Can not stat: %s: %m\n", argv[0]);

Should the fprintf print path instead of argv[0]?

Yes.

Quoted 5 lines

libselinux/utils/sefcontext_compile.c int main(int argc, char *argv[]) · line 344

Quoted 3 lines
libselinux/utils/sefcontext_compile.c +3 -0
+		exit(EXIT_FAILURE);
+	}
+

Looks good otherwise. I'll add to the repo with that change if that's okay.

Quoted 9 lines

- Steve

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

Sounds great.