From 099aead590608cd9edb49acf73873b03b88576b6 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 23 Jul 2024 11:01:57 +0800 Subject: [PATCH] lib: Ensure we don't find bind mounts for device target Resolves: RHEL-35885 commit 9252d6b1b492016aa11a73340f286822e6d545f2 Author: Colin Walters Date: Fri Jul 19 11:44:09 2024 -0400 lib: Ensure we don't find bind mounts for device target There's comment here that `--source` somehow avoids bind mounts, but that appears not to be the case in my testing. I think we just happened to be lucky before now with the `--first` picking the value we wanted. Instead of using `--first` and hoping for the best, parse the mounts and skip ones which are bind mounts explicitly. Signed-off-by: Colin Walters Signed-off-by: Lichen Liu --- kdump-lib-initramfs.sh | 11 +++++++++-- kdump-lib.sh | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 41dc751..6eaec93 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -101,8 +101,15 @@ get_fs_type_from_target() get_mntpoint_from_target() { - # --source is applied to ensure non-bind mount is returned - get_mount_info TARGET source "$1" -f + local SOURCE TARGET + findmnt -k --pairs -o SOURCE,TARGET "$1" | while read line; do + eval "$line" + # omit sources that are bind mounts i.e. they contain a [/path/to/subpath]. + if [[ ! "$SOURCE" =~ \[ ]]; then + echo $TARGET + break + fi + done } is_ssh_dump_target() diff --git a/kdump-lib.sh b/kdump-lib.sh index 0ccabc0..28ee6c0 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -213,7 +213,7 @@ get_bind_mount_source() _fsroot=${_src#${_src_nofsroot}[} _fsroot=${_fsroot%]} - _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) + _mnt=$(get_mntpoint_from_target "$_src_nofsroot") # for btrfs, _fsroot will also contain the subvol value as well, strip it if [[ $_fstype == btrfs ]]; then