From nobody Wed Nov 03 17:45:28 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9916118205BA; Wed, 3 Nov 2021 17:45:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HkvLc417cz3n8m; Wed, 3 Nov 2021 17:45:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5B4341CD53; Wed, 3 Nov 2021 17:45:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A3HjSw6016392; Wed, 3 Nov 2021 17:45:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A3HjSi8016391; Wed, 3 Nov 2021 17:45:28 GMT (envelope-from git) Date: Wed, 3 Nov 2021 17:45:28 GMT Message-Id: <202111031745.1A3HjSi8016391@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 3358df297325 - main - udp_input: remove a BSD stack relict List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3358df2973251b4de690f197640eca5d794e0194 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=3358df2973251b4de690f197640eca5d794e0194 commit 3358df2973251b4de690f197640eca5d794e0194 Author: Gleb Smirnoff AuthorDate: 2021-10-28 07:07:02 +0000 Commit: Gleb Smirnoff CommitDate: 2021-11-03 17:39:34 +0000 udp_input: remove a BSD stack relict I should had removed it 9 years ago in 8ad458a471ca. That commit left save_ip as a write-only variable. With save_ip removed we got one case when IP header can be modified: the calculation of IP checksum with zeroed out header. This place already has had a header saver char b[9]. However, the b[9] saver didn't cover the ip_sum field, which we explicitly overwrite aliased as (struct ipovly *)->ih_len. This was fine in cb34210012d4e, since checksum doesn't need to be restored if packet is consumed. Now we need to extend up to ip_sum field. In collaboration with: ae Differential revision: https://reviews.freebsd.org/D32719 --- sys/netinet/udp_usrreq.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 46d687690713..7c5a642da040 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -398,7 +398,6 @@ udp_input(struct mbuf **mp, int *offp, int proto) struct inpcb *inp; uint16_t len, ip_len; struct inpcbinfo *pcbinfo; - struct ip save_ip; struct sockaddr_in udp_in[2]; struct mbuf *m; struct m_tag *fwd_tag; @@ -474,15 +473,6 @@ udp_input(struct mbuf **mp, int *offp, int proto) m_adj(m, len - ip_len); } - /* - * Save a copy of the IP header in case we want restore it for - * sending an ICMP error message in response. - */ - if (!V_udp_blackhole) - save_ip = *ip; - else - memset(&save_ip, 0, sizeof(save_ip)); - /* * Checksum extended UDP header and data. */ @@ -499,14 +489,15 @@ udp_input(struct mbuf **mp, int *offp, int proto) m->m_pkthdr.csum_data + proto)); uh_sum ^= 0xffff; } else { - char b[9]; + char b[offsetof(struct ipovly, ih_src)]; + struct ipovly *ipov = (struct ipovly *)ip; - bcopy(((struct ipovly *)ip)->ih_x1, b, 9); - bzero(((struct ipovly *)ip)->ih_x1, 9); - ((struct ipovly *)ip)->ih_len = (proto == IPPROTO_UDP) ? + bcopy(ipov, b, sizeof(b)); + bzero(ipov, sizeof(ipov->ih_x1)); + ipov->ih_len = (proto == IPPROTO_UDP) ? uh->uh_ulen : htons(ip_len); uh_sum = in_cksum(m, len + sizeof (struct ip)); - bcopy(b, ((struct ipovly *)ip)->ih_x1, 9); + bcopy(b, ipov, sizeof(b)); } if (uh_sum) { UDPSTAT_INC(udps_badsum); @@ -714,7 +705,6 @@ udp_input(struct mbuf **mp, int *offp, int proto) goto badunlocked; if (badport_bandlim(BANDLIM_ICMP_UNREACH) < 0) goto badunlocked; - *ip = save_ip; icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); return (IPPROTO_DONE); }