Skip to contentSkip to conversation

sandbox/seunshare: prevent path traversal via -W/-P

PATCH In review Stephen Smalley 1 participant 2 messages May 13 – May 18 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 sandbox/seunshare: prevent path traversal via -W/-P

The -W/-P options specify the wayland or pipewire socket name respectively. The option argument is then concatenated with the runuserdir to create a pathname. We don't want to allow it to be used to construct arbitrary paths outside of the runuserdir. Also, check and handle
errors when bind mounting the pipewire socket file.

---
 sandbox/seunshare.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
sandbox/seunshare.c +8 -1
index 0dfc5cb2..945a3b21 100644
@@ -849,6 +849,12 @@ int main(int argc, char **argv) {
 		}
 	}
 
+	if ((wayland_display && (strchr(wayland_display, '/') || strstr(wayland_display, ".."))) ||
+		(pipewire_socket && (strchr(pipewire_socket, '/') || strstr(pipewire_socket, "..")))) {
+		fprintf(stderr, _("Error: -W/-P must be a socket name, not a path\n"));
+		return -1;
+	}
+
 	if (! homedir_s && ! tmpdir_s) {
 		fprintf(stderr, _("Error: tmpdir and/or homedir required\n %s\n"), USAGE_STRING);
 		return -1;
@@ -990,7 +996,8 @@ int main(int argc, char **argv) {
 					perror(_("Out of memory"));
 					goto childerr;
 				}
-				seunshare_mount_file(pipewire_path, pipewire_path_s);
+				if (seunshare_mount_file(pipewire_path, pipewire_path_s) == -1)
+					goto childerr;
 			}
 		}
 
Signature · 1 line
2.53.0
author maintainer
#1 lore raw
Quoted 11 lines · Stephen Smalley

The -W/-P options specify the wayland or pipewire socket name respectively. The option argument is then concatenated with the runuserdir to create a pathname. We don't want to allow it to be used to construct arbitrary paths outside of the runuserdir. Also, check and handle
errors when bind mounting the pipewire socket file.

---
 sandbox/seunshare.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Merged.