Merge lp:~moha/ubuntu/trusty/openvswitch/fix-for-1315306 into lp:ubuntu/trusty/openvswitch

Proposed by Mohanjith
Status: Work in progress
Proposed branch: lp:~moha/ubuntu/trusty/openvswitch/fix-for-1315306
Merge into: lp:ubuntu/trusty/openvswitch
Diff against target: 570 lines (+550/-0)
3 files modified
debian/changelog (+6/-0)
debian/patches/1315306-gre-patch.patch (+543/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~moha/ubuntu/trusty/openvswitch/fix-for-1315306
Reviewer Review Type Date Requested Status
James Page Needs Fixing
Review via email: mp+218510@code.launchpad.net

Description of the change

When use gre vport, openvswitch register a gre_cisco_protocol but
does not supply a err_handler with it. The gre_cisco_err() in
net/ipv4/gre_demux.c expect err_handler be provided with the
gre_cisco_protocol implementation, and call ->err_handler() without
existence check, cause the kernel crash.

This patch provide a err_handler to fix this bug.

Source http://git.openvswitch.org/cgi-bin/gitweb.cgi?p=openvswitch;a=commit;h=43f31ef528f5e4b4751036ce2ef90ea1334bbe3f

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

Hi Mohanjith

Firstly, thanks for the merge proposal.

1) General observations

Looking at bug 1315306, I think that the bug you are hitting resides in the openvswitch module found directly in the in-tree kernel module as well as the dkms package provided by openvswitch itself.

Its worth noting that the dkms package is not compatible with the 3.13 kernel shipped with 14.04 - this was intentional as the in-tree module provides (and in some places exceeds) the function of the dkms provided modules - it was retained for backporting activities only for 3.2 kernel users on 12.04.

2) This proposal

See inline comments

Thanks

James

review: Needs Fixing

Unmerged revisions

61. By Mohanjith Sudirikku Hannadige <email address hidden>

debian/patches/1315306-gre-patch.patch: supply a dummy err_handler of gre_cisco_protocol to prevent kernel crash

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2014-02-23 13:49:27 +0000
+++ debian/changelog 2014-05-06 21:06:26 +0000
@@ -1,3 +1,9 @@
1openvswitch (2.0.1+git20140120-0ubuntu3) UNRELEASED; urgency=medium
2
3 * debian/patches/1315306-gre-patch.patch: supply a dummy err_handler of gre_cisco_protocol to prevent kernel crash
4
5 -- Mohanjith Sudirikku Hannadige <moha@codemaster.fi> Tue, 06 May 2014 20:51:14 +0000
6
1openvswitch (2.0.1+git20140120-0ubuntu2) trusty; urgency=medium7openvswitch (2.0.1+git20140120-0ubuntu2) trusty; urgency=medium
28
3 * Rebuild to drop files installed into /usr/share/pyshared.9 * Rebuild to drop files installed into /usr/share/pyshared.
410
=== added file 'debian/patches/1315306-gre-patch.patch'
--- debian/patches/1315306-gre-patch.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/1315306-gre-patch.patch 2014-05-06 21:06:26 +0000
@@ -0,0 +1,543 @@
1## Description: add some description
2## Origin/Author: add some origin or author
3## Bug: bug URL
4Index: openvswitch.moha/datapath/linux/compat/include/net/gre.h
5===================================================================
6--- openvswitch.moha.orig/datapath/linux/compat/include/net/gre.h 2014-05-06 20:49:51.459706000 +0000
7+++ openvswitch.moha/datapath/linux/compat/include/net/gre.h 2014-05-06 20:50:57.258957000 +0000
8@@ -80,6 +80,8 @@
9
10 struct gre_cisco_protocol {
11 int (*handler)(struct sk_buff *skb, const struct tnl_ptk_info *tpi);
12+ int (*err_handler)(struct sk_buff *skb, u32 info,
13+ const struct tnl_ptk_info *tpi);
14 u8 priority;
15 };
16
17Index: openvswitch.moha/datapath/linux/compat/include/net/gre.h.orig
18===================================================================
19--- /dev/null 1970-01-01 00:00:00.000000000 +0000
20+++ openvswitch.moha/datapath/linux/compat/include/net/gre.h.orig 2014-05-06 20:49:51.459706000 +0000
21@@ -0,0 +1,116 @@
22+#ifndef __LINUX_GRE_WRAPPER_H
23+#define __LINUX_GRE_WRAPPER_H
24+
25+#include <linux/skbuff.h>
26+#include <net/ip_tunnels.h>
27+
28+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
29+#include_next <net/gre.h>
30+
31+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) */
32+
33+#define GREPROTO_CISCO 0
34+#define GREPROTO_MAX 2
35+
36+struct gre_protocol {
37+ int (*handler)(struct sk_buff *skb);
38+};
39+
40+int gre_add_protocol(const struct gre_protocol *proto, u8 version);
41+int gre_del_protocol(const struct gre_protocol *proto, u8 version);
42+
43+#endif
44+
45+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
46+struct gre_base_hdr {
47+ __be16 flags;
48+ __be16 protocol;
49+};
50+#define GRE_HEADER_SECTION 4
51+
52+static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
53+{
54+ __be16 tflags = 0;
55+
56+ if (flags & GRE_CSUM)
57+ tflags |= TUNNEL_CSUM;
58+ if (flags & GRE_ROUTING)
59+ tflags |= TUNNEL_ROUTING;
60+ if (flags & GRE_KEY)
61+ tflags |= TUNNEL_KEY;
62+ if (flags & GRE_SEQ)
63+ tflags |= TUNNEL_SEQ;
64+ if (flags & GRE_STRICT)
65+ tflags |= TUNNEL_STRICT;
66+ if (flags & GRE_REC)
67+ tflags |= TUNNEL_REC;
68+ if (flags & GRE_VERSION)
69+ tflags |= TUNNEL_VERSION;
70+
71+ return tflags;
72+}
73+
74+static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
75+{
76+ __be16 flags = 0;
77+
78+ if (tflags & TUNNEL_CSUM)
79+ flags |= GRE_CSUM;
80+ if (tflags & TUNNEL_ROUTING)
81+ flags |= GRE_ROUTING;
82+ if (tflags & TUNNEL_KEY)
83+ flags |= GRE_KEY;
84+ if (tflags & TUNNEL_SEQ)
85+ flags |= GRE_SEQ;
86+ if (tflags & TUNNEL_STRICT)
87+ flags |= GRE_STRICT;
88+ if (tflags & TUNNEL_REC)
89+ flags |= GRE_REC;
90+ if (tflags & TUNNEL_VERSION)
91+ flags |= GRE_VERSION;
92+
93+ return flags;
94+}
95+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
96+
97+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
98+/* GRE demux not available, implement our own demux. */
99+#define MAX_GRE_PROTO_PRIORITY 255
100+#define gre_cisco_protocol rpl_gre_cisco_protocol
101+
102+struct gre_cisco_protocol {
103+ int (*handler)(struct sk_buff *skb, const struct tnl_ptk_info *tpi);
104+ u8 priority;
105+};
106+
107+#define gre_cisco_register rpl_gre_cisco_register
108+int gre_cisco_register(struct gre_cisco_protocol *proto);
109+
110+#define gre_cisco_unregister rpl_gre_cisco_unregister
111+int gre_cisco_unregister(struct gre_cisco_protocol *proto);
112+
113+#endif
114+
115+#define gre_build_header rpl_gre_build_header
116+void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
117+ int hdr_len);
118+
119+#define gre_handle_offloads rpl_gre_handle_offloads
120+struct sk_buff *gre_handle_offloads(struct sk_buff *skb, bool gre_csum);
121+
122+#define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
123+static inline int ip_gre_calc_hlen(__be16 o_flags)
124+{
125+ int addend = 4;
126+
127+ if (o_flags & TUNNEL_CSUM)
128+ addend += 4;
129+ if (o_flags & TUNNEL_KEY)
130+ addend += 4;
131+ if (o_flags & TUNNEL_SEQ)
132+ addend += 4;
133+ return addend;
134+}
135+
136+
137+#endif
138Index: openvswitch.moha/datapath/vport-gre.c
139===================================================================
140--- openvswitch.moha.orig/datapath/vport-gre.c 2014-05-06 20:49:51.459706000 +0000
141+++ openvswitch.moha/datapath/vport-gre.c 2014-05-06 20:50:57.262957000 +0000
142@@ -118,6 +118,25 @@
143 return PACKET_RCVD;
144 }
145
146+/* Called with rcu_read_lock and BH disabled. */
147+static int gre_err(struct sk_buff *skb, u32 info,
148+ const struct tnl_ptk_info *tpi)
149+{
150+ struct ovs_net *ovs_net;
151+ struct vport *vport;
152+
153+ ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
154+ if ((tpi->flags & TUNNEL_KEY) && (tpi->flags & TUNNEL_SEQ))
155+ vport = rcu_dereference(ovs_net->vport_net.gre64_vport);
156+ else
157+ vport = rcu_dereference(ovs_net->vport_net.gre_vport);
158+
159+ if (unlikely(!vport))
160+ return PACKET_REJECT;
161+ else
162+ return PACKET_RCVD;
163+}
164+
165 static int __send(struct vport *vport, struct sk_buff *skb,
166 int tunnel_hlen,
167 __be32 seq, __be16 gre64_flag)
168@@ -190,6 +209,7 @@
169
170 static struct gre_cisco_protocol gre_protocol = {
171 .handler = gre_rcv,
172+ .err_handler = gre_err,
173 .priority = 1,
174 };
175
176Index: openvswitch.moha/datapath/vport-gre.c.orig
177===================================================================
178--- /dev/null 1970-01-01 00:00:00.000000000 +0000
179+++ openvswitch.moha/datapath/vport-gre.c.orig 2014-05-06 20:49:51.459706000 +0000
180@@ -0,0 +1,363 @@
181+/*
182+ * Copyright (c) 2007-2012 Nicira, Inc.
183+ *
184+ * This program is free software; you can redistribute it and/or
185+ * modify it under the terms of version 2 of the GNU General Public
186+ * License as published by the Free Software Foundation.
187+ *
188+ * This program is distributed in the hope that it will be useful, but
189+ * WITHOUT ANY WARRANTY; without even the implied warranty of
190+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
191+ * General Public License for more details.
192+ *
193+ * You should have received a copy of the GNU General Public License
194+ * along with this program; if not, write to the Free Software
195+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
196+ * 02110-1301, USA
197+ */
198+
199+#include <linux/kconfig.h>
200+#if IS_ENABLED(CONFIG_NET_IPGRE_DEMUX)
201+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
202+
203+#include <linux/if.h>
204+#include <linux/skbuff.h>
205+#include <linux/ip.h>
206+#include <linux/if_tunnel.h>
207+#include <linux/if_vlan.h>
208+#include <linux/in.h>
209+#include <linux/if_vlan.h>
210+#include <linux/in.h>
211+#include <linux/in_route.h>
212+#include <linux/inetdevice.h>
213+#include <linux/jhash.h>
214+#include <linux/list.h>
215+#include <linux/kernel.h>
216+#include <linux/workqueue.h>
217+#include <linux/rculist.h>
218+#include <net/net_namespace.h>
219+#include <net/netns/generic.h>
220+#include <net/route.h>
221+#include <net/xfrm.h>
222+
223+#include <net/icmp.h>
224+#include <net/ip.h>
225+#include <net/ip_tunnels.h>
226+#include <net/gre.h>
227+#include <net/protocol.h>
228+
229+#include "datapath.h"
230+#include "vport.h"
231+
232+/* Returns the least-significant 32 bits of a __be64. */
233+static __be32 be64_get_low32(__be64 x)
234+{
235+#ifdef __BIG_ENDIAN
236+ return (__force __be32)x;
237+#else
238+ return (__force __be32)((__force u64)x >> 32);
239+#endif
240+}
241+
242+static __be16 filter_tnl_flags(__be16 flags)
243+{
244+ return flags & (TUNNEL_CSUM | TUNNEL_KEY);
245+}
246+
247+static struct sk_buff *__build_header(struct sk_buff *skb,
248+ int tunnel_hlen,
249+ __be32 seq, __be16 gre64_flag)
250+{
251+ const struct ovs_key_ipv4_tunnel *tun_key = OVS_CB(skb)->tun_key;
252+ struct tnl_ptk_info tpi;
253+
254+ skb = gre_handle_offloads(skb, !!(tun_key->tun_flags & TUNNEL_CSUM));
255+ if (IS_ERR(skb))
256+ return NULL;
257+
258+ tpi.flags = filter_tnl_flags(tun_key->tun_flags) | gre64_flag;
259+
260+ tpi.proto = htons(ETH_P_TEB);
261+ tpi.key = be64_get_low32(tun_key->tun_id);
262+ tpi.seq = seq;
263+ gre_build_header(skb, &tpi, tunnel_hlen);
264+
265+ return skb;
266+}
267+
268+static __be64 key_to_tunnel_id(__be32 key, __be32 seq)
269+{
270+#ifdef __BIG_ENDIAN
271+ return (__force __be64)((__force u64)seq << 32 | (__force u32)key);
272+#else
273+ return (__force __be64)((__force u64)key << 32 | (__force u32)seq);
274+#endif
275+}
276+
277+/* Called with rcu_read_lock and BH disabled. */
278+static int gre_rcv(struct sk_buff *skb,
279+ const struct tnl_ptk_info *tpi)
280+{
281+ struct ovs_key_ipv4_tunnel tun_key;
282+ struct ovs_net *ovs_net;
283+ struct vport *vport;
284+ __be64 key;
285+
286+ ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
287+ if ((tpi->flags & TUNNEL_KEY) && (tpi->flags & TUNNEL_SEQ))
288+ vport = rcu_dereference(ovs_net->vport_net.gre64_vport);
289+ else
290+ vport = rcu_dereference(ovs_net->vport_net.gre_vport);
291+ if (unlikely(!vport))
292+ return PACKET_REJECT;
293+
294+ key = key_to_tunnel_id(tpi->key, tpi->seq);
295+ ovs_flow_tun_key_init(&tun_key, ip_hdr(skb), key, filter_tnl_flags(tpi->flags));
296+
297+ ovs_vport_receive(vport, skb, &tun_key);
298+ return PACKET_RCVD;
299+}
300+
301+static int __send(struct vport *vport, struct sk_buff *skb,
302+ int tunnel_hlen,
303+ __be32 seq, __be16 gre64_flag)
304+{
305+ struct net *net = ovs_dp_get_net(vport->dp);
306+ struct rtable *rt;
307+ int min_headroom;
308+ __be16 df;
309+ __be32 saddr;
310+ int err;
311+
312+ /* Route lookup */
313+ saddr = OVS_CB(skb)->tun_key->ipv4_src;
314+ rt = find_route(ovs_dp_get_net(vport->dp),
315+ &saddr,
316+ OVS_CB(skb)->tun_key->ipv4_dst,
317+ IPPROTO_GRE,
318+ OVS_CB(skb)->tun_key->ipv4_tos,
319+ skb->mark);
320+ if (IS_ERR(rt)) {
321+ err = PTR_ERR(rt);
322+ goto error;
323+ }
324+
325+ min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
326+ + tunnel_hlen + sizeof(struct iphdr)
327+ + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
328+
329+ if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
330+ int head_delta = SKB_DATA_ALIGN(min_headroom -
331+ skb_headroom(skb) +
332+ 16);
333+ err = pskb_expand_head(skb, max_t(int, head_delta, 0),
334+ 0, GFP_ATOMIC);
335+ if (unlikely(err))
336+ goto err_free_rt;
337+ }
338+
339+ if (vlan_tx_tag_present(skb)) {
340+ if (unlikely(!__vlan_put_tag(skb,
341+ skb->vlan_proto,
342+ vlan_tx_tag_get(skb)))) {
343+ err = -ENOMEM;
344+ goto err_free_rt;
345+ }
346+ vlan_set_tci(skb, 0);
347+ }
348+
349+ /* Push Tunnel header. */
350+ skb = __build_header(skb, tunnel_hlen, seq, gre64_flag);
351+ if (unlikely(!skb)) {
352+ err = 0;
353+ goto err_free_rt;
354+ }
355+
356+ df = OVS_CB(skb)->tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ?
357+ htons(IP_DF) : 0;
358+
359+ skb->local_df = 1;
360+
361+ return iptunnel_xmit(net, rt, skb, saddr,
362+ OVS_CB(skb)->tun_key->ipv4_dst, IPPROTO_GRE,
363+ OVS_CB(skb)->tun_key->ipv4_tos,
364+ OVS_CB(skb)->tun_key->ipv4_ttl, df);
365+err_free_rt:
366+ ip_rt_put(rt);
367+error:
368+ return err;
369+}
370+
371+static struct gre_cisco_protocol gre_protocol = {
372+ .handler = gre_rcv,
373+ .priority = 1,
374+};
375+
376+static int gre_ports;
377+static int gre_init(void)
378+{
379+ int err;
380+
381+ gre_ports++;
382+ if (gre_ports > 1)
383+ return 0;
384+
385+ err = gre_cisco_register(&gre_protocol);
386+ if (err)
387+ pr_warn("cannot register gre protocol handler\n");
388+
389+ return err;
390+}
391+
392+static void gre_exit(void)
393+{
394+ gre_ports--;
395+ if (gre_ports > 0)
396+ return;
397+
398+ gre_cisco_unregister(&gre_protocol);
399+}
400+
401+static const char *gre_get_name(const struct vport *vport)
402+{
403+ return vport_priv(vport);
404+}
405+
406+static struct vport *gre_create(const struct vport_parms *parms)
407+{
408+ struct net *net = ovs_dp_get_net(parms->dp);
409+ struct ovs_net *ovs_net;
410+ struct vport *vport;
411+ int err;
412+
413+ err = gre_init();
414+ if (err)
415+ return ERR_PTR(err);
416+
417+ ovs_net = net_generic(net, ovs_net_id);
418+ if (ovsl_dereference(ovs_net->vport_net.gre_vport)) {
419+ vport = ERR_PTR(-EEXIST);
420+ goto error;
421+ }
422+
423+ vport = ovs_vport_alloc(IFNAMSIZ, &ovs_gre_vport_ops, parms);
424+ if (IS_ERR(vport))
425+ goto error;
426+
427+ strncpy(vport_priv(vport), parms->name, IFNAMSIZ);
428+ rcu_assign_pointer(ovs_net->vport_net.gre_vport, vport);
429+ return vport;
430+
431+error:
432+ gre_exit();
433+ return vport;
434+}
435+
436+static void gre_tnl_destroy(struct vport *vport)
437+{
438+ struct net *net = ovs_dp_get_net(vport->dp);
439+ struct ovs_net *ovs_net;
440+
441+ ovs_net = net_generic(net, ovs_net_id);
442+
443+ rcu_assign_pointer(ovs_net->vport_net.gre_vport, NULL);
444+ ovs_vport_deferred_free(vport);
445+ gre_exit();
446+}
447+
448+static int gre_send(struct vport *vport, struct sk_buff *skb)
449+{
450+ int hlen;
451+
452+ if (unlikely(!OVS_CB(skb)->tun_key))
453+ return -EINVAL;
454+
455+ hlen = ip_gre_calc_hlen(OVS_CB(skb)->tun_key->tun_flags);
456+
457+ return __send(vport, skb, hlen, 0, 0);
458+}
459+
460+const struct vport_ops ovs_gre_vport_ops = {
461+ .type = OVS_VPORT_TYPE_GRE,
462+ .create = gre_create,
463+ .destroy = gre_tnl_destroy,
464+ .get_name = gre_get_name,
465+ .send = gre_send,
466+};
467+
468+/* GRE64 vport. */
469+static struct vport *gre64_create(const struct vport_parms *parms)
470+{
471+ struct net *net = ovs_dp_get_net(parms->dp);
472+ struct ovs_net *ovs_net;
473+ struct vport *vport;
474+ int err;
475+
476+ err = gre_init();
477+ if (err)
478+ return ERR_PTR(err);
479+
480+ ovs_net = net_generic(net, ovs_net_id);
481+ if (ovsl_dereference(ovs_net->vport_net.gre64_vport)) {
482+ vport = ERR_PTR(-EEXIST);
483+ goto error;
484+ }
485+
486+ vport = ovs_vport_alloc(IFNAMSIZ, &ovs_gre64_vport_ops, parms);
487+ if (IS_ERR(vport))
488+ goto error;
489+
490+ strncpy(vport_priv(vport), parms->name, IFNAMSIZ);
491+ rcu_assign_pointer(ovs_net->vport_net.gre64_vport, vport);
492+ return vport;
493+error:
494+ gre_exit();
495+ return vport;
496+}
497+
498+static void gre64_tnl_destroy(struct vport *vport)
499+{
500+ struct net *net = ovs_dp_get_net(vport->dp);
501+ struct ovs_net *ovs_net;
502+
503+ ovs_net = net_generic(net, ovs_net_id);
504+
505+ rcu_assign_pointer(ovs_net->vport_net.gre64_vport, NULL);
506+ ovs_vport_deferred_free(vport);
507+ gre_exit();
508+}
509+
510+static __be32 be64_get_high32(__be64 x)
511+{
512+#ifdef __BIG_ENDIAN
513+ return (__force __be32)((__force u64)x >> 32);
514+#else
515+ return (__force __be32)x;
516+#endif
517+}
518+
519+static int gre64_send(struct vport *vport, struct sk_buff *skb)
520+{
521+ int hlen = GRE_HEADER_SECTION + /* GRE Hdr */
522+ GRE_HEADER_SECTION + /* GRE Key */
523+ GRE_HEADER_SECTION; /* GRE SEQ */
524+ __be32 seq;
525+
526+ if (unlikely(!OVS_CB(skb)->tun_key))
527+ return -EINVAL;
528+
529+ if (OVS_CB(skb)->tun_key->tun_flags & TUNNEL_CSUM)
530+ hlen += GRE_HEADER_SECTION;
531+
532+ seq = be64_get_high32(OVS_CB(skb)->tun_key->tun_id);
533+ return __send(vport, skb, hlen, seq, (TUNNEL_KEY|TUNNEL_SEQ));
534+}
535+
536+const struct vport_ops ovs_gre64_vport_ops = {
537+ .type = OVS_VPORT_TYPE_GRE64,
538+ .create = gre64_create,
539+ .destroy = gre64_tnl_destroy,
540+ .get_name = gre_get_name,
541+ .send = gre64_send,
542+};
543+#endif
0544
=== modified file 'debian/patches/series'
--- debian/patches/series 2014-01-20 12:55:24 +0000
+++ debian/patches/series 2014-05-06 21:06:26 +0000
@@ -2,3 +2,4 @@
2fix-3.11-support.patch2fix-3.11-support.patch
3xcp-interface-reconfigure.patch3xcp-interface-reconfigure.patch
4kernel-3.12-support.patch4kernel-3.12-support.patch
51315306-gre-patch.patch

Subscribers

People subscribed via source and target branches

to all changes: