From nobody@FreeBSD.org  Thu Oct 21 17:19:41 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C6918106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2010 17:19:41 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id B61AE8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2010 17:19:41 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o9LHJfeg046180
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2010 17:19:41 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o9LHJfTN046179;
	Thu, 21 Oct 2010 17:19:41 GMT
	(envelope-from nobody)
Message-Id: <201010211719.o9LHJfTN046179@www.freebsd.org>
Date: Thu, 21 Oct 2010 17:19:41 GMT
From: Gleb Kurtsou <gk@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [fs] [patch] Skip empty directory entries during name lookup (unionfs, dirent_exists())
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         151629
>Category:       kern
>Synopsis:       [fs] [patch] Skip empty directory entries during name lookup (unionfs, dirent_exists())
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 21 17:20:11 UTC 2010
>Closed-Date:    
>Last-Modified:  Sat Oct 23 07:56:13 UTC 2010
>Originator:     Gleb Kurtsou
>Release:        
>Organization:
>Environment:
FreeBSD tops 9.0-CURRENT FreeBSD 9.0-CURRENT #25 r212049+d758796
>Description:
At least UFS and EXT2 use "empty" directory entries, i.e. dirent with zero d_fileno, as a placeholder for removed entries.

Such entries are skipped by libc and elsewhere in the kernel.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

commit 2a41d458eff5cde0ae15bf72f3d62c9a6630d618
Author: Gleb Kurtsou <gleb.kurtsou@gmail.com>
Date:   Sun Oct 17 23:40:11 2010 +0300

    Skip empty directory entries (entries with zero inode number) during name lookup

diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c
index 2e74844..ccd97cd 100644
--- a/sys/fs/unionfs/union_subr.c
+++ b/sys/fs/unionfs/union_subr.c
@@ -1177,7 +1177,7 @@ unionfs_check_rmdir(struct vnode *vp, struct ucred *cred, struct thread *td)
 		edp = (struct dirent*)&buf[sizeof(buf) - uio.uio_resid];
 		for (dp = (struct dirent*)buf; !error && dp < edp;
 		     dp = (struct dirent*)((caddr_t)dp + dp->d_reclen)) {
-			if (dp->d_type == DT_WHT ||
+			if (dp->d_type == DT_WHT || dp->d_fileno == 0 ||
 			    (dp->d_namlen == 1 && dp->d_name[0] == '.') ||
 			    (dp->d_namlen == 2 && !bcmp(dp->d_name, "..", 2)))
 				continue;
diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c
index 195e735..9e2ec90 100644
--- a/sys/kern/vfs_default.c
+++ b/sys/kern/vfs_default.c
@@ -338,7 +338,7 @@ dirent_exists(struct vnode *vp, const char *dirname, struct thread *td)
 		if (error)
 			goto out;
 
-		if ((dp->d_type != DT_WHT) &&
+		if (dp->d_type != DT_WHT && dp->d_fileno != 0 &&
 		    !strcmp(dp->d_name, dirname)) {
 			found = 1;
 			goto out;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Oct 23 07:56:02 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151629 
>Unformatted:
