summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2018-07-01 16:33:16 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2018-07-01 16:33:16 +0000
commitacc217be4c2bd21627b99a8df031f89fa0a4dc54 (patch)
tree66135d8afd4c28817ca3f22934f3775ca07fe245 /sys
parent6fe7029021e7db12c29322b45521dc33412e00e2 (diff)
Lock the file descriptor table when accessing the `fd_ofileflags' array.
This prevents the array from being freed too early. In the function unp_internalize(), the locking also ensures the per-fdp flags stay coherent with the file instance. OK mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_descrip.c4
-rw-r--r--sys/kern/kern_sysctl.c7
-rw-r--r--sys/kern/uipc_usrreq.c5
3 files changed, 12 insertions, 4 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index bc4e90c294f..94df1844fae 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.172 2018/06/27 16:37:25 visa Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.173 2018/07/01 16:33:15 visa Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -433,7 +433,9 @@ restart:
return (error);
case F_GETFD:
+ fdplock(fdp);
*retval = fdp->fd_ofileflags[fd] & UF_EXCLOSE ? 1 : 0;
+ fdpunlock(fdp);
break;
case F_SETFD:
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index a33d6ae9d19..3106bbb1de3 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.343 2018/06/20 10:52:49 mpi Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.344 2018/07/01 16:33:15 visa Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1264,8 +1264,11 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
kf->p_tid = -1;
strlcpy(kf->p_comm, pr->ps_comm, sizeof(kf->p_comm));
}
- if (fdp != NULL)
+ if (fdp != NULL) {
+ fdplock(fdp);
kf->fd_ofileflags = fdp->fd_ofileflags[fd];
+ fdpunlock(fdp);
+ }
}
/*
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index d4f2af0fae0..8bea7cde97c 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.131 2018/06/23 11:33:32 visa Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.132 2018/07/01 16:33:15 visa Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -839,6 +839,7 @@ morespace:
ip = ((int *)CMSG_DATA(cm)) + nfds - 1;
rp = ((struct fdpass *)CMSG_DATA(cm)) + nfds - 1;
+ fdplock(fdp);
for (i = 0; i < nfds; i++) {
memcpy(&fd, ip, sizeof fd);
ip--;
@@ -868,8 +869,10 @@ morespace:
}
unp_rights++;
}
+ fdpunlock(fdp);
return (0);
fail:
+ fdpunlock(fdp);
if (fp != NULL)
FRELE(fp, p);
/* Back out what we just did. */