aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2025-04-09 12:15:57 +0200
committerKarel Zak <kzak@redhat.com>2025-04-09 13:38:45 +0200
commit437a271f7108f689d350f1b3d837490d3d283c3c (patch)
treea7887c131defe9d3fd03e8092604149dbfe13c14 /libmount/src
parent5462fa3435544344727b8644205ae427dfd5fcba (diff)
downloadutil-linux-437a271f7108f689d350f1b3d837490d3d283c3c.tar.gz
libmount: (subdir) restrict for real mounts only
It's now possible to use, for example, for bind operations, but it does not make sense as you can specify the target with the subdirectory. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/hook_subdir.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/libmount/src/hook_subdir.c b/libmount/src/hook_subdir.c
index 1e5d79958a..7cbb2c88d4 100644
--- a/libmount/src/hook_subdir.c
+++ b/libmount/src/hook_subdir.c
@@ -313,6 +313,7 @@ static int is_subdir_required(struct libmnt_context *cxt, int *rc, char **subdir
struct libmnt_optlist *ol;
struct libmnt_opt *opt;
const char *dir = NULL;
+ unsigned long flags = 0;
assert(cxt);
assert(rc);
@@ -328,16 +329,26 @@ static int is_subdir_required(struct libmnt_context *cxt, int *rc, char **subdir
return 0;
dir = mnt_opt_get_value(opt);
-
if (!dir || !*dir) {
DBG(HOOK, ul_debug("failed to parse X-mount.subdir '%s'", dir));
*rc = -MNT_ERR_MOUNTOPT;
- } else {
- *subdir = strdup(dir);
- if (!*subdir)
- *rc = -ENOMEM;
+ return 0;
+ }
+
+ *rc = mnt_optlist_get_flags(ol, &flags, cxt->map_linux, 0);
+ if (*rc)
+ return 0;
+
+ if (flags & MS_REMOUNT || flags & MS_BIND || flags & MS_MOVE
+ || mnt_context_propagation_only(cxt)) {
+ DBG(HOOK, ul_debug("ignore subdir= (bind/move/remount/..)"));
+ return 0;
}
+ *subdir = strdup(dir);
+ if (!*subdir)
+ *rc = -ENOMEM;
+
return *rc == 0;
}