Pushdown Giant for: profil(), ntp_adjtime(), ogethostname(),

osethostname(), ogethostid(), osethostid()
This commit is contained in:
Matthew Dillon 2001-09-01 05:47:58 +00:00
parent 3e443c0512
commit 6f1e8c186f
3 changed files with 113 additions and 44 deletions

View File

@ -38,6 +38,8 @@
#include <sys/sysproto.h> #include <sys/sysproto.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <sys/timetc.h> #include <sys/timetc.h>
@ -270,6 +272,9 @@ struct ntp_adjtime_args {
}; };
#endif #endif
/*
* MPSAFE
*/
int int
ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap) ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap)
{ {
@ -292,11 +297,12 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap)
* the STA_PLL bit in the status word is cleared, the state and * the STA_PLL bit in the status word is cleared, the state and
* status words are reset to the initial values at boot. * status words are reset to the initial values at boot.
*/ */
mtx_lock(&Giant);
modes = ntv.modes; modes = ntv.modes;
if (modes) if (modes)
error = suser(p); error = suser(p);
if (error) if (error)
return (error); goto done2;
s = splclock(); s = splclock();
if (modes & MOD_MAXERROR) if (modes & MOD_MAXERROR)
time_maxerror = ntv.maxerror; time_maxerror = ntv.maxerror;
@ -397,7 +403,7 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap)
error = copyout((caddr_t)&ntv, (caddr_t)uap->tp, sizeof(ntv)); error = copyout((caddr_t)&ntv, (caddr_t)uap->tp, sizeof(ntv));
if (error) if (error)
return (error); goto done2;
/* /*
* Status word error decode. See comments in * Status word error decode. See comments in
@ -409,10 +415,13 @@ ntp_adjtime(struct proc *p, struct ntp_adjtime_args *uap)
(time_status & STA_PPSTIME && (time_status & STA_PPSTIME &&
time_status & STA_PPSJITTER) || time_status & STA_PPSJITTER) ||
(time_status & STA_PPSFREQ && (time_status & STA_PPSFREQ &&
time_status & (STA_PPSWANDER | STA_PPSERROR))) time_status & (STA_PPSWANDER | STA_PPSERROR))) {
p->p_retval[0] = TIME_ERROR; p->p_retval[0] = TIME_ERROR;
else } else {
p->p_retval[0] = time_state; p->p_retval[0] = time_state;
}
done2:
mtx_unlock(&Giant);
return (error); return (error);
} }

View File

@ -41,6 +41,8 @@
#include <sys/sysproto.h> #include <sys/sysproto.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/utsname.h> #include <sys/utsname.h>
@ -53,6 +55,9 @@ struct gethostname_args {
u_int len; u_int len;
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
ogethostname(p, uap) ogethostname(p, uap)
@ -60,12 +65,15 @@ ogethostname(p, uap)
struct gethostname_args *uap; struct gethostname_args *uap;
{ {
int name[2]; int name[2];
int error;
size_t len = uap->len; size_t len = uap->len;
name[0] = CTL_KERN; name[0] = CTL_KERN;
name[1] = KERN_HOSTNAME; name[1] = KERN_HOSTNAME;
return (userland_sysctl(p, name, 2, uap->hostname, &len, mtx_lock(&Giant);
1, 0, 0, 0)); error = userland_sysctl(p, name, 2, uap->hostname, &len, 1, 0, 0, 0);
mtx_unlock(&Giant);
return(error);
} }
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
@ -74,6 +82,9 @@ struct sethostname_args {
u_int len; u_int len;
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
osethostname(p, uap) osethostname(p, uap)
@ -85,10 +96,13 @@ osethostname(p, uap)
name[0] = CTL_KERN; name[0] = CTL_KERN;
name[1] = KERN_HOSTNAME; name[1] = KERN_HOSTNAME;
if ((error = suser_xxx(0, p, PRISON_ROOT))) mtx_lock(&Giant);
return (error); if ((error = suser_xxx(0, p, PRISON_ROOT)) == 0) {
return (userland_sysctl(p, name, 2, 0, 0, 0, error = userland_sysctl(p, name, 2, 0, 0, 0,
uap->hostname, uap->len, 0)); uap->hostname, uap->len, 0);
}
mtx_unlock(&Giant);
return (error);
} }
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
@ -96,6 +110,9 @@ struct ogethostid_args {
int dummy; int dummy;
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
ogethostid(p, uap) ogethostid(p, uap)
@ -114,6 +131,9 @@ struct osethostid_args {
long hostid; long hostid;
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
osethostid(p, uap) osethostid(p, uap)
@ -122,18 +142,21 @@ osethostid(p, uap)
{ {
int error; int error;
if ((error = suser(p))) mtx_lock(&Giant);
return (error); if ((error = suser(p)) == 0)
hostid = uap->hostid; hostid = uap->hostid;
return (0); mtx_unlock(&Giant);
return (error);
} }
/*
* MPSAFE
*/
int int
oquota(p, uap) oquota(p, uap)
struct proc *p; struct proc *p;
struct oquota_args *uap; struct oquota_args *uap;
{ {
return (ENOSYS); return (ENOSYS);
} }
#endif /* COMPAT_43 */ #endif /* COMPAT_43 */
@ -152,44 +175,52 @@ struct uname_args {
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
uname(p, uap) uname(p, uap)
struct proc *p; struct proc *p;
struct uname_args *uap; struct uname_args *uap;
{ {
int name[2], rtval; int name[2], error;
size_t len; size_t len;
char *s, *us; char *s, *us;
name[0] = CTL_KERN; name[0] = CTL_KERN;
name[1] = KERN_OSTYPE; name[1] = KERN_OSTYPE;
len = sizeof uap->name->sysname; len = sizeof (uap->name->sysname);
rtval = userland_sysctl(p, name, 2, uap->name->sysname, &len, mtx_lock(&Giant);
error = userland_sysctl(p, name, 2, uap->name->sysname, &len,
1, 0, 0, 0); 1, 0, 0, 0);
if( rtval) return rtval; if (error)
goto done2;
subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
name[1] = KERN_HOSTNAME; name[1] = KERN_HOSTNAME;
len = sizeof uap->name->nodename; len = sizeof uap->name->nodename;
rtval = userland_sysctl(p, name, 2, uap->name->nodename, &len, error = userland_sysctl(p, name, 2, uap->name->nodename, &len,
1, 0, 0, 0); 1, 0, 0, 0);
if( rtval) return rtval; if (error)
goto done2;
subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
name[1] = KERN_OSRELEASE; name[1] = KERN_OSRELEASE;
len = sizeof uap->name->release; len = sizeof uap->name->release;
rtval = userland_sysctl(p, name, 2, uap->name->release, &len, error = userland_sysctl(p, name, 2, uap->name->release, &len,
1, 0, 0, 0); 1, 0, 0, 0);
if( rtval) return rtval; if (error)
goto done2;
subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
/* /*
name = KERN_VERSION; name = KERN_VERSION;
len = sizeof uap->name->version; len = sizeof uap->name->version;
rtval = userland_sysctl(p, name, 2, uap->name->version, &len, error = userland_sysctl(p, name, 2, uap->name->version, &len,
1, 0, 0, 0); 1, 0, 0, 0);
if( rtval) return rtval; if (error)
goto done2;
subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
*/ */
@ -199,23 +230,25 @@ uname(p, uap)
for(s = version; *s && *s != '#'; s++); for(s = version; *s && *s != '#'; s++);
for(us = uap->name->version; *s && *s != ':'; s++) { for(us = uap->name->version; *s && *s != ':'; s++) {
rtval = subyte( us++, *s); error = subyte( us++, *s);
if( rtval) if (error)
return rtval; goto done2;
} }
rtval = subyte( us++, 0); error = subyte( us++, 0);
if( rtval) if (error)
return rtval; goto done2;
name[0] = CTL_HW; name[0] = CTL_HW;
name[1] = HW_MACHINE; name[1] = HW_MACHINE;
len = sizeof uap->name->machine; len = sizeof uap->name->machine;
rtval = userland_sysctl(p, name, 2, uap->name->machine, &len, error = userland_sysctl(p, name, 2, uap->name->machine, &len,
1, 0, 0, 0); 1, 0, 0, 0);
if( rtval) return rtval; if (error)
goto done2;
subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
done2:
return 0; mtx_unlock(&Giant);
return (error);
} }
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
@ -225,16 +258,25 @@ struct getdomainname_args {
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
getdomainname(p, uap) getdomainname(p, uap)
struct proc *p; struct proc *p;
struct getdomainname_args *uap; struct getdomainname_args *uap;
{ {
int domainnamelen = strlen(domainname) + 1; int domainnamelen;
int error;
mtx_lock(&Giant);
domainnamelen = strlen(domainname) + 1;
if ((u_int)uap->len > domainnamelen + 1) if ((u_int)uap->len > domainnamelen + 1)
uap->len = domainnamelen + 1; uap->len = domainnamelen + 1;
return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len)); error = copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len);
mtx_unlock(&Giant);
return (error);
} }
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
@ -244,6 +286,9 @@ struct setdomainname_args {
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
setdomainname(p, uap) setdomainname(p, uap)
@ -252,13 +297,18 @@ setdomainname(p, uap)
{ {
int error, domainnamelen; int error, domainnamelen;
mtx_lock(&Giant);
if ((error = suser(p))) if ((error = suser(p)))
return (error); goto done2;
if ((u_int)uap->len > sizeof (domainname) - 1) if ((u_int)uap->len > sizeof (domainname) - 1) {
return EINVAL; error = EINVAL;
goto done2;
}
domainnamelen = uap->len; domainnamelen = uap->len;
error = copyin((caddr_t)uap->domainname, domainname, uap->len); error = copyin((caddr_t)uap->domainname, domainname, uap->len);
domainname[domainnamelen] = 0; domainname[domainnamelen] = 0;
done2:
mtx_unlock(&Giant);
return (error); return (error);
} }

View File

@ -351,6 +351,9 @@ struct profil_args {
u_int scale; u_int scale;
}; };
#endif #endif
/*
* MPSAFE
*/
/* ARGSUSED */ /* ARGSUSED */
int int
profil(p, uap) profil(p, uap)
@ -359,12 +362,17 @@ profil(p, uap)
{ {
register struct uprof *upp; register struct uprof *upp;
int s; int s;
int error = 0;
if (uap->scale > (1 << 16)) mtx_lock(&Giant);
return (EINVAL);
if (uap->scale > (1 << 16)) {
error = EINVAL;
goto done2;
}
if (uap->scale == 0) { if (uap->scale == 0) {
stopprofclock(p); stopprofclock(p);
return (0); goto done2;
} }
upp = &p->p_stats->p_prof; upp = &p->p_stats->p_prof;
@ -377,7 +385,9 @@ profil(p, uap)
startprofclock(p); startprofclock(p);
splx(s); splx(s);
return (0); done2:
mtx_unlock(&Giant);
return (error);
} }
/* /*