chiark / gitweb /
nspawn: newer kernels (>= 3.14) allow resetting the audit loginuid, make use of this
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Feb 2014 01:52:39 +0000 (02:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Feb 2014 02:02:09 +0000 (03:02 +0100)
man/systemd-nspawn.xml
src/nspawn/nspawn.c
src/shared/audit.c

index 9d8db83e81ba9e845c0fe41f919e58c869b365de..8f92b8430461ce2efd6216df824255a048cd9956 100644 (file)
                 contain this file out-of-the-box.</para>
         </refsect1>
 
-        <refsect1>
-                <title>Incompatibility with Auditing</title>
-
-                <para>Note that the kernel auditing subsystem is
-                currently broken when used together with
-                containers. We hence recommend turning it off entirely
-                by booting with <literal>audit=0</literal> on the
-                kernel command line, or by turning it off at kernel
-                build time. If auditing is enabled in the kernel,
-                operating systems booted in an nspawn container might
-                refuse log-in attempts.</para>
-        </refsect1>
-
         <refsect1>
                 <title>Options</title>
 
index 97ef6c799d4281705e97e4533c6f60feb7bda604..d5add4a45ea44fa20a568005a3cbafa19e89ab4b 100644 (file)
@@ -1198,15 +1198,37 @@ static int terminate_machine(pid_t pid) {
         return 0;
 }
 
-static bool audit_enabled(void) {
-        int fd;
+static int reset_audit_loginuid(void) {
+        _cleanup_free_ char *p = NULL;
+        int r;
+
+        if (arg_share_system)
+                return 0;
+
+        r = read_one_line_file("/proc/self/loginuid", &p);
+        if (r == -EEXIST)
+                return 0;
+        if (r < 0) {
+                log_error("Failed to read /proc/self/loginuid: %s", strerror(-r));
+                return r;
+        }
+
+        /* Already reset? */
+        if (streq(p, "4294967295"))
+                return 0;
+
+        r = write_string_file("/proc/self/loginuid", "4294967295");
+        if (r < 0) {
+                log_error("Failed to reset audit login UID. This probably means that your kernel is too\n"
+                          "old and you have audit enabled. Note that the auditing subsystem is known to\n"
+                          "be incompatible with containers on old kernels. Please make sure to upgrade\n"
+                          "your kernel or to off auditing with 'audit=0' on the kernel command line before\n"
+                          "using systemd-nspawn. Sleeping for 5s... (%s)\n", strerror(-r));
 
-        fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
-        if (fd >= 0) {
-                close_nointr_nofail(fd);
-                return true;
+                sleep(5);
         }
-        return false;
+
+        return 0;
 }
 
 int main(int argc, char *argv[]) {
@@ -1271,13 +1293,6 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (arg_boot && audit_enabled()) {
-                log_warning("The kernel auditing subsystem is known to be incompatible with containers.\n"
-                            "Please make sure to turn off auditing with 'audit=0' on the kernel command\n"
-                            "line before using systemd-nspawn. Sleeping for 5s...\n");
-                sleep(5);
-        }
-
         if (path_equal(arg_directory, "/")) {
                 log_error("Spawning container on root directory not supported.");
                 goto finish;
@@ -1436,6 +1451,9 @@ int main(int argc, char *argv[]) {
                                 goto child_fail;
                         }
 
+                        if (reset_audit_loginuid() < 0)
+                                goto child_fail;
+
                         if (prctl(PR_SET_PDEATHSIG, SIGKILL) < 0) {
                                 log_error("PR_SET_PDEATHSIG failed: %m");
                                 goto child_fail;
index 8038ac3c12f4affb90ee4997004738139c22e5b6..546644773720934a18412394fb7d3687567eed3e 100644 (file)
@@ -42,10 +42,6 @@ int audit_session_from_pid(pid_t pid, uint32_t *id) {
 
         assert(id);
 
-        /* Audit doesn't support containers right now */
-        if (detect_container(NULL) > 0)
-                return -ENOTSUP;
-
         p = procfs_file_alloca(pid, "sessionid");
 
         r = read_one_line_file(p, &s);
@@ -71,10 +67,6 @@ int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
 
         assert(uid);
 
-        /* Audit doesn't support containers right now */
-        if (detect_container(NULL) > 0)
-                return -ENOTSUP;
-
         p = procfs_file_alloca(pid, "loginuid");
 
         r = read_one_line_file(p, &s);