fmount removes everything in /mnt and /media if no argument is supplied

67 views
Skip to first unread message

Jess Whyte

unread,
Dec 10, 2021, 3:30:42 PM12/10/21
to BitCurator Users
Hi,

We think the BCC should review the use of fmount or revise the script. fmount -u appears to wipe out all directories under /mnt and /media if no argument is supplied

Currently, BitCurator uses John Lehr's "fmount" script (located in /usr/local/bin/fmount) and called by the ~/.local/share/nautilus/scripts/Disk Image Mount and Disk Image Unmount scripts that run when right-clicking a mounted volume (or anything really) and clicking > scripts > Disk Image Unmount. The script, at least for us, has inadvertently removed content on other attached devices (mounted under /mnt or /media). The dangerous portions of this script are here:

--starting at line 123--
## $OPTIND points to the next, unparsed argument
shift "$(( $OPTIND -1 ))"
IMAGE=($@)
DIR_NAME=$(basename ${IMAGE%.*})#check for root access
[[ $UID -ne 0 ]] && echo "Root access required." >&2 && exit 1## Determine volumes and starting offsets
if [ $UMOUNT -eq 1 ]
then
    for DIR in media mnt
    do
        if [ -d /$DIR/$DIR_NAME ]
        then
            echo "Unmounting volumes at /${DIR}/$DIR_NAME/" >&2
            umount /$DIR/$DIR_NAME/* 2>/dev/null
            umount /$DIR/$DIR_NAME 2>/dev/null
            rm -vrf /$DIR/$DIR_NAME
        fi
    done

----------------

The nautilus script runs on all arguments "sudo fmount -u $@" and fmount does the same in line 125 'IMAGE="$@"'. If no argument is provided or if there is an issue with the argument, this affects the subsequent $IMAGE, and $DIR_NAME variables. If no $DIR_NAMEs are then created, then line 141 'rm -vrf /$DIR/$DIR_NAME' essentially removes all directories ($DIR) found under /mnt and /media, meaning any content on mounted media, e.g. if you had a separate USB key plugged in and it mounted as /media/USB, a rm -vrf would be run on it.

This isn't typically a feature we use (the nautilus scripts), but we tried it yesterday and subsequently lost content on an attached device under /media and /mnt was removed. I've tried this on two separate machines now, and got a coworker to check my work. Has anyone else seen this?

e.g.

run command: sudo fmount -u
output:
basename: missing operand
Try 'basename --help' for more information.
Unmounting volumes at /media//
removed directory '/media/storage'
removed directory '/media/test'
removed '/media/test/hello'
removed directory '/media/'
Unmounting volumes at  /mnt//
removed directory  '/mnt/'

Running Ubuntu 18.04.6 LTS.

Thank you,




jessica.whyte

unread,
Jan 10, 2022, 10:56:40 AM1/10/22
to BitCurator Users
Hi,

I am following up on this because I think the use of a sudo rm -vrf in a script is or could be harmful, particularly if anyone has any network storage devices (e.g. share drives) mounted under /media or /mnt.

Has anyone else experienced this issue?

Thank you,

Jess

Kam Woods

unread,
Jan 11, 2022, 1:32:06 AM1/11/22
to bitcurat...@googlegroups.com
Fixed in release 2.2.24, now live at https://github.com/BitCurator/bitcurator-distro/wiki/Releases. The pre-built VM can be downloaded at https://distro.ibiblio.org/bitcurator/BitCurator-2.2.24.tar.gz.

The fmount script has been modified to disallow running without a target. Using the unmount flag (or selecting the unmount option in the context menu) now operates only on the path(s) of the volume(s) mounted from source image in /media and /mnt, and removes (via find and rmdir rather than rm) only empty directories that match the pattern of that path after the volume(s) has/have been unmounted.

2.2.24 also includes source checkout updates for liblightgrep and dumpfloppy.

Kam

--
You received this message because you are subscribed to the Google Groups "BitCurator Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcurator-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bitcurator-users/29795c90-301e-4c2b-ac64-ad6a50998649n%40googlegroups.com.

Jess Whyte

unread,
Jan 11, 2022, 9:10:36 AM1/11/22
to bitcurat...@googlegroups.com
Thank you! I like the ideas of a target check, and using find and -empty. 

I’ll update and test this week. I really appreciate this. 

You received this message because you are subscribed to a topic in the Google Groups "BitCurator Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bitcurator-users/bWvTFw8Zync/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bitcurator-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bitcurator-users/CAAOjFxCGw%3D9j9U%3DMi3iLjMi-i_JjBo2ksW5NS4o8swcFYAkg2g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages