]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commit
e2fsck: fix checks done for mounted vs. read-only
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 24 May 2012 21:34:56 +0000 (15:34 -0600)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 28 May 2012 14:31:24 +0000 (10:31 -0400)
commit732e26b98e5c79a4298dbe341f43b54b354bb241
tree8caedbeb4a7a7fc8dfa6a53075db9d1d04e5330e
parent88f8f33cef74f64ff8b4d69381d5a0cf276dd04f
e2fsck: fix checks done for mounted vs. read-only

Currently, if e2fsck is run without the "-n" flag (i.e. it
might modify the filesystem), there is no guarantee that it will
open the filesystem with the EXCLUSIVE flag (i.e. O_EXCL) to
prevent the block device from being checked (in most cases this
means mounted, but it could also be an MD/LVM member device).

Conversely, if e2fsck is run with "-n" (i.e. read-only), and
/etc/mtab or /proc/mounts does not report the block device as
mounted then e2fsck thinks the filesystem is unmounted.  In this
case, e2fsck incorrectly sets the EXCLUSIVE flag, which causes
the check to fail, even though e2fsck is running read-only.

To fix this, do not open with EXCLUSIVE if it is a read-only check,
and always open with EXCLUSIVE if the filesystem might be changed.
This also prevents filesystem mounts while e2fsck is running.

Also refuse allow e2fsck to run at all if the filesystem is BUSY.
The e2fsck check_mount() was checking for MOUNTED, but not BUSY,
and it should refuse to run outright if the block device is BUSY.
The previous MOUNTED heuristics pre-date the O_EXCL reservation
by the kernel, so there could be uncertainty due to stale /etc/mtab
data, but with newer kernels a busy device should never be modified.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/unix.c