2014-04-04 23:06:22

by Jesse Gross

[permalink] [raw]
Subject: Re: [PATCH v2] openvswitch: supply a dummy err_handler of gre_cisco_protocol to prevent kernel crash

On Tue, Apr 1, 2014 at 5:23 PM, Wei Zhang <[email protected]> wrote:
> 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.
>
> v2 -> v1: use the same logic of the gre_rcv() to distinguish which packet is
> intended to us!

As a tip on kernel process: if you put the version information after
three dashes below the signed-off-by line then git will automatically
remove it when the final patch is applied.

> diff --git a/net/openvswitch/vport-gre.c b/net/openvswitch/vport-gre.c
> index a3d6951..f391df1 100644
> --- a/net/openvswitch/vport-gre.c
> +++ b/net/openvswitch/vport-gre.c
> @@ -110,6 +110,21 @@ static int gre_rcv(struct sk_buff *skb,
> return PACKET_RCVD;
> }
>
> +/* Called with rcu_read_lock and BH disabled. */
> +static int gre_err(struct sk_buff *skb, u32 info,
> + const struct tnl_ptk_info *tpi)
> +{
> + struct ovs_net *ovs_net;
> + struct vport *vport;
> +
> + ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
> + vport = rcu_dereference(ovs_net->vport_net.gre_vport);
> + if (unlikely(!vport))
> + return PACKET_REJECT;
> + else
> + return PACKET_RCVD;

Sorry, I forgot to say this before - if we receive the packet then we
should also call consume_skb() on it.


2014-04-05 04:21:04

by Wei Zhang

[permalink] [raw]
Subject: Re: [PATCH v2] openvswitch: supply a dummy err_handler of gre_cisco_protocol to prevent kernel crash

At 2014-04-05 07:05:59,"Jesse Gross" <[email protected]> wrote:
>On Tue, Apr 1, 2014 at 5:23 PM, Wei Zhang <[email protected]> wrote:
>>
>> v2 -> v1: use the same logic of the gre_rcv() to distinguish which packet is
>> intended to us!
>
>As a tip on kernel process: if you put the version information after
>three dashes below the signed-off-by line then git will automatically
>remove it when the final patch is applied.

Thanks, should I modify it and send a v3 patch?

>
>> diff --git a/net/openvswitch/vport-gre.c b/net/openvswitch/vport-gre.c
>> index a3d6951..f391df1 100644
>> --- a/net/openvswitch/vport-gre.c
>> +++ b/net/openvswitch/vport-gre.c
>> @@ -110,6 +110,21 @@ static int gre_rcv(struct sk_buff *skb,
>>         return PACKET_RCVD;
>>  }
>>
>> +/* Called with rcu_read_lock and BH disabled. */
>> +static int gre_err(struct sk_buff *skb, u32 info,
>> +                  const struct tnl_ptk_info *tpi)
>> +{
>> +       struct ovs_net *ovs_net;
>> +       struct vport *vport;
>> +
>> +       ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
>> +       vport = rcu_dereference(ovs_net->vport_net.gre_vport);
>> +       if (unlikely(!vport))
>> +               return PACKET_REJECT;
>> +       else
>> +               return PACKET_RCVD;
>
>Sorry, I forgot to say this before - if we receive the packet then we
>should also call consume_skb() on it.

Maybe there is no need to call consume_skb()? The icmp_rcv() would
call kfree_skb() for us. I also checked the ipgre_err(), it return 
PACKET_RCVD without call consume_skb() too.

Regards,
Wei Zhang????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2014-04-09 00:46:24

by Jesse Gross

[permalink] [raw]
Subject: Re: [PATCH v2] openvswitch: supply a dummy err_handler of gre_cisco_protocol to prevent kernel crash

On Fri, Apr 4, 2014 at 9:20 PM, wei zhang <[email protected]> wrote:
> At 2014-04-05 07:05:59,"Jesse Gross" <[email protected]> wrote:
>>On Tue, Apr 1, 2014 at 5:23 PM, Wei Zhang <[email protected]> wrote:
>>>
>>> v2 -> v1: use the same logic of the gre_rcv() to distinguish which packet is
>>> intended to us!
>>
>>As a tip on kernel process: if you put the version information after
>>three dashes below the signed-off-by line then git will automatically
>>remove it when the final patch is applied.
>
> Thanks, should I modify it and send a v3 patch?
>
>>
>>> diff --git a/net/openvswitch/vport-gre.c b/net/openvswitch/vport-gre.c
>>> index a3d6951..f391df1 100644
>>> --- a/net/openvswitch/vport-gre.c
>>> +++ b/net/openvswitch/vport-gre.c
>>> @@ -110,6 +110,21 @@ static int gre_rcv(struct sk_buff *skb,
>>> return PACKET_RCVD;
>>> }
>>>
>>> +/* Called with rcu_read_lock and BH disabled. */
>>> +static int gre_err(struct sk_buff *skb, u32 info,
>>> + const struct tnl_ptk_info *tpi)
>>> +{
>>> + struct ovs_net *ovs_net;
>>> + struct vport *vport;
>>> +
>>> + ovs_net = net_generic(dev_net(skb->dev), ovs_net_id);
>>> + vport = rcu_dereference(ovs_net->vport_net.gre_vport);
>>> + if (unlikely(!vport))
>>> + return PACKET_REJECT;
>>> + else
>>> + return PACKET_RCVD;
>>
>>Sorry, I forgot to say this before - if we receive the packet then we
>>should also call consume_skb() on it.
>
> Maybe there is no need to call consume_skb()? The icmp_rcv() would
> call kfree_skb() for us. I also checked the ipgre_err(), it return
> PACKET_RCVD without call consume_skb() too.

Thanks, you are right. I applied your patch as is.