From avg@topspin.kiev.ua  Fri Mar 18 15:46:39 2005
Return-Path: <avg@topspin.kiev.ua>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 12E1016A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Mar 2005 15:46:39 +0000 (GMT)
Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 194BA43D48
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Mar 2005 15:46:37 +0000 (GMT)
	(envelope-from avg@topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (oddity-e.topspin.kiev.ua [212.40.38.87])
	by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id RAA00929
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Mar 2005 17:46:35 +0200 (EET)
	(envelope-from avg@topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (localhost [127.0.0.1])
	by oddity.topspin.kiev.ua (8.13.1/8.13.1) with ESMTP id j2IFkYSP001477
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Mar 2005 17:46:34 +0200 (EET)
	(envelope-from avg@oddity.topspin.kiev.ua)
Received: (from avg@localhost)
	by oddity.topspin.kiev.ua (8.13.1/8.13.1/Submit) id j2IFkYxg001476;
	Fri, 18 Mar 2005 17:46:34 +0200 (EET)
	(envelope-from avg)
Message-Id: <200503181546.j2IFkYxg001476@oddity.topspin.kiev.ua>
Date: Fri, 18 Mar 2005 17:46:34 +0200 (EET)
From: Andriy Gapon <avg@icyb.net.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: udf fs: readdir returns error when it should not
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         78987
>Category:       kern
>Synopsis:       [udf] [patch] udf fs: readdir returns error when it should not
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    scottl
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 18 15:50:02 GMT 2005
>Closed-Date:    Mon Mar 23 13:35:17 UTC 2009
>Last-Modified:  Mon Mar 23 13:35:17 UTC 2009
>Originator:     Andriy Gapon
>Release:        FreeBSD 5.3-RELEASE-p5 i386
>Organization:
>Environment:
System: FreeBSD 5.3-RELEASE-p5 i386


	
>Description:
while reading large enough directory from a udf filesystem,
when total size of directory entries is greater than size of
a userland buffer, udf readdir leaks to userland its internal
error code used to mark such condition. This happens because
the calling code neglects to distinguish between real uiomove()
errors and internal flag set in udf_uiodir() when 
uio->uio_resid < de_size
In my case the error ocurred when a directory had 436 entries in it.
Kernel produced the following messages:
uiomove returned -1
>How-To-Repeat:
1a. find a UDF disk with a director(y|ies) with many files
or
1b. create a UDF filesystem with a directory with a lot of files in it,
using sysutils/udfclient for example
2. perform ls -l on the directory
3. see that ls returns only a small subset of entries and the following
messages are produced by kernel:
uiomove returned -1
>Fix:
The following code is based on the similar code in isofs/cd9660, it
keeps proper handling for error==-1, but does not let it be returned
to userland and removes a message about it.

	

--- bigdir.patch begins here ---
--- sys/fs/udf/udf_vnops.c.orig_orig	Thu Mar 17 15:08:39 2005
+++ sys/fs/udf/udf_vnops.c	Thu Mar 17 15:13:41 2005
@@ -787,7 +790,8 @@
 			    ds->this_off);
 		}
 		if (error) {
-			printf("uiomove returned %d\n", error);
+			if(error > 0)
+				printf("uiomove returned %d\n", error);
 			break;
 		}
 
@@ -797,6 +801,8 @@
 	*a->a_eofflag = uiodir.eofflag;
 	uio->uio_offset = ds->offset + ds->off;
 
+	if(error < 0)
+		error = 0;
 	if (!error)
 		error = ds->error;
 
--- bigdir.patch ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->scottl 
Responsible-Changed-By: pjd 
Responsible-Changed-When: Mon Mar 28 09:21:43 GMT 2005 
Responsible-Changed-Why:  
Assign to author. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78987 

From: Andriy Gapon <avg@icyb.net.ua>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/78987: [udf] [patch] udf fs: readdir returns error when
 it should not
Date: Wed, 24 May 2006 15:49:57 +0300

 This problem is still present in 6.1.
 The same patch is applicable.
 
 -- 
 Andriy Gapon

From: Andriy Gapon <avg@icyb.net.ua>
To: Robert Jenssen <robertjenssen@ozemail.com.au>
Cc: bug-followup@freebsd.org
Subject: Re: kern/78987: udf fs: readdir returns error when it should not
Date: Mon, 19 Jan 2009 14:40:25 +0200

 on 19/01/2009 14:24 Robert Jenssen said the following:
 > Hi,
 > 
 > To echo Andriy:
 > 
 > This problem is still present in 7.1.
 > The same patch is applicable. 
 > Unfortunately, Andriy's patch doesn't seem to be a complete solution. I 
 > happened to make a DL-DVD having a directory with 640 JPGs. Without the patch 
 > I get the error message "kernel: uiomove returned -1" when I ls that 
 > directory. With Andriy's patch "ls" sees the first 67 files. 
 > Interestingly, "ls -al" reports the first 23 files as expected but then for 
 > files 24 to 67 says "Input/output error". I had no problems reading this DVD 
 > on WinXP or Centos5-2. I'd be happy to look further.
 
 Please try the patch in:
 http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/120989
 
 It has more fixes plus enhancements for features and performance.
 
 -- 
 Andriy Gapon

