Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bonding,llc: Fix structure sizeof incompatibility for some PDUs

With some combinations of arch/compiler (e.g. arm-linux-gcc) the sizeof
operator on structure returns value greater than expected. In cases when the
structure is used for mapping PDU fields it may lead to unexpected results
(such as holes and alignment problems in skb data). __packed prevents this
undesired behavior.

Signed-off-by: Vitalii Demianets <vitas@nppfactor.kiev.ua>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vitalii Demianets and committed by
David S. Miller
a10e1466 ca067070

+9 -9
+5 -5
drivers/net/bonding/bond_3ad.h
··· 39 39 40 40 typedef struct mac_addr { 41 41 u8 mac_addr_value[ETH_ALEN]; 42 - } mac_addr_t; 42 + } __packed mac_addr_t; 43 43 44 44 enum { 45 45 BOND_AD_STABLE = 0, ··· 134 134 u8 tlv_type_terminator; // = terminator 135 135 u8 terminator_length; // = 0 136 136 u8 reserved_50[50]; // = 0 137 - } lacpdu_t; 137 + } __packed lacpdu_t; 138 138 139 139 typedef struct lacpdu_header { 140 140 struct ethhdr hdr; 141 141 struct lacpdu lacpdu; 142 - } lacpdu_header_t; 142 + } __packed lacpdu_header_t; 143 143 144 144 // Marker Protocol Data Unit(PDU) structure(43.5.3.2 in the 802.3ad standard) 145 145 typedef struct bond_marker { ··· 155 155 u8 tlv_type_terminator; // = 0x00 156 156 u8 terminator_length; // = 0x00 157 157 u8 reserved_90[90]; // = 0 158 - } bond_marker_t; 158 + } __packed bond_marker_t; 159 159 160 160 typedef struct bond_marker_header { 161 161 struct ethhdr hdr; 162 162 struct bond_marker marker; 163 - } bond_marker_header_t; 163 + } __packed bond_marker_header_t; 164 164 165 165 #pragma pack() 166 166
+4 -4
include/net/llc_pdu.h
··· 199 199 u8 ssap; 200 200 u8 ctrl_1; 201 201 u8 ctrl_2; 202 - }; 202 + } __packed; 203 203 204 204 static inline struct llc_pdu_sn *llc_pdu_sn_hdr(struct sk_buff *skb) 205 205 { ··· 211 211 u8 dsap; 212 212 u8 ssap; 213 213 u8 ctrl_1; 214 - }; 214 + } __packed; 215 215 216 216 static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb) 217 217 { ··· 359 359 u8 fmt_id; /* always 0x81 for LLC */ 360 360 u8 type; /* different if NULL/non-NULL LSAP */ 361 361 u8 rw; /* sender receive window */ 362 - }; 362 + } __packed; 363 363 364 364 /** 365 365 * llc_pdu_init_as_xid_cmd - sets bytes 3, 4 & 5 of LLC header as XID ··· 415 415 u8 curr_ssv; /* current send state variable val */ 416 416 u8 curr_rsv; /* current receive state variable */ 417 417 u8 ind_bits; /* indicator bits set with macro */ 418 - }; 418 + } __packed; 419 419 420 420 extern void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 type); 421 421 extern void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value);