]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip vrf: make ipvrf_exec SELinux-aware
authorAndrea Claudi <aclaudi@redhat.com>
Wed, 23 Aug 2023 17:30:02 +0000 (19:30 +0200)
committerDavid Ahern <dsahern@kernel.org>
Fri, 25 Aug 2023 00:34:40 +0000 (17:34 -0700)
When using ip vrf and SELinux is enabled, make sure to set the exec file
context before calling cmd_exec.

This ensures that the command is executed with the right context,
falling back to the ifconfig_t context when needed.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/selinux.h
ip/ipvrf.c
lib/selinux.c

index 499aa966a7fb76bd7a1a6d6662ac0f69511b6a76..592c76808a466050be28299bd0232aeeca4c8abf 100644 (file)
@@ -6,4 +6,5 @@ void freecon(char *context);
 int getpidcon(pid_t pid, char **context);
 int getfilecon(const char *path, char **context);
 int security_get_initial_context(const char *name,  char **context);
+int setexecfilecon(const char *filename, const char *fallback_type);
 #endif
index d6b59adbb21640be800f6795bf0b19df85f6dae8..12beaec34d409f83e7e66ea25f8d0d8c792e19f3 100644 (file)
@@ -24,6 +24,7 @@
 #include "utils.h"
 #include "ip_common.h"
 #include "bpf_util.h"
+#include "selinux.h"
 
 #define CGRP_PROC_FILE  "/cgroup.procs"
 
@@ -455,6 +456,11 @@ static int ipvrf_exec(int argc, char **argv)
                return -1;
        }
 
+       if (is_selinux_enabled() && setexecfilecon(argv[1], "ifconfig_t")) {
+               fprintf(stderr, "setexecfilecon for \"%s\" failed\n", argv[1]);
+               return -1;
+       }
+
        return -cmd_exec(argv[1], argv + 1, !!batch_mode, do_switch, argv[0]);
 }
 
index 4e6805fcb4bac9e350f4ffeb2450689513b085f7..7e5dd16d04709173a0e3210066fdd0730c1ec95a 100644 (file)
@@ -30,3 +30,8 @@ int security_get_initial_context(const char *name,  char **context)
        *context = NULL;
        return -1;
 }
+
+int setexecfilecon(const char *filename, const char *fallback_type)
+{
+       return -1;
+}