From 777e98f2f294438651c0e377297c0dab70e230a5 Mon Sep 17 00:00:00 2001 From: akoshibe Date: Tue, 21 Aug 2018 16:40:23 +0000 Subject: [PATCH] Fix alignment fault in switchd(8) on sparc64. Use memcpy to set oxm_value, which isn't aligned to 64 bits. Based on pointers from Ori Bernstein Reported by Ryan Keating ok yasuoka@ deraadt@ --- sys/net/switchofp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/net/switchofp.c b/sys/net/switchofp.c index 7100ac070b8..9d4b1169f81 100644 --- a/sys/net/switchofp.c +++ b/sys/net/switchofp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: switchofp.c,v 1.70 2018/02/19 08:59:52 mpi Exp $ */ +/* $OpenBSD: switchofp.c,v 1.71 2018/08/21 16:40:23 akoshibe Exp $ */ /* * Copyright (c) 2016 Kazuya GODA @@ -2455,12 +2455,12 @@ swofp_ox_match_put_uint32(struct ofp_match *om, uint8_t type, uint32_t val) int off = ntohs(om->om_length); struct ofp_ox_match *oxm; + val = htonl(val); oxm = (struct ofp_ox_match *)((caddr_t)om + off); oxm->oxm_class = htons(OFP_OXM_C_OPENFLOW_BASIC); OFP_OXM_SET_FIELD(oxm, type); oxm->oxm_length = sizeof(uint32_t); - *(uint32_t *)oxm->oxm_value = htonl(val); - + memcpy(oxm->oxm_value, &val, sizeof(val)); om->om_length = htons(ntohs(om->om_length) + sizeof(*oxm) + sizeof(uint32_t)); @@ -2473,12 +2473,12 @@ swofp_ox_match_put_uint64(struct ofp_match *om, uint8_t type, uint64_t val) struct ofp_ox_match *oxm; int off = ntohs(om->om_length); + val = htobe64(val); oxm = (struct ofp_ox_match *)((caddr_t)om + off); oxm->oxm_class = htons(OFP_OXM_C_OPENFLOW_BASIC); OFP_OXM_SET_FIELD(oxm, type); oxm->oxm_length = sizeof(uint64_t); - *(uint64_t *)oxm->oxm_value = htobe64(val); - + memcpy(oxm->oxm_value, &val, sizeof(val)); om->om_length = htons(ntohs(om->om_length) + sizeof(*oxm) + sizeof(uint64_t)); -- 2.20.1