From: Robert Jenssen <robertjenssen@ozemail.com.au>
To: bug-followup@freebsd.org,
 avg@icyb.net.ua
Cc:  
Subject: Re: kern/78987: udf fs: readdir returns error when it should not
Date: Mon, 19 Jan 2009 23:24:33 +1100

 Hi,
 
 To echo Andriy:
 
 This problem is still present in 7.1.
 The same patch is applicable. 
 
 Unfortunately, Andriy's patch doesn't seem to be a complete solution. I 
 happened to make a DL-DVD having a directory with 640 JPGs. Without the patch 
 I get the error message "kernel: uiomove returned -1" when I ls that 
 directory. With Andriy's patch "ls" sees the first 67 files. 
 Interestingly, "ls -al" reports the first 23 files as expected but then for 
 files 24 to 67 says "Input/output error". I had no problems reading this DVD 
 on WinXP or Centos5-2. I'd be happy to look further.
 
 Rob Jenssen

From: Robert Jenssen <robertjenssen@ozemail.com.au>
To: Andriy Gapon <avg@icyb.net.ua>
Cc: bug-followup@freebsd.org
Subject: Re: kern/78987: udf fs: readdir returns error when it should not   kern/120989: [udf] [patch] UDF (with DVD RAM) isn't mountable/readable
Date: Tue, 20 Jan 2009 10:35:53 +1100

 On Mon, 19 Jan 2009 11:40:25 pm Andriy Gapon wrote:
 > on 19/01/2009 14:24 Robert Jenssen said the following:
 > > Hi,
 > > 
 > > To echo Andriy:
 > > 
 > > This problem is still present in 7.1.
 > > The same patch is applicable. 
 > > Unfortunately, Andriy's patch doesn't seem to be a complete solution. I 
 > > happened to make a DL-DVD having a directory with 640 JPGs. Without the 
 patch 
 > > I get the error message "kernel: uiomove returned -1" when I ls that 
 > > directory. With Andriy's patch "ls" sees the first 67 files. 
 > > Interestingly, "ls -al" reports the first 23 files as expected but then 
 for 
 > > files 24 to 67 says "Input/output error". I had no problems reading this 
 DVD 
 > > on WinXP or Centos5-2. I'd be happy to look further.
 > 
 > Please try the patch in:
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/120989
 > 
 > It has more fixes plus enhancements for features and performance.
 > 
 > -- 
 > Andriy Gapon
 > 
 
 Thanks Andriy. I applied the patch and can now see the entire directory.
 
 Rob Jenssen

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/78987: commit references a PR
Date: Thu, 19 Feb 2009 15:05:42 +0000 (UTC)

 Author: avg
 Date: Thu Feb 19 15:05:30 2009
 New Revision: 188815
 URL: http://svn.freebsd.org/changeset/base/188815
 
 Log:
   fs/udf: fix incorrect error return (-1) when reading a large dir
   
   Not enough space in user-land buffer is not an error, userland
   will read further until eof is reached. So instead of propagating
   -1 to caller we convert it to zero/success.
   
   cd9660 code works exactly the same way.
   
   PR:		kern/78987
   Reviewed by:	jhb (mentor)
   Approved by:	jhb (mentor)
 
 Modified:
   head/sys/fs/udf/udf_vnops.c
 
 Modified: head/sys/fs/udf/udf_vnops.c
 ==============================================================================
 --- head/sys/fs/udf/udf_vnops.c	Thu Feb 19 14:39:52 2009	(r188814)
 +++ head/sys/fs/udf/udf_vnops.c	Thu Feb 19 15:05:30 2009	(r188815)
 @@ -831,17 +831,16 @@ udf_readdir(struct vop_readdir_args *a)
  			error = udf_uiodir(&uiodir, dir.d_reclen, uio,
  			    ds->this_off);
  		}
 -		if (error) {
 -			printf("uiomove returned %d\n", error);
 +		if (error)
  			break;
 -		}
 -
  	}
  
  	/* tell the calling layer whether we need to be called again */
  	*a->a_eofflag = uiodir.eofflag;
  	uio->uio_offset = ds->offset + ds->off;
  
 +	if(error < 0)
 +		error = 0;
  	if (!error)
  		error = ds->error;
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: gavin 
State-Changed-When: Mon Mar 23 13:34:42 UTC 2009 
State-Changed-Why:  
This has been fixed in HEAD and merged to 7.x (confirmed by avg on IRC) 

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