Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixfiles: Unmount temporary bind mounts on SIGINT
`fixfiles -M relabel` temporary bind mounts filestems before relabeling
but it leaves a directory mounted in /tmp/tmp.XXXX when a user hits
CTRL-C. It means that if the user run `fixfiles -M relabel` again and
answered Y to clean out /tmp directory, it would remove all data from
mounted fs.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2125355

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
  • Loading branch information
bachradsusi committed Sep 15, 2022
1 parent 02bdee3 commit a4cb900
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions policycoreutils/scripts/fixfiles
Expand Up @@ -207,6 +207,14 @@ rpm -q --qf '[%{FILESTATES} %{FILENAMES}\n]' "$1" | grep '^0 ' | cut -f2- -d ' '
[ ${PIPESTATUS[0]} != 0 ] && echo "$1 not found" >/dev/stderr
}

# unmount tmp bind mount before exit
umount_TMP_MOUNT() {
if [ -n "$TMP_MOUNT" ]; then
umount "${TMP_MOUNT}${m}"
fi
exit 130
}

#
# restore
# if called with -n will only check file context
Expand Down Expand Up @@ -251,6 +259,7 @@ case "$RESTORE_MODE" in
else
# we bind mount so we can fix the labels of files that have already been
# mounted over
trap umount_TMP_MOUNT SIGINT
for m in `echo $FILESYSTEMSRW`; do
TMP_MOUNT="$(mktemp -d)"
test -z ${TMP_MOUNT+x} && echo "Unable to find temporary directory!" && exit 1
Expand All @@ -261,6 +270,7 @@ case "$RESTORE_MODE" in
umount "${TMP_MOUNT}${m}" || exit 1
rm -rf "${TMP_MOUNT}" || echo "Error cleaning up."
done;
trap SIGINT
fi
else
echo >&2 "fixfiles: No suitable file systems found"
Expand Down

0 comments on commit a4cb900

Please sign in to comment.