aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2023-08-03 11:43:28 +0200
committerKarel Zak <kzak@redhat.com>2023-08-03 11:58:22 +0200
commit1b2d8187360157b00b47f52522fc039d82e34e6b (patch)
tree4c93a51038d529206b83678ea5a850f7f66226c6 /libmount/src
parenta6dd313bf2f5bc901ddc65262807075587ecb895 (diff)
downloadutil-linux-1b2d8187360157b00b47f52522fc039d82e34e6b.tar.gz
libmount: don't canonicalize symlinks for bind operation
The new kernel mount API can bind over symlink by default. Unfortunately, libmount always canonicalizes all paths (due to backward compatibility, search in mountinfo, search in fstab, etc.). Possible workaround is -c, --no-canonicalize but it disable all paths canonicalization, tags to paths conversions etc. This patch disables the canonicalization only for the target path (if symlink) on bind operation. Fixes: https://github.com/util-linux/util-linux/issues/2370 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/context_mount.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index 05c84f1702..5aec87d6c3 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -669,6 +669,7 @@ static int prepare_target(struct libmnt_context *cxt)
const char *tgt, *prefix;
int rc = 0;
struct libmnt_ns *ns_old;
+ struct stat st;
assert(cxt);
assert(cxt->fs);
@@ -708,7 +709,10 @@ static int prepare_target(struct libmnt_context *cxt)
return -MNT_ERR_NAMESPACE;
/* canonicalize the path */
- if (rc == 0) {
+ if (rc == 0 &&
+ !(cxt->optlist && mnt_optlist_is_bind(cxt->optlist)
+ && mnt_safe_lstat(tgt, &st) == 0 && S_ISLNK(st.st_mode))) {
+
struct libmnt_cache *cache = mnt_context_get_cache(cxt);
if (cache) {