summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvisa <visa@openbsd.org>2020-12-30 17:02:32 +0000
committervisa <visa@openbsd.org>2020-12-30 17:02:32 +0000
commit8b4cfecaa6c916e318c4c1d78d8494903448f14b (patch)
treede73df0a07b878e1bc7ca2a360d3ef15e5ee3027
parentUse int64_t for intermediate values in int32_MINMAX to prevent signed (diff)
downloadwireguard-openbsd-8b4cfecaa6c916e318c4c1d78d8494903448f14b.tar.xz
wireguard-openbsd-8b4cfecaa6c916e318c4c1d78d8494903448f14b.zip
Set klist lock for pipes.
OK anton@, mpi@
-rw-r--r--sys/kern/sys_pipe.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 5b4398f722f..f9bae89aa46 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_pipe.c,v 1.125 2020/12/25 12:59:52 visa Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.126 2020/12/30 17:02:32 visa Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -126,6 +126,7 @@ void pipe_iounlock(struct pipe *);
int pipe_iosleep(struct pipe *, const char *);
struct pipe_pair *pipe_pair_create(void);
+void pipe_pair_destroy(struct pipe_pair *);
/*
* The pipe system call for the DTYPE_PIPE type of pipes
@@ -853,7 +854,7 @@ pipe_destroy(struct pipe *cpipe)
rw_exit_write(cpipe->pipe_lock);
if (ppipe == NULL)
- pool_put(&pipe_pair_pool, cpipe->pipe_pair);
+ pipe_pair_destroy(cpipe->pipe_pair);
}
/*
@@ -913,9 +914,7 @@ filt_pipedetach(struct knote *kn)
{
struct pipe *cpipe = kn->kn_hook;
- rw_enter_write(cpipe->pipe_lock);
- klist_remove_locked(&cpipe->pipe_sel.si_note, kn);
- rw_exit_write(cpipe->pipe_lock);
+ klist_remove(&cpipe->pipe_sel.si_note, kn);
}
int
@@ -997,6 +996,9 @@ pipe_pair_create(void)
pp->pp_wpipe.pipe_lock = &pp->pp_lock;
pp->pp_rpipe.pipe_lock = &pp->pp_lock;
+ klist_init_rwlock(&pp->pp_wpipe.pipe_sel.si_note, &pp->pp_lock);
+ klist_init_rwlock(&pp->pp_rpipe.pipe_sel.si_note, &pp->pp_lock);
+
if (pipe_create(&pp->pp_wpipe) || pipe_create(&pp->pp_rpipe))
goto err;
return (pp);
@@ -1005,3 +1007,11 @@ err:
pipe_destroy(&pp->pp_rpipe);
return (NULL);
}
+
+void
+pipe_pair_destroy(struct pipe_pair *pp)
+{
+ klist_free(&pp->pp_wpipe.pipe_sel.si_note);
+ klist_free(&pp->pp_rpipe.pipe_sel.si_note);
+ pool_put(&pipe_pair_pool, pp);
+}