1. Dec 01, 2016
    • David S. Miller's avatar
      Merge branch 'l2tp-fixes' · 7752f727
      David S. Miller authored
      Guillaume Nault says:
      
      ====================
      l2tp: fixes for l2tp_ip and l2tp_ip6 socket handling
      
      This series addresses problems found while working on commit 32c23116
      
      
      ("l2tp: fix racy SOCK_ZAPPED flag check in l2tp_ip{,6}_bind()").
      
      The first three patches fix races in socket's connect, recv and bind
      operations. The last two ones fix scenarios where l2tp fails to
      correctly lookup its userspace sockets.
      
      Apart from the last patch, which is l2tp_ip6 specific, every patch
      fixes the same problem in the L2TP IPv4 and IPv6 code.
      
      All problems fixed by this series exist since the creation of the
      l2tp_ip and l2tp_ip6 modules.
      
      Changes since v1:
        * Patch #3: fix possible uninitialised use of 'ret' in l2tp_ip_bind().
      ====================
      
      Acked-by: default avatarJames Chapman <jchapman@katalix.com>
      7752f727
    • Guillaume Nault's avatar
      l2tp: fix address test in __l2tp_ip6_bind_lookup() · 31e2f21f
      Guillaume Nault authored
      
      
      The '!(addr && ipv6_addr_equal(addr, laddr))' part of the conditional
      matches if addr is NULL or if addr != laddr.
      But the intend of __l2tp_ip6_bind_lookup() is to find a sockets with
      the same address, so the ipv6_addr_equal() condition needs to be
      inverted.
      
      For better clarity and consistency with the rest of the expression, the
      (!X || X == Y) notation is used instead of !(X && X != Y).
      
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      31e2f21f
    • Guillaume Nault's avatar
      l2tp: fix lookup for sockets not bound to a device in l2tp_ip · df90e688
      Guillaume Nault authored
      
      
      When looking up an l2tp socket, we must consider a null netdevice id as
      wild card. There are currently two problems caused by
      __l2tp_ip_bind_lookup() not considering 'dif' as wild card when set to 0:
      
        * A socket bound to a device (i.e. with sk->sk_bound_dev_if != 0)
          never receives any packet. Since __l2tp_ip_bind_lookup() is called
          with dif == 0 in l2tp_ip_recv(), sk->sk_bound_dev_if is always
          different from 'dif' so the socket doesn't match.
      
        * Two sockets, one bound to a device but not the other, can be bound
          to the same address. If the first socket binding to the address is
          the one that is also bound to a device, the second socket can bind
          to the same address without __l2tp_ip_bind_lookup() noticing the
          overlap.
      
      To fix this issue, we need to consider that any null device index, be
      it 'sk->sk_bound_dev_if' or 'dif', matches with any other value.
      We also need to pass the input device index to __l2tp_ip_bind_lookup()
      on reception so that sockets bound to a device never receive packets
      from other devices.
      
      This patch fixes l2tp_ip6 in the same way.
      
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      df90e688
    • Guillaume Nault's avatar
      l2tp: fix racy socket lookup in l2tp_ip and l2tp_ip6 bind() · d5e3a190
      Guillaume Nault authored
      It's not enough to check for sockets bound to same address at the
      beginning of l2tp_ip{,6}_bind(): even if no socket is found at that
      time, a socket with the same address could be bound before we take
      the l2tp lock again.
      
      This patch moves the lookup right before inserting the new socket, so
      that no change can ever happen to the list between address lookup and
      socket insertion.
      
      Care is taken to avoid side effects on the socket in case of failure.
      That is, modifications of the socket are done after the lookup, when
      binding is guaranteed to succeed, and before releasing the l2tp lock,
      so that concurrent lookups will always see fully initialised sockets.
      
      For l2tp_ip, 'ret' is set to -EINVAL before checking the SOCK_ZAPPED
      bit. Error code was mistakenly set to -EADDRINUSE on error by commit
      32c23116
      
       ("l2tp: fix racy SOCK_ZAPPED flag check in l2tp_ip{,6}_bind()").
      Using -EINVAL restores original behaviour.
      
      For l2tp_ip6, the lookup is now always done with the correct bound
      device. Before this patch, when binding to a link-local address, the
      lookup was done with the original sk->sk_bound_dev_if, which was later
      overwritten with addr->l2tp_scope_id. Lookup is now performed with the
      final sk->sk_bound_dev_if value.
      
      Finally, the (addr_len >= sizeof(struct sockaddr_in6)) check has been
      dropped: addr is a sockaddr_l2tpip6 not sockaddr_in6 and addr_len has
      already been checked at this point (this part of the code seems to have
      been copy-pasted from net/ipv6/raw.c).
      
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      d5e3a190
    • Guillaume Nault's avatar
      l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv() · a3c18422
      Guillaume Nault authored
      
      
      Socket must be held while under the protection of the l2tp lock; there
      is no guarantee that sk remains valid after the read_unlock_bh() call.
      
      Same issue for l2tp_ip and l2tp_ip6.
      
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      a3c18422
    • Guillaume Nault's avatar
      l2tp: lock socket before checking flags in connect() · 0382a25a
      Guillaume Nault authored
      
      
      Socket flags aren't updated atomically, so the socket must be locked
      while reading the SOCK_ZAPPED flag.
      
      This issue exists for both l2tp_ip and l2tp_ip6. For IPv6, this patch
      also brings error handling for __ip6_datagram_connect() failures.
      
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0382a25a
    • Hariprasad Shenai's avatar
    • Nikita Yushchenko's avatar
      net: fec: cache statistics while device is down · 80cca775
      Nikita Yushchenko authored
      
      
      Execution 'ethtool -S' on fec device that is down causes OOPS on Vybrid
      board:
      
      Unhandled fault: external abort on non-linefetch (0x1008) at 0xe0898200
      pgd = ddecc000
      [e0898200] *pgd=9e406811, *pte=400d1653, *ppte=400d1453
      Internal error: : 1008 [#1] SMP ARM
      ...
      
      Reason of OOPS is that fec_enet_get_ethtool_stats() accesses fec
      registers while IPG clock is stopped by PM.
      
      Fix that by caching statistics in fec_enet_private. Cache is initialized
      at device probe time, and updated at statistics request time if device
      is up, and also just before turning device off on down path.
      
      Additional locking is not needed, since cached statistics is accessed
      either before device is registered, or under rtnl_lock().
      
      Signed-off-by: default avatarNikita Yushchenko <nikita.yoush@cogentembedded.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      80cca775
    • Haishuang Yan's avatar
      vxlan: fix a potential issue when create a new vxlan fdb entry. · 17b46365
      Haishuang Yan authored
      
      
      vxlan_fdb_append may return error, so add the proper check,
      otherwise it will cause memory leak.
      
      Signed-off-by: default avatarHaishuang Yan <yanhaishuang@cmss.chinamobile.com>
      
      Changes in v2:
        - Unnecessary to initialize rc to zero.
      Acked-by: default avatarJiri Benc <jbenc@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      17b46365
    • Daniele Di Proietto's avatar
      openvswitch: Fix skb leak in IPv6 reassembly. · f92a80a9
      Daniele Di Proietto authored
      If nf_ct_frag6_gather() returns an error other than -EINPROGRESS, it
      means that we still have a reference to the skb.  We should free it
      before returning from handle_fragments, as stated in the comment above.
      
      Fixes: daaa7d64
      
       ("netfilter: ipv6: avoid nf_iterate recursion")
      CC: Florian Westphal <fw@strlen.de>
      CC: Pravin B Shelar <pshelar@ovn.org>
      CC: Joe Stringer <joe@ovn.org>
      Signed-off-by: default avatarDaniele Di Proietto <diproiettod@ovn.org>
      Acked-by: default avatarPravin B Shelar <pshelar@ovn.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      f92a80a9
  2. Nov 30, 2016
  3. Nov 29, 2016
    • Michael Holzheu's avatar
      bpf/samples: Fix PT_REGS_IP on s390x and use it · 2dbb4c05
      Michael Holzheu authored
      
      
      The files "sampleip_kern.c" and "trace_event_kern.c" directly access
      "ctx->regs.ip" which is not available on s390x. Fix this and use the
      PT_REGS_IP() macro instead.
      
      Also fix the macro for s390x and use "psw.addr" from "pt_regs".
      
      Reported-by: default avatarZvonko Kosic <zvonko.kosic@de.ibm.com>
      Signed-off-by: default avatarMichael Holzheu <holzheu@linux.vnet.ibm.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2dbb4c05
    • Nikita Yushchenko's avatar
      net: dsa: fix unbalanced dsa_switch_tree reference counting · 7a99cd6e
      Nikita Yushchenko authored
      _dsa_register_switch() gets a dsa_switch_tree object either via
      dsa_get_dst() or via dsa_add_dst(). Former path does not increase kref
      in returned object (resulting into caller not owning a reference),
      while later path does create a new object (resulting into caller owning
      a reference).
      
      The rest of _dsa_register_switch() assumes that it owns a reference, and
      calls dsa_put_dst().
      
      This causes a memory breakage if first switch in the tree initialized
      successfully, but second failed to initialize. In particular, freed
      dsa_swith_tree object is left referenced by switch that was initialized,
      and later access to sysfs attributes of that switch cause OOPS.
      
      To fix, need to add kref_get() call to dsa_get_dst().
      
      Fixes: 83c0afae
      
       ("net: dsa: Add new binding implementation")
      Signed-off-by: default avatarNikita Yushchenko <nikita.yoush@cogentembedded.com>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      7a99cd6e
    • David Ahern's avatar
      net: handle no dst on skb in icmp6_send · 79dc7e3f
      David Ahern authored
      Andrey reported the following while fuzzing the kernel with syzkaller:
      
      kasan: CONFIG_KASAN_INLINE enabled
      kasan: GPF could be caused by NULL-ptr deref or user memory access
      general protection fault: 0000 [#1] SMP KASAN
      Modules linked in:
      CPU: 0 PID: 3859 Comm: a.out Not tainted 4.9.0-rc6+ #429
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
      task: ffff8800666d4200 task.stack: ffff880067348000
      RIP: 0010:[<ffffffff833617ec>]  [<ffffffff833617ec>]
      icmp6_send+0x5fc/0x1e30 net/ipv6/icmp.c:451
      RSP: 0018:ffff88006734f2c0  EFLAGS: 00010206
      RAX: ffff8800666d4200 RBX: 0000000000000000 RCX: 0000000000000000
      RDX: 0000000000000000 RSI: dffffc0000000000 RDI: 0000000000000018
      RBP: ffff88006734f630 R08: ffff880064138418 R09: 0000000000000003
      R10: dffffc0000000000 R11: 0000000000000005 R12: 0000000000000000
      R13: ffffffff84e7e200 R14: ffff880064138484 R15: ffff8800641383c0
      FS:  00007fb3887a07c0(0000) GS:ffff88006cc00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000020000000 CR3: 000000006b040000 CR4: 00000000000006f0
      Stack:
       ffff8800666d4200 ffff8800666d49f8 ffff8800666d4200 ffffffff84c02460
       ffff8800666d4a1a 1ffff1000ccdaa2f ffff88006734f498 0000000000000046
       ffff88006734f440 ffffffff832f4269 ffff880064ba7456 0000000000000000
      Call Trace:
       [<ffffffff83364ddc>] icmpv6_param_prob+0x2c/0x40 net/ipv6/icmp.c:557
       [<     inline     >] ip6_tlvopt_unknown net/ipv6/exthdrs.c:88
       [<ffffffff83394405>] ip6_parse_tlv+0x555/0x670 net/ipv6/exthdrs.c:157
       [<ffffffff8339a759>] ipv6_parse_hopopts+0x199/0x460 net/ipv6/exthdrs.c:663
       [<ffffffff832ee773>] ipv6_rcv+0xfa3/0x1dc0 net/ipv6/ip6_input.c:191
       ...
      
      icmp6_send / icmpv6_send is invoked for both rx and tx paths. In both
      cases the dst->dev should be preferred for determining the L3 domain
      if the dst has been set on the skb. Fallback to the skb->dev if it has
      not. This covers the case reported here where icmp6_send is invoked on
      Rx before the route lookup.
      
      Fixes: 5d41ce29
      
       ("net: icmp6_send should use dst dev to determine L3 domain")
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarDavid Ahern <dsa@cumulusnetworks.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      79dc7e3f
    • David S. Miller's avatar
      Merge branch 'mlx4-fixes' · 2fc8d112
      David S. Miller authored
      Tariq Toukan says:
      
      ====================
      mlx4 bug fixes for 4.9
      
      This patchset includes 2 bug fixes:
      * In patch 1 we revert the commit that avoids invoking unregister_netdev
      in shutdown flow, as it introduces netdev presence issues where
      it can be accessed unsafely by ndo operations during the flow.
      * Patch 2 is a simple fix for a variable uninitialization issue.
      
      Series generated against net commit:
      6998cc6e
      
       tipc: resolve connection flow control compatibility problem
      ====================
      
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2fc8d112
    • Jack Morgenstein's avatar
      net/mlx4: Fix uninitialized fields in rule when adding promiscuous mode to... · 44b911e7
      Jack Morgenstein authored
      net/mlx4: Fix uninitialized fields in rule when adding promiscuous mode to device managed flow steering
      
      In procedure mlx4_flow_steer_promisc_add(), several fields
      were left uninitialized in the rule structure.
      Correctly initialize these fields.
      
      Fixes: 592e49dd
      
       ("net/mlx4: Implement promiscuous mode with device managed flow-steering")
      Signed-off-by: default avatarJack Morgenstein <jackm@dev.mellanox.co.il>
      Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      44b911e7
    • Tariq Toukan's avatar
      Revert "net/mlx4_en: Avoid unregister_netdev at shutdown flow" · b4353708
      Tariq Toukan authored
      This reverts commit 9d769311.
      
      Using unregister_netdev at shutdown flow prevents calling
      the netdev's ndos or trying to access its freed resources.
      
      This fixes crashes like the following:
       Call Trace:
        [<ffffffff81587a6e>] dev_get_phys_port_id+0x1e/0x30
        [<ffffffff815a36ce>] rtnl_fill_ifinfo+0x4be/0xff0
        [<ffffffff815a53f3>] rtmsg_ifinfo_build_skb+0x73/0xe0
        [<ffffffff815a5476>] rtmsg_ifinfo.part.27+0x16/0x50
        [<ffffffff815a54c8>] rtmsg_ifinfo+0x18/0x20
        [<ffffffff8158a6c6>] netdev_state_change+0x46/0x50
        [<ffffffff815a5e78>] linkwatch_do_dev+0x38/0x50
        [<ffffffff815a6165>] __linkwatch_run_queue+0xf5/0x170
        [<ffffffff815a6205>] linkwatch_event+0x25/0x30
        [<ffffffff81099a82>] process_one_work+0x152/0x400
        [<ffffffff8109a325>] worker_thread+0x125/0x4b0
        [<ffffffff8109a200>] ? rescuer_thread+0x350/0x350
        [<ffffffff8109fc6a>] kthread+0xca/0xe0
        [<ffffffff8109fba0>] ? kthread_park+0x60/0x60
        [<ffffffff816a1285>] ret_from_fork+0x25/0x30
      
      Fixes: 9d769311
      
       ("net/mlx4_en: Avoid unregister_netdev at shutdown flow")
      Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
      Reported-by: default avatarSebastian Ott <sebott@linux.vnet.ibm.com>
      Reported-by: default avatarSteve Wise <swise@opengridcomputing.com>
      Cc: Jiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      b4353708