diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 5aae4bea0..3d8446002 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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= (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);