Skip to content

Commit ea4bb5c

Browse files
jahurleygregkh
authored andcommitted
net: openvswitch: fix csum updates for MPLS actions
[ Upstream commit 0e3183c ] Skbs may have their checksum value populated by HW. If this is a checksum calculated over the entire packet then the CHECKSUM_COMPLETE field is marked. Changes to the data pointer on the skb throughout the network stack still try to maintain this complete csum value if it is required through functions such as skb_postpush_rcsum. The MPLS actions in Open vSwitch modify a CHECKSUM_COMPLETE value when changes are made to packet data without a push or a pull. This occurs when the ethertype of the MAC header is changed or when MPLS lse fields are modified. The modification is carried out using the csum_partial function to get the csum of a buffer and add it into the larger checksum. The buffer is an inversion of the data to be removed followed by the new data. Because the csum is calculated over 16 bits and these values align with 16 bits, the effect is the removal of the old value from the CHECKSUM_COMPLETE and addition of the new value. However, the csum fed into the function and the outcome of the calculation are also inverted. This would only make sense if it was the new value rather than the old that was inverted in the input buffer. Fix the issue by removing the bit inverts in the csum_partial calculation. The bug was verified and the fix tested by comparing the folded value of the updated CHECKSUM_COMPLETE value with the folded value of a full software checksum calculation (reset skb->csum to 0 and run skb_checksum_complete(skb)). Prior to the fix the outcomes differed but after they produce the same result. Fixes: 25cd9ba ("openvswitch: Add basic MPLS support to kernel") Fixes: bc7cc59 ("openvswitch: update checksum in {push,pop}_mpls") Signed-off-by: John Hurley <john.hurley@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Simon Horman <simon.horman@netronome.com> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 192a452 commit ea4bb5c

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎net/openvswitch/actions.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
166166
if (skb->ip_summed == CHECKSUM_COMPLETE) {
167167
__be16 diff[] = { ~(hdr->h_proto), ethertype };
168168

169-
skb->csum = ~csum_partial((char *)diff, sizeof(diff),
170-
~skb->csum);
169+
skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum);
171170
}
172171

173172
hdr->h_proto = ethertype;
@@ -259,8 +258,7 @@ static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
259258
if (skb->ip_summed == CHECKSUM_COMPLETE) {
260259
__be32 diff[] = { ~(stack->label_stack_entry), lse };
261260

262-
skb->csum = ~csum_partial((char *)diff, sizeof(diff),
263-
~skb->csum);
261+
skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum);
264262
}
265263

266264
stack->label_stack_entry = lse;

0 commit comments

Comments
 (0)