From: Ben Pfaff Date: Sat, 5 Apr 2014 18:14:02 +0000 (-0700) Subject: packets: Fix misaligned data accesses for MPLS and SCTP fields. X-Git-Tag: v2.1.1~16 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=21db3de7f1e1c0972efe3e735970630f39ade608 packets: Fix misaligned data accesses for MPLS and SCTP fields. The other 32-bit data fields in protocol headers were already using ovs_16aligned_be32, but MPLS and SCTP had been overlooked. This fixes the failure of test 681 seen here: https://buildd.debian.org/status/fetch.php?pkg=openvswitch&arch=sparc&ver=2.1.0%2Bgit20140325-1&stamp=1396438624 Signed-off-by: Ben Pfaff Acked-by: Jarno Rajahalme --- diff --git a/lib/flow.c b/lib/flow.c index f1d2cad29..8c544cb87 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,11 +112,12 @@ parse_mpls(struct ofpbuf *b, struct flow *flow) bool top = true; while ((mh = ofpbuf_try_pull(b, sizeof *mh))) { + ovs_be32 mpls_lse = get_16aligned_be32(&mh->mpls_lse); if (top) { top = false; - flow->mpls_lse = mh->mpls_lse; + flow->mpls_lse = mpls_lse; } - if (mh->mpls_lse & htonl(MPLS_BOS_MASK)) { + if (mpls_lse & htonl(MPLS_BOS_MASK)) { break; } } diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 4c89b3676..4e57f9eb6 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ ofp_packet_to_string(const void *data, size_t len) } else if (flow.nw_proto == IPPROTO_SCTP) { struct sctp_header *sh = buf.l4; ds_put_format(&ds, " sctp_csum:%"PRIx32, - ntohl(sh->sctp_csum)); + ntohl(get_16aligned_be32(&sh->sctp_csum))); } } diff --git a/lib/packets.c b/lib/packets.c index ed3832bbc..a17983ec4 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -313,7 +313,7 @@ set_mpls_lse(struct ofpbuf *packet, ovs_be32 mpls_lse) /* Packet type should be MPLS to set label stack entry. */ if (is_mpls(packet)) { /* Update mpls label stack entry. */ - mh->mpls_lse = mpls_lse; + put_16aligned_be32(&mh->mpls_lse, mpls_lse); } } @@ -336,7 +336,7 @@ push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse) } /* Push new MPLS shim header onto packet. */ - mh.mpls_lse = lse; + put_16aligned_be32(&mh.mpls_lse, lse); push_mpls_lse(packet, &mh); } @@ -354,7 +354,7 @@ pop_mpls(struct ofpbuf *packet, ovs_be16 ethtype) mh = packet->l2_5; len = (char*)packet->l2_5 - (char*)packet->l2; set_ethertype(packet, ethtype); - if (mh->mpls_lse & htonl(MPLS_BOS_MASK)) { + if (get_16aligned_be32(&mh->mpls_lse) & htonl(MPLS_BOS_MASK)) { packet->l2_5 = NULL; } else { packet->l2_5 = (char*)packet->l2_5 + MPLS_HLEN; @@ -882,15 +882,15 @@ packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst) ovs_be32 old_csum, old_correct_csum, new_csum; uint16_t tp_len = packet->size - ((uint8_t*)sh - (uint8_t*)packet->data); - old_csum = sh->sctp_csum; - sh->sctp_csum = 0; + old_csum = get_16aligned_be32(&sh->sctp_csum); + put_16aligned_be32(&sh->sctp_csum, 0); old_correct_csum = crc32c(packet->l4, tp_len); sh->sctp_src = src; sh->sctp_dst = dst; new_csum = crc32c(packet->l4, tp_len); - sh->sctp_csum = old_csum ^ old_correct_csum ^ new_csum; + put_16aligned_be32(&sh->sctp_csum, old_csum ^ old_correct_csum ^ new_csum); } /* If 'packet' is a TCP packet, returns the TCP flags. Otherwise, returns 0. diff --git a/lib/packets.h b/lib/packets.h index f3e1dfb7b..a57e0708f 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -323,7 +323,7 @@ BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header)); #define MPLS_HLEN 4 struct mpls_hdr { - ovs_be32 mpls_lse; + ovs_16aligned_be32 mpls_lse; }; BUILD_ASSERT_DECL(MPLS_HLEN == sizeof(struct mpls_hdr)); @@ -470,8 +470,8 @@ BUILD_ASSERT_DECL(ICMP_HEADER_LEN == sizeof(struct icmp_header)); struct sctp_header { ovs_be16 sctp_src; ovs_be16 sctp_dst; - ovs_be32 sctp_vtag; - ovs_be32 sctp_csum; + ovs_16aligned_be32 sctp_vtag; + ovs_16aligned_be32 sctp_csum; }; BUILD_ASSERT_DECL(SCTP_HEADER_LEN == sizeof(struct sctp_header));