make emul_sysctl() work with emulations loaded via LKM, properly bound check
name[0]
This commit is contained in:
parent
ebd670f0bc
commit
3ffbb4470d
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_sysctl.c,v 1.104 2002/03/20 00:27:26 christos Exp $ */
|
||||
/* $NetBSD: kern_sysctl.c,v 1.105 2002/04/02 20:21:51 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
|
@ -43,7 +43,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.104 2002/03/20 00:27:26 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.105 2002/04/02 20:21:51 jdolecek Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_insecure.h"
|
||||
|
@ -824,33 +824,53 @@ int
|
|||
emul_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen, struct proc *p)
|
||||
{
|
||||
extern int nexecs_builtin;
|
||||
extern const struct execsw execsw_builtin[];
|
||||
static struct {
|
||||
const char *name;
|
||||
int type;
|
||||
} emulations[] = CTL_EMUL_NAMES;
|
||||
const struct emul *e;
|
||||
const char *ename;
|
||||
#ifdef LKM
|
||||
extern struct lock exec_lock; /* XXX */
|
||||
int error;
|
||||
#else
|
||||
extern int nexecs_builtin;
|
||||
extern const struct execsw execsw_builtin[];
|
||||
int i;
|
||||
#endif
|
||||
|
||||
/* all sysctl names at this level are name and field */
|
||||
if (namelen < 2)
|
||||
return (ENOTDIR); /* overloaded */
|
||||
|
||||
if (name[0] >= EMUL_MAXID || name[0] == 0)
|
||||
if ((u_int) name[0] >= EMUL_MAXID || name[0] == 0)
|
||||
return (EOPNOTSUPP);
|
||||
|
||||
ename = emulations[name[0]].name;
|
||||
|
||||
#ifdef LKM
|
||||
lockmgr(&exec_lock, LK_SHARED, NULL);
|
||||
if ((e = emul_search(ename))) {
|
||||
error = (*e->e_sysctl)(name + 1, namelen - 1, oldp, oldlenp,
|
||||
newp, newlen, p);
|
||||
} else
|
||||
error = EOPNOTSUPP;
|
||||
lockmgr(&exec_lock, LK_RELEASE, NULL);
|
||||
|
||||
return (error);
|
||||
#else
|
||||
for (i = 0; i < nexecs_builtin; i++) {
|
||||
const struct emul *e = execsw_builtin[i].es_emul;
|
||||
if (e != NULL && strcmp(ename, e->e_name) == 0 &&
|
||||
execsw_builtin[i].es_sysctl != NULL)
|
||||
return (*execsw_builtin[i].es_sysctl)(name + 1, namelen - 1,
|
||||
oldp, oldlenp, newp, newlen, p);
|
||||
e = execsw_builtin[i].es_emul;
|
||||
if (e == NULL || strcmp(ename, e->e_name) != 0 ||
|
||||
e->es_sysctl != NULL)
|
||||
continue;
|
||||
|
||||
return (*e->e_sysctl)(name + 1, namelen - 1, oldp, oldlenp,
|
||||
newp, newlen, p);
|
||||
}
|
||||
|
||||
return (EOPNOTSUPP);
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Convenience macros.
|
||||
|
|
Loading…
Reference in New Issue