[klibc] [PATCH v2] ipconfig: align reads of ext for RISC architectures

Jesse Taube
Fri, 28 Feb 2025 05:25:03 -0000

Some RISC architectures such as Sparc64 will busfault when reading data
from exts if they are not type aligned. Use memcpy to read the data from
exts to ensure type alignment.

A similar issue was fixed in dhcpcd here:
https://github.com/NetworkConfiguration/dhcpcd/issues/430
https://github.com/ColinMcInnes/dhcpcd/commit/07a5fdd7d34b072e52c316877d14c6d2581cb379

Signed-off-by: Jesse Taube <mr.bossman075 at gmail.com>
---
V1 -> V2:
 - Update commit title to use RISC
 - Update commit body

Sorry for missing the changes and version bump in the previous commit.
Also the response to V1 went to spam, sorry for the delay.
---
 usr/kinit/ipconfig/dhcp_proto.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
index 4e560b84..2b83de45 100644
--- a/usr/kinit/ipconfig/dhcp_proto.c
+++ b/usr/kinit/ipconfig/dhcp_proto.c
@@ -112,8 +112,11 @@ static int dhcp_parse(struct netdev *dev, struct bootp_hdr
*hdr,
 				break;
 			switch (opt) {
 			case 51:	/* IP Address Lease Time */
-				if (len == 4)
-					leasetime = ntohl(*(uint32_t *)ext);
+				if (len == 4) {
+					/* Sparc64 needs ext reads to be type aligned */
+					memcpy(&leasetime, ext, 4);
+					leasetime = ntohl(leasetime);
+				}
 				break;
 			case 53:	/* DHCP Message Type */
 				if (len == 1)
--
2.47.2