RE: [PATCH] netlink: align attributes on 64-bits
From: David Laight <hidden>
Date: 2012-12-17 10:09:27
- if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen)))
+ int align = IS_ALIGNED((unsigned long)skb_tail_pointer(skb), sizeof(void *)) ? 0 : 4;
+
+ if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen) + align))
return -EMSGSIZE;
+ if (align) {
+ /* Goal is to add an attribute with size 4. We know that
+ * NLA_HDRLEN is 4, hence payload is 0.
+ */
+ __nla_reserve(skb, 0, 0);
+ }
+Shouldn't the size of the dummy parameter be based on the value of 'align' - and that be based on the amount of padding needed? That aligns the write pointer, what guarantees the alignment of the start of the buffer - so that the reader will find aligned data? What guarantees that the reader will read the data into an 8-byte aligned buffer. There is also the lurking issue of items that require more than 8-byte alignment. (x86/amd64 requires 16-byte alignment for 16-byte SSE2 regs and 32-byte alignment for the AVX regs.) Will anyone ever want to put such items into a netlink message? David