All of lore.kernel.org
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Richard Weinberger <richard@nod.at>
Cc: Sami Liedes <sami.liedes@iki.fi>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: Intentionally corrupted vfat fs causing BUG
Date: Fri, 24 Oct 2014 00:28:58 +0900	[thread overview]
Message-ID: <87oat29551.fsf@devron.myhome.or.jp> (raw)
In-Reply-To: <5443E87A.2060207@nod.at> (Richard Weinberger's message of "Sun, 19 Oct 2014 18:36:10 +0200")

Richard Weinberger <richard@nod.at> writes:

>> Well, anyway, I don't object like that simple patch.
>> 
>> My worry is, I feel we need something like online-fsck finally if we
>> tackled fully to avoid issues (I still didn't analyze about this issue
>> seriously and fully), and measurable overheads.
>> 
>> And I myself have interest to online/runtime-fsck (i.e. detect and fix)
>> though, I don't have interest to make it generic operations, and I would
>> not have interest to tackle for all FSes...
>> 
>
> What about this one?

Looks like strange. If we want to tackle this at per-FS. We should not
return double linked dir at first.  Since double linked breaks dir
hierarchy, even if this one can avoid that Oops, double linked can be
easily the cause of another Oops, deadlock, etc.

Well, this patch is untested though. For example, somethings like
following. But, again, this fixes only one of cases in double linked.
(And to fix fully, my mind was already talked.)

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---

 fs/fat/namei_msdos.c |    9 +++++++++
 fs/fat/namei_vfat.c  |    9 +++++++++
 2 files changed, 18 insertions(+)

diff -puN fs/fat/namei_vfat.c~vfat-detect-dir-loop fs/fat/namei_vfat.c
--- linux-tux3/fs/fat/namei_vfat.c~vfat-detect-dir-loop	2014-10-20 17:44:17.874542711 +0900
+++ linux-tux3-hirofumi/fs/fat/namei_vfat.c	2014-10-20 17:42:24.494864616 +0900
@@ -735,6 +735,15 @@ static struct dentry *vfat_lookup(struct
 		goto error;
 	}
 
+	/* Simple sanity check to avoid Oops. */
+	if (inode == dentry->d_parent->d_inode) {
+		fat_fs_error(sb, "%s: detected directory loop (i_pos %lld)",
+			     __func__, MSDOS_I(inode)->i_pos);
+		iput(inode);
+		err = -EIO;
+		goto error;
+	}
+
 	alias = d_find_alias(inode);
 	if (alias && !vfat_d_anon_disconn(alias)) {
 		/*
diff -puN fs/fat/namei_msdos.c~vfat-detect-dir-loop fs/fat/namei_msdos.c
--- linux-tux3/fs/fat/namei_msdos.c~vfat-detect-dir-loop	2014-10-20 17:44:25.858520043 +0900
+++ linux-tux3-hirofumi/fs/fat/namei_msdos.c	2014-10-20 17:45:42.654302012 +0900
@@ -215,6 +215,15 @@ static struct dentry *msdos_lookup(struc
 	case 0:
 		inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
 		brelse(sinfo.bh);
+
+		/* Simple sanity check to avoid Oops. */
+		if (inode == dentry->d_parent->d_inode) {
+			fat_fs_error(sb,
+				     "%s: detected directory loop (i_pos %lld)",
+				     __func__, MSDOS_I(inode)->i_pos);
+			iput(inode);
+			inode = ERR_PTR(-EIO);
+		}
 		break;
 	default:
 		inode = ERR_PTR(err);
_
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

  reply	other threads:[~2014-10-23 15:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 20:57 Intentionally corrupted vfat fs causing BUG Sami Liedes
2014-10-11 10:20 ` Richard Weinberger
2014-10-12 12:08 ` OGAWA Hirofumi
2014-10-12 19:04   ` Richard Weinberger
2014-10-12 20:40     ` Sami Liedes
2014-10-13  7:57     ` OGAWA Hirofumi
2014-10-13  8:22       ` Richard Weinberger
2014-10-13  8:35         ` OGAWA Hirofumi
2014-10-13  8:39           ` Richard Weinberger
2014-10-13  8:59             ` OGAWA Hirofumi
2014-10-13 14:36               ` Richard Weinberger
2014-10-19 16:36               ` Richard Weinberger
2014-10-23 15:28                 ` OGAWA Hirofumi [this message]
2014-10-23 16:01                   ` Al Viro
2014-10-23 16:16                     ` Al Viro
2014-10-23 16:45                       ` OGAWA Hirofumi
2014-10-23 16:50                         ` OGAWA Hirofumi
2014-10-23 16:55                           ` Richard Weinberger
2014-10-23 16:55                         ` Al Viro
2014-10-23 17:21                           ` Al Viro
2014-10-23 17:58                             ` OGAWA Hirofumi
2014-10-23 20:46                             ` Sami Liedes
2014-10-23 17:35                           ` OGAWA Hirofumi
2014-10-23 17:54                           ` J. Bruce Fields
2014-10-23 18:05                             ` Al Viro
2014-10-23 18:16                               ` J. Bruce Fields
2014-10-23 16:56                         ` Al Viro

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=87oat29551.fsf@devron.myhome.or.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=sami.liedes@iki.fi \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.