When implementing "read directory", when there are too many empty entries

in a row, and we need to try to read the next block, and have passed a
non-NULL cookie pointer to VOP_READDIR, ensure that we free the cookie
buffer before re-doing VOP_READDIR, so that we don't leak memory.
This fix is similar to nfs_serv.c revisions 1.115 + 1.124.

This should fix the long-standing problem observed by e.g. using Linux-
emulated programs to take backup of servers, which is one of the problems
which were reported in PR#42661.

Thanks to pooka@ for the hints for traversing the VOP* layer.
This commit is contained in:
he 2010-03-03 08:20:38 +00:00
parent 513fda32eb
commit 7a30544200
11 changed files with 97 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls_30.c,v 1.30 2009/01/26 13:00:04 njoly Exp $ */
/* $NetBSD: vfs_syscalls_30.c,v 1.31 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_30.c,v 1.30 2009/01/26 13:00:04 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_30.c,v 1.31 2010/03/03 08:20:38 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -305,8 +305,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG(uap, buf))
if (outp == SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_misc.c,v 1.109 2009/11/04 21:23:02 rmind Exp $ */
/* $NetBSD: ibcs2_misc.c,v 1.110 2010/03/03 08:20:39 he Exp $ */
/*
* Copyright (c) 1992, 1993
@ -95,7 +95,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.109 2009/11/04 21:23:02 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.110 2010/03/03 08:20:39 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -472,8 +472,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG(uap, buf))
if (outp == SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:
@ -602,8 +606,12 @@ again:
resid -= ibcs2_reclen;
}
/* if we squished out the whole block, try again */
if (outp == SCARG(uap, buf))
if (outp == SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:
*retval = SCARG(uap, nbytes) - resid;

View File

@ -1,4 +1,4 @@
/* $NetBSD: irix_dirent.c,v 1.23 2008/04/28 20:23:41 martin Exp $ */
/* $NetBSD: irix_dirent.c,v 1.24 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 1994, 2001, 2008 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_dirent.c,v 1.23 2008/04/28 20:23:41 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_dirent.c,v 1.24 2010/03/03 08:20:38 he Exp $");
#include <sys/types.h>
#include <sys/signal.h>
@ -173,8 +173,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (char *)SCARG(uap, buf))
if (outp == (char *)SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:
@ -324,8 +328,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (char *)SCARG(uap, buf))
if (outp == (char *)SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_file64.c,v 1.49 2009/05/15 17:02:54 pooka Exp $ */
/* $NetBSD: linux_file64.c,v 1.50 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 1995, 1998, 2000, 2008 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.49 2009/05/15 17:02:54 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.50 2010/03/03 08:20:38 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -336,8 +336,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (void *)SCARG(uap, dent))
if (outp == (void *)SCARG(uap, dent)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_misc.c,v 1.213 2009/12/05 20:11:17 pooka Exp $ */
/* $NetBSD: linux_misc.c,v 1.214 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.213 2009/12/05 20:11:17 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.214 2010/03/03 08:20:38 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -803,8 +803,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (void *)SCARG(uap, dent))
if (outp == (void *)SCARG(uap, dent)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
if (oldcall)

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux32_dirent.c,v 1.9 2009/07/22 15:49:29 njoly Exp $ */
/* $NetBSD: linux32_dirent.c,v 1.10 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux32_dirent.c,v 1.9 2009/07/22 15:49:29 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux32_dirent.c,v 1.10 2010/03/03 08:20:38 he Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -229,8 +229,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (void *)SCARG_P32(uap, dent))
if (outp == (void *)SCARG_P32(uap, dent)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
if (oldcall)

View File

@ -1,4 +1,4 @@
/* $NetBSD: osf1_file.c,v 1.37 2009/08/09 22:49:01 haad Exp $ */
/* $NetBSD: osf1_file.c,v 1.38 2010/03/03 08:20:38 he Exp $ */
/*
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: osf1_file.c,v 1.37 2009/08/09 22:49:01 haad Exp $");
__KERNEL_RCSID(0, "$NetBSD: osf1_file.c,v 1.38 2010/03/03 08:20:38 he Exp $");
#if defined(_KERNEL_OPT)
#include "opt_syscall_debug.h"
@ -232,8 +232,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (char *)SCARG(uap, buf))
if (outp == (char *)SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos_misc.c,v 1.165 2009/06/29 05:08:16 dholland Exp $ */
/* $NetBSD: sunos_misc.c,v 1.166 2010/03/03 08:20:39 he Exp $ */
/*
* Copyright (c) 1992, 1993
@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.165 2009/06/29 05:08:16 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.166 2010/03/03 08:20:39 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -459,8 +459,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG(uap, buf))
if (outp == SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos32_misc.c,v 1.68 2010/03/02 21:09:21 pooka Exp $ */
/* $NetBSD: sunos32_misc.c,v 1.69 2010/03/03 08:20:39 he Exp $ */
/* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp */
/*
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.68 2010/03/02 21:09:21 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.69 2010/03/03 08:20:39 he Exp $");
#define COMPAT_SUNOS 1
@ -696,8 +696,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG_P32(uap, buf))
if (outp == SCARG_P32(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_misc.c,v 1.148 2009/11/05 18:39:38 rafal Exp $ */
/* $NetBSD: svr4_misc.c,v 1.149 2010/03/03 08:20:38 he Exp $ */
/*-
* Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.148 2009/11/05 18:39:38 rafal Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.149 2010/03/03 08:20:38 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -304,8 +304,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == (char *) SCARG(uap, dp))
if (outp == (char *) SCARG(uap, dp)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:
@ -425,8 +429,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG(uap, buf))
if (outp == SCARG(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_32_misc.c,v 1.67 2009/11/05 18:39:38 rafal Exp $ */
/* $NetBSD: svr4_32_misc.c,v 1.68 2010/03/03 08:20:39 he Exp $ */
/*-
* Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.67 2009/11/05 18:39:38 rafal Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.68 2010/03/03 08:20:39 he Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -304,8 +304,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG_P32(uap, dp))
if (outp == SCARG_P32(uap, dp)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof:
@ -425,8 +429,12 @@ again:
}
/* if we squished out the whole block, try again */
if (outp == SCARG_P32(uap, buf))
if (outp == SCARG_P32(uap, buf)) {
if (cookiebuf)
free(cookiebuf, M_TEMP);
cookiebuf = NULL;
goto again;
}
fp->f_offset = off; /* update the vnode offset */
eof: