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

MacOS misaligned pointer dereference in DataLinkReceiver with invalid interface #641

Open
tgross35 opened this issue Aug 26, 2023 · 2 comments · May be fixed by #655
Open

MacOS misaligned pointer dereference in DataLinkReceiver with invalid interface #641

tgross35 opened this issue Aug 26, 2023 · 2 comments · May be fixed by #655

Comments

@tgross35
Copy link

I am attempting to run the example at https://github.com/libpnet/libpnet/blob/main/examples/arp_packet.rs on MacOS but am getting a misaligned pointer error:

thread 'main' panicked at /Users/tmgross/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pnet_datalink-0.34.0/src/bpf.rs:416:44:
misaligned pointer dereference: address must be a multiple of 0x4 but is 0x7fd3e400ca0e
stack backtrace:
   0: rust_begin_unwind
             at /rustc/58eefc33adf769a1abe12ad94b3e6811185b4ce5/library/std/src/panicking.rs:617:5
   1: core::panicking::panic_nounwind_fmt
             at /rustc/58eefc33adf769a1abe12ad94b3e6811185b4ce5/library/core/src/panicking.rs:96:14
   2: core::panicking::panic_misaligned_pointer_dereference
             at /rustc/58eefc33adf769a1abe12ad94b3e6811185b4ce5/library/core/src/panicking.rs:175:5
   3: <pnet_datalink::backend::DataLinkReceiverImpl as pnet_datalink::DataLinkReceiver>::next
             at /Users/tmgross/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pnet_datalink-0.34.0/src/bpf.rs:416:44
   4: wakeupcall::arp::get_mac_through_arp
             at ./src/arp.rs:79:19
   5: wakeupcall::arp::scan
             at ./src/arp.rs:26:10

I was testing with interface name lo0 so this is probably not an interface that has any useful data anyway, but I would expect this to fail with an error rather than catching a misaligned read.

Compiling in release mode actually seems to make this do the right thing, I get an Err("failure") instead.

@tgross35
Copy link
Author

Relevant line that causes the error

ptr as isize + (*packet).bh_hdrlen as isize - buffer.as_ptr() as isize;

@frankplow
Copy link

I am also experiencing this issue on MacOS. For me, as far as I can tell, it appears to be specific to the loopback interface.

@frankplow frankplow linked a pull request Oct 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants