Skip to content

Simplify message serialisation code and test#92

Merged
efd6 merged 2 commits intoelastic:mainfrom
efd6:serialisation
Feb 3, 2022
Merged

Simplify message serialisation code and test#92
efd6 merged 2 commits intoelastic:mainfrom
efd6:serialisation

Conversation

@efd6
Copy link
Copy Markdown
Contributor

@efd6 efd6 commented Sep 29, 2021

This reduces the load on encoding/binary.Read and others at the cost of using unsafe. Given that we are close to the border of the kernel here, this is pretty reasonable. Testing is increased to ensure that message serialisation is at least round-trippable.

Please take a look.

@elasticmachine
Copy link
Copy Markdown
Collaborator

elasticmachine commented Sep 29, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Reason: null

  • Start Time: 2022-02-01T08:42:15.147+0000

  • Duration: 4 min 36 sec

  • Commit: bced8d2

Test stats 🧪

Test Results
Failed 0
Passed 367
Skipped 40
Total 407

@efd6 efd6 added the Team:Security-External Integrations Label for the Security External Integrations team label Oct 18, 2021
@efd6 efd6 requested review from adriansr and andrewkroh October 18, 2021 20:43
Copy link
Copy Markdown
Contributor

@adriansr adriansr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small nits

rule/binary.go Outdated
if out.Len()%4 > 0 {
out.Write(make([]byte, 4-(out.Len()%4)))
}
const ruleHeaderSize = int(unsafe.Sizeof(auditRuleData{}) - unsafe.Sizeof([]byte(nil)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the header here means everything in auditRuleData except the Buf []byte field.

This feels a little unsafe, what about splitting auditRuleData in two separate structs, for example auditRuleHeader with the header fields and a new auditRuleData made of the struct composition of auditRuleHeader and the internal-use fields. This way there's less risk of forgetting to subtract a new field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@efd6
Copy link
Copy Markdown
Contributor Author

efd6 commented Oct 24, 2021

PTAL

@andrewkroh andrewkroh requested a review from adriansr October 28, 2021 15:10
efd6 added 2 commits February 1, 2022 18:57
Conventionally Go eschews use of unsafe byte ordering tricks for message
serialisation but given that the kernel makes use of them, and we need to use
one to determine which ordering to use in encoding/binary anyway, we may as
well use them.
Copy link
Copy Markdown
Contributor

@adriansr adriansr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@efd6 efd6 merged commit c9d7185 into elastic:main Feb 3, 2022
renini pushed a commit to renini/go-libaudit that referenced this pull request Jun 26, 2024
Conventionally Go eschews use of unsafe byte ordering tricks for message
serialisation but given that the kernel makes use of them, and we need to use
one to determine which ordering to use in encoding/binary anyway, we may as
well use them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Security-External Integrations Label for the Security External Integrations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants