From: Karel Zak Date: Thu, 25 Jun 2026 10:32:46 +0000 (+0200) Subject: libmount: use uniq_id for target mount verification X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e677abc421450b54783e0194597b09ed382cf93d;p=thirdparty%2Futil-linux.git libmount: use uniq_id for target mount verification Prefer the unique mount ID (STATX_MNT_ID_UNIQUE) over the old mount ID when verifying that a mount landed on the expected target in mnt_context_reopen_target_fd(). Fall back to the old ID when uniq_id is not available. Signed-off-by: Karel Zak --- diff --git a/libmount/src/context.c b/libmount/src/context.c index d5d9151b3..9ae857eb4 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -420,23 +420,33 @@ int mnt_context_reopen_target_fd(struct libmnt_context *cxt) return -errno; /* verify the mount landed on the expected target; - * cxt->fs->id is set from fd_tree in hook_create_mount() */ - if (cxt->fs && cxt->fs->id > 0) { - int id = 0; + * IDs are set from fd_tree in hook_create_mount() */ + if (cxt->fs && (cxt->fs->uniq_id || cxt->fs->id > 0)) { + int mismatch = 0; - if (mnt_id_from_fd(cxt->fd_target, NULL, &id) == 0 - && id != cxt->fs->id) { + if (cxt->fs->uniq_id) { + uint64_t uniq_id = 0; + + if (mnt_id_from_fd(cxt->fd_target, &uniq_id, NULL) == 0 + && uniq_id != cxt->fs->uniq_id) + mismatch = 1; + } else { + int id = 0; + + if (mnt_id_from_fd(cxt->fd_target, NULL, &id) == 0 + && id != cxt->fs->id) + mismatch = 1; + } + if (mismatch) { const char *tgt = mnt_fs_get_target(cxt->fs); - DBG_OBJ(CXT, cxt, ul_debug( - "target mount ID mismatch (expected %d, got %d), umounting", - cxt->fs->id, id)); + DBG_OBJ(CXT, cxt, ul_debug("target mount ID mismatch, umounting")); if (tgt) umount2(tgt, MNT_DETACH); mnt_context_close_target_fd(cxt); return -EPERM; } - DBG_OBJ(CXT, cxt, ul_debug("target mount ID verified (%d)", id)); + DBG_OBJ(CXT, cxt, ul_debug("target mount ID verified")); } return 0;