1. 21 8月, 2023 1 次提交
    • F
      net: openvswitch: fix flow memory leak in ovs_flow_cmd_new · 0023f0c4
      Fedor Pchelkin 提交于
      stable inclusion
      from stable-v5.10.168
      commit 70154489f531587996f3e9d7cceeee65cff0001d
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I7URR4
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=70154489f531587996f3e9d7cceeee65cff0001d
      
      ----------------------------------------------------
      
      [ Upstream commit 0c598aed ]
      
      Syzkaller reports a memory leak of new_flow in ovs_flow_cmd_new() as it is
      not freed when an allocation of a key fails.
      
      BUG: memory leak
      unreferenced object 0xffff888116668000 (size 632):
        comm "syz-executor231", pid 1090, jiffies 4294844701 (age 18.871s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000defa3494>] kmem_cache_zalloc include/linux/slab.h:654 [inline]
          [<00000000defa3494>] ovs_flow_alloc+0x19/0x180 net/openvswitch/flow_table.c:77
          [<00000000c67d8873>] ovs_flow_cmd_new+0x1de/0xd40 net/openvswitch/datapath.c:957
          [<0000000010a539a8>] genl_family_rcv_msg_doit+0x22d/0x330 net/netlink/genetlink.c:739
          [<00000000dff3302d>] genl_family_rcv_msg net/netlink/genetlink.c:783 [inline]
          [<00000000dff3302d>] genl_rcv_msg+0x328/0x590 net/netlink/genetlink.c:800
          [<000000000286dd87>] netlink_rcv_skb+0x153/0x430 net/netlink/af_netlink.c:2515
          [<0000000061fed410>] genl_rcv+0x24/0x40 net/netlink/genetlink.c:811
          [<000000009dc0f111>] netlink_unicast_kernel net/netlink/af_netlink.c:1313 [inline]
          [<000000009dc0f111>] netlink_unicast+0x545/0x7f0 net/netlink/af_netlink.c:1339
          [<000000004a5ee816>] netlink_sendmsg+0x8e7/0xde0 net/netlink/af_netlink.c:1934
          [<00000000482b476f>] sock_sendmsg_nosec net/socket.c:651 [inline]
          [<00000000482b476f>] sock_sendmsg+0x152/0x190 net/socket.c:671
          [<00000000698574ba>] ____sys_sendmsg+0x70a/0x870 net/socket.c:2356
          [<00000000d28d9e11>] ___sys_sendmsg+0xf3/0x170 net/socket.c:2410
          [<0000000083ba9120>] __sys_sendmsg+0xe5/0x1b0 net/socket.c:2439
          [<00000000c00628f8>] do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46
          [<000000004abfdcf4>] entry_SYSCALL_64_after_hwframe+0x61/0xc6
      
      To fix this the patch rearranges the goto labels to reflect the order of
      object allocations and adds appropriate goto statements on the error
      paths.
      
      Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
      
      Fixes: 68bb1010 ("openvswitch: Fix flow lookup to use unmasked key")
      Signed-off-by: NFedor Pchelkin <pchelkin@ispras.ru>
      Signed-off-by: NAlexey Khoroshilov <khoroshilov@ispras.ru>
      Acked-by: NEelco Chaudron <echaudro@redhat.com>
      Reviewed-by: NSimon Horman <simon.horman@corigine.com>
      Link: https://lore.kernel.org/r/20230201210218.361970-1-pchelkin@ispras.ruSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: Nzhaoxiaoqiang11 <zhaoxiaoqiang11@jd.com>
      0023f0c4
  2. 14 8月, 2023 1 次提交
    • E
      openvswitch: Fix flow lookup to use unmasked key · 1d732b60
      Eelco Chaudron 提交于
      stable inclusion
      from stable-v5.10.163
      commit 6736b61ecf230dd656464de0f514bdeadb384f20
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I7PJ9N
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6736b61ecf230dd656464de0f514bdeadb384f20
      
      ----------------------------------------------------
      
      [ Upstream commit 68bb1010 ]
      
      The commit mentioned below causes the ovs_flow_tbl_lookup() function
      to be called with the masked key. However, it's supposed to be called
      with the unmasked key. This due to the fact that the datapath supports
      installing wider flows, and OVS relies on this behavior. For example
      if ipv4(src=1.1.1.1/192.0.0.0, dst=1.1.1.2/192.0.0.0) exists, a wider
      flow (smaller mask) of ipv4(src=192.1.1.1/128.0.0.0,dst=192.1.1.2/
      128.0.0.0) is allowed to be added.
      
      However, if we try to add a wildcard rule, the installation fails:
      
      $ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \
        ipv4(src=1.1.1.1/192.0.0.0,dst=1.1.1.2/192.0.0.0,frag=no)" 2
      $ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \
        ipv4(src=192.1.1.1/0.0.0.0,dst=49.1.1.2/0.0.0.0,frag=no)" 2
      ovs-vswitchd: updating flow table (File exists)
      
      The reason is that the key used to determine if the flow is already
      present in the system uses the original key ANDed with the mask.
      This results in the IP address not being part of the (miniflow) key,
      i.e., being substituted with an all-zero value. When doing the actual
      lookup, this results in the key wrongfully matching the first flow,
      and therefore the flow does not get installed.
      
      This change reverses the commit below, but rather than having the key
      on the stack, it's allocated.
      
      Fixes: 190aa3e7 ("openvswitch: Fix Frame-size larger than 1024 bytes warning.")
      Signed-off-by: NEelco Chaudron <echaudro@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: Nzhaoxiaoqiang11 <zhaoxiaoqiang11@jd.com>
      1d732b60
  3. 25 7月, 2023 1 次提交
  4. 23 5月, 2023 1 次提交
  5. 19 4月, 2023 2 次提交
  6. 27 10月, 2022 2 次提交
  7. 26 7月, 2022 1 次提交
    • P
      openvswitch: fix OOB access in reserve_sfa_size() · 490085c2
      Paolo Valerio 提交于
      stable inclusion
      from stable-v5.10.113
      commit 0837ff17d052b7d755d5086208c3445867aaff82
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5ISAH
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0837ff17d052b7d755d5086208c3445867aaff82
      
      --------------------------------
      
      commit cefa91b2 upstream.
      
      Given a sufficiently large number of actions, while copying and
      reserving memory for a new action of a new flow, if next_offset is
      greater than MAX_ACTIONS_BUFSIZE, the function reserve_sfa_size() does
      not return -EMSGSIZE as expected, but it allocates MAX_ACTIONS_BUFSIZE
      bytes increasing actions_len by req_size. This can then lead to an OOB
      write access, especially when further actions need to be copied.
      
      Fix it by rearranging the flow action size check.
      
      KASAN splat below:
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      
      ==================================================================
      BUG: KASAN: slab-out-of-bounds in reserve_sfa_size+0x1ba/0x380 [openvswitch]
      Write of size 65360 at addr ffff888147e4001c by task handler15/836
      
      CPU: 1 PID: 836 Comm: handler15 Not tainted 5.18.0-rc1+ #27
      ...
      Call Trace:
       <TASK>
       dump_stack_lvl+0x45/0x5a
       print_report.cold+0x5e/0x5db
       ? __lock_text_start+0x8/0x8
       ? reserve_sfa_size+0x1ba/0x380 [openvswitch]
       kasan_report+0xb5/0x130
       ? reserve_sfa_size+0x1ba/0x380 [openvswitch]
       kasan_check_range+0xf5/0x1d0
       memcpy+0x39/0x60
       reserve_sfa_size+0x1ba/0x380 [openvswitch]
       __add_action+0x24/0x120 [openvswitch]
       ovs_nla_add_action+0xe/0x20 [openvswitch]
       ovs_ct_copy_action+0x29d/0x1130 [openvswitch]
       ? __kernel_text_address+0xe/0x30
       ? unwind_get_return_address+0x56/0xa0
       ? create_prof_cpu_mask+0x20/0x20
       ? ovs_ct_verify+0xf0/0xf0 [openvswitch]
       ? prep_compound_page+0x198/0x2a0
       ? __kasan_check_byte+0x10/0x40
       ? kasan_unpoison+0x40/0x70
       ? ksize+0x44/0x60
       ? reserve_sfa_size+0x75/0x380 [openvswitch]
       __ovs_nla_copy_actions+0xc26/0x2070 [openvswitch]
       ? __zone_watermark_ok+0x420/0x420
       ? validate_set.constprop.0+0xc90/0xc90 [openvswitch]
       ? __alloc_pages+0x1a9/0x3e0
       ? __alloc_pages_slowpath.constprop.0+0x1da0/0x1da0
       ? unwind_next_frame+0x991/0x1e40
       ? __mod_node_page_state+0x99/0x120
       ? __mod_lruvec_page_state+0x2e3/0x470
       ? __kasan_kmalloc_large+0x90/0xe0
       ovs_nla_copy_actions+0x1b4/0x2c0 [openvswitch]
       ovs_flow_cmd_new+0x3cd/0xb10 [openvswitch]
       ...
      
      Cc: stable@vger.kernel.org
      Fixes: f28cd2af ("openvswitch: fix flow actions reallocation")
      Signed-off-by: NPaolo Valerio <pvalerio@redhat.com>
      Acked-by: NEelco Chaudron <echaudro@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      490085c2
  8. 18 7月, 2022 2 次提交
  9. 06 7月, 2022 2 次提交
  10. 26 5月, 2022 1 次提交
    • P
      openvswitch: Fix setting ipv6 fields causing hw csum failure · 22afcea4
      Paul Blakey 提交于
      stable inclusion
      from stable-v5.10.103
      commit 1df9d552fe84bb7d7a6a361b5bb8a9273f9f799d
      bugzilla: https://gitee.com/openeuler/kernel/issues/I56NE7
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1df9d552fe84bb7d7a6a361b5bb8a9273f9f799d
      
      --------------------------------
      
      commit d9b5ae5c upstream.
      
      Ipv6 ttl, label and tos fields are modified without first
      pulling/pushing the ipv6 header, which would have updated
      the hw csum (if available). This might cause csum validation
      when sending the packet to the stack, as can be seen in
      the trace below.
      
      Fix this by updating skb->csum if available.
      
      Trace resulted by ipv6 ttl dec and then sending packet
      to conntrack [actions: set(ipv6(hlimit=63)),ct(zone=99)]:
      [295241.900063] s_pf0vf2: hw csum failure
      [295241.923191] Call Trace:
      [295241.925728]  <IRQ>
      [295241.927836]  dump_stack+0x5c/0x80
      [295241.931240]  __skb_checksum_complete+0xac/0xc0
      [295241.935778]  nf_conntrack_tcp_packet+0x398/0xba0 [nf_conntrack]
      [295241.953030]  nf_conntrack_in+0x498/0x5e0 [nf_conntrack]
      [295241.958344]  __ovs_ct_lookup+0xac/0x860 [openvswitch]
      [295241.968532]  ovs_ct_execute+0x4a7/0x7c0 [openvswitch]
      [295241.979167]  do_execute_actions+0x54a/0xaa0 [openvswitch]
      [295242.001482]  ovs_execute_actions+0x48/0x100 [openvswitch]
      [295242.006966]  ovs_dp_process_packet+0x96/0x1d0 [openvswitch]
      [295242.012626]  ovs_vport_receive+0x6c/0xc0 [openvswitch]
      [295242.028763]  netdev_frame_hook+0xc0/0x180 [openvswitch]
      [295242.034074]  __netif_receive_skb_core+0x2ca/0xcb0
      [295242.047498]  netif_receive_skb_internal+0x3e/0xc0
      [295242.052291]  napi_gro_receive+0xba/0xe0
      [295242.056231]  mlx5e_handle_rx_cqe_mpwrq_rep+0x12b/0x250 [mlx5_core]
      [295242.062513]  mlx5e_poll_rx_cq+0xa0f/0xa30 [mlx5_core]
      [295242.067669]  mlx5e_napi_poll+0xe1/0x6b0 [mlx5_core]
      [295242.077958]  net_rx_action+0x149/0x3b0
      [295242.086762]  __do_softirq+0xd7/0x2d6
      [295242.090427]  irq_exit+0xf7/0x100
      [295242.093748]  do_IRQ+0x7f/0xd0
      [295242.096806]  common_interrupt+0xf/0xf
      [295242.100559]  </IRQ>
      [295242.102750] RIP: 0033:0x7f9022e88cbd
      [295242.125246] RSP: 002b:00007f9022282b20 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffda
      [295242.132900] RAX: 0000000000000005 RBX: 0000000000000010 RCX: 0000000000000000
      [295242.140120] RDX: 00007f9022282ba8 RSI: 00007f9022282a30 RDI: 00007f9014005c30
      [295242.147337] RBP: 00007f9014014d60 R08: 0000000000000020 R09: 00007f90254a8340
      [295242.154557] R10: 00007f9022282a28 R11: 0000000000000246 R12: 0000000000000000
      [295242.161775] R13: 00007f902308c000 R14: 000000000000002b R15: 00007f9022b71f40
      
      Fixes: 3fdbd1ce ("openvswitch: add ipv6 'set' action")
      Signed-off-by: NPaul Blakey <paulb@nvidia.com>
      Link: https://lore.kernel.org/r/20220223163416.24096-1-paulb@nvidia.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NYu Liao <liaoyu15@huawei.com>
      Reviewed-by: NWei Li <liwei391@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      22afcea4
  11. 19 10月, 2021 1 次提交
  12. 15 6月, 2021 1 次提交
  13. 03 6月, 2021 1 次提交
    • D
      openvswitch: fix stack OOB read while fragmenting IPv4 packets · f2822913
      Davide Caratti 提交于
      stable inclusion
      from stable-5.10.36
      commit a1478374b0bda89b4277a8afd39208271faad4be
      bugzilla: 51867
      CVE: NA
      
      --------------------------------
      
      commit 7c0ea593 upstream.
      
      running openvswitch on kernels built with KASAN, it's possible to see the
      following splat while testing fragmentation of IPv4 packets:
      
       BUG: KASAN: stack-out-of-bounds in ip_do_fragment+0x1b03/0x1f60
       Read of size 1 at addr ffff888112fc713c by task handler2/1367
      
       CPU: 0 PID: 1367 Comm: handler2 Not tainted 5.12.0-rc6+ #418
       Hardware name: Red Hat KVM, BIOS 1.11.1-4.module+el8.1.0+4066+0f1aadab 04/01/2014
       Call Trace:
        dump_stack+0x92/0xc1
        print_address_description.constprop.7+0x1a/0x150
        kasan_report.cold.13+0x7f/0x111
        ip_do_fragment+0x1b03/0x1f60
        ovs_fragment+0x5bf/0x840 [openvswitch]
        do_execute_actions+0x1bd5/0x2400 [openvswitch]
        ovs_execute_actions+0xc8/0x3d0 [openvswitch]
        ovs_packet_cmd_execute+0xa39/0x1150 [openvswitch]
        genl_family_rcv_msg_doit.isra.15+0x227/0x2d0
        genl_rcv_msg+0x287/0x490
        netlink_rcv_skb+0x120/0x380
        genl_rcv+0x24/0x40
        netlink_unicast+0x439/0x630
        netlink_sendmsg+0x719/0xbf0
        sock_sendmsg+0xe2/0x110
        ____sys_sendmsg+0x5ba/0x890
        ___sys_sendmsg+0xe9/0x160
        __sys_sendmsg+0xd3/0x170
        do_syscall_64+0x33/0x40
        entry_SYSCALL_64_after_hwframe+0x44/0xae
       RIP: 0033:0x7f957079db07
       Code: c3 66 90 41 54 41 89 d4 55 48 89 f5 53 89 fb 48 83 ec 10 e8 eb ec ff ff 44 89 e2 48 89 ee 89 df 41 89 c0 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 44 89 c7 48 89 44 24 08 e8 24 ed ff ff 48
       RSP: 002b:00007f956ce35a50 EFLAGS: 00000293 ORIG_RAX: 000000000000002e
       RAX: ffffffffffffffda RBX: 0000000000000019 RCX: 00007f957079db07
       RDX: 0000000000000000 RSI: 00007f956ce35ae0 RDI: 0000000000000019
       RBP: 00007f956ce35ae0 R08: 0000000000000000 R09: 00007f9558006730
       R10: 0000000000000000 R11: 0000000000000293 R12: 0000000000000000
       R13: 00007f956ce37308 R14: 00007f956ce35f80 R15: 00007f956ce35ae0
      
       The buggy address belongs to the page:
       page:00000000af2a1d93 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x112fc7
       flags: 0x17ffffc0000000()
       raw: 0017ffffc0000000 0000000000000000 dead000000000122 0000000000000000
       raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
       page dumped because: kasan: bad access detected
      
       addr ffff888112fc713c is located in stack of task handler2/1367 at offset 180 in frame:
        ovs_fragment+0x0/0x840 [openvswitch]
      
       this frame has 2 objects:
        [32, 144) 'ovs_dst'
        [192, 424) 'ovs_rt'
      
       Memory state around the buggy address:
        ffff888112fc7000: f3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        ffff888112fc7080: 00 f1 f1 f1 f1 00 00 00 00 00 00 00 00 00 00 00
       >ffff888112fc7100: 00 00 00 f2 f2 f2 f2 f2 f2 00 00 00 00 00 00 00
                                               ^
        ffff888112fc7180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        ffff888112fc7200: 00 00 00 00 00 00 f2 f2 f2 00 00 00 00 00 00 00
      
      for IPv4 packets, ovs_fragment() uses a temporary struct dst_entry. Then,
      in the following call graph:
      
        ip_do_fragment()
          ip_skb_dst_mtu()
            ip_dst_mtu_maybe_forward()
              ip_mtu_locked()
      
      the pointer to struct dst_entry is used as pointer to struct rtable: this
      turns the access to struct members like rt_mtu_locked into an OOB read in
      the stack. Fix this changing the temporary variable used for IPv4 packets
      in ovs_fragment(), similarly to what is done for IPv6 few lines below.
      
      Fixes: d52e5a7e ("ipv4: lock mtu in fnhe when received PMTU < net.ipv4.route.min_pmt")
      Cc: <stable@vger.kernel.org>
      Acked-by: NEelco Chaudron <echaudro@redhat.com>
      Signed-off-by: NDavide Caratti <dcaratti@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      f2822913
  14. 26 4月, 2021 2 次提交
  15. 09 3月, 2021 1 次提交
  16. 05 12月, 2020 1 次提交
  17. 04 12月, 2020 1 次提交
  18. 28 11月, 2020 1 次提交
  19. 04 11月, 2020 1 次提交
  20. 19 10月, 2020 1 次提交
  21. 14 10月, 2020 1 次提交
  22. 09 10月, 2020 1 次提交
    • D
      openvswitch: handle DNAT tuple collision · 8aa7b526
      Dumitru Ceara 提交于
      With multiple DNAT rules it's possible that after destination
      translation the resulting tuples collide.
      
      For example, two openvswitch flows:
      nw_dst=10.0.0.10,tp_dst=10, actions=ct(commit,table=2,nat(dst=20.0.0.1:20))
      nw_dst=10.0.0.20,tp_dst=10, actions=ct(commit,table=2,nat(dst=20.0.0.1:20))
      
      Assuming two TCP clients initiating the following connections:
      10.0.0.10:5000->10.0.0.10:10
      10.0.0.10:5000->10.0.0.20:10
      
      Both tuples would translate to 10.0.0.10:5000->20.0.0.1:20 causing
      nf_conntrack_confirm() to fail because of tuple collision.
      
      Netfilter handles this case by allocating a null binding for SNAT at
      egress by default.  Perform the same operation in openvswitch for DNAT
      if no explicit SNAT is requested by the user and allocate a null binding
      for SNAT for packets in the "original" direction.
      
      Reported-at: https://bugzilla.redhat.com/1877128Suggested-by: NFlorian Westphal <fw@strlen.de>
      Fixes: 05752523 ("openvswitch: Interface with NAT.")
      Signed-off-by: NDumitru Ceara <dceara@redhat.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      8aa7b526
  23. 06 10月, 2020 1 次提交
  24. 05 10月, 2020 1 次提交
  25. 04 10月, 2020 1 次提交
    • G
      net/sched: act_vlan: Add {POP,PUSH}_ETH actions · 19fbcb36
      Guillaume Nault 提交于
      Implement TCA_VLAN_ACT_POP_ETH and TCA_VLAN_ACT_PUSH_ETH, to
      respectively pop and push a base Ethernet header at the beginning of a
      frame.
      
      POP_ETH is just a matter of pulling ETH_HLEN bytes. VLAN tags, if any,
      must be stripped before calling POP_ETH.
      
      PUSH_ETH is restricted to skbs with no mac_header, and only the MAC
      addresses can be configured. The Ethertype is automatically set from
      skb->protocol. These restrictions ensure that all skb's fields remain
      consistent, so that this action can't confuse other part of the
      networking stack (like GSO).
      
      Since openvswitch already had these actions, consolidate the code in
      skbuff.c (like for vlan and mpls push/pop).
      Signed-off-by: NGuillaume Nault <gnault@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      19fbcb36
  26. 03 10月, 2020 1 次提交
  27. 19 9月, 2020 1 次提交
  28. 02 9月, 2020 4 次提交
  29. 01 9月, 2020 1 次提交
  30. 24 8月, 2020 1 次提交
  31. 14 8月, 2020 1 次提交
  32. 06 8月, 2020 1 次提交