@@ -137,12 +137,12 @@ func (s *AuditSuite) TestBuildMessageHeaderLayout(c *C) {
137137 payload := []byte ("hello" )
138138 msg := seclog .AuditWriterBuildMessage (aw , payload )
139139
140- // Total length: 16 (header) + 5 (payload ) = 21, aligned to 24.
140+ // Total length: NLMSG_SPACE(5 + 1 ) = align(22) = 24.
141141 c .Assert (len (msg ), Equals , 24 )
142142
143143 // nlmsghdr fields in native byte order.
144144 totalLen := arch .Endian ().Uint32 (msg [0 :4 ])
145- c .Check (totalLen , Equals , uint32 (21 ))
145+ c .Check (totalLen , Equals , uint32 (24 ))
146146
147147 msgType := arch .Endian ().Uint16 (msg [4 :6 ])
148148 c .Check (msgType , Equals , uint16 (seclog .AuditTrustedApp ))
@@ -159,8 +159,9 @@ func (s *AuditSuite) TestBuildMessageHeaderLayout(c *C) {
159159 // Payload follows header.
160160 c .Check (string (msg [syscall .SizeofNlMsghdr :syscall .SizeofNlMsghdr + 5 ]), Equals , "hello" )
161161
162- // Padding bytes after payload should be zero .
162+ // NUL byte for kernel null-termination .
163163 c .Check (msg [21 ], Equals , byte (0 ))
164+ // Padding bytes should be zero.
164165 c .Check (msg [22 ], Equals , byte (0 ))
165166 c .Check (msg [23 ], Equals , byte (0 ))
166167}
@@ -181,27 +182,44 @@ func (s *AuditSuite) TestBuildMessageSequenceIncrements(c *C) {
181182 c .Check (seq3 , Equals , uint32 (3 ))
182183}
183184
185+ func (s * AuditSuite ) TestBuildMessageSequenceSkipsZero (c * C ) {
186+ aw := & seclog.AuditWriter {}
187+
188+ // Set sequence just before wraparound.
189+ seclog .AuditWriterSetSeq (aw , ^ uint32 (0 )) // math.MaxUint32
190+
191+ msg1 := seclog .AuditWriterBuildMessage (aw , []byte ("x" ))
192+ msg2 := seclog .AuditWriterBuildMessage (aw , []byte ("y" ))
193+
194+ seq1 := arch .Endian ().Uint32 (msg1 [8 :12 ])
195+ seq2 := arch .Endian ().Uint32 (msg2 [8 :12 ])
196+
197+ // Should skip 0 and go to 1, then 2.
198+ c .Check (seq1 , Equals , uint32 (1 ))
199+ c .Check (seq2 , Equals , uint32 (2 ))
200+ }
201+
184202func (s * AuditSuite ) TestBuildMessageAlignedPayload (c * C ) {
185203 aw := & seclog.AuditWriter {}
186204
187- // Payload of exactly 4 bytes: total = 20 which is already aligned .
205+ // Payload of exactly 4 bytes: NLMSG_SPACE(4 + 1) = align(21) = 24 .
188206 msg := seclog .AuditWriterBuildMessage (aw , []byte ("abcd" ))
189- c .Check (len (msg ), Equals , 20 )
207+ c .Check (len (msg ), Equals , 24 )
190208
191209 totalLen := arch .Endian ().Uint32 (msg [0 :4 ])
192- c .Check (totalLen , Equals , uint32 (20 ))
210+ c .Check (totalLen , Equals , uint32 (24 ))
193211}
194212
195213func (s * AuditSuite ) TestBuildMessageEmptyPayload (c * C ) {
196214 aw := & seclog.AuditWriter {}
197215
198216 msg := seclog .AuditWriterBuildMessage (aw , []byte {})
199217
200- // 16-byte header, already aligned .
201- c .Check (len (msg ), Equals , 16 )
218+ // NLMSG_SPACE(0 + 1) = align(17) = 20 .
219+ c .Check (len (msg ), Equals , 20 )
202220
203221 totalLen := arch .Endian ().Uint32 (msg [0 :4 ])
204- c .Check (totalLen , Equals , uint32 (16 ))
222+ c .Check (totalLen , Equals , uint32 (20 ))
205223}
206224
207225func (s * AuditSuite ) TestNlmsgAlignAlreadyAligned (c * C ) {
0 commit comments