Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: add type safe Pointer wrapper #1670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Feb 6, 2025

Add TypedPointer which is a type safe wrapper around Pointer. This relieves users of the generated bindings from knowing which types are expected. This should make it less likely that we cause a hard to debug panic or crash due to the kernel overwriting runtime memory.

sys.Pointer still exists because there are some cases where we legitimately don't know what type to point at, for example the link info APIs. Map APIs are also unchanged for now because they don't benefit much from converting to TypedPointer[byte].

@github-actions github-actions bot added the breaking-change Changes exported API label Feb 6, 2025
@lmb lmb force-pushed the sys-generic-pointer branch from d6fc75b to 1fc7a4f Compare February 6, 2025 11:55
@lmb
Copy link
Collaborator Author

lmb commented Feb 6, 2025

The breaking change is due to replacing ebpf.MapID and ProgramID with a type alias.

@kolyshkin
Copy link
Contributor

I like the approach!

It will be better to separate the actual overrun fix from the new type system.

I've also updated the fix in #1660 to not break the existing API nor return truncated pointers, PTAL @lmb

@lmb lmb force-pushed the sys-generic-pointer branch from 1fc7a4f to ae08243 Compare February 12, 2025 10:09
@lmb lmb marked this pull request as ready for review February 12, 2025 10:09
@lmb lmb requested review from dylandreimerink, mmat11 and a team as code owners February 12, 2025 10:09
@lmb lmb force-pushed the sys-generic-pointer branch from ae08243 to c11a8e0 Compare February 12, 2025 10:13
Add TypedPointer which is a type safe wrapper around Pointer. This
relieves users of the generated bindings from knowing which types
are expected. This should make it less likely that we cause a hard
to debug panic or crash due to the kernel overwriting runtime memory.

sys.Pointer still exists because there are some cases where we
legitimately don't know what type to point at, for example the link info
APIs. Map APIs are also unchanged for now because they don't benefit
much from converting to TypedPointer[byte].

The trick to include "_ [0]*T" in TypedPointer is taken from atomic.Pointer
in the Go stdlib.

Signed-off-by: Lorenz Bauer <[email protected]>
@lmb lmb force-pushed the sys-generic-pointer branch from c11a8e0 to 427cfcd Compare February 14, 2025 10:06
Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

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

I like this! More type safety more better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes exported API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants