From nobody Sun May 4 17:09:28 2025 X-Original-To: dev-commits-src-main@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 4ZrB3D3QYFz5tyS3; Sun, 04 May 2025 17:09: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZrB3D2d3xz44Wl; Sun, 04 May 2025 17:09:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746378568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+EvGTalhRWtfQzXNncD1D2OsoS3J690XJFyQSp0L4c0=; b=Isuu76J+Byu1yXWiPjb/AaD3XgA9QDTDyADo5PSLat1cCzVe3NSU1OyKY5dhW62LlhuYrm gloT9cqDYvtwcZKbFEr1WeRYNyQ+iS6O9aI4r5Z+vG0cd7z6Ue0jEVT4oRluNvGPdvG6hb 5ZYfrspgzGq8MXQTpACnKDdcPCRd4WXxZ7mr50YJh52DzxJMvAaa/0thvIREY0akGtaQn3 dDh3fsWt+WL0rWVsrmjeH51IhxNtK6sZe1rZFdF6ESGV7byxQDW9ocaJF0swISDrwqMHKB rFlriFWmn6+Gxkghch4JCX8UR4YWKAH/RGeq9yXkvDeeF66zSFdNQWDfBtl5Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746378568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+EvGTalhRWtfQzXNncD1D2OsoS3J690XJFyQSp0L4c0=; b=IECS5VKb1kHpl8+daR3uZ+yUKEz/Y4E6hlvh6DzKg/lipi/p9cG8zJlKWA+pMrk4pufzE6 udg64H41hkv1eCwC+JLk4JJbQmvEo0FjQbDqatEoP7arFe1v9h8PjjmTP8WDILBjSFHLdB ejc47jc1l8WBfMLV4PlHGPcAwrgSVkIdqkrzWsbGDqcmNQ/joV70z51BhenpBcA1kvQkrt ii/jReMtgI86Hn0+9Q1d4pt9wWORP8NXv+HOGEiEPIxgpsYeIipOhR64wSljEByiSTHVG6 biJm08uYEXZovTlFQmGSTg7RE1ozW8oKdZRezqFTJiLRRDo6bNqZQFPPcM9Dug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746378568; a=rsa-sha256; cv=none; b=gBZNq/LzvjwXDqAoUebpv8Ds2maXuUI5/AZmoQCdl/NcHPmKo7uFMtiIkgFtMA38ZHbyLf dLcnI1ZJP8BlR1zZNvD1tOUQmWYMUePGgliBLfEFwoyRqi3c68D4bpjwHJcligSeaF9klW B4G07d6T6T9CLTIbN2SikU2yC9Uyyg78TwG7doBT5xU4K5BBTHILEtIyYkBSsEUpZYT2DG uSRZQP4uKmaBxgAHig7tFjuPd9XU36TRtUjCEViiCrZQ26s+VjBTCUjmUXMX+tM63QvkXG wMky9LKrjl1s1D7fTBD/b7V+fjRGd7i4cCpDLMbGEo3rSmA2Tp3R2mmLeEY/Ag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4ZrB3D1lfSzdBk; Sun, 04 May 2025 17:09:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 544H9S4t060483; Sun, 4 May 2025 17:09:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 544H9SU1060480; Sun, 4 May 2025 17:09:28 GMT (envelope-from git) Date: Sun, 4 May 2025 17:09:28 GMT Message-Id: <202505041709.544H9SU1060480@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michal Meloun Subject: git: 9ee759f3676f - main - Decorate IPv4 structures used for byte buffer overlays as packed. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mmel X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9ee759f3676f700f8224a95216f659f87f5d9ae9 Auto-Submitted: auto-generated The branch main has been updated by mmel: URL: https://cgit.FreeBSD.org/src/commit/?id=9ee759f3676f700f8224a95216f659f87f5d9ae9 commit 9ee759f3676f700f8224a95216f659f87f5d9ae9 Author: Michal Meloun AuthorDate: 2025-05-01 08:54:05 +0000 Commit: Michal Meloun CommitDate: 2025-05-04 11:48:04 +0000 Decorate IPv4 structures used for byte buffer overlays as packed. The C language only allows pointer casting to another type if both sides have compatible alignments, unaligned casts causes undefined behavior. Since we do not have declared (and therefore not checked) mbuf alignments for the various input functions in the IP stack, the worst case (alignment to char*) should be expected. A lot of work still needs to be done on IPv6, especially on the terrible accesses to in6_addr members. It should have no performance impact on all unaligned architectures. MFC after: 1 month Reviewed by: kib PR: 272965 Differential Revision: https://reviews.freebsd.org/D50103 --- sys/netinet/dccp.h | 2 +- sys/netinet/ip.h | 4 ++-- sys/netinet/ip_var.h | 2 +- sys/netinet/pim.h | 2 +- sys/netinet/tcp.h | 2 +- sys/netinet/udp.h | 2 +- tests/sys/netinet/ip_reass_test.c | 12 ++++++++---- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sys/netinet/dccp.h b/sys/netinet/dccp.h index 4fb6a0d2ab3e..da83a1b06861 100644 --- a/sys/netinet/dccp.h +++ b/sys/netinet/dccp.h @@ -64,7 +64,7 @@ struct dccphdr { uint8_t seq[6]; } longseq; } d_seqno; -}; +} __packed; #define d_seqno_short d_seqno.shortseq; #define d_seqno_long d_seqno.longseq.seq; diff --git a/sys/netinet/ip.h b/sys/netinet/ip.h index 44db466912d0..6de41a7e79fa 100644 --- a/sys/netinet/ip.h +++ b/sys/netinet/ip.h @@ -67,7 +67,7 @@ struct ip { u_char ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src,ip_dst; /* source and dest address */ -} __packed __aligned(2); +} __packed; #define IP_MAXPACKET 65535 /* maximum packet size */ @@ -187,7 +187,7 @@ struct ip_timestamp { uint32_t ipt_time; /* network format */ } ipt_ta[1]; } ipt_timestamp; -}; +} __packed; /* Flag bits for ipt_flg. */ #define IPOPT_TS_TSONLY 0 /* timestamps only */ diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 18ca5861a40e..f782ebc53eb0 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -47,7 +47,7 @@ struct ipovly { u_short ih_len; /* protocol length */ struct in_addr ih_src; /* source internet address */ struct in_addr ih_dst; /* destination internet address */ -}; +} __packed; #ifdef _KERNEL /* diff --git a/sys/netinet/pim.h b/sys/netinet/pim.h index 98230fc6ae2d..4744ffc7e9d8 100644 --- a/sys/netinet/pim.h +++ b/sys/netinet/pim.h @@ -71,7 +71,7 @@ struct pim { #endif /* ! _PIM_VT */ uint8_t pim_reserved; /* Reserved */ uint16_t pim_cksum; /* IP-style checksum */ -}; +} __packed; /* KAME-related name backward compatibility */ #define pim_ver pim_vers #define pim_rsv pim_reserved diff --git a/sys/netinet/tcp.h b/sys/netinet/tcp.h index 94d41ff67836..41a49b318cd5 100644 --- a/sys/netinet/tcp.h +++ b/sys/netinet/tcp.h @@ -77,7 +77,7 @@ struct tcphdr { u_short th_win; /* window */ u_short th_sum; /* checksum */ u_short th_urp; /* urgent pointer */ -}; +} __packed; static __inline uint16_t __tcp_get_flags(const struct tcphdr *th) diff --git a/sys/netinet/udp.h b/sys/netinet/udp.h index edff456ba70e..010f2210b516 100644 --- a/sys/netinet/udp.h +++ b/sys/netinet/udp.h @@ -44,7 +44,7 @@ struct udphdr { u_short uh_dport; /* destination port */ u_short uh_ulen; /* udp length */ u_short uh_sum; /* udp checksum */ -}; +} __packed; /* * User-settable options (used with setsockopt). diff --git a/tests/sys/netinet/ip_reass_test.c b/tests/sys/netinet/ip_reass_test.c index a65bfa34e1d4..538815bd7a2c 100644 --- a/tests/sys/netinet/ip_reass_test.c +++ b/tests/sys/netinet/ip_reass_test.c @@ -60,12 +60,16 @@ update_cksum(struct ip *ip) { size_t i; uint32_t cksum; - uint16_t *cksump; + uint8_t *cksump; + uint16_t tmp; ip->ip_sum = 0; - cksump = (uint16_t *)ip; - for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(*cksump); cksump++, i++) - cksum += ntohs(*cksump); + cksump = (char *)ip; + for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(uint16_t); i++) { + tmp = *cksump++; + tmp = tmp << 8 | *cksump++; + cksum += ntohs(tmp); + } cksum = (cksum >> 16) + (cksum & 0xffff); cksum = ~(cksum + (cksum >> 16)); ip->ip_sum = htons((uint16_t)cksum);