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
This commit is contained in:
brooks 2018-03-30 21:38:53 +00:00
parent 019d267b75
commit 2b96daf50f
2 changed files with 15 additions and 0 deletions

View File

@ -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>

View File

@ -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)