From patchwork Mon May 28 20:29:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Dilger X-Patchwork-Id: 161641 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 EEC4EB6FAB for ; Tue, 29 May 2012 06:29:10 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755179Ab2E1U3H (ORCPT ); Mon, 28 May 2012 16:29:07 -0400 Received: from idcmail-mo2no.shaw.ca ([64.59.134.9]:60339 "EHLO idcmail-mo2no.shaw.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755177Ab2E1U3G convert rfc822-to-8bit (ORCPT ); Mon, 28 May 2012 16:29:06 -0400 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd6ml1no-ssvc.prod.shaw.ca) ([10.0.144.222]) by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 28 May 2012 14:29:05 -0600 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=Cufqhujp69hR+MhiHu40yK/USb/hlYs0+irVU46A6+k= c=1 sm=1 a=O-b3OA9KJHoA:10 a=BLceEmwcHowA:10 a=kj9zAlcOel0A:10 a=akHhUqyx16pf1Jmt3m6W8Q==:17 a=VPuMasf8_NCbnvXS82QA:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Received: from unknown (HELO cabot-100.adilger.int) ([68.147.209.146]) by pd6ml1no-dmz.prod.shaw.ca with ESMTP; 28 May 2012 14:29:05 -0600 Subject: Re: [PATCH] vfs: avoid hang caused by attempting to rmdir an invalid file system Mime-Version: 1.0 (Apple Message framework v1084) From: Andreas Dilger In-Reply-To: <1338226422-8845-1-git-send-email-tytso@mit.edu> Date: Mon, 28 May 2012 14:29:05 -0600 Cc: linux-fsdevel@vger.kernel.org, Ext4 Developers List , viro@ZenIV.linux.org.uk, sami.liedes@iki.fi Message-Id: <4790434C-0DF2-4186-BE4C-CE97633F107C@dilger.ca> References: <1338226422-8845-1-git-send-email-tytso@mit.edu> To: Theodore Ts'o X-Mailer: Apple Mail (2.1084) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 2012-05-28, at 11:33 AM, Theodore Ts'o wrote: > If we rmdir a directory which is a hard link to '.', we will deadlock > trying to grab the directory's i_mutex. Check for this condition and > return EINVAL, which is what we return if the user attempts to rmdir > "/foo/bar/." > > Signed-off-by: "Theodore Ts'o" > --- > fs/namei.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/fs/namei.c b/fs/namei.c > index 0062dd1..081f872 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2774,6 +2774,17 @@ static long do_rmdir(int dfd, const char __user *pathname) > error = -ENOENT; > goto exit3; > } > + if (nd.path.dentry->d_inode == dentry->d_inode) { > + /* > + * Corrupt file system where there is a symlink to > + * '.'; treat it as if we are trying to rmdir '.' > + * > + * XXX Should we call into the low-level file system > + * to request that the file system be marked corrupt? > + */ > + error = -EINVAL; > + goto exit3; > + } > error = mnt_want_write(nd.path.mnt); > if (error) > goto exit3; This patch is good from the POV of covering all filesystems, and avoiding the deadlock at the dcache level. It would be possible to detect this problem in the filesystem itself during lookup, before the bad link got into the dcache itself. Something like: Though -EIO could be replaced with -EBADF or -ELOOP, or something else. Cheers, Andreas --- 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/fs/ext4/namei.c b/fs/ext4/namei.c index 349d7b3..4a9c99d 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1037,6 +1037,12 @@ static struct dentry *ext4_lookup(struct inode EXT4_ERROR_INODE(dir, "bad inode number: %u", ino); return ERR_PTR(-EIO); } + if (ino == dir->i_ino) { + EXT4_ERROR_INODE(dir, "'%.*s' linked to parent dir", + dentry->d_name.len, + dentry->d_name.name); + return ERR_PTR(-EIO); + } inode = ext4_iget(dir->i_sb, ino); if (inode == ERR_PTR(-ESTALE)) { EXT4_ERROR_INODE(dir,