Author: brooks
Date: Fri Mar 30 21:38:53 2018
New Revision: 331831
URL: https://svnweb.freebsd.org/changeset/base/331831

Log:
  Document and enforce assumptions about struct (in6_)ifreq.
  
  - The two types must be type-punnable for shared members of ifr_ifru.
    This allows compatibility accessors to be shared.
  
  - There must be no padding gap between ifr_name and ifr_ifru.  This is
    assumed in tcpdump's use of SIOCGIFFLAGS output which attempts to be
    broadly portable.  This is true for all current architectures, but very
    large (256-bit) fat-pointers could violate this invariant.
  
  Reviewed by:  kib
  Obtained from:        CheriBSD
  Sponsored by: DARPA, AFRL
  Differential Revision:        https://reviews.freebsd.org/D14910

Modified:
  head/sys/net/if.c
  head/sys/netinet6/in6.c

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c   Fri Mar 30 20:27:47 2018        (r331830)
+++ head/sys/net/if.c   Fri Mar 30 21:38:53 2018        (r331831)
@@ -97,6 +97,13 @@
 
 #include <security/mac/mac_framework.h>
 
+/*
+ * Consumers of struct ifreq such as tcpdump assume no pad between ifr_name
+ * and ifr_ifru when it is used in SIOCGIFCONF.
+ */
+_Static_assert(sizeof(((struct ifreq *)0)->ifr_name) ==
+    offsetof(struct ifreq, ifr_ifru), "gap between ifr_name and ifr_ifru");
+
 #ifdef COMPAT_FREEBSD32
 #include <sys/mount.h>
 #include <compat/freebsd32/freebsd32.h>

Modified: head/sys/netinet6/in6.c
==============================================================================
--- head/sys/netinet6/in6.c     Fri Mar 30 20:27:47 2018        (r331830)
+++ head/sys/netinet6/in6.c     Fri Mar 30 21:38:53 2018        (r331831)
@@ -112,6 +112,14 @@ __FBSDID("$FreeBSD$");
 #include <netinet6/in6_fib.h>
 #include <netinet6/in6_pcb.h>
 
+/*
+ * struct in6_ifreq and struct ifreq must be type punnable for common members
+ * of ifr_ifru to allow accessors to be shared.
+ */
+_Static_assert(offsetof(struct in6_ifreq, ifr_ifru) ==
+    offsetof(struct ifreq, ifr_ifru),
+    "struct in6_ifreq and struct ifreq are not type punnable");
+
 VNET_DECLARE(int, icmp6_nodeinfo_oldmcprefix);
 #define V_icmp6_nodeinfo_oldmcprefix   VNET(icmp6_nodeinfo_oldmcprefix)
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to