From owner-svn-src-head@freebsd.org Thu May 30 14:24:29 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 432CA15C434C; Thu, 30 May 2019 14:24:29 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D52108D3DD; Thu, 30 May 2019 14:24:28 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C5811A52F; Thu, 30 May 2019 14:24:28 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4UEOS00098762; Thu, 30 May 2019 14:24:28 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4UEORXr098755; Thu, 30 May 2019 14:24:27 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201905301424.x4UEORXr098755@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Thu, 30 May 2019 14:24:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348419 - in head: crypto/heimdal/lib/ipc share/man/man4 sys/compat/linux sys/kern sys/sys usr.sbin/mountd X-SVN-Group: head X-SVN-Commit-Author: dchagin X-SVN-Commit-Paths: in head: crypto/heimdal/lib/ipc share/man/man4 sys/compat/linux sys/kern sys/sys usr.sbin/mountd X-SVN-Commit-Revision: 348419 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D52108D3DD X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.973,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 May 2019 14:24:29 -0000 Author: dchagin Date: Thu May 30 14:24:26 2019 New Revision: 348419 URL: https://svnweb.freebsd.org/changeset/base/348419 Log: Complete LOCAL_PEERCRED support. Cache pid of the remote process in the struct xucred. Do not bump XUCRED_VERSION as struct layout is not changed. PR: 215202 Reviewed by: tijl MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D20415 Modified: head/crypto/heimdal/lib/ipc/server.c head/share/man/man4/unix.4 head/sys/compat/linux/linux_socket.c head/sys/kern/kern_prot.c head/sys/kern/uipc_usrreq.c head/sys/sys/ucred.h head/usr.sbin/mountd/mountd.c Modified: head/crypto/heimdal/lib/ipc/server.c ============================================================================== --- head/crypto/heimdal/lib/ipc/server.c Thu May 30 14:21:51 2019 (r348418) +++ head/crypto/heimdal/lib/ipc/server.c Thu May 30 14:24:26 2019 (r348419) @@ -550,7 +550,7 @@ update_client_creds(struct client *c) { c->unixrights.uid = peercred.cr_uid; c->unixrights.gid = peercred.cr_gid; - c->unixrights.pid = 0; + c->unixrights.pid = peercred.cr_pid; return 1; } } Modified: head/share/man/man4/unix.4 ============================================================================== --- head/share/man/man4/unix.4 Thu May 30 14:21:51 2019 (r348418) +++ head/share/man/man4/unix.4 Thu May 30 14:24:26 2019 (r348419) @@ -310,6 +310,7 @@ struct xucred { uid_t cr_uid; /* effective user id */ short cr_ngroups; /* number of groups */ gid_t cr_groups[XU_NGROUPS]; /* groups */ + pid_t cr_pid; /* process id of the sending process */ }; .Ed The Modified: head/sys/compat/linux/linux_socket.c ============================================================================== --- head/sys/compat/linux/linux_socket.c Thu May 30 14:21:51 2019 (r348418) +++ head/sys/compat/linux/linux_socket.c Thu May 30 14:24:26 2019 (r348419) @@ -1519,10 +1519,7 @@ linux_getsockopt(struct thread *td, struct linux_getso name, &xu, UIO_SYSSPACE, &xulen); if (error != 0) return (error); - /* - * XXX Use 0 for pid as the FreeBSD does not cache peer pid. - */ - lxu.pid = 0; + lxu.pid = xu.cr_pid; lxu.uid = xu.cr_uid; lxu.gid = xu.cr_gid; return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu))); Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Thu May 30 14:21:51 2019 (r348418) +++ head/sys/kern/kern_prot.c Thu May 30 14:24:26 2019 (r348419) @@ -1957,6 +1957,14 @@ cru2x(struct ucred *cr, struct xucred *xcr) ngroups * sizeof(*cr->cr_groups)); } +void inline +cru2xt(struct thread *td, struct xucred *xcr) +{ + + cru2x(td->td_ucred, xcr); + xcr->cr_pid = td->td_proc->p_pid; +} + /* * Set initial process credentials. * Callers are responsible for providing the reference for provided credentials. Modified: head/sys/kern/uipc_usrreq.c ============================================================================== --- head/sys/kern/uipc_usrreq.c Thu May 30 14:21:51 2019 (r348418) +++ head/sys/kern/uipc_usrreq.c Thu May 30 14:24:26 2019 (r348419) @@ -912,7 +912,7 @@ uipc_listen(struct socket *so, int backlog, struct thr SOCK_LOCK(so); error = solisten_proto_check(so); if (error == 0) { - cru2x(td->td_ucred, &unp->unp_peercred); + cru2xt(td, &unp->unp_peercred); solisten_proto(so, backlog); } SOCK_UNLOCK(so); @@ -1656,7 +1656,7 @@ void unp_copy_peercred(struct thread *td, struct unpcb *client_unp, struct unpcb *server_unp, struct unpcb *listen_unp) { - cru2x(td->td_ucred, &client_unp->unp_peercred); + cru2xt(td, &client_unp->unp_peercred); client_unp->unp_flags |= UNP_HAVEPC; memcpy(&server_unp->unp_peercred, &listen_unp->unp_peercred, @@ -2755,8 +2755,8 @@ db_print_xucred(int indent, struct xucred *xu) int comma, i; db_print_indent(indent); - db_printf("cr_version: %u cr_uid: %u cr_ngroups: %d\n", - xu->cr_version, xu->cr_uid, xu->cr_ngroups); + db_printf("cr_version: %u cr_uid: %u cr_pid: %d cr_ngroups: %d\n", + xu->cr_version, xu->cr_uid, xu->cr_pid, xu->cr_ngroups); db_print_indent(indent); db_printf("cr_groups: "); comma = 0; Modified: head/sys/sys/ucred.h ============================================================================== --- head/sys/sys/ucred.h Thu May 30 14:21:51 2019 (r348418) +++ head/sys/sys/ucred.h Thu May 30 14:24:26 2019 (r348419) @@ -87,10 +87,14 @@ struct xucred { uid_t cr_uid; /* effective user id */ short cr_ngroups; /* number of groups */ gid_t cr_groups[XU_NGROUPS]; /* groups */ - void *_cr_unused1; /* compatibility with old ucred */ + union { + void *_cr_unused1; /* compatibility with old ucred */ + pid_t _pid; + } _cr; }; #define XUCRED_VERSION 0 +#define cr_pid _cr._pid /* This can be used for both ucred and xucred structures. */ #define cr_gid cr_groups[0] @@ -114,6 +118,7 @@ void crfree(struct ucred *cr); struct ucred *crget(void); struct ucred *crhold(struct ucred *cr); void cru2x(struct ucred *cr, struct xucred *xcr); +void cru2xt(struct thread *td, struct xucred *xcr); void crsetgroups(struct ucred *cr, int n, gid_t *groups); int groupmember(gid_t gid, struct ucred *cred); #endif /* _KERNEL */ Modified: head/usr.sbin/mountd/mountd.c ============================================================================== --- head/usr.sbin/mountd/mountd.c Thu May 30 14:21:51 2019 (r348418) +++ head/usr.sbin/mountd/mountd.c Thu May 30 14:24:26 2019 (r348419) @@ -244,7 +244,7 @@ static struct xucred def_anon = { (uid_t)65534, 1, { (gid_t)65533 }, - NULL + { NULL } }; static int force_v2 = 0; static int resvport_only = 1;