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

dhcpcd crashes with a bus error during startup on sparc64 #430

Open
koachan opened this issue Jan 14, 2025 · 4 comments
Open

dhcpcd crashes with a bus error during startup on sparc64 #430

koachan opened this issue Jan 14, 2025 · 4 comments
Labels

Comments

@koachan
Copy link

koachan commented Jan 14, 2025

Sample log:

# dhcpcd -dB enp12s0f0
main: control_open: Connection refused
dhcpcd-10.1.0 starting
DUID 00:01:00:01:2e:02:4d:64:00:10:e0:3a:79:4c
enp12s0f0: executing: /lib/dhcpcd/dhcpcd-run-hooks PREINIT
enp12s0f0: executing: /lib/dhcpcd/dhcpcd-run-hooks CARRIER
enp12s0f0: IAID e0:3a:79:4c
enp12s0f0: delaying IPv6 router solicitation for 0.4 seconds
enp12s0f0: delaying IPv4 for 1.2 seconds
enp12s0f0: soliciting an IPv6 router
enp12s0f0: sending Router Solicitation
enp12s0f0: reading lease: /var/lib/dhcpcd/enp12s0f0.lease
enp12s0f0: rebinding lease of 192.168.2.2
enp12s0f0: sending REQUEST (xid 0x6c5949ec), next in 4.0 seconds
Bus error

GDB backtrace:

dhcp_packet (ifp=0x1000021d5f0, data=0x7feffffc31a "E\020\001H", len=328, bpf_flags=1) at dhcp.c:3582
3582            if (!checksums_valid(data, &from, bpf_flags)) 

#0  dhcp_packet (ifp=0x1000021d5f0, data=0x7feffffc31a "E\020\001H", len=328, bpf_flags=1) at dhcp.c:3582
#1  0x00000100000355fc in dhcp_readbpf (arg=0x1000021d5f0, events=<optimized out>) at dhcp.c:3621
#2  0x000001000001712c in eloop_run_ppoll (eloop=0x1000021c690, ts=<optimized out>, signals=0x7feffffeb90) at eloop.c:1106
#3  eloop_start (eloop=0x1000021c690, signals=0x7feffffeb90) at eloop.c:1228
#4  0x0000010000015418 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at dhcpcd.c:2650

System setup:
Gentoo on sparc64 with 6.6.30 Linux kernel, glibc 2.40, dhcpcd 10.1.0, and clang 19.1.4.

A quick look shows that dhcp_readbpf creates an uint8_t buffer which then gets casted into a const struct ip * inside checksums_valid, but struct ip appear to have stronger alignment requirements, so when the pointer is dereferenced it crashes from the misaligned access.

@koachan
Copy link
Author

koachan commented Jan 14, 2025

By the way, force-aligning the buffer like so makes it work, but I feel like this is more of a workaround than a proper fix:

diff --git a/src/dhcp.c b/src/dhcp.c
index 9e23ab62..f1ce0355 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -3715,7 +3715,7 @@ static void
 dhcp_readbpf(void *arg, unsigned short events)
 {
        struct interface *ifp = arg;
-       uint8_t buf[FRAMELEN_MAX];
+       uint8_t buf[FRAMELEN_MAX] __attribute__((aligned(8)));
        ssize_t bytes;
        struct dhcp_state *state = D_STATE(ifp);
        struct bpf *bpf = state->bpf;

@rsmarples
Copy link
Member

How about moving uint8_t buf[FRAMELEN_MAX]; to the top of the block so it's declared first?
Stack should be word aligned in each function to that might fix it without the need for the attribute.

If that fails, we could malloc and free it I guess which should fix it too.

@rsmarples rsmarples added the bug label Jan 14, 2025
@koachan
Copy link
Author

koachan commented Jan 14, 2025

How about moving uint8_t buf[FRAMELEN_MAX]; to the top of the block so it's declared first? Stack should be word aligned in each function to that might fix it without the need for the attribute.

This doesn't seem to fix the issue, unfortunately.

@rsmarples
Copy link
Member

How about moving uint8_t buf[FRAMELEN_MAX]; to the top of the block so it's declared first? Stack should be word aligned in each function to that might fix it without the need for the attribute.

This doesn't seem to fix the issue, unfortunately.

Shame. Does using malloc rather than a buffer on stack fix it?

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

No branches or pull requests

2 participants