linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Niu <niu@whamcloud.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: e2fsprogs: Avoid infinite loop in ext2fs_find_block_device()
Date: Thu, 03 Nov 2011 14:45:29 +0800	[thread overview]
Message-ID: <4EB23889.1010807@whamcloud.com> (raw)

hello, Ted

In my rhel5 system, there are lots of loop links in the /dev/.udev/failed folder, which makes the e2fsprogs
'make check' stuck in 't_ext_jnl_rm'. I'm not sure if the loop links are generated by udev defect or misconfiguration,
but anyway, I think the ext2fs_find_block_device() should do some sanity check to avoid infinite loop.

I made a simple patch which breaks the loop when depth reaching 5 in ext2fs_find_block_device(), any comments? Thank you.

>From 5ef3b82266e7fb5edbce4febc4924b0beaccacf1 Mon Sep 17 00:00:00 2001
From: Niu Yawei <niu@whamcloud.com>
Date: Wed, 2 Nov 2011 04:31:11 +0800
Subject: [PATCH] Avoid infinite loop in ext2fs_find_block_device()

The ext2fs_find_block_device() should stop searching when the
directory depth reaching a certain threshold, otherwise, it could
run into infinite loop if there are loop links in the device
directory.

Signed-off-by: Niu Yawei <niu@whamcloud.com>
---
 lib/ext2fs/finddev.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/lib/ext2fs/finddev.c b/lib/ext2fs/finddev.c
index 13ef14b..61f9754 100644
--- a/lib/ext2fs/finddev.c
+++ b/lib/ext2fs/finddev.c
@@ -128,6 +128,7 @@ char *ext2fs_find_block_device(dev_t device)
 	struct dir_list *list = 0, *new_list = 0;
 	struct dir_list *current;
 	char	*ret_path = 0;
+	int    level = 0;
 
 	/*
 	 * Add the starting directories to search...
@@ -154,6 +155,9 @@ char *ext2fs_find_block_device(dev_t device)
 		if (list == 0) {
 			list = new_list;
 			new_list = 0;
+			/* Avoid infinite loop */
+			if (++level > 5)
+				break;
 		}
 	}
 	free_dirlist(&list);
-- 
1.7.1




             reply	other threads:[~2011-11-03  6:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03  6:45 Niu [this message]
2011-11-03 14:47 ` e2fsprogs: Avoid infinite loop in ext2fs_find_block_device() Eric Sandeen
2011-11-03 15:27   ` Theodore Tso
2011-11-04 12:50     ` Niu
2011-11-20  4:18       ` Ted Ts'o
2011-11-20  8:17       ` Christian Kujau

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=4EB23889.1010807@whamcloud.com \
    --to=niu@whamcloud.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).