]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't call mount.<type> helper with usernames
authorKarel Zak <kzak@redhat.com>
Mon, 22 May 2023 15:26:55 +0000 (17:26 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 5 Jun 2023 09:58:46 +0000 (11:58 +0200)
This is v2.39 regression. The "user" mount option is internally
converted to "user=<name>", but this should not be exported to
the mount helpers.

The mount helper accepts the <name> only if specified in mount options
(cifs uses user=). The real username as generated by libmount is not
relevant in this case.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c

index 5aae4bea0f344d3bfdc61d00509d68bf7166820f..3d8446002a951882760986406a95ca300d3e35ca 100644 (file)
@@ -377,9 +377,7 @@ int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg)
 
 static int exec_helper(struct libmnt_context *cxt)
 {
-       struct libmnt_optlist *ol;
        struct libmnt_ns *ns_tgt = mnt_context_get_target_ns(cxt);
-       const char *o = NULL;
        char *namespace = NULL;
        int rc;
        pid_t pid;
@@ -391,14 +389,6 @@ static int exec_helper(struct libmnt_context *cxt)
 
        DBG(CXT, ul_debugobj(cxt, "mount: executing helper %s", cxt->helper));
 
-       ol = mnt_context_get_optlist(cxt);
-       if (!ol)
-               return -ENOMEM;
-
-       rc = mnt_optlist_get_optstr(ol, &o, NULL, MNT_OL_FLTR_HELPERS);
-       if (rc)
-               return rc;
-
        if (ns_tgt->fd != -1
            && asprintf(&namespace, "/proc/%i/fd/%i",
                        getpid(), ns_tgt->fd) == -1) {
@@ -412,8 +402,24 @@ static int exec_helper(struct libmnt_context *cxt)
        case 0:
        {
                const char *args[14], *type;
+               struct libmnt_optlist *ol = mnt_context_get_optlist(cxt);
+               struct libmnt_opt *opt;
+               const char *o = NULL;
                int i = 0;
 
+               if (!ol)
+                       _exit(EXIT_FAILURE);
+
+               /* Call helper with original user=<name> (aka "saved user")
+                * or remove the username at all.
+                */
+               opt = mnt_optlist_get_opt(ol, MNT_MS_USER, cxt->map_userspace);
+               if (opt && !(cxt->flags & MNT_FL_SAVED_USER))
+                       mnt_opt_set_value(opt, NULL);
+
+               if (mnt_optlist_get_optstr(ol, &o, NULL, MNT_OL_FLTR_HELPERS))
+                       _exit(EXIT_FAILURE);
+
                if (drop_permissions() != 0)
                        _exit(EXIT_FAILURE);