From owner-svn-src-all@freebsd.org Thu Nov 22 20:49:44 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 31CDC11074ED; Thu, 22 Nov 2018 20:49:44 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CDC8486D5A; Thu, 22 Nov 2018 20:49:43 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AEEBC14F17; Thu, 22 Nov 2018 20:49:43 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wAMKnh7M014586; Thu, 22 Nov 2018 20:49:43 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wAMKnf99014576; Thu, 22 Nov 2018 20:49:41 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201811222049.wAMKnf99014576@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 22 Nov 2018 20:49:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340783 - in head/sys: kern netinet netinet6 ofed/drivers/infiniband/ulp/sdp X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in head/sys: kern netinet netinet6 ofed/drivers/infiniband/ulp/sdp X-SVN-Commit-Revision: 340783 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CDC8486D5A X-Spamd-Result: default: False [1.21 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_SPAM_SHORT(0.06)[0.056,0]; NEURAL_SPAM_MEDIUM(0.74)[0.738,0]; NEURAL_SPAM_LONG(0.42)[0.420,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Nov 2018 20:49:44 -0000 Author: markj Date: Thu Nov 22 20:49:41 2018 New Revision: 340783 URL: https://svnweb.freebsd.org/changeset/base/340783 Log: Plug some networking sysctl leaks. Various network protocol sysctl handlers were not zero-filling their output buffers and thus would export uninitialized stack memory to userland. Fix a number of such handlers. Reported by: Thomas Barabosch, Fraunhofer FKIE Reviewed by: tuexen MFC after: 3 days Security: kernel memory disclosure Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18301 Modified: head/sys/kern/uipc_socket.c head/sys/kern/uipc_usrreq.c head/sys/netinet/in_pcb.c head/sys/netinet/ip_divert.c head/sys/netinet/raw_ip.c head/sys/netinet/sctp_sysctl.c head/sys/netinet/tcp_subr.c head/sys/netinet/udp_usrreq.c head/sys/netinet6/ip6_mroute.c head/sys/ofed/drivers/infiniband/ulp/sdp/sdp_main.c Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/kern/uipc_socket.c Thu Nov 22 20:49:41 2018 (r340783) @@ -4007,6 +4007,7 @@ void sotoxsocket(struct socket *so, struct xsocket *xso) { + bzero(xso, sizeof(*xso)); xso->xso_len = sizeof *xso; xso->xso_so = (uintptr_t)so; xso->so_type = so->so_type; @@ -4025,8 +4026,6 @@ sotoxsocket(struct socket *so, struct xsocket *xso) xso->so_incqlen = so->sol_incqlen; xso->so_qlimit = so->sol_qlimit; xso->so_oobmark = 0; - bzero(&xso->so_snd, sizeof(xso->so_snd)); - bzero(&xso->so_rcv, sizeof(xso->so_rcv)); } else { xso->so_state |= so->so_qstate; xso->so_qlen = xso->so_incqlen = xso->so_qlimit = 0; Modified: head/sys/kern/uipc_usrreq.c ============================================================================== --- head/sys/kern/uipc_usrreq.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/kern/uipc_usrreq.c Thu Nov 22 20:49:41 2018 (r340783) @@ -1809,7 +1809,7 @@ unp_pcblist(SYSCTL_HANDLER_ARGS) /* * OK, now we're committed to doing something. */ - xug = malloc(sizeof(*xug), M_TEMP, M_WAITOK); + xug = malloc(sizeof(*xug), M_TEMP, M_WAITOK | M_ZERO); UNP_LINK_RLOCK(); gencnt = unp_gencnt; n = unp_count; Modified: head/sys/netinet/in_pcb.c ============================================================================== --- head/sys/netinet/in_pcb.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/in_pcb.c Thu Nov 22 20:49:41 2018 (r340783) @@ -2883,11 +2883,10 @@ void in_pcbtoxinpcb(const struct inpcb *inp, struct xinpcb *xi) { + bzero(xi, sizeof(*xi)); xi->xi_len = sizeof(struct xinpcb); if (inp->inp_socket) sotoxsocket(inp->inp_socket, &xi->xi_socket); - else - bzero(&xi->xi_socket, sizeof(struct xsocket)); bcopy(&inp->inp_inc, &xi->inp_inc, sizeof(struct in_conninfo)); xi->inp_gencnt = inp->inp_gencnt; xi->inp_ppcb = (uintptr_t)inp->inp_ppcb; Modified: head/sys/netinet/ip_divert.c ============================================================================== --- head/sys/netinet/ip_divert.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/ip_divert.c Thu Nov 22 20:49:41 2018 (r340783) @@ -664,6 +664,7 @@ div_pcblist(SYSCTL_HANDLER_ARGS) if (error != 0) return (error); + bzero(&xig, sizeof(xig)); xig.xig_len = sizeof xig; xig.xig_count = n; xig.xig_gen = gencnt; Modified: head/sys/netinet/raw_ip.c ============================================================================== --- head/sys/netinet/raw_ip.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/raw_ip.c Thu Nov 22 20:49:41 2018 (r340783) @@ -1060,6 +1060,7 @@ rip_pcblist(SYSCTL_HANDLER_ARGS) n = V_ripcbinfo.ipi_count; INP_INFO_WUNLOCK(&V_ripcbinfo); + bzero(&xig, sizeof(xig)); xig.xig_len = sizeof xig; xig.xig_count = n; xig.xig_gen = gencnt; Modified: head/sys/netinet/sctp_sysctl.c ============================================================================== --- head/sys/netinet/sctp_sysctl.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/sctp_sysctl.c Thu Nov 22 20:49:41 2018 (r340783) @@ -395,6 +395,9 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM); return (EPERM); } + memset(&xinpcb, 0, sizeof(xinpcb)); + memset(&xstcb, 0, sizeof(xstcb)); + memset(&xraddr, 0, sizeof(xraddr)); LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { SCTP_INP_RLOCK(inp); if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) { Modified: head/sys/netinet/tcp_subr.c ============================================================================== --- head/sys/netinet/tcp_subr.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/tcp_subr.c Thu Nov 22 20:49:41 2018 (r340783) @@ -556,6 +556,7 @@ sysctl_net_inet_list_func_info(SYSCTL_HANDLER_ARGS) cnt++; #endif if (req->oldptr != NULL) { + bzero(&tfi, sizeof(tfi)); tfi.tfi_refcnt = f->tf_fb->tfb_refcnt; tfi.tfi_id = f->tf_fb->tfb_id; (void)strncpy(tfi.tfi_alias, f->tf_name, @@ -2154,6 +2155,7 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS) if (error != 0) return (error); + bzero(&xig, sizeof(xig)); xig.xig_len = sizeof xig; xig.xig_count = n + m; xig.xig_gen = gencnt; @@ -3215,8 +3217,8 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *x struct tcpcb *tp = intotcpcb(inp); sbintime_t now; + bzero(xt, sizeof(*xt)); if (inp->inp_flags & INP_TIMEWAIT) { - bzero(xt, sizeof(struct xtcpcb)); xt->t_state = TCPS_TIME_WAIT; } else { xt->t_state = tp->t_state; @@ -3244,7 +3246,6 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *x bcopy(tp->t_fb->tfb_tcp_block_name, xt->xt_stack, TCP_FUNCTION_NAME_LEN_MAX); - bzero(xt->xt_logid, TCP_LOG_ID_LEN); #ifdef TCP_BLACKBOX (void)tcp_log_get_id(tp, xt->xt_logid); #endif Modified: head/sys/netinet/udp_usrreq.c ============================================================================== --- head/sys/netinet/udp_usrreq.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet/udp_usrreq.c Thu Nov 22 20:49:41 2018 (r340783) @@ -887,6 +887,7 @@ udp_pcblist(SYSCTL_HANDLER_ARGS) if (error != 0) return (error); + bzero(&xig, sizeof(xig)); xig.xig_len = sizeof xig; xig.xig_count = n; xig.xig_gen = gencnt; Modified: head/sys/netinet6/ip6_mroute.c ============================================================================== --- head/sys/netinet6/ip6_mroute.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/netinet6/ip6_mroute.c Thu Nov 22 20:49:41 2018 (r340783) @@ -203,7 +203,8 @@ sysctl_mif6table(SYSCTL_HANDLER_ARGS) struct mif6_sctl *out; int error; - out = malloc(sizeof(struct mif6_sctl) * MAXMIFS, M_TEMP, M_WAITOK); + out = malloc(sizeof(struct mif6_sctl) * MAXMIFS, M_TEMP, + M_WAITOK | M_ZERO); for (int i = 0; i < MAXMIFS; i++) { out[i].m6_flags = mif6table[i].m6_flags; out[i].m6_rate_limit = mif6table[i].m6_rate_limit; Modified: head/sys/ofed/drivers/infiniband/ulp/sdp/sdp_main.c ============================================================================== --- head/sys/ofed/drivers/infiniband/ulp/sdp/sdp_main.c Thu Nov 22 20:05:57 2018 (r340782) +++ head/sys/ofed/drivers/infiniband/ulp/sdp/sdp_main.c Thu Nov 22 20:49:41 2018 (r340783) @@ -1810,6 +1810,7 @@ sdp_pcblist(SYSCTL_HANDLER_ARGS) if (error != 0) return (error); + bzero(&xig, sizeof(xig)); xig.xig_len = sizeof xig; xig.xig_count = n; xig.xig_gen = 0;