summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2019-02-13 11:55:22 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2019-02-13 11:55:22 +0000
commit622c7a69aacb2b5d2f4bf2b5765f8cb81718825e (patch)
tree2a261d69084db1276ecc5e3bfdbc7b1afddcb1a3
parent13dcd41b74ef9118073e90a2a81894063f23d10d (diff)
Allow SO_PEERCRED to be called on sockets created with socketpair.
OK claudio@ and jca@
-rw-r--r--lib/libc/sys/getsockopt.29
-rw-r--r--sys/kern/uipc_usrreq.c14
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index a0d48c6ddf7..f3c618035f6 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getsockopt.2,v 1.54 2019/01/11 06:10:13 jsg Exp $
+.\" $OpenBSD: getsockopt.2,v 1.55 2019/02/13 11:55:21 martijn Exp $
.\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: January 11 2019 $
+.Dd $Mdocdate: February 13 2019 $
.Dt GETSOCKOPT 2
.Os
.Sh NAME
@@ -351,9 +351,10 @@ credentials from the other side of the connection
.Dv AF_UNIX
sockets).
These credentials are from the time that
-.Xr bind 2
-or
+.Xr bind 2 ,
.Xr connect 2
+or
+.Xr socketpair 2
were called.
.Pp
The
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 01a65ccf3f2..6444de09019 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.138 2019/02/04 21:40:52 bluhm Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.139 2019/02/13 11:55:21 martijn Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -108,6 +108,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
struct mbuf *control, struct proc *p)
{
struct unpcb *unp = sotounpcb(so);
+ struct unpcb *unp2;
struct socket *so2;
int error = 0;
@@ -141,6 +142,17 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
case PRU_CONNECT2:
error = unp_connect2(so, (struct socket *)nam);
+ if (!error) {
+ unp->unp_connid.uid = p->p_ucred->cr_uid;
+ unp->unp_connid.gid = p->p_ucred->cr_gid;
+ unp->unp_connid.pid = p->p_p->ps_pid;
+ unp->unp_flags |= UNP_FEIDS;
+ unp2 = sotounpcb((struct socket *)nam);
+ unp2->unp_connid.uid = p->p_ucred->cr_uid;
+ unp2->unp_connid.gid = p->p_ucred->cr_gid;
+ unp2->unp_connid.pid = p->p_p->ps_pid;
+ unp2->unp_flags |= UNP_FEIDS;
+ }
break;
case PRU_DISCONNECT: