Install floppies (haha) don't get built with ktrace/ptrace, so they don't

include kern/sys_process.c. Move proc_uidmatch() to kern/kern_proc.c which
always gets built instead.

Pointed out by Kurt Schreiner on current-users@:

    http://mail-index.netbsd.org/current-users/2009/10/03/msg010745.html
This commit is contained in:
elad 2009-10-04 03:15:08 +00:00
parent 875c2ae09f
commit fa69dc186a
2 changed files with 37 additions and 40 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_proc.c,v 1.153 2009/10/03 03:38:31 elad Exp $ */
/* $NetBSD: kern_proc.c,v 1.154 2009/10/04 03:15:08 elad Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.153 2009/10/03 03:38:31 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.154 2009/10/04 03:15:08 elad Exp $");
#include "opt_kstack.h"
#include "opt_maxuprc.h"
@ -1436,3 +1436,36 @@ proc_setspecific(struct proc *p, specificdata_key_t key, void *data)
specificdata_setspecific(proc_specificdata_domain,
&p->p_specdataref, key, data);
}
int
proc_uidmatch(kauth_cred_t cred, kauth_cred_t target)
{
int r = 0;
if (kauth_cred_getuid(cred) != kauth_cred_getuid(target) ||
kauth_cred_getuid(cred) != kauth_cred_getsvuid(target)) {
/*
* suid proc of ours or proc not ours
*/
r = EPERM;
} else if (kauth_cred_getgid(target) != kauth_cred_getsvgid(target)) {
/*
* sgid proc has sgid back to us temporarily
*/
r = EPERM;
} else {
/*
* our rgid must be in target's group list (ie,
* sub-processes started by a sgid process)
*/
int ismember = 0;
if (kauth_cred_ismember_gid(cred,
kauth_cred_getgid(target), &ismember) != 0 ||
!ismember)
r = EPERM;
}
return (r);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_process.c,v 1.149 2009/10/02 22:38:45 elad Exp $ */
/* $NetBSD: sys_process.c,v 1.150 2009/10/04 03:15:08 elad Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -118,7 +118,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.149 2009/10/02 22:38:45 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.150 2009/10/04 03:15:08 elad Exp $");
#include "opt_ptrace.h"
#include "opt_ktrace.h"
@ -1032,39 +1032,3 @@ process_stoptrace(void)
KERNEL_LOCK(l->l_biglocks, l);
}
#endif /* KTRACE || PTRACE */
/*
* common code for corename, rlimit, and stopflag.
*/
int
proc_uidmatch(kauth_cred_t cred, kauth_cred_t target)
{
int r = 0;
if (kauth_cred_getuid(cred) != kauth_cred_getuid(target) ||
kauth_cred_getuid(cred) != kauth_cred_getsvuid(target)) {
/*
* suid proc of ours or proc not ours
*/
r = EPERM;
} else if (kauth_cred_getgid(target) != kauth_cred_getsvgid(target)) {
/*
* sgid proc has sgid back to us temporarily
*/
r = EPERM;
} else {
/*
* our rgid must be in target's group list (ie,
* sub-processes started by a sgid process)
*/
int ismember = 0;
if (kauth_cred_ismember_gid(cred,
kauth_cred_getgid(target), &ismember) != 0 ||
!ismember)
r = EPERM;
}
return (r);
}