summaryrefslogtreecommitdiff
path: root/sys/net/pfkeyv2.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2022-10-03 16:43:53 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2022-10-03 16:43:53 +0000
commit664e716c25187e8df24c685ad24616ba16bf6205 (patch)
tree56665a3f1021af1784fe972cd6365ad9b07d458e /sys/net/pfkeyv2.c
parent9ada79011110198e0b48f901fda0f53caae40a5b (diff)
System calls should not fail due to temporary memory shortage in
malloc(9) or pool_get(9). Pass down a wait flag to pru_attach(). During syscall socket(2) it is ok to wait, this logic was missing for internet pcb. Pfkey and route sockets were already waiting. sonewconn() must not wait when called during TCP 3-way handshake. This logic has been preserved. Unix domain stream socket connect(2) can wait until the other side has created the socket to accept. OK mvs@
Diffstat (limited to 'sys/net/pfkeyv2.c')
-rw-r--r--sys/net/pfkeyv2.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index b8f123a0802..022bd5ae025 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.252 2022/09/03 22:43:38 mvs Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.253 2022/10/03 16:43:52 bluhm Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -169,7 +169,7 @@ static int npromisc = 0;
void pfkey_init(void);
-int pfkeyv2_attach(struct socket *, int);
+int pfkeyv2_attach(struct socket *, int, int);
int pfkeyv2_detach(struct socket *);
int pfkeyv2_disconnect(struct socket *);
int pfkeyv2_shutdown(struct socket *);
@@ -269,7 +269,7 @@ pfkey_init(void)
* Attach a new PF_KEYv2 socket.
*/
int
-pfkeyv2_attach(struct socket *so, int proto)
+pfkeyv2_attach(struct socket *so, int proto, int wait)
{
struct pkpcb *kp;
int error;
@@ -281,7 +281,10 @@ pfkeyv2_attach(struct socket *so, int proto)
if (error)
return (error);
- kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO);
+ kp = pool_get(&pkpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
+ if (kp == NULL)
+ return (ENOBUFS);
so->so_pcb = kp;
refcnt_init(&kp->kcb_refcnt);
kp->kcb_socket = so;