linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Tso <tytso@mit.edu>
To: Peng Tao <bergwolf@gmail.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH]mke2fs: don't check mount flags for regular files
Date: Wed, 22 Apr 2009 22:27:11 -0400	[thread overview]
Message-ID: <20090423022711.GA15541@mit.edu> (raw)
In-Reply-To: <1237883493-30521-1-git-send-email-bergwolf@gmail.com>

On Tue, Mar 24, 2009 at 04:31:33PM +0800, Peng Tao wrote:
> mke2fs scans /proc/mounts for mount flags of a device. But for regular files,
> this is unnecessary and may cause troubles.
> 
> This can be triggered by:
> $dd if=/dev/null of=rootfs bs=1024 seek=100000 count=0
> $mke2fs -t ext3 -F rootfs
> mke2fs 1.41.4 (27-Jan-2009)
> rootfs is mounted; will not make a filesystem here!

Actually, this is quite necessary; regular files can be mounted using
the loop device, and we want to catch this case.  So simply patching
out the check for regular files is the wrong thing to do, and hides
the real problem.

The correct patch to solve the problem you've reported is attached,
and has been checked into e2fsprogs source repository.

						- Ted

commit f9110f4480eade2d849c4cc08efa49bf0f7f5148
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Wed Apr 22 22:20:22 2009 -0400

    libext2fs: Skip relative pathnames in /etc/mtab in ismounted.c
    
    The functions which test to see if a device is mounted can get
    confused by entries in /etc/mtab for virtual filesystems:
    
    rootfs / rootfs rw 0 0
    none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
    
    If the device name doesn't start with a slash, ignore the /etc/mtab
    entry, so that relative pathnames passed into functions such as
    ext2fs_check_mount_point() or ext2fs_check_if_mounted() don't return
    false positives.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 4a7c8c6..4c5500f 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -65,6 +65,8 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
 		}
 	}
 	while ((mnt = getmntent (f)) != NULL) {
+		if (mnt->mnt_fsname[0] != '/')
+			continue;
 		if (strcmp(file, mnt->mnt_fsname) == 0)
 			break;
 		if (stat(mnt->mnt_fsname, &st_buf) == 0) {

      reply	other threads:[~2009-04-23  2:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-24  8:31 [PATCH]mke2fs: don't check mount flags for regular files Peng Tao
2009-04-23  2:27 ` Theodore Tso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090423022711.GA15541@mit.edu \
    --to=tytso@mit.edu \
    --cc=bergwolf@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).