rework handling of bind mounts

Instead of only looking for bind mounts from within a tomb due to bind-hooks, also consider bind mounts that happenfrom the outside (example: open a tomb and manually issue a mount --bind /media/tomb some/other/location).
Such a mount wouldn't be filtered before (only looking for an additional [/path/] added to TARGET.
Instead look for every mount that is related to the respective /dev/mapper/ entry of a tomb and also close or list them.
This helps to avoid to loop again against mounted tombs inside the main loop which loops over mounted tombs.
This commit is contained in:
Narrat 2024-08-06 18:40:20 +02:00 committed by Jaromil
parent 42e233d2b0
commit 33f7878a22

25
tomb
View File

@ -2779,13 +2779,12 @@ list_tomb_binds() {
[[ -z "$1" ]] && { [[ -z "$1" ]] && {
_failure "Internal error: list_tomb_binds called without argument." } _failure "Internal error: list_tomb_binds called without argument." }
# much simpler than the crazy from before # ignore the first line of the result for the respective source (mapper),
# in fact, the second parameter is now redundant # as this will be the canonical first mount (aka main mount)
# as we only need the tomb mapper name
findmnt --source=/dev/mapper/"$1" -rno SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \ findmnt --source=/dev/mapper/"$1" -rno SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| awk ' | awk '
FNR==1 {next}
{ {
if(index($1,"[")==0) next;
print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]" print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]"
} }
' '
@ -3056,7 +3055,8 @@ umount_tomb() {
_message "Closing tomb ::1 tomb name:: mounted on ::2 mount point::" \ _message "Closing tomb ::1 tomb name:: mounted on ::2 mount point::" \
$tombname "$tombmount" $tombname "$tombmount"
# check if there are bind mounted dirs and close them # check if there are bind mounted dirs and close them first
# Can be due to bind-hooks or outside --bind mounts
bind_tombs=(`list_tomb_binds "$mapper"`) bind_tombs=(`list_tomb_binds "$mapper"`)
for b in ${bind_tombs}; do for b in ${bind_tombs}; do
bind_mapper="${b[(ws:;:)1]}" bind_mapper="${b[(ws:;:)1]}"
@ -3066,18 +3066,7 @@ umount_tomb() {
_failure "Tomb bind hook ::1 hook:: is busy, cannot close tomb." "$bind_mount" _failure "Tomb bind hook ::1 hook:: is busy, cannot close tomb." "$bind_mount"
done done
# check if the tomb is actually still mounted. Background: # umount the main mount
# When mounted on a binded directory in appears twice in 'list_tomb_binds'
# and will get umounted automatically through the above function
# causing an error and a remaining (decrypted!) loop device
# posing a security risk.
# See https://github.com/dyne/Tomb/issues/273
# checking for tombs still mounted
mounted_tombs=(`list_tomb_mounts`)
for t in ${mounted_tombs}; do
usedmount=${t[(ws:;:)2]}
[[ "$usedmount" == "$tombmount" ]] && {
_verbose "Performing umount of ::1 mount point::" "$tombmount" _verbose "Performing umount of ::1 mount point::" "$tombmount"
touch "${tombmount}"/.cleanexit touch "${tombmount}"/.cleanexit
_sudo umount "${tombmount}" _sudo umount "${tombmount}"
@ -3085,8 +3074,6 @@ umount_tomb() {
rm -f "${tombmount}"/.cleanexit rm -f "${tombmount}"/.cleanexit
_failure "Tomb is busy, cannot umount!" _failure "Tomb is busy, cannot umount!"
} }
}
done
# If we used a default mountpoint and is now empty, delete it # If we used a default mountpoint and is now empty, delete it
tombname_regex=${tombname//\[/} tombname_regex=${tombname//\[/}