summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/man9/vnsubr.923
-rw-r--r--sys/arch/sparc64/dev/vdsp.c4
-rw-r--r--sys/dev/usb/uvideo.c4
-rw-r--r--sys/dev/vnd.c4
-rw-r--r--sys/kern/kern_acct.c4
-rw-r--r--sys/kern/kern_ktrace.c4
-rw-r--r--sys/kern/kern_sig.c5
-rw-r--r--sys/kern/vfs_syscalls.c4
-rw-r--r--sys/kern/vfs_vnops.c22
-rw-r--r--sys/ufs/ufs/ufs_quota.c4
10 files changed, 53 insertions, 25 deletions
diff --git a/share/man/man9/vnsubr.9 b/share/man/man9/vnsubr.9
index f836e377a55..fd0740549b2 100644
--- a/share/man/man9/vnsubr.9
+++ b/share/man/man9/vnsubr.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vnsubr.9,v 1.14 2018/05/02 02:24:55 visa Exp $
+.\" $OpenBSD: vnsubr.9,v 1.15 2019/10/06 16:24:14 beck Exp $
.\" $NetBSD: vnsubr.9,v 1.21 2004/05/25 14:54:56 hannken Exp $
.\"
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 2 2018 $
+.Dd $Mdocdate: October 6 2019 $
.Dt VNSUBR 9
.Os
.Sh NAME
@@ -148,10 +148,25 @@ Common code to mark the vnode
as being the text of a running process.
.It Fn vn_open "ndp" "fmode" "cmode"
Common code for vnode open operations.
+.Pp
The pathname is described in the
.Vt nameidata
-pointer (see
-.Xr namei 9 ) .
+structure pointed to by the
+.Fa ndp
+argument.
+When initializing the nameidata structure for
+.Fn vn_open
+with
+.Xr NDINIT 9 ,
+The
+.Fa op
+must be specified as 0, and the
+.Fa flags
+may only be 0, or KERNELPATH.
+The lookup mode and flags are set internally
+by
+.Fn vn_open .
+.Pp
The arguments
.Fa fmode
and
diff --git a/sys/arch/sparc64/dev/vdsp.c b/sys/arch/sparc64/dev/vdsp.c
index 9d50c2ffe18..189eec982f3 100644
--- a/sys/arch/sparc64/dev/vdsp.c
+++ b/sys/arch/sparc64/dev/vdsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vdsp.c,v 1.45 2018/05/02 02:24:55 visa Exp $ */
+/* $OpenBSD: vdsp.c,v 1.46 2019/10/06 16:24:14 beck Exp $ */
/*
* Copyright (c) 2009, 2011, 2014 Mark Kettenis
*
@@ -918,7 +918,7 @@ vdsp_open(void *arg1)
if (name == NULL)
return;
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
+ NDINIT(&nd, 0, 0, UIO_SYSSPACE, name, p);
error = vn_open(&nd, FREAD | FWRITE, 0);
if (error) {
printf("VOP_OPEN: %s, %d\n", name, error);
diff --git a/sys/dev/usb/uvideo.c b/sys/dev/usb/uvideo.c
index a3652d1b164..e5ca9f68c66 100644
--- a/sys/dev/usb/uvideo.c
+++ b/sys/dev/usb/uvideo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvideo.c,v 1.203 2019/08/07 11:16:02 patrick Exp $ */
+/* $OpenBSD: uvideo.c,v 1.204 2019/10/06 16:24:14 beck Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
@@ -2885,7 +2885,7 @@ uvideo_debug_file_open(struct uvideo_softc *sc)
char name[] = "/tmp/uvideo.mjpeg";
int error;
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p);
+ NDINIT(&nd, 0, 0, UIO_SYSSPACE, name, p);
error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW, S_IRUSR | S_IWUSR);
if (error) {
DPRINTF(1, "%s: %s: can't create debug file %s!\n",
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c
index c7ecc9be87e..b5044cc8e57 100644
--- a/sys/dev/vnd.c
+++ b/sys/dev/vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vnd.c,v 1.168 2018/04/28 03:13:04 visa Exp $ */
+/* $OpenBSD: vnd.c,v 1.169 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
@@ -444,7 +444,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
* directories, sockets, etc. so we don't have to worry about
* them.
*/
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vnd_file, p);
+ NDINIT(&nd, 0, 0, UIO_USERSPACE, vio->vnd_file, p);
sc->sc_flags &= ~VNF_READONLY;
error = vn_open(&nd, FREAD|FWRITE, 0);
if (error == EROFS) {
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 7cc5dfd2cbd..6d85501d26a 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_acct.c,v 1.40 2019/08/15 07:29:21 anton Exp $ */
+/* $OpenBSD: kern_acct.c,v 1.41 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */
/*-
@@ -118,7 +118,7 @@ sys_acct(struct proc *p, void *v, register_t *retval)
* writing and make sure it's 'normal'.
*/
if (SCARG(uap, path) != NULL) {
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path),
+ NDINIT(&nd, 0, 0, UIO_USERSPACE, SCARG(uap, path),
p);
if ((error = vn_open(&nd, FWRITE|O_APPEND, 0)) != 0)
return (error);
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 39249d4118c..39bd1183d5b 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_ktrace.c,v 1.99 2018/08/05 14:23:57 beck Exp $ */
+/* $OpenBSD: kern_ktrace.c,v 1.100 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */
/*
@@ -511,7 +511,7 @@ sys_ktrace(struct proc *p, void *v, register_t *retval)
struct nameidata nd;
cred = p->p_ucred;
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fname, p);
+ NDINIT(&nd, 0, 0, UIO_USERSPACE, fname, p);
nd.ni_pledge = PLEDGE_CPATH | PLEDGE_WPATH;
nd.ni_unveil = UNVEIL_CREATE | UNVEIL_WRITE;
if ((error = vn_open(&nd, FWRITE|O_NOFOLLOW, 0)) != 0)
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index ccfec90fb38..2b93e41fac7 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.234 2019/10/03 13:58:59 deraadt Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.235 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -1593,7 +1593,8 @@ coredump(struct proc *p)
cred->cr_gid = 0;
}
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p);
+ /* incrash should be 0 or KERNELPATH only */
+ NDINIT(&nd, 0, incrash, UIO_SYSSPACE, name, p);
error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW | O_NONBLOCK,
S_IRUSR | S_IWUSR);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 975893a171e..23a96822126 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.335 2019/08/31 17:59:33 beck Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.336 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1146,7 +1146,7 @@ doopenat(struct proc *p, int fd, const char *path, int oflags, mode_t mode,
cmode = ((mode &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT;
if ((p->p_p->ps_flags & PS_PLEDGE))
cmode &= ACCESSPERMS;
- NDINITAT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fd, path, p);
+ NDINITAT(&nd, 0, 0, UIO_USERSPACE, fd, path, p);
nd.ni_pledge = ni_pledge;
nd.ni_unveil = ni_unveil;
p->p_dupfd = -1; /* XXX check for fdopen */
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 353fc7a3feb..b4cdf2f06a3 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_vnops.c,v 1.107 2019/08/26 18:56:29 anton Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.108 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
@@ -91,13 +91,26 @@ vn_open(struct nameidata *ndp, int fmode, int cmode)
struct cloneinfo *cip;
int error;
- if ((fmode & (FREAD|FWRITE)) == 0)
+ /*
+ * The only valid flag to pass in here from NDINIT is
+ * KERNELPATH, This function will override the nameiop based
+ * on the fmode and cmode flags, So validate that our caller
+ * has not set other flags or operations in the nameidata
+ * structure.
+ */
+ /* XXX consider changing to KASSERT after release */
+ if (!(ndp->ni_cnd.cn_flags == 0 || ndp->ni_cnd.cn_flags == KERNELPATH))
+ return EINVAL;
+ if (!(ndp->ni_cnd.cn_nameiop == 0))
+ return EINVAL;
+
+ if ((fmode & (FREAD|FWRITE)) == 0)
return (EINVAL);
if ((fmode & (O_TRUNC | FWRITE)) == O_TRUNC)
return (EINVAL);
if (fmode & O_CREAT) {
ndp->ni_cnd.cn_nameiop = CREATE;
- ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
+ ndp->ni_cnd.cn_flags |= LOCKPARENT | LOCKLEAF;
if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
ndp->ni_cnd.cn_flags |= FOLLOW;
if ((error = namei(ndp)) != 0)
@@ -132,8 +145,7 @@ vn_open(struct nameidata *ndp, int fmode, int cmode)
}
} else {
ndp->ni_cnd.cn_nameiop = LOOKUP;
- ndp->ni_cnd.cn_flags =
- ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
+ ndp->ni_cnd.cn_flags |= ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
if ((error = namei(ndp)) != 0)
return (error);
vp = ndp->ni_vp;
diff --git a/sys/ufs/ufs/ufs_quota.c b/sys/ufs/ufs/ufs_quota.c
index 5786222c029..53d27d8b92f 100644
--- a/sys/ufs/ufs/ufs_quota.c
+++ b/sys/ufs/ufs/ufs_quota.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ufs_quota.c,v 1.44 2018/05/27 06:02:15 visa Exp $ */
+/* $OpenBSD: ufs_quota.c,v 1.45 2019/10/06 16:24:14 beck Exp $ */
/* $NetBSD: ufs_quota.c,v 1.8 1996/02/09 22:36:09 christos Exp $ */
/*
@@ -494,7 +494,7 @@ quotaon(struct proc *p, struct mount *mp, int type, caddr_t fname)
#endif
vpp = &ump->um_quotas[type];
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fname, p);
+ NDINIT(&nd, 0, 0, UIO_USERSPACE, fname, p);
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0)
return (error);
vp = nd.ni_vp;