Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

ub in RingBufPayload #333

Open
Sherlock-Holo opened this issue Jun 8, 2022 · 1 comment
Open

ub in RingBufPayload #333

Sherlock-Holo opened this issue Jun 8, 2022 · 1 comment

Comments

@Sherlock-Holo
Copy link

in rust, we can't get the &mut from a pointer *mut, even it is not null

https://github.com/foniod/redbpf/blob/eed2cdc62c08633d83215af696445ec91f30649b/redbpf-probes/src/ringbuf.rs#L167=

here redbpf get the &mut from the *mut, we don't know if kernel init the memory with zero or not, but in rust, memory filled with zero should not be seems as initialize

and the as_mut also says

If the value may be uninitialized, as_uninit_mut must be used instead.

I recommand return the ptr directly and remove the unsafe mark, user who want to use it to init field should use https://doc.rust-lang.org/core/ptr/macro.addr_of_mut.html and use ptr::write to init field

@Sherlock-Holo
Copy link
Author

or return the NonNull tell user the pointer is not null

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant