Skip to content

Commit d5e91be

Browse files
authored
[CWS] clear top bit flag in nsec ctime/mtime (#42227)
### What does this PR do? In torvalds/linux@4e40eff the kernel started using the top bit of the nsec as a flag, let's clear it before using the nsec value. ### Motivation ### Describe how you validated your changes ### Additional Notes Co-authored-by: paul.cacheux <[email protected]>
1 parent 6d31cc2 commit d5e91be

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/security/secl/model/unmarshallers_linux.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,25 @@ func (e *FileFields) UnmarshalBinary(data []byte) (int, error) {
390390
e.Mode = binary.NativeEndian.Uint16(data[20:22])
391391

392392
timeSec := binary.NativeEndian.Uint64(data[24:32])
393-
timeNsec := binary.NativeEndian.Uint64(data[32:40])
393+
timeNsec := clearTopBitNsec(binary.NativeEndian.Uint64(data[32:40]))
394394
e.CTime = uint64(time.Unix(int64(timeSec), int64(timeNsec)).UnixNano())
395395

396396
timeSec = binary.NativeEndian.Uint64(data[40:48])
397-
timeNsec = binary.NativeEndian.Uint64(data[48:56])
397+
timeNsec = clearTopBitNsec(binary.NativeEndian.Uint64(data[48:56]))
398398
e.MTime = uint64(time.Unix(int64(timeSec), int64(timeNsec)).UnixNano())
399399

400400
return FileFieldsSize, nil
401401
}
402402

403+
// in https://github.com/torvalds/linux/commit/4e40eff0b5737c0de39e1ae5812509efbc0b986e
404+
// the kernel started using the top bit of the nsec as a flag, let's clear it
405+
// before using the nsec value
406+
func clearTopBitNsec(nsec uint64) uint64 {
407+
w := uint32(nsec)
408+
w = w & ^(uint32(1) << 31)
409+
return uint64(w)
410+
}
411+
403412
// UnmarshalBinary unmarshalls a binary representation of itself
404413
func (e *FileEvent) UnmarshalBinary(data []byte) (int, error) {
405414
return UnmarshalBinary(data, &e.FileFields)

0 commit comments

Comments
 (0)