Skip to content

Commit

Permalink
libmount: don't call hooks after mount.<type> helper
Browse files Browse the repository at this point in the history
In case more filesystems are specified (or when libmount follows
/{etc,proc}/filesystems) then the library may try to use and
initialize the new API because for some filesystems, we need
exec(/sbin/mount.<type>) and for another fsopen().

The hooks that use the API have to smart and detect that the mount
operation was done in external /sbin/mount.<type> helper. And in this
case, the new API file descriptors must be ignored.

The exception is propagation flags, mount(8) can set the flags after
exec(/sbin/mount.<type>), for example, "mount -t ntfs --make-private".

Fixes: #2267
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed May 25, 2023
1 parent 12c616b commit f94a776
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libmount/src/context_mount.c
Expand Up @@ -508,6 +508,8 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
assert(cxt->fs);
assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));

mnt_context_reset_status(cxt);

if (try_type) {
rc = mnt_context_prepare_helper(cxt, "mount", try_type);
if (rc)
Expand Down
13 changes: 13 additions & 0 deletions libmount/src/hook_mount.c
Expand Up @@ -239,6 +239,10 @@ static int hook_create_mount(struct libmnt_context *cxt,
int rc = 0;

assert(cxt);

if (mnt_context_helper_executed(cxt))
return 0;

assert(cxt->fs);

api = get_sysapi(cxt);
Expand Down Expand Up @@ -309,6 +313,9 @@ static int hook_reconfigure_mount(struct libmnt_context *cxt,

assert(cxt);

if (mnt_context_helper_executed(cxt))
return 0;

api = get_sysapi(cxt);
assert(api);
assert(api->fd_tree >= 0);
Expand Down Expand Up @@ -379,6 +386,9 @@ static int hook_set_vfsflags(struct libmnt_context *cxt,
uint64_t set = 0, clr = 0;
int rc = 0;

if (mnt_context_helper_executed(cxt))
return 0;

DBG(HOOK, ul_debugobj(hs, "setting VFS flags"));

ol = mnt_context_get_optlist(cxt);
Expand Down Expand Up @@ -471,6 +481,9 @@ static int hook_attach_target(struct libmnt_context *cxt,
const char *target;
int rc = 0;

if (mnt_context_helper_executed(cxt))
return 0;

target = mnt_fs_get_target(cxt->fs);
if (!target)
return -EINVAL;
Expand Down

0 comments on commit f94a776

Please sign in to comment.