Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sys/compat Pull up:
details: https://anonhg.NetBSD.org/src/rev/6f60dcd5859a
branches: netbsd-1-5
changeset: 489310:6f60dcd5859a
user: sommerfeld <sommerfeld%NetBSD.org@localhost>
date: Wed Aug 30 03:59:18 2000 +0000
description:
Pull up:
syssrc/sys/compat/common/compat_util.c 1.16
syssrc/sys/compat/hpux/hpux_file.c 1.14
syssrc/sys/compat/ibcs2/ibcs2_misc.c 1.52
syssrc/sys/compat/ibcs2/ibcs2_stat.c 1.16
syssrc/sys/compat/linux/common/linux_file.c 1.29
syssrc/sys/compat/linux/common/linux_misc_notalpha.c 1.58
syssrc/sys/compat/svr4/svr4_stat.c 1.40
syssrc/sys/compat/svr4/svr4_stream.c 1.40,1.41
Approved by thorpej and jhawk.
Emulation stackgap sanity checks, based partly on fixes from
FreeBSD-SA00:42.
Change stackgap_alloc to bounds-check the allocation vs. the stack
gap, returning NULL if there isn't room for the allocation.
Change emul_find() to check for a NULL return from stackgap_alloc()
and convert that into ENAMETOOLONG.
Reorder various emulation syscalls so that all *_CHECK_ALT_{EXIST,CREAT}
calls (which turn into emul_find() under the covers come *after* small,
fixed-size stackgap_alloc() calls.
Clean up ibcs2 {get,set}groups.
Add range checks to svr4_stream.c
diffstat:
sys/compat/common/compat_util.c | 19 ++++++-
sys/compat/hpux/hpux_file.c | 5 +-
sys/compat/ibcs2/ibcs2_misc.c | 62 ++++++++++++++++----------
sys/compat/ibcs2/ibcs2_stat.c | 9 ++-
sys/compat/linux/common/linux_file.c | 5 +-
sys/compat/linux/common/linux_misc_notalpha.c | 4 +-
sys/compat/svr4/svr4_stat.c | 29 +++++------
sys/compat/svr4/svr4_stream.c | 27 ++++++++++-
8 files changed, 101 insertions(+), 59 deletions(-)
diffs (truncated from 451 to 300 lines):
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/common/compat_util.c
--- a/sys/compat/common/compat_util.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/common/compat_util.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_util.c,v 1.14 1999/04/27 15:42:37 christos Exp $ */
+/* $NetBSD: compat_util.c,v 1.14.12.1 2000/08/30 03:59:18 sommerfeld Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -187,9 +187,13 @@
else {
sz = &ptr[len] - buf;
*pbuf = stackgap_alloc(sgp, sz + 1);
+ if (*pbuf == NULL) {
+ error = ENAMETOOLONG;
+ goto bad;
+ }
if ((error = copyout(buf, (void *)*pbuf, sz)) != 0) {
*pbuf = path;
- return error;
+ goto bad;
}
free(buf, M_TEMP);
}
@@ -243,8 +247,15 @@
size_t sz;
{
void *p = (void *) *sgp;
-
- *sgp += ALIGN(sz);
+ caddr_t nsgp;
+ struct emul *e = curproc->p_emul; /* XXX */
+ int sigsize = e->e_esigcode - e->e_sigcode;
+
+ sz = ALIGN(sz);
+ nsgp = *sgp + sz;
+ if (nsgp > (((caddr_t)PS_STRINGS) - sigsize))
+ return NULL;
+ *sgp = nsgp;
return p;
}
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/hpux/hpux_file.c
--- a/sys/compat/hpux/hpux_file.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/hpux/hpux_file.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hpux_file.c,v 1.13 1999/02/09 20:21:18 christos Exp $ */
+/* $NetBSD: hpux_file.c,v 1.13.18.1 2000/08/30 03:59:19 sommerfeld Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -482,10 +482,9 @@
int error;
sg = stackgap_init(p->p_emul);
-
+ st = stackgap_alloc(&sg, sizeof (struct stat));
HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
- st = stackgap_alloc(&sg, sizeof (struct stat));
SCARG(&sa, ub) = st;
SCARG(&sa, path) = SCARG(uap, path);
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/ibcs2/ibcs2_misc.c
--- a/sys/compat/ibcs2/ibcs2_misc.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/ibcs2/ibcs2_misc.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ibcs2_misc.c,v 1.47 2000/03/30 11:27:16 augustss Exp $ */
+/* $NetBSD: ibcs2_misc.c,v 1.47.4.1 2000/08/30 03:59:19 sommerfeld Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -639,27 +639,39 @@
syscallarg(ibcs2_gid_t *) gidset;
} */ *uap = v;
int error, i;
- ibcs2_gid_t *iset = NULL;
+ ibcs2_gid_t iset[NGROUPS_MAX];
+ gid_t nset[NGROUPS_MAX];
struct sys_getgroups_args sa;
- gid_t *gp;
+ int gidsetsize;
caddr_t sg = stackgap_init(p->p_emul);
- SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
- if (SCARG(uap, gidsetsize)) {
+ gidsetsize = SCARG(uap, gidsetsize);
+ if (gidsetsize > NGROUPS_MAX)
+ return EINVAL;
+
+ SCARG(&sa, gidsetsize) = gidsetsize;
+
+ if (gidsetsize) {
SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX *
sizeof(gid_t *));
- iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) *
- sizeof(ibcs2_gid_t));
}
if ((error = sys_getgroups(p, &sa, retval)) != 0)
return error;
- for (i = 0, gp = SCARG(&sa, gidset); i < retval[0]; i++)
- iset[i] = (ibcs2_gid_t)*gp++;
- if (retval[0] && (error = copyout((caddr_t)iset,
- (caddr_t)SCARG(uap, gidset),
- sizeof(ibcs2_gid_t) * retval[0])))
- return error;
- return 0;
+ if (gidsetsize) {
+ gidsetsize = retval[0];
+ if (gidsetsize < 0)
+ gidsetsize = 0;
+ error = copyin((caddr_t)SCARG(&sa, gidset), (caddr_t)nset,
+ sizeof(gid_t) * gidsetsize);
+ if (error)
+ return error;
+ for (i = 0; i < gidsetsize; i++)
+ iset[i] = (ibcs2_gid_t)nset[i];
+ error = copyout((caddr_t)iset,
+ (caddr_t)SCARG(uap, gidset),
+ sizeof(ibcs2_gid_t) * retval[0]);
+ }
+ return error;
}
int
@@ -673,24 +685,28 @@
syscallarg(ibcs2_gid_t *) gidset;
} */ *uap = v;
int error, i;
- ibcs2_gid_t *iset;
+ ibcs2_gid_t iset[NGROUPS_MAX];
struct sys_setgroups_args sa;
- gid_t *gp;
+ gid_t gp[NGROUPS_MAX], *ngid;
caddr_t sg = stackgap_init(p->p_emul);
SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
- gp = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) * sizeof(gid_t *));
- iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
- sizeof(ibcs2_gid_t *));
+ if (SCARG(uap, gidsetsize) > NGROUPS_MAX)
+ return EINVAL;
+
if (SCARG(&sa, gidsetsize)) {
error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset,
- sizeof(ibcs2_gid_t *) * SCARG(uap, gidsetsize));
+ sizeof(ibcs2_gid_t) * SCARG(uap, gidsetsize));
if (error)
return error;
}
for (i = 0; i < SCARG(&sa, gidsetsize); i++)
gp[i]= (gid_t)iset[i];
- SCARG(&sa, gidset) = gp;
+ ngid = stackgap_alloc(&sg, NGROUPS_MAX * sizeof(gid_t));
+ error = copyout(gp, ngid, SCARG(&sa, gidsetsize) * sizeof(gid_t));
+ if (error)
+ return error;
+ SCARG(&sa, gidset) = ngid;
return sys_setgroups(p, &sa, retval);
}
@@ -1028,8 +1044,9 @@
int error;
struct sys_utimes_args sa;
struct timeval *tp;
+
caddr_t sg = stackgap_init(p->p_emul);
-
+ tp = stackgap_alloc(&sg, 2 * sizeof(struct timeval *));
IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
SCARG(&sa, path) = SCARG(uap, path);
if (SCARG(uap, buf)) {
@@ -1039,7 +1056,6 @@
sizeof(ubuf));
if (error)
return error;
- tp = stackgap_alloc(&sg, 2 * sizeof(struct timeval *));
tp[0].tv_sec = ubuf.actime;
tp[0].tv_usec = 0;
tp[1].tv_sec = ubuf.modtime;
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/ibcs2/ibcs2_stat.c
--- a/sys/compat/ibcs2/ibcs2_stat.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/ibcs2/ibcs2_stat.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ibcs2_stat.c,v 1.14 2000/03/30 11:27:16 augustss Exp $ */
+/* $NetBSD: ibcs2_stat.c,v 1.14.4.1 2000/08/30 03:59:20 sommerfeld Exp $ */
/*
* Copyright (c) 1995, 1998 Scott Bartram
* All rights reserved.
@@ -260,10 +260,10 @@
struct sys___stat13_args cup;
int error;
caddr_t sg = stackgap_init(p->p_emul);
-
+ SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
SCARG(&cup, path) = SCARG(uap, path);
- SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
+
if ((error = sys___stat13(p, &cup, retval)) != 0)
return error;
if ((error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
@@ -289,9 +289,10 @@
int error;
caddr_t sg = stackgap_init(p->p_emul);
+ SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
SCARG(&cup, path) = SCARG(uap, path);
- SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
+
if ((error = sys___lstat13(p, &cup, retval)) != 0)
return error;
if ((error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/linux/common/linux_file.c
--- a/sys/compat/linux/common/linux_file.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/linux/common/linux_file.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_file.c,v 1.28 1999/12/05 21:24:30 tron Exp $ */
+/* $NetBSD: linux_file.c,v 1.28.4.1 2000/08/30 03:59:20 sommerfeld Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -494,10 +494,9 @@
struct linux_sys_stat_args *uap = v;
sg = stackgap_init(p->p_emul);
-
+ st = stackgap_alloc(&sg, sizeof (struct stat));
LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
- st = stackgap_alloc(&sg, sizeof (struct stat));
SCARG(&sa, ub) = st;
SCARG(&sa, path) = SCARG(uap, path);
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/linux/common/linux_misc_notalpha.c
--- a/sys/compat/linux/common/linux_misc_notalpha.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/linux/common/linux_misc_notalpha.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_misc_notalpha.c,v 1.53.4.1 2000/07/13 20:16:28 thorpej Exp $ */
+/* $NetBSD: linux_misc_notalpha.c,v 1.53.4.2 2000/08/30 03:59:20 sommerfeld Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -230,6 +230,7 @@
struct linux_utimbuf lut;
sg = stackgap_init(p->p_emul);
+ tvp = (struct timeval *) stackgap_alloc(&sg, sizeof(tv));
LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
SCARG(&ua, path) = SCARG(uap, path);
@@ -240,7 +241,6 @@
tv[0].tv_usec = tv[1].tv_usec = 0;
tv[0].tv_sec = lut.l_actime;
tv[1].tv_sec = lut.l_modtime;
- tvp = (struct timeval *) stackgap_alloc(&sg, sizeof(tv));
if ((error = copyout(tv, tvp, sizeof tv)))
return error;
SCARG(&ua, tptr) = tvp;
diff -r b0518cff6852 -r 6f60dcd5859a sys/compat/svr4/svr4_stat.c
--- a/sys/compat/svr4/svr4_stat.c Wed Aug 30 00:55:44 2000 +0000
+++ b/sys/compat/svr4/svr4_stat.c Wed Aug 30 03:59:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: svr4_stat.c,v 1.37.4.1 2000/07/14 18:27:33 thorpej Exp $ */
+/* $NetBSD: svr4_stat.c,v 1.37.4.2 2000/08/30 03:59:20 sommerfeld Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -181,11 +181,9 @@
int error;
caddr_t sg = stackgap_init(p->p_emul);
+ SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
-
SCARG(&cup, path) = SCARG(uap, path);
- SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
-
if ((error = sys___stat13(p, &cup, retval)) != 0)
return error;
@@ -227,10 +225,9 @@
int error;
caddr_t sg = stackgap_init(p->p_emul);
+ SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
-
SCARG(&cup, path) = SCARG(uap, path);
- SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
if ((error = sys___lstat13(p, &cup, retval)) != 0)
return error;
@@ -305,10 +302,10 @@
int error;
caddr_t sg = stackgap_init(p->p_emul);
+
+ SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
Home |
Main Index |
Thread Index |
Old Index