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/linux/common | |
| 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/linux/common')
| -rw-r--r-- | sys/compat/linux/common/linux_cdrom.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_fdio.c | 5 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_file.c | 5 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_hdio.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_misc.c | 7 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_mtio.c | 5 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_oldolduname.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_olduname.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_sched.c | 6 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_signal.c | 12 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_socket.c | 7 | ||||
| -rw-r--r-- | sys/compat/linux/common/linux_time.c | 6 |
12 files changed, 53 insertions, 24 deletions
diff --git a/sys/compat/linux/common/linux_cdrom.c b/sys/compat/linux/common/linux_cdrom.c index 07d84540c02..dbc9b1c45af 100644 --- a/sys/compat/linux/common/linux_cdrom.c +++ b/sys/compat/linux/common/linux_cdrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_cdrom.c,v 1.27 2008/04/28 20:23:43 martin Exp $ */ +/* $NetBSD: linux_cdrom.c,v 1.28 2021/09/07 11:43:04 riastradh Exp $ */ /* * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_cdrom.c,v 1.27 2008/04/28 20:23:43 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_cdrom.c,v 1.28 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -186,6 +186,7 @@ linux_ioctl_cdrom(struct lwp *l, const struct linux_sys_ioctl_args *uap, registe if (error) break; + memset(&l_tochdr, 0, sizeof(l_tochdr)); l_tochdr.cdth_trk0 = t_header.starting_track; l_tochdr.cdth_trk1 = t_header.ending_track; @@ -238,6 +239,7 @@ linux_ioctl_cdrom(struct lwp *l, const struct linux_sys_ioctl_args *uap, registe if (error) break; + memset(&l_volctrl, 0, sizeof(l_volctrl)); l_volctrl.channel0 = t_vol.vol[0]; l_volctrl.channel1 = t_vol.vol[1]; l_volctrl.channel2 = t_vol.vol[2]; diff --git a/sys/compat/linux/common/linux_fdio.c b/sys/compat/linux/common/linux_fdio.c index bf9b5be0590..01593f48f27 100644 --- a/sys/compat/linux/common/linux_fdio.c +++ b/sys/compat/linux/common/linux_fdio.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_fdio.c,v 1.13 2008/03/21 21:54:58 ad Exp $ */ +/* $NetBSD: linux_fdio.c,v 1.14 2021/09/07 11:43:04 riastradh Exp $ */ /* * Copyright (c) 2000 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_fdio.c,v 1.13 2008/03/21 21:54:58 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_fdio.c,v 1.14 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -107,6 +107,7 @@ linux_ioctl_fdio(struct lwp *l, const struct linux_sys_ioctl_args *uap, error = ioctlf(fp, FDIOCGETFORMAT, &fparams); if (error != 0) break; + memset(&lflop, 0, sizeof(lflop)); lflop.size = fparams.ncyl * fparams.nspt * fparams.ntrk; lflop.sect = fparams.nspt; lflop.head = fparams.ntrk; diff --git a/sys/compat/linux/common/linux_file.c b/sys/compat/linux/common/linux_file.c index e1ca8eff968..36ae0e429b1 100644 --- a/sys/compat/linux/common/linux_file.c +++ b/sys/compat/linux/common/linux_file.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_file.c,v 1.118 2020/05/23 23:42:41 ad Exp $ */ +/* $NetBSD: linux_file.c,v 1.119 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.118 2020/05/23 23:42:41 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.119 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -445,6 +445,7 @@ static void bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp) { + memset(lsp, 0, sizeof(*lsp)); lsp->lst_dev = linux_fakedev(bsp->st_dev, 0); lsp->lst_ino = bsp->st_ino; lsp->lst_mode = (linux_mode_t)bsp->st_mode; diff --git a/sys/compat/linux/common/linux_hdio.c b/sys/compat/linux/common/linux_hdio.c index 79300d3ebd0..992f94da8eb 100644 --- a/sys/compat/linux/common/linux_hdio.c +++ b/sys/compat/linux/common/linux_hdio.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_hdio.c,v 1.18 2019/02/03 03:19:26 mrg Exp $ */ +/* $NetBSD: linux_hdio.c,v 1.19 2021/09/07 11:43:04 riastradh Exp $ */ /* * Copyright (c) 2000 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_hdio.c,v 1.18 2019/02/03 03:19:26 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_hdio.c,v 1.19 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -113,6 +113,7 @@ linux_ioctl_hdio(struct lwp *l, const struct linux_sys_ioctl_args *uap, error = error1; break; } + memset(&hdg, 0, sizeof(hdg)); hdg.start = error1 != 0 ? pi.pi_offset : 0; hdg.heads = label.d_ntracks; hdg.cylinders = label.d_ncylinders; @@ -131,6 +132,7 @@ linux_ioctl_hdio(struct lwp *l, const struct linux_sys_ioctl_args *uap, error = error1; break; } + memset(&hdg_big, 0, sizeof(hdg_big)); hdg_big.start = error1 != 0 ? pi.pi_offset : 0; hdg_big.heads = label.d_ntracks; hdg_big.cylinders = label.d_ncylinders; diff --git a/sys/compat/linux/common/linux_misc.c b/sys/compat/linux/common/linux_misc.c index 4b94795bb21..bb05299d4c0 100644 --- a/sys/compat/linux/common/linux_misc.c +++ b/sys/compat/linux/common/linux_misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.c,v 1.251 2020/06/11 22:21:05 ad Exp $ */ +/* $NetBSD: linux_misc.c,v 1.252 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.251 2020/06/11 22:21:05 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.252 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -629,6 +629,8 @@ linux_sys_times(struct lwp *l, const struct linux_sys_times_args *uap, register_ struct linux_tms ltms; struct rusage ru; + memset(<ms, 0, sizeof(ltms)); + mutex_enter(p->p_lock); calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL); ltms.ltms_utime = CONVTCK(ru.ru_utime); @@ -1399,6 +1401,7 @@ linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, r 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(uap, rlp), sizeof(orl)); diff --git a/sys/compat/linux/common/linux_mtio.c b/sys/compat/linux/common/linux_mtio.c index b92051d65f2..8c54725d38d 100644 --- a/sys/compat/linux/common/linux_mtio.c +++ b/sys/compat/linux/common/linux_mtio.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_mtio.c,v 1.7 2008/03/21 21:54:58 ad Exp $ */ +/* $NetBSD: linux_mtio.c,v 1.8 2021/09/07 11:43:04 riastradh Exp $ */ /* * Copyright (c) 2005 Soren S. Jorvang. All rights reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_mtio.c,v 1.7 2008/03/21 21:54:58 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_mtio.c,v 1.8 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -106,6 +106,7 @@ linux_ioctl_mtio(struct lwp *l, const struct linux_sys_ioctl_args *uap, error = ioctlf(fp, MTIOCTOP, &mt); break; case LINUX_MTIOCGET: + memset(&lmtget, 0, sizeof(lmtget)); lmtget.mt_type = LINUX_MT_ISUNKNOWN; lmtget.mt_resid = 0; lmtget.mt_dsreg = 0; diff --git a/sys/compat/linux/common/linux_oldolduname.c b/sys/compat/linux/common/linux_oldolduname.c index c48939d49e5..e356259c70d 100644 --- a/sys/compat/linux/common/linux_oldolduname.c +++ b/sys/compat/linux/common/linux_oldolduname.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_oldolduname.c,v 1.66 2008/04/28 20:23:43 martin Exp $ */ +/* $NetBSD: linux_oldolduname.c,v 1.67 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_oldolduname.c,v 1.66 2008/04/28 20:23:43 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_oldolduname.c,v 1.67 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -58,6 +58,8 @@ linux_sys_oldolduname(struct lwp *l, const struct linux_sys_oldolduname_args *ua } */ struct linux_oldoldutsname luts; + memset(&luts, 0, sizeof(luts)); + strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname)); strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename)); strlcpy(luts.l_release, linux_release, sizeof(luts.l_release)); diff --git a/sys/compat/linux/common/linux_olduname.c b/sys/compat/linux/common/linux_olduname.c index 20f9cde0581..39dffeaa087 100644 --- a/sys/compat/linux/common/linux_olduname.c +++ b/sys/compat/linux/common/linux_olduname.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_olduname.c,v 1.66 2008/04/28 20:23:43 martin Exp $ */ +/* $NetBSD: linux_olduname.c,v 1.67 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_olduname.c,v 1.66 2008/04/28 20:23:43 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_olduname.c,v 1.67 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -61,6 +61,8 @@ linux_sys_olduname(struct lwp *l, const struct linux_sys_olduname_args *uap, reg } */ struct linux_oldutsname luts; + memset(&luts, 0, sizeof(luts)); + strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname)); strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename)); strlcpy(luts.l_release, linux_release, sizeof(luts.l_release)); diff --git a/sys/compat/linux/common/linux_sched.c b/sys/compat/linux/common/linux_sched.c index ea301c19971..2e1b973d7c7 100644 --- a/sys/compat/linux/common/linux_sched.c +++ b/sys/compat/linux/common/linux_sched.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_sched.c,v 1.78 2020/05/23 23:42:41 ad Exp $ */ +/* $NetBSD: linux_sched.c,v 1.79 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1999, 2019 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.78 2020/05/23 23:42:41 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.79 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/mount.h> @@ -346,6 +346,8 @@ sched_native2linux(int native_policy, struct sched_param *native_params, KASSERT(prio <= SCHED_PRI_MAX); KASSERT(linux_params != NULL); + memset(linux_params, 0, sizeof(*linux_params)); + DPRINTF(("%s: native: policy %d, priority %d\n", __func__, native_policy, prio)); diff --git a/sys/compat/linux/common/linux_signal.c b/sys/compat/linux/common/linux_signal.c index 92b44250ec0..4ab265fc42f 100644 --- a/sys/compat/linux/common/linux_signal.c +++ b/sys/compat/linux/common/linux_signal.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_signal.c,v 1.83 2020/05/23 23:42:41 ad Exp $ */ +/* $NetBSD: linux_signal.c,v 1.84 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.83 2020/05/23 23:42:41 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.84 2021/09/07 11:43:04 riastradh Exp $"); #define COMPAT_LINUX 1 @@ -274,6 +274,8 @@ linux_to_native_sigflags(const unsigned long lsf) void linux_old_to_native_sigaction(struct sigaction *bsa, const struct linux_old_sigaction *lsa) { + + memset(bsa, 0, sizeof(*bsa)); bsa->sa_handler = lsa->linux_sa_handler; linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask); bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags); @@ -282,6 +284,8 @@ linux_old_to_native_sigaction(struct sigaction *bsa, const struct linux_old_siga void native_to_linux_old_sigaction(struct linux_old_sigaction *lsa, const struct sigaction *bsa) { + + memset(lsa, 0, sizeof(*lsa)); lsa->linux_sa_handler = bsa->sa_handler; native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask); lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags); @@ -294,6 +298,8 @@ native_to_linux_old_sigaction(struct linux_old_sigaction *lsa, const struct siga void linux_to_native_sigaction(struct sigaction *bsa, const struct linux_sigaction *lsa) { + + memset(bsa, 0, sizeof(*bsa)); bsa->sa_handler = lsa->linux_sa_handler; linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask); bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags); @@ -302,6 +308,8 @@ linux_to_native_sigaction(struct sigaction *bsa, const struct linux_sigaction *l void native_to_linux_sigaction(struct linux_sigaction *lsa, const struct sigaction *bsa) { + + memset(lsa, 0, sizeof(*lsa)); lsa->linux_sa_handler = bsa->sa_handler; native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask); lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags); diff --git a/sys/compat/linux/common/linux_socket.c b/sys/compat/linux/common/linux_socket.c index b6e3c637e47..90f1c9c4edf 100644 --- a/sys/compat/linux/common/linux_socket.c +++ b/sys/compat/linux/common/linux_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_socket.c,v 1.152 2020/11/03 22:08:44 christos Exp $ */ +/* $NetBSD: linux_socket.c,v 1.153 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.152 2020/11/03 22:08:44 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.153 2021/09/07 11:43:04 riastradh Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -440,6 +440,7 @@ linux_sys_sendto(struct lwp *l, const struct linux_sys_sendto_args *uap, registe static void linux_to_bsd_msghdr(const struct linux_msghdr *lmsg, struct msghdr *bmsg) { + memset(bmsg, 0, sizeof(*bmsg)); bmsg->msg_name = lmsg->msg_name; bmsg->msg_namelen = lmsg->msg_namelen; bmsg->msg_iov = lmsg->msg_iov; @@ -452,6 +453,7 @@ linux_to_bsd_msghdr(const struct linux_msghdr *lmsg, struct msghdr *bmsg) static void bsd_to_linux_msghdr(const struct msghdr *bmsg, struct linux_msghdr *lmsg) { + memset(lmsg, 0, sizeof(*lmsg)); lmsg->msg_name = bmsg->msg_name; lmsg->msg_namelen = bmsg->msg_namelen; lmsg->msg_iov = bmsg->msg_iov; @@ -699,6 +701,7 @@ linux_copyout_msg_control(struct lwp *l, struct msghdr *mp, struct mbuf *control * 1. different values for level/type on some archs * 2. different alignment of CMSG_DATA on some archs */ + memset(&linux_cmsg, 0, sizeof(linux_cmsg)); linux_cmsg.cmsg_len = cmsg->cmsg_len - LINUX_CMSG_ALIGN_DELTA; linux_cmsg.cmsg_level = cmsg->cmsg_level; linux_cmsg.cmsg_type = cmsg->cmsg_type; diff --git a/sys/compat/linux/common/linux_time.c b/sys/compat/linux/common/linux_time.c index 7d689ff76a9..62943defd2c 100644 --- a/sys/compat/linux/common/linux_time.c +++ b/sys/compat/linux/common/linux_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_time.c,v 1.39 2017/07/29 02:31:22 riastradh Exp $ */ +/* $NetBSD: linux_time.c,v 1.40 2021/09/07 11:43:04 riastradh Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.39 2017/07/29 02:31:22 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.40 2021/09/07 11:43:04 riastradh Exp $"); #include <sys/param.h> #include <sys/ucred.h> @@ -117,6 +117,7 @@ linux_sys_settimeofday(struct lwp *l, const struct linux_sys_settimeofday_args * void native_to_linux_timespec(struct linux_timespec *ltp, struct timespec *ntp) { + memset(ltp, 0, sizeof(*ltp)); ltp->tv_sec = ntp->tv_sec; ltp->tv_nsec = ntp->tv_nsec; } @@ -124,6 +125,7 @@ native_to_linux_timespec(struct linux_timespec *ltp, struct timespec *ntp) void linux_to_native_timespec(struct timespec *ntp, struct linux_timespec *ltp) { + memset(ntp, 0, sizeof(*ntp)); ntp->tv_sec = ltp->tv_sec; ntp->tv_nsec = ltp->tv_nsec; } |
