Skip to content

Commit 9c2aece

Browse files
aarcampaboch
authored andcommitted
fix: zero the genlmsghdr reserved field in Genlmsg
The kernel struct is defined as follows: struct genlmsghdr { __u8 cmd; __u8 version; __u16 reserved; }; Genlmsg declared only Command and Version (2 bytes), but SizeofGenlmsg is 4 and Serialize() unsafe-casts the struct to [4]byte. The extra two bytes contained arbitrary contents read from adjacent memory and emitted as the genlmsghdr reserved field. The kernel's genl_header_check() conditionally rejects a non-zero reserved field with EINVAL ("genlmsghdr.reserved field is not 0") which surfaced when adding new netdev commands. Add an explicit Reserved uint16 field so the struct is genuinely 4 bytes and serializes the reserved word as zero. Signed-off-by: Aaron Campbell <aaron@monkey.org>
1 parent 1d39b13 commit 9c2aece

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

nl/genetlink_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ const (
7272
)
7373

7474
type Genlmsg struct {
75-
Command uint8
76-
Version uint8
75+
Command uint8
76+
Version uint8
77+
Reserved uint16
7778
}
7879

7980
func (msg *Genlmsg) Len() int {

0 commit comments

Comments
 (0)