fixup locking for UNMNT_BELOW.
SCCS-vsn: sys/miscfs/union/union.h 8.2
SCCS-vsn: sys/miscfs/union/union_subr.c 8.4
SCCS-vsn: sys/miscfs/union/union_vnops.c 8.6
SCCS-vsn: sys/miscfs/union/union_vfsops.c 8.4
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)union.h 8.1 (Berkeley) %G%
+ * @(#)union.h 8.2 (Berkeley) %G%
struct vnode *um_lowervp;
struct ucred *um_cred; /* Credentials of user calling mount */
int um_cmode; /* cmask from mount process */
struct vnode *um_lowervp;
struct ucred *um_cred; /* Credentials of user calling mount */
int um_cmode; /* cmask from mount process */
+ int um_op; /* Operation mode */
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)union_subr.c 8.3 (Berkeley) %G%
+ * @(#)union_subr.c 8.4 (Berkeley) %G%
*/
#include <sys/param.h>
*/
#include <sys/param.h>
cn.cn_nameiop = CREATE;
cn.cn_flags = (LOCKPARENT|HASBUF|SAVENAME|SAVESTART|ISLASTCN);
cn.cn_proc = cnp->cn_proc;
cn.cn_nameiop = CREATE;
cn.cn_flags = (LOCKPARENT|HASBUF|SAVENAME|SAVESTART|ISLASTCN);
cn.cn_proc = cnp->cn_proc;
- cn.cn_cred = um->um_cred;
+ if (um->um_op == UNMNT_ABOVE)
+ cn.cn_cred = cnp->cn_cred;
+ else
+ cn.cn_cred = um->um_cred;
cn.cn_nameptr = cn.cn_pnbuf;
cn.cn_namelen = cnp->cn_namelen;
cn.cn_hash = cnp->cn_hash;
cn.cn_nameptr = cn.cn_pnbuf;
cn.cn_namelen = cnp->cn_namelen;
cn.cn_hash = cnp->cn_hash;
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)union_vfsops.c 8.3 (Berkeley) %G%
+ * @(#)union_vfsops.c 8.4 (Berkeley) %G%
struct vnode *upperrootvp = NULLVP;
struct union_mount *um;
struct ucred *cred = 0;
struct vnode *upperrootvp = NULLVP;
struct union_mount *um;
struct ucred *cred = 0;
char *cp;
int len;
u_int size;
char *cp;
int len;
u_int size;
* mounted-on directory. This allows the mount_union
* command to be made setuid root so allowing anyone
* to do union mounts onto any directory on which they
* mounted-on directory. This allows the mount_union
* command to be made setuid root so allowing anyone
* to do union mounts onto any directory on which they
- * have write permission.
+ * have write (also delete and rename) permission.
*/
error = VOP_ACCESS(mp->mnt_vnodecovered, VWRITE, cred, p);
if (error)
goto bad;
*/
error = VOP_ACCESS(mp->mnt_vnodecovered, VWRITE, cred, p);
if (error)
goto bad;
+ error = VOP_GETATTR(mp->mnt_vnodecovered, &va, cred, p);
+ if (error)
+ goto bad;
+ if ((va.va_mode & VSVTX) &&
+ (va.va_uid != 0) &&
+ (va.va_uid != cred->cr_uid)) {
+ error = EACCES;
+ goto bad;
+ }
* same as providing a mount under option to the mount syscall.
*/
* same as providing a mount under option to the mount syscall.
*/
- switch (args.mntflags & UNMNT_OPMASK) {
+ um->um_op = args.mntflags & UNMNT_OPMASK;
+ switch (um->um_op) {
case UNMNT_ABOVE:
um->um_lowervp = lowerrootvp;
um->um_uppervp = upperrootvp;
case UNMNT_ABOVE:
um->um_lowervp = lowerrootvp;
um->um_uppervp = upperrootvp;
* flag implies that some of the files might be stored locally
* then you will want to change the conditional.
*/
* flag implies that some of the files might be stored locally
* then you will want to change the conditional.
*/
- if (((um->um_lowervp == NULLVP) ||
- (um->um_lowervp->v_mount->mnt_flag & MNT_LOCAL)) &&
- (um->um_uppervp->v_mount->mnt_flag & MNT_LOCAL))
- mp->mnt_flag |= MNT_LOCAL;
+ if (um->um_op == UNMNT_ABOVE) {
+ if (((um->um_lowervp == NULLVP) ||
+ (um->um_lowervp->v_mount->mnt_flag & MNT_LOCAL)) &&
+ (um->um_uppervp->v_mount->mnt_flag & MNT_LOCAL))
+ mp->mnt_flag |= MNT_LOCAL;
+ }
/*
* Copy in the upper layer's RDONLY flag. This is for the benefit
/*
* Copy in the upper layer's RDONLY flag. This is for the benefit
(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
- switch (args.mntflags & UNMNT_OPMASK) {
case UNMNT_ABOVE:
cp = "un-above:";
break;
case UNMNT_ABOVE:
cp = "un-above:";
break;
{
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
int error;
{
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
int error;
#ifdef UNION_DIAGNOSTIC
printf("union_root(mp = %x, lvp = %x, uvp = %x)\n", mp,
#ifdef UNION_DIAGNOSTIC
printf("union_root(mp = %x, lvp = %x, uvp = %x)\n", mp,
* Return locked reference to root.
*/
VREF(um->um_uppervp);
* Return locked reference to root.
*/
VREF(um->um_uppervp);
- VOP_LOCK(um->um_uppervp);
+ if ((um->um_op == UNMNT_BELOW) &&
+ VOP_ISLOCKED(um->um_uppervp)) {
+ loselock = 1;
+ } else {
+ VOP_LOCK(um->um_uppervp);
+ loselock = 0;
+ }
if (um->um_lowervp)
VREF(um->um_lowervp);
error = union_allocvp(vpp, mp,
if (um->um_lowervp)
VREF(um->um_lowervp);
error = union_allocvp(vpp, mp,
um->um_lowervp);
if (error) {
um->um_lowervp);
if (error) {
+ if (!loselock)
+ VOP_UNLOCK(um->um_uppervp);
vrele(um->um_uppervp);
if (um->um_lowervp)
vrele(um->um_lowervp);
} else {
(*vpp)->v_flag |= VROOT;
vrele(um->um_uppervp);
if (um->um_lowervp)
vrele(um->um_lowervp);
} else {
(*vpp)->v_flag |= VROOT;
+ if (loselock)
+ VTOUNION(*vpp)->un_flags &= ~UN_ULOCK;
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)union_vnops.c 8.5 (Berkeley) %G%
+ * @(#)union_vnops.c 8.6 (Berkeley) %G%
*/
#include <sys/param.h>
*/
#include <sys/param.h>
#include <sys/queue.h>
#include <miscfs/union/union.h>
#include <sys/queue.h>
#include <miscfs/union/union.h>
+#define FIXUP(un) { \
+ if (((un)->un_flags & UN_ULOCK) == 0) { \
+ union_fixup(un); \
+ } \
+}
+
+static void
+union_fixup(un)
+ struct union_node *un;
+{
+
+ VOP_LOCK(un->un_uppervp);
+ un->un_flags |= UN_ULOCK;
+}
+
static int
union_lookup1(udvp, dvp, vpp, cnp)
struct vnode *udvp;
static int
union_lookup1(udvp, dvp, vpp, cnp)
struct vnode *udvp;
int lockparent = cnp->cn_flags & LOCKPARENT;
int rdonly = cnp->cn_flags & RDONLY;
struct union_mount *um = MOUNTTOUNIONMOUNT(dvp->v_mount);
int lockparent = cnp->cn_flags & LOCKPARENT;
int rdonly = cnp->cn_flags & RDONLY;
struct union_mount *um = MOUNTTOUNIONMOUNT(dvp->v_mount);
+ struct ucred *saved_cred;
cnp->cn_flags |= LOCKPARENT;
cnp->cn_flags |= LOCKPARENT;
* on and just return that vnode.
*/
if (upperdvp) {
* on and just return that vnode.
*/
if (upperdvp) {
uerror = union_lookup1(um->um_uppervp, upperdvp,
&uppervp, cnp);
/*if (uppervp == upperdvp)
uerror = union_lookup1(um->um_uppervp, upperdvp,
&uppervp, cnp);
/*if (uppervp == upperdvp)
*/
nameiop = cnp->cn_nameiop;
cnp->cn_nameiop = LOOKUP;
*/
nameiop = cnp->cn_nameiop;
cnp->cn_nameiop = LOOKUP;
+ if (um->um_op == UNMNT_BELOW) {
+ saved_cred = cnp->cn_cred;
+ cnp->cn_cred = um->um_cred;
+ }
lerror = union_lookup1(um->um_lowervp, lowerdvp,
&lowervp, cnp);
lerror = union_lookup1(um->um_lowervp, lowerdvp,
&lowervp, cnp);
+ if (um->um_op == UNMNT_BELOW)
+ cnp->cn_cred = saved_cred;
cnp->cn_nameiop = nameiop;
if (lowervp != lowerdvp)
cnp->cn_nameiop = nameiop;
if (lowervp != lowerdvp)
int error;
struct vnode *vp;
int error;
struct vnode *vp;
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
int error;
struct vnode *vp;
int error;
struct vnode *vp;
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
if (!error)
uprintf("union: copied up %s\n",
un->un_path);
if (!error)
uprintf("union: copied up %s\n",
un->un_path);
}
un->un_flags &= ~UN_ULOCK;
}
un->un_flags &= ~UN_ULOCK;
error = VOP_OPEN(tvp, mode, cred, p);
return (error);
error = VOP_OPEN(tvp, mode, cred, p);
return (error);
int error = EACCES;
struct vnode *vp;
int error = EACCES;
struct vnode *vp;
+ if (vp = un->un_uppervp) {
+ FIXUP(un);
+ return (VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p));
+ }
+
if (vp = un->un_lowervp) {
VOP_LOCK(vp);
error = VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p);
if (vp = un->un_lowervp) {
VOP_LOCK(vp);
error = VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p);
+ if (error == 0) {
+ struct union_mount *um = MOUNTTOUNIONMOUNT(vp->v_mount);
+
+ if (um->um_op == UNMNT_BELOW)
+ error = VOP_ACCESS(vp, ap->a_mode,
+ um->um_cred, ap->a_p);
+ }
VOP_UNLOCK(vp);
if (error)
return (error);
}
VOP_UNLOCK(vp);
if (error)
return (error);
}
- if (vp = un->un_uppervp)
- error = VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p);
-
vp = un->un_uppervp;
if (vp != NULLVP) {
vp = un->un_uppervp;
if (vp != NULLVP) {
error = VOP_GETATTR(vp, vap, ap->a_cred, ap->a_p);
if (error)
return (error);
error = VOP_GETATTR(vp, vap, ap->a_cred, ap->a_p);
if (error)
return (error);
* otherwise return read-only filesystem error.
*/
if (un->un_uppervp != NULLVP) {
* otherwise return read-only filesystem error.
*/
if (un->un_uppervp != NULLVP) {
error = VOP_SETATTR(un->un_uppervp, ap->a_vap,
ap->a_cred, ap->a_p);
} else {
error = VOP_SETATTR(un->un_uppervp, ap->a_vap,
ap->a_cred, ap->a_p);
} else {
if (dolock)
VOP_LOCK(vp);
if (dolock)
VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_READ(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
error = VOP_READ(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
if (dolock)
VOP_LOCK(vp);
if (dolock)
VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
if (dolock)
VOP_LOCK(targetvp);
if (dolock)
VOP_LOCK(targetvp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_FSYNC(targetvp, ap->a_cred,
ap->a_waitfor, ap->a_p);
if (dolock)
error = VOP_FSYNC(targetvp, ap->a_cred,
ap->a_waitfor, ap->a_p);
if (dolock)
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(vp);
un->un_flags |= UN_KLOCK;
vput(ap->a_vp);
VREF(vp);
un->un_flags |= UN_KLOCK;
vput(ap->a_vp);
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_vp);
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_vp);
VREF(vp);
vrele(ap->a_tdvp);
VREF(vp);
vrele(ap->a_tdvp);
fdvp = un->un_uppervp;
VREF(fdvp);
vrele(ap->a_fdvp);
fdvp = un->un_uppervp;
VREF(fdvp);
vrele(ap->a_fdvp);
fvp = un->un_uppervp;
VREF(fvp);
vrele(ap->a_fvp);
fvp = un->un_uppervp;
VREF(fvp);
vrele(ap->a_fvp);
int error;
struct vnode *vp;
int error;
struct vnode *vp;
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
struct vnode *dvp = dun->un_uppervp;
struct vnode *vp = un->un_uppervp;
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
dun->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(vp);
un->un_flags |= UN_KLOCK;
vput(ap->a_vp);
VREF(vp);
un->un_flags |= UN_KLOCK;
vput(ap->a_vp);
struct vnode *vp;
struct mount *mp = ap->a_dvp->v_mount;
struct vnode *vp;
struct mount *mp = ap->a_dvp->v_mount;
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
VREF(dvp);
un->un_flags |= UN_KLOCK;
vput(ap->a_dvp);
int error = 0;
struct union_node *un = VTOUNION(ap->a_vp);
int error = 0;
struct union_node *un = VTOUNION(ap->a_vp);
+ if (un->un_uppervp) {
+ FIXUP(un);
error = VOP_READDIR(un->un_uppervp, ap->a_uio, ap->a_cred);
error = VOP_READDIR(un->un_uppervp, ap->a_uio, ap->a_cred);
if (dolock)
VOP_LOCK(vp);
if (dolock)
VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_READLINK(vp, ap->a_uio, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
error = VOP_READLINK(vp, ap->a_uio, ap->a_cred);
if (dolock)
VOP_UNLOCK(vp);
int islocked = un->un_flags & UN_LOCKED;
int dolock = (vp == LOWERVP(ap->a_dvp));
int islocked = un->un_flags & UN_LOCKED;
int dolock = (vp == LOWERVP(ap->a_dvp));
- if (islocked && dolock)
- VOP_LOCK(vp);
+ if (islocked) {
+ if (dolock)
+ VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_dvp));
+ }
error = VOP_ABORTOP(vp, ap->a_cnp);
if (islocked && dolock)
VOP_UNLOCK(vp);
error = VOP_ABORTOP(vp, ap->a_cnp);
if (islocked && dolock)
VOP_UNLOCK(vp);
if (dolock)
VOP_LOCK(vp);
if (dolock)
VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_BMAP(vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp);
if (dolock)
VOP_UNLOCK(vp);
error = VOP_BMAP(vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp);
if (dolock)
VOP_UNLOCK(vp);
if (dolock)
VOP_LOCK(vp);
if (dolock)
VOP_LOCK(vp);
+ else
+ FIXUP(VTOUNION(ap->a_vp));
error = VOP_PATHCONF(vp, ap->a_name, ap->a_retval);
if (dolock)
VOP_UNLOCK(vp);
error = VOP_PATHCONF(vp, ap->a_name, ap->a_retval);
if (dolock)
VOP_UNLOCK(vp);