diff options
| author | riastradh <riastradh@NetBSD.org> | 2021-09-07 11:43:02 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2021-09-07 11:43:02 +0000 |
| commit | d50c96bb491810004b0fd3ea08acbff05abd6140 (patch) | |
| tree | e16d154152093b1cf3e149fd08f9ae1198e78a9e /sys/compat/linux32 | |
| parent | 8c28c0027cf16b13c944b0927bedb3108488033d (diff) | |
sys/compat: Memset zero before copyout.
Just in case of uninitialized padding which would lead to kernel
stack disclosure. If the compiler can prove the memset redundant
then it can optimize it away; otherwise better safe than sorry.
Diffstat (limited to 'sys/compat/linux32')
| -rw-r--r-- | sys/compat/linux32/arch/amd64/linux32_machdep.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux32/common/linux32_exec_elf32.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux32/common/linux32_resource.c | 5 | ||||
| -rw-r--r-- | sys/compat/linux32/common/linux32_signal.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux32/common/linux32_time.c | 10 |
5 files changed, 23 insertions, 10 deletions
diff --git a/sys/compat/linux32/arch/amd64/linux32_machdep.c b/sys/compat/linux32/arch/amd64/linux32_machdep.c index 70a9ac2e3fb..31843580fb1 100644 --- a/sys/compat/linux32/arch/amd64/linux32_machdep.c +++ b/sys/compat/linux32/arch/amd64/linux32_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_machdep.c,v 1.45 2019/05/19 08:46:15 maxv Exp $ */ +/* $NetBSD: linux32_machdep.c,v 1.46 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -31,7 +31,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_machdep.c,v 1.45 2019/05/19 08:46:15 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_machdep.c,v 1.46 2021/09/07 11:43:04 riastradh Exp $"); #if defined(_KERNEL_OPT) #include "opt_user_ldt.h" @@ -126,6 +126,8 @@ linux32_old_sendsig(const ksiginfo_t *ksi, const sigset_t *mask) DPRINTF(("old: onstack = %d, fp = %p sig = %d rip = 0x%lx\n", onstack, fp, sig, tf->tf_rip)); + memset(&frame, 0, sizeof(frame)); + /* Build stack frame for signal trampoline. */ NETBSD32PTR32(frame.sf_handler, catcher); frame.sf_sig = native_to_linux32_signo[sig]; diff --git a/sys/compat/linux32/common/linux32_exec_elf32.c b/sys/compat/linux32/common/linux32_exec_elf32.c index 19ed2980f41..a34a95ad2fd 100644 --- a/sys/compat/linux32/common/linux32_exec_elf32.c +++ b/sys/compat/linux32/common/linux32_exec_elf32.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_exec_elf32.c,v 1.19 2016/08/06 15:13:13 maxv Exp $ */ +/* $NetBSD: linux32_exec_elf32.c,v 1.20 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998, 2000, 2001,2006 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.19 2016/08/06 15:13:13 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.20 2021/09/07 11:43:04 riastradh Exp $"); #define ELFSIZE 32 @@ -227,6 +227,8 @@ linux32_elf32_copyargs(struct lwp *l, struct exec_package *pack, *stackp += len; #if 0 + memset(&esd, 0, sizeof(esd)); + memcpy(esd.kernel_vsyscall, linux32_kernel_vsyscall, sizeof(linux32_kernel_vsyscall)); diff --git a/sys/compat/linux32/common/linux32_resource.c b/sys/compat/linux32/common/linux32_resource.c index 54970167ec7..35788a56c4e 100644 --- a/sys/compat/linux32/common/linux32_resource.c +++ b/sys/compat/linux32/common/linux32_resource.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_resource.c,v 1.11 2012/09/22 22:34:03 joerg Exp $ */ +/* $NetBSD: linux32_resource.c,v 1.12 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_resource.c,v 1.11 2012/09/22 22:34:03 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_resource.c,v 1.12 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -87,6 +87,7 @@ linux32_sys_getrlimit(struct lwp *l, const struct linux32_sys_getrlimit_args *ua if (which < 0) return -which; + memset(&orl, 0, sizeof(orl)); bsd_to_linux_rlimit(&orl, &l->l_proc->p_rlimit[which]); return copyout(&orl, SCARG_P32(uap, rlp), sizeof(orl)); diff --git a/sys/compat/linux32/common/linux32_signal.c b/sys/compat/linux32/common/linux32_signal.c index 8c6624e42c1..e9913e8599a 100644 --- a/sys/compat/linux32/common/linux32_signal.c +++ b/sys/compat/linux32/common/linux32_signal.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_signal.c,v 1.20 2019/08/23 08:31:11 maxv Exp $ */ +/* $NetBSD: linux32_signal.c,v 1.21 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_signal.c,v 1.20 2019/08/23 08:31:11 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_signal.c,v 1.21 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/ucred.h> @@ -215,6 +215,7 @@ linux32_to_native_sigflags(const unsigned long lsf) void linux32_to_native_sigaction(struct sigaction *bsa, const struct linux32_sigaction *lsa) { + memset(bsa, 0, sizeof(*bsa)); bsa->sa_handler = NETBSD32PTR64(lsa->linux_sa_handler); linux32_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask); bsa->sa_flags = linux32_to_native_sigflags(lsa->linux_sa_flags); @@ -223,6 +224,7 @@ linux32_to_native_sigaction(struct sigaction *bsa, const struct linux32_sigactio void native_to_linux32_sigaction(struct linux32_sigaction *lsa, const struct sigaction *bsa) { + memset(lsa, 0, sizeof(*lsa)); NETBSD32PTR32(lsa->linux_sa_handler, bsa->sa_handler); native_to_linux32_sigset(&lsa->linux_sa_mask, &bsa->sa_mask); lsa->linux_sa_flags = native_to_linux32_sigflags(bsa->sa_flags); diff --git a/sys/compat/linux32/common/linux32_time.c b/sys/compat/linux32/common/linux32_time.c index a6b9173e950..ff1bf856531 100644 --- a/sys/compat/linux32/common/linux32_time.c +++ b/sys/compat/linux32/common/linux32_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_time.c,v 1.37 2012/10/02 01:44:28 christos Exp $ */ +/* $NetBSD: linux32_time.c,v 1.38 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.37 2012/10/02 01:44:28 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.38 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -166,6 +166,8 @@ linux32_sys_times(struct lwp *l, const struct linux32_sys_times_args *uap, regis struct linux32_tms ltms32; struct rusage ru; + memset(<ms32, 0, sizeof(ltms32)); + mutex_enter(p->p_lock); calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL); ltms32.ltms32_utime = CONVTCK(ru.ru_utime); @@ -237,6 +239,8 @@ linux32_sys_utime(struct lwp *l, const struct linux32_sys_utime_args *uap, regis void native_to_linux32_timespec(struct linux32_timespec *ltp, struct timespec *ntp) { + + memset(ltp, 0, sizeof(*ltp)); ltp->tv_sec = ntp->tv_sec; ltp->tv_nsec = ntp->tv_nsec; } @@ -244,6 +248,8 @@ native_to_linux32_timespec(struct linux32_timespec *ltp, struct timespec *ntp) void linux32_to_native_timespec(struct timespec *ntp, struct linux32_timespec *ltp) { + + memset(ntp, 0, sizeof(*ntp)); ntp->tv_sec = ltp->tv_sec; ntp->tv_nsec = ltp->tv_nsec; } |
