Tue Feb 25 19:12:14 2020 UTC ()
Pull up following revision(s) (requested by maxv in ticket #1509):

	sys/kern/uipc_socket.c: revision 1.288

Zero out 'tv', to prevent uninitialized bytes in its padding from leaking
to userland. Found by kMSan.


(martin)
diff -r1.255.2.4 -r1.255.2.5 src/sys/kern/uipc_socket.c

cvs diff -r1.255.2.4 -r1.255.2.5 src/sys/kern/uipc_socket.c (expand / switch to unified diff)

--- src/sys/kern/uipc_socket.c 2018/11/12 09:43:19 1.255.2.4
+++ src/sys/kern/uipc_socket.c 2020/02/25 19:12:14 1.255.2.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uipc_socket.c,v 1.255.2.4 2018/11/12 09:43:19 martin Exp $ */ 1/* $NetBSD: uipc_socket.c,v 1.255.2.5 2020/02/25 19:12:14 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran. 8 * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -61,27 +61,27 @@ @@ -61,27 +61,27 @@
61 * 61 *
62 * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 62 * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95
63 */ 63 */
64 64
65/* 65/*
66 * Socket operation routines. 66 * Socket operation routines.
67 * 67 *
68 * These routines are called by the routines in sys_socket.c or from a 68 * These routines are called by the routines in sys_socket.c or from a
69 * system process, and implement the semantics of socket operations by 69 * system process, and implement the semantics of socket operations by
70 * switching out to the protocol specific routines. 70 * switching out to the protocol specific routines.
71 */ 71 */
72 72
73#include <sys/cdefs.h> 73#include <sys/cdefs.h>
74__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255.2.4 2018/11/12 09:43:19 martin Exp $"); 74__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255.2.5 2020/02/25 19:12:14 martin Exp $");
75 75
76#ifdef _KERNEL_OPT 76#ifdef _KERNEL_OPT
77#include "opt_compat_netbsd.h" 77#include "opt_compat_netbsd.h"
78#include "opt_sock_counters.h" 78#include "opt_sock_counters.h"
79#include "opt_sosend_loan.h" 79#include "opt_sosend_loan.h"
80#include "opt_mbuftrace.h" 80#include "opt_mbuftrace.h"
81#include "opt_somaxkva.h" 81#include "opt_somaxkva.h"
82#include "opt_multiprocessor.h" /* XXX */ 82#include "opt_multiprocessor.h" /* XXX */
83#include "opt_sctp.h" 83#include "opt_sctp.h"
84#endif 84#endif
85 85
86#include <sys/param.h> 86#include <sys/param.h>
87#include <sys/systm.h> 87#include <sys/systm.h>
@@ -2005,26 +2005,27 @@ sogetopt1(struct socket *so, struct sock @@ -2005,26 +2005,27 @@ sogetopt1(struct socket *so, struct sock
2005 otv.tv_sec = optval / hz; 2005 otv.tv_sec = optval / hz;
2006 otv.tv_usec = (optval % hz) * tick; 2006 otv.tv_usec = (optval % hz) * tick;
2007 2007
2008 error = sockopt_set(sopt, &otv, sizeof(otv)); 2008 error = sockopt_set(sopt, &otv, sizeof(otv));
2009 break; 2009 break;
2010 } 2010 }
2011#endif /* COMPAT_50 */ 2011#endif /* COMPAT_50 */
2012 2012
2013 case SO_SNDTIMEO: 2013 case SO_SNDTIMEO:
2014 case SO_RCVTIMEO: 2014 case SO_RCVTIMEO:
2015 optval = (opt == SO_SNDTIMEO ? 2015 optval = (opt == SO_SNDTIMEO ?
2016 so->so_snd.sb_timeo : so->so_rcv.sb_timeo); 2016 so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
2017 2017
 2018 memset(&tv, 0, sizeof(tv));
2018 tv.tv_sec = optval / hz; 2019 tv.tv_sec = optval / hz;
2019 tv.tv_usec = (optval % hz) * tick; 2020 tv.tv_usec = (optval % hz) * tick;
2020 2021
2021 error = sockopt_set(sopt, &tv, sizeof(tv)); 2022 error = sockopt_set(sopt, &tv, sizeof(tv));
2022 break; 2023 break;
2023 2024
2024 case SO_OVERFLOWED: 2025 case SO_OVERFLOWED:
2025 error = sockopt_setint(sopt, so->so_rcv.sb_overflowed); 2026 error = sockopt_setint(sopt, so->so_rcv.sb_overflowed);
2026 break; 2027 break;
2027 2028
2028 default: 2029 default:
2029 error = ENOPROTOOPT; 2030 error = ENOPROTOOPT;
2030 break; 2031 break;