NetBSD Problem Report #1124
From gnats Wed Jun 7 18:26:07 1995
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.10/8.6.10) with ESMTP id SAA15208 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Wed, 7 Jun 1995 18:26:07 -0700
Message-Id: <199506080006.UAA00401@kolvir.blrc.ma.us>
Date: Wed, 7 Jun 1995 20:06:36 -0400
From: John Kohl <jtk@kolvir.blrc.ma.us>
Reply-To: jtk@kolvir.blrc.ma.us
To: gnats-bugs@NetBSD.ORG
Subject: more union FS bugs (kernel traps on null VP references)
X-Send-Pr-Version: 3.2
>Number: 1124
>Category: kern
>Synopsis: union FS can deref null vnode pointer
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Jun 07 18:35:02 +0000 1995
>Closed-Date: Tue Jun 27 01:16:26 +0000 1995
>Last-Modified:
>Originator: John Kohl
>Release: -current, 06 June 1995
>Organization:
NetBSD Kernel Hackers `R` Us
>Environment:
System: NetBSD kolvir 1.0A NetBSD 1.0A (KOLVIR) #465: Wed Jun 7 19:51:11 EDT 1995 jtk@kolvir:/u1/NetBSD-current/src/sys/arch/i386/compile/KOLVIR i386
>Description:
The union file system can dereference a null vnode pointer. It happens
when there is no lower layer vnode (usually when the top file layer is
the only one with that file, e.g. an object file), and that file is
removed while another process has the file open.
>How-To-Repeat:
0) mount a union FS. Go to a place with a file that exists only in the
upper layer.
choose 1 or 2:
1) cat the file, suspend the cat. remove the file. kill the cat.
watch the kernel die in union_close().
2) cat the file, put it in the background. remove the file. watch the
kernel die in union_read().
>Fix:
This seems to do the trick. I'm not happy with the need to forcibly
remove the vnode out from under a process--this means that the 'cat'
command gets an error back from read rather than keeping a reference to
the real vnode.
ALSO, note there's a bug fix in here. As currently coded,
union_removed_upper() will trap on a null deref if UN_ULOCK is set on
the union node passed to it, because it removes the upper vnode before
calling the unlock routine. In the diffs below I just hold onto the
vnode separately and vput() it when UN_ULOCK is set.
Maybe instead of these diffs the union layer should just uncache the
union node and hold the uppervp referenced until the vnode is closed?
(Can it set a reclaim-on-inactivation flag to force a reclaim when it's
done being active?)
===================================================================
RCS file: RCS/union_subr.c,v
retrieving revision 1.1
diff -c -r1.1 union_subr.c
*** union_subr.c 1995/06/07 23:18:03 1.1
--- union_subr.c 1995/06/07 23:49:54
***************
*** 941,950 ****
--- 941,976 ----
return (VOP_CLOSE(vp, fmode, cred, p));
}
+ /*
+ * You can't rely on the union node existing after this call, because
+ * it may be a pair of NULLVPs and thus disappear.
+ *
+ * All the callers in union_vnops.c (so far) do not reference it after their
+ * calls here.
+ */
void
union_removed_upper(un)
struct union_node *un;
{
+ struct vnode *uvp = un->un_uppervp;
+
+ /*
+ * forcibly revoke any users of this node if we have no hope of
+ * doing anything useful with it (i.e. both vnodes would be NULLVP).
+ * We must do this without setting uppervp to NULLVP, otherwise
+ * we might block waiting for someone else to finish using the
+ * node and they'd trip over the doubly-null union node.
+ */
+ if (un->un_lowervp == NULLVP) {
+ if (un->un_flags & UN_ULOCK) {
+ un->un_flags &= ~UN_ULOCK;
+ VOP_UNLOCK(uvp);
+ }
+ vgone(UNIONTOV(un));
+ return;
+ }
+
+ VREF(uvp); /* hold in case needed for unlock */
union_newupper(un, NULLVP);
union_diruncache(un);
***************
*** 956,963 ****
if (un->un_flags & UN_ULOCK) {
un->un_flags &= ~UN_ULOCK;
! VOP_UNLOCK(un->un_uppervp);
! }
}
#if 0
--- 982,991 ----
if (un->un_flags & UN_ULOCK) {
un->un_flags &= ~UN_ULOCK;
! vput(uvp);
! } else
! vrele(uvp);
!
}
#if 0
===================================================================
RCS file: RCS/union_vnops.c,v
retrieving revision 1.8
diff -c -r1.8 union_vnops.c
*** union_vnops.c 1995/06/01 23:01:52 1.8
--- union_vnops.c 1995/06/07 23:24:50
***************
*** 580,585 ****
--- 580,591 ----
--un->un_openl;
vp = un->un_lowervp;
}
+ /*
+ * A stranded union node may end up here with both vnodes NULL,
+ * in which case we don't do anything.
+ */
+ if (vp == NULLVP)
+ return 0;
ap->a_vp = vp;
return (VCALL(vp, VOFFSET(vop_close), ap));
>Release-Note:
>Audit-Trail:
From: John Kohl <jtk@atria.com>
To: gnats-bugs@netbsd.org
Subject: Re: kern/1124: union FS can deref null vnode pointer
Date: Thu, 8 Jun 1995 08:41:17 -0400
Please don't apply the first set of patches here.
I'll work on new patches that don't revoke the vnode (and thereby break
semantics) but instead hold it in some sort of limbo state, so that it
can't be found by new requests, until it is deactivated.
==John
From: John Kohl <jtk@kolvir.blrc.ma.us>
To: gnats-bugs@NetBSD.ORG
Subject: Re: kern/1124: more union FS bugs (kernel traps on null VP references)
Date: Thu, 15 Jun 1995 21:36:44 -0400
Here is a much more proper patch for the null VP reference union FS bug.
==John
===================================================================
RCS file: RCS/union_subr.c,v
retrieving revision 1.1
diff -c -r1.1 union_subr.c
*** union_subr.c 1995/06/07 23:18:03 1.1
--- union_subr.c 1995/06/16 01:21:07
***************
*** 945,952 ****
union_removed_upper(un)
struct union_node *un;
{
-
- union_newupper(un, NULLVP);
union_diruncache(un);
if (un->un_flags & UN_CACHED) {
--- 945,950 ----
***************
*** 958,963 ****
--- 956,971 ----
un->un_flags &= ~UN_ULOCK;
VOP_UNLOCK(un->un_uppervp);
}
+ /*
+ * When lowervp is NULLVP, this routine would end up creating
+ * a bogus union node with no upper or lower VP (that causes
+ * heartache in many places that assume at least on VP
+ * exists). Since we've removed this node from the cache
+ * hash chains, it won't be found again. When all current holders
+ * release it, union_inactive() will vgone() it.
+ */
+ if (un->un_lowervp != NULLVP)
+ union_newupper(un, NULLVP);
}
#if 0
===================================================================
RCS file: RCS/union_vnops.c,v
retrieving revision 1.1.2.2
diff -c -r1.1.2.2 union_vnops.c
*** union_vnops.c 1995/06/01 23:00:52 1.1.2.2
--- union_vnops.c 1995/06/16 01:22:49
***************
***************
*** 537,542 ****
--- 580,595 ----
--un->un_openl;
vp = un->un_lowervp;
}
+ #ifdef UNION_DIAGNOSTIC
+ /*
+ * A stranded union node may end up here with both vnodes NULL,
+ * in which case we don't do anything.
+ */
+ if (vp == NULLVP) {
+ vprint("empty union vnode", vp);
+ panic("union_close empty vnode");
+ }
+ #endif
ap->a_vp = vp;
return (VCALL(vp, VOFFSET(vop_close), ap));
From: "Charles M. Hannum" <mycroft@ai.mit.edu>
To: jtk@kolvir.blrc.ma.us
Subject: Re: kern/1124: more union FS bugs (kernel traps on null VP references)
Date: Fri, 16 Jun 1995 00:12:34 -0400
Here is a much more proper patch for the null VP reference union FS bug.
[...]
+ if (un->un_lowervp != NULLVP)
+ union_newupper(un, NULLVP);
This doesn't strike me as completely correct, either. In the case
where lowervp is not NULL, you're essentially changing the currently
open file descriptions to point to the lower node rather than the
upper one. They should continue to point to the upper one until it is
deactivated.
From: John Kohl <jtk@kolvir.blrc.ma.us>
To: mycroft@ai.mit.edu
Subject: Re: kern/1124: more union FS bugs (kernel traps on null VP references)
Date: Fri, 16 Jun 1995 00:54:38 -0400
>>>>> "CH" == Charles M Hannum <mycroft@ai.mit.edu> writes:
CH> [...]
CH> + if (un->un_lowervp != NULLVP)
CH> + union_newupper(un, NULLVP);
CH> This doesn't strike me as completely correct, either. In the case
CH> where lowervp is not NULL, you're essentially changing the currently
CH> open file descriptions to point to the lower node rather than the
CH> upper one. They should continue to point to the upper one until it is
CH> deactivated.
A good point. To do this, you can just remove that quoted `if'
statement and the call to union_newupper. Since the node won't be on
cache hash chains, it still won't be found by other activations and any
existing refs to the node will continue to access what they were using.
As described in my comment and as implemented in union_inactive(), the
vnode will vanish when unreferenced.
==John
State-Changed-From-To: open->closed
State-Changed-By: gwr
State-Changed-When: Mon Jun 26 21:16:26 EDT 1995
State-Changed-Why:
Applied the latest-and-greated patches discussed by Charles Hannum
and John Kohl. (Tested and committed by Gordon Ross.)
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.