summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2017-01-23 22:34:11 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2017-01-23 22:34:11 +0000
commiteacee96ec48d5bfa4ac95765a069137815608ba4 (patch)
tree51ae6e2a1f1c4f5e8b96c627337d6a5f7c4ab0ea /sys
parentabbe48e3493ac822f3c2d7d0f5ca122ae60a4ae9 (diff)
Avoid curproc dance in dupfdopen(), by passing a struct proc *
ok guenther mpi
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_descrip.c16
-rw-r--r--sys/kern/vfs_syscalls.c4
-rw-r--r--sys/sys/filedesc.h4
3 files changed, 13 insertions, 11 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index e3201b9f2c1..e4b44839b37 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.136 2016/09/24 18:39:17 tedu Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.137 2017/01/23 22:34:10 deraadt Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -1253,8 +1253,10 @@ filedescopen(dev_t dev, int mode, int type, struct proc *p)
* Duplicate the specified descriptor to a free descriptor.
*/
int
-dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode)
+dupfdopen(struct proc *p, int indx, int mode)
{
+ struct filedesc *fdp = p->p_fd;
+ int dupfd = p->p_dupfd;
struct file *wfp;
fdpassertlocked(fdp);
@@ -1263,10 +1265,10 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode)
* Assume that the filename was user-specified; applications do
* not tend to open /dev/fd/# when they can just call dup()
*/
- if ((curproc->p_p->ps_flags & (PS_SUGIDEXEC | PS_SUGID))) {
- if (curproc->p_descfd == 255)
+ if ((p->p_p->ps_flags & (PS_SUGIDEXEC | PS_SUGID))) {
+ if (p->p_descfd == 255)
return (EPERM);
- if (curproc->p_descfd != curproc->p_dupfd)
+ if (p->p_descfd != dupfd)
return (EPERM);
}
@@ -1277,7 +1279,7 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode)
* because fd_getfile will return NULL if the file at indx is
* newly created by falloc (FIF_LARVAL).
*/
- if ((wfp = fd_getfile(fdp, dfd)) == NULL)
+ if ((wfp = fd_getfile(fdp, dupfd)) == NULL)
return (EBADF);
/*
@@ -1291,7 +1293,7 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode)
fdp->fd_ofiles[indx] = wfp;
fdp->fd_ofileflags[indx] = (fdp->fd_ofileflags[indx] & UF_EXCLOSE) |
- (fdp->fd_ofileflags[dfd] & ~UF_EXCLOSE);
+ (fdp->fd_ofileflags[dupfd] & ~UF_EXCLOSE);
wfp->f_count++;
fd_used(fdp, indx);
return (0);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 04df68e17d4..585485281cb 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.268 2017/01/15 23:18:05 bluhm Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.269 2017/01/23 22:34:10 deraadt Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -829,7 +829,7 @@ doopenat(struct proc *p, int fd, const char *path, int oflags, mode_t mode,
if (error == ENODEV &&
p->p_dupfd >= 0 && /* XXX from fdopen */
(error =
- dupfdopen(fdp, indx, p->p_dupfd, flags)) == 0) {
+ dupfdopen(p, indx, flags)) == 0) {
closef(fp, p);
*retval = indx;
goto out;
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index 148c8bc0182..136133189b7 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: filedesc.h,v 1.30 2015/05/06 08:52:17 mpi Exp $ */
+/* $OpenBSD: filedesc.h,v 1.31 2017/01/23 22:34:10 deraadt Exp $ */
/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */
/*
@@ -121,7 +121,7 @@ struct filedesc0 {
* Kernel global variables and routines.
*/
void filedesc_init(void);
-int dupfdopen(struct filedesc *, int, int, int);
+int dupfdopen(struct proc *, int, int);
int fdalloc(struct proc *p, int want, int *result);
void fdexpand(struct proc *);
int falloc(struct proc *p, struct file **resultfp, int *resultfd);