From patchwork Mon Jun 24 06:29:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 253633 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44A2E2C007C for ; Mon, 24 Jun 2013 16:39:52 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752470Ab3FXGjw (ORCPT ); Mon, 24 Jun 2013 02:39:52 -0400 Received: from TYO200.gate.nec.co.jp ([210.143.35.50]:40673 "EHLO tyo200.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751922Ab3FXGjv (ORCPT ); Mon, 24 Jun 2013 02:39:51 -0400 Received: from tyo202.gate.nec.co.jp ([10.7.69.202]) by tyo200.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id r5O6doN1004835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 24 Jun 2013 15:39:50 +0900 (JST) Received: from mailgate3.nec.co.jp ([10.7.69.197]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id r5O6Xjua007534; Mon, 24 Jun 2013 15:33:45 +0900 (JST) Received: from mailsv.nec.co.jp (imss63.nec.co.jp [10.7.69.158]) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) with ESMTP id r5O6Xj327458; Mon, 24 Jun 2013 15:33:45 +0900 (JST) Received: from mail03.kamome.nec.co.jp (mail03.kamome.nec.co.jp [10.25.43.7]) by mailsv.nec.co.jp (8.13.8/8.13.4) with ESMTP id r5O6XjuI012721; Mon, 24 Jun 2013 15:33:45 +0900 (JST) Received: from zuizan.jp.nec.com ([10.26.220.9] [10.26.220.9]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-280598; Mon, 24 Jun 2013 15:29:08 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTPA id BT-MMP-44464; Mon, 24 Jun 2013 15:29:08 +0900 Message-ID: <51C7E733.8090003@sx.jp.nec.com> Date: Mon, 24 Jun 2013 15:29:07 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Andreas Dilger , tytso@mit.edu CC: linux-ext4@vger.kernel.org Subject: [PATCH 2/2 V2] mke2fs: disallow creating FS on a loop mounted file with no option Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When /etc/mtab is a symlink of /proc/mounts, mke2fs can create a filesystem on the loop mounted file without -F option. In this case, we should specify -F option twice. How to reproduce: # mke2fs -t ext4 -Fq /mnt/mp1/fs.img # mount -o loop /mnt/mp1/fs.img /mnt/mp2 # mke2fs -t ext4 -q /mnt/mp1/fs.img /mnt/mp1/fs.img is not a block special device. Proceed anyway? (y,n) y # echo $? 0 Signed-off-by: Kazuya Mio --- configure.in | 2 ++ lib/ext2fs/ismounted.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/configure.in b/configure.in index 8963d17..fe29aa3 100644 --- a/configure.in +++ b/configure.in @@ -912,6 +912,8 @@ AC_CHECK_HEADERS(m4_flatten([ linux/falloc.h linux/fd.h linux/major.h + linux/version.h + linux/loop.h net/if_dl.h netinet/in.h sys/disklabel.h diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index 6a223df..499b4c0 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -21,6 +21,14 @@ #ifdef HAVE_LINUX_FD_H #include #endif +#ifdef HAVE_LINUX_VERSION_H +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) /* kernel >= 2.6 */ +#ifdef HAVE_LINUX_LOOP_H +#include +#endif /* HAVE_LINUX_LOOP_H */ +#endif /* kernel >= 2.6 */ +#endif /* HAVE_LINUX_VERSION_H */ #ifdef HAVE_MNTENT_H #include #endif @@ -31,6 +39,7 @@ #endif /* HAVE_GETMNTINFO */ #include #include +#include #include "ext2_fs.h" #include "ext2fs.h" @@ -51,6 +60,11 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, ino_t file_ino=0; FILE *f; int fd; +#if defined(HAVE_LINUX_LOOP_H) && defined(LOOP_GET_STATUS64) + int result = 0; + struct loop_info64 lo_info; + memset(&lo_info, 0, sizeof(struct loop_info64)); +#endif /* defined(HAVE_LINUX_LOOP_H) && defined(LOOP_GET_STATUS64) */ *mount_flags = 0; if ((f = setmntent (mtab_file, "r")) == NULL) @@ -70,6 +84,30 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, continue; if (strcmp(file, mnt->mnt_fsname) == 0) break; +#if defined(HAVE_LINUX_LOOP_H) && defined(LOOP_GET_STATUS64) + /* + * Check to see if a regular file is mounted. + * If /etc/mtab/ is a symlink of /proc/mounts, you will need + * the following check because the name in /proc/mounts + * is a loopback device not a regular file. + */ + if (strncmp(mnt->mnt_fsname, "/dev/loop", 9) == 0) { + fd = open(mnt->mnt_fsname, O_RDONLY); + if (fd < 0) { + retval = errno; + goto errout; + } + result = ioctl(fd, LOOP_GET_STATUS64, &lo_info); + close(fd); + if (result < 0) { + retval = errno; + goto errout; + } + if (file_dev == lo_info.lo_device && + file_ino == lo_info.lo_inode) + break; + } +#endif /* defined(HAVE_LINUX_LOOP_H) && defined(LOOP_GET_STATUS64) */ if (stat(mnt->mnt_fsname, &st_buf) == 0) { if (S_ISBLK(st_buf.st_mode)) { #ifndef __GNU__