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
This commit is contained in:
parent
1410bfe142
commit
c5afec6e89
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348419
@ -550,7 +550,7 @@ update_client_creds(struct client *c)
|
|||||||
{
|
{
|
||||||
c->unixrights.uid = peercred.cr_uid;
|
c->unixrights.uid = peercred.cr_uid;
|
||||||
c->unixrights.gid = peercred.cr_gid;
|
c->unixrights.gid = peercred.cr_gid;
|
||||||
c->unixrights.pid = 0;
|
c->unixrights.pid = peercred.cr_pid;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,6 +310,7 @@ struct xucred {
|
|||||||
uid_t cr_uid; /* effective user id */
|
uid_t cr_uid; /* effective user id */
|
||||||
short cr_ngroups; /* number of groups */
|
short cr_ngroups; /* number of groups */
|
||||||
gid_t cr_groups[XU_NGROUPS]; /* groups */
|
gid_t cr_groups[XU_NGROUPS]; /* groups */
|
||||||
|
pid_t cr_pid; /* process id of the sending process */
|
||||||
};
|
};
|
||||||
.Ed
|
.Ed
|
||||||
The
|
The
|
||||||
|
@ -1519,10 +1519,7 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
|
|||||||
name, &xu, UIO_SYSSPACE, &xulen);
|
name, &xu, UIO_SYSSPACE, &xulen);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
/*
|
lxu.pid = xu.cr_pid;
|
||||||
* XXX Use 0 for pid as the FreeBSD does not cache peer pid.
|
|
||||||
*/
|
|
||||||
lxu.pid = 0;
|
|
||||||
lxu.uid = xu.cr_uid;
|
lxu.uid = xu.cr_uid;
|
||||||
lxu.gid = xu.cr_gid;
|
lxu.gid = xu.cr_gid;
|
||||||
return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu)));
|
return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu)));
|
||||||
|
@ -1957,6 +1957,14 @@ cru2x(struct ucred *cr, struct xucred *xcr)
|
|||||||
ngroups * sizeof(*cr->cr_groups));
|
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.
|
* Set initial process credentials.
|
||||||
* Callers are responsible for providing the reference for provided credentials.
|
* Callers are responsible for providing the reference for provided credentials.
|
||||||
|
@ -912,7 +912,7 @@ uipc_listen(struct socket *so, int backlog, struct thread *td)
|
|||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
error = solisten_proto_check(so);
|
error = solisten_proto_check(so);
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
cru2x(td->td_ucred, &unp->unp_peercred);
|
cru2xt(td, &unp->unp_peercred);
|
||||||
solisten_proto(so, backlog);
|
solisten_proto(so, backlog);
|
||||||
}
|
}
|
||||||
SOCK_UNLOCK(so);
|
SOCK_UNLOCK(so);
|
||||||
@ -1656,7 +1656,7 @@ void
|
|||||||
unp_copy_peercred(struct thread *td, struct unpcb *client_unp,
|
unp_copy_peercred(struct thread *td, struct unpcb *client_unp,
|
||||||
struct unpcb *server_unp, struct unpcb *listen_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;
|
client_unp->unp_flags |= UNP_HAVEPC;
|
||||||
|
|
||||||
memcpy(&server_unp->unp_peercred, &listen_unp->unp_peercred,
|
memcpy(&server_unp->unp_peercred, &listen_unp->unp_peercred,
|
||||||
@ -2755,8 +2755,8 @@ db_print_xucred(int indent, struct xucred *xu)
|
|||||||
int comma, i;
|
int comma, i;
|
||||||
|
|
||||||
db_print_indent(indent);
|
db_print_indent(indent);
|
||||||
db_printf("cr_version: %u cr_uid: %u cr_ngroups: %d\n",
|
db_printf("cr_version: %u cr_uid: %u cr_pid: %d cr_ngroups: %d\n",
|
||||||
xu->cr_version, xu->cr_uid, xu->cr_ngroups);
|
xu->cr_version, xu->cr_uid, xu->cr_pid, xu->cr_ngroups);
|
||||||
db_print_indent(indent);
|
db_print_indent(indent);
|
||||||
db_printf("cr_groups: ");
|
db_printf("cr_groups: ");
|
||||||
comma = 0;
|
comma = 0;
|
||||||
|
@ -87,10 +87,14 @@ struct xucred {
|
|||||||
uid_t cr_uid; /* effective user id */
|
uid_t cr_uid; /* effective user id */
|
||||||
short cr_ngroups; /* number of groups */
|
short cr_ngroups; /* number of groups */
|
||||||
gid_t cr_groups[XU_NGROUPS]; /* 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 XUCRED_VERSION 0
|
||||||
|
|
||||||
|
#define cr_pid _cr._pid
|
||||||
/* This can be used for both ucred and xucred structures. */
|
/* This can be used for both ucred and xucred structures. */
|
||||||
#define cr_gid cr_groups[0]
|
#define cr_gid cr_groups[0]
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ void crfree(struct ucred *cr);
|
|||||||
struct ucred *crget(void);
|
struct ucred *crget(void);
|
||||||
struct ucred *crhold(struct ucred *cr);
|
struct ucred *crhold(struct ucred *cr);
|
||||||
void cru2x(struct ucred *cr, struct xucred *xcr);
|
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);
|
void crsetgroups(struct ucred *cr, int n, gid_t *groups);
|
||||||
int groupmember(gid_t gid, struct ucred *cred);
|
int groupmember(gid_t gid, struct ucred *cred);
|
||||||
#endif /* _KERNEL */
|
#endif /* _KERNEL */
|
||||||
|
@ -244,7 +244,7 @@ static struct xucred def_anon = {
|
|||||||
(uid_t)65534,
|
(uid_t)65534,
|
||||||
1,
|
1,
|
||||||
{ (gid_t)65533 },
|
{ (gid_t)65533 },
|
||||||
NULL
|
{ NULL }
|
||||||
};
|
};
|
||||||
static int force_v2 = 0;
|
static int force_v2 = 0;
|
||||||
static int resvport_only = 1;
|
static int resvport_only = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user