Skip to content
  1. Feb 09, 2022
    • Florian Westphal's avatar
      netfilter: nat: limit port clash resolution attempts · 8070f13e
      Florian Westphal authored
      commit a504b703
      
       upstream.
      
      In case almost or all available ports are taken, clash resolution can
      take a very long time, resulting in soft lockup.
      
      This can happen when many to-be-natted hosts connect to same
      destination:port (e.g. a proxy) and all connections pass the same SNAT.
      
      Pick a random offset in the acceptable range, then try ever smaller
      number of adjacent port numbers, until either the limit is reached or a
      useable port was found.  This results in at most 248 attempts
      (128 + 64 + 32 + 16 + 8, i.e. 4 restarts with new search offset)
      instead of 64000+,
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8070f13e
    • Florian Westphal's avatar
      netfilter: nat: remove l4 protocol port rovers · ffebec7f
      Florian Westphal authored
      commit 6ed5943f
      
       upstream.
      
      This is a leftover from days where single-cpu systems were common:
      Store last port used to resolve a clash to use it as a starting point when
      the next conflict needs to be resolved.
      
      When we have parallel attempt to connect to same address:port pair,
      its likely that both cores end up computing the same "available" port,
      as both use same starting port, and newly used ports won't become
      visible to other cores until the conntrack gets confirmed later.
      
      One of the cores then has to drop the packet at insertion time because
      the chosen new tuple turns out to be in use after all.
      
      Lets simplify this: remove port rover and use a pseudo-random starting
      point.
      
      Note that this doesn't make netfilter default to 'fully random' mode;
      the 'rover' was only used if NAT could not reuse source port as-is.
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ffebec7f
    • Eric Dumazet's avatar
      ipv4: tcp: send zero IPID in SYNACK messages · 08ed3cab
      Eric Dumazet authored
      [ Upstream commit 970a5a3e ]
      
      In commit 431280ee ("ipv4: tcp: send zero IPID for RST and
      ACK sent in SYN-RECV and TIME-WAIT state") we took care of some
      ctl packets sent by TCP.
      
      It turns out we need to use a similar strategy for SYNACK packets.
      
      By default, they carry IP_DF and IPID==0, but there are ways
      to ask them to use the hashed IP ident generator and thus
      be used to build off-path attacks.
      (Ref: Off-Path TCP Exploits of the Mixed IPID Assignment)
      
      One of this way is to force (before listener is started)
      echo 1 >/proc/sys/net/ipv4/ip_no_pmtu_disc
      
      Another way is using forged ICMP ICMP_FRAG_NEEDED
      with a very small MTU (like 68) to force a false return from
      ip_dont_fragment()
      
      In this patch, ip_build_and_send_pkt() uses the following
      heuristics.
      
      1) Most SYNACK packets are smaller than IPV4_MIN_MTU and therefore
      can use IP_DF regardless of the listener or route pmtu setting.
      
      2) In case the SYNACK packet is bigger than IPV4_MIN_MTU,
      we use prandom_u32() generator instead of the IPv4 hashed ident one.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarRay Che <xijiache@gmail.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Cc: Geoff Alexander <alexandg@cs.unm.edu>
      Cc: Willy Tarreau <w@1wt.eu>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      08ed3cab
    • Eric Dumazet's avatar
      ipv4: raw: lock the socket in raw_bind() · 3edc5260
      Eric Dumazet authored
      [ Upstream commit 153a0d18 ]
      
      For some reason, raw_bind() forgot to lock the socket.
      
      BUG: KCSAN: data-race in __ip4_datagram_connect / raw_bind
      
      write to 0xffff8881170d4308 of 4 bytes by task 5466 on cpu 0:
       raw_bind+0x1b0/0x250 net/ipv4/raw.c:739
       inet_bind+0x56/0xa0 net/ipv4/af_inet.c:443
       __sys_bind+0x14b/0x1b0 net/socket.c:1697
       __do_sys_bind net/socket.c:1708 [inline]
       __se_sys_bind net/socket.c:1706 [inline]
       __x64_sys_bind+0x3d/0x50 net/socket.c:1706
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      read to 0xffff8881170d4308 of 4 bytes by task 5468 on cpu 1:
       __ip4_datagram_connect+0xb7/0x7b0 net/ipv4/datagram.c:39
       ip4_datagram_connect+0x2a/0x40 net/ipv4/datagram.c:89
       inet_dgram_connect+0x107/0x190 net/ipv4/af_inet.c:576
       __sys_connect_file net/socket.c:1900 [inline]
       __sys_connect+0x197/0x1b0 net/socket.c:1917
       __do_sys_connect net/socket.c:1927 [inline]
       __se_sys_connect net/socket.c:1924 [inline]
       __x64_sys_connect+0x3d/0x50 net/socket.c:1924
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      value changed: 0x00000000 -> 0x0003007f
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 1 PID: 5468 Comm: syz-executor.5 Not tainted 5.17.0-rc1-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3edc5260
    • Hangyu Hua's avatar
      yam: fix a memory leak in yam_siocdevprivate() · 4bd197ce
      Hangyu Hua authored
      [ Upstream commit 29eb3154 ]
      
      ym needs to be free when ym->cmd != SIOCYAMSMCS.
      
      Fixes: 0781168e
      
       ("yam: fix a missing-check bug")
      Signed-off-by: default avatarHangyu Hua <hbh25y@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4bd197ce
    • Sukadev Bhattiprolu's avatar
      ibmvnic: don't spin in tasklet · e966de19
      Sukadev Bhattiprolu authored
      [ Upstream commit 48079e7f ]
      
      ibmvnic_tasklet() continuously spins waiting for responses to all
      capability requests. It does this to avoid encountering an error
      during initialization of the vnic. However if there is a bug in the
      VIOS and we do not receive a response to one or more queries the
      tasklet ends up spinning continuously leading to hard lock ups.
      
      If we fail to receive a message from the VIOS it is reasonable to
      timeout the login attempt rather than spin indefinitely in the tasklet.
      
      Fixes: 249168ad
      
       ("ibmvnic: Make CRQ interrupt tasklet wait for all capabilities crqs")
      Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Reviewed-by: default avatarDany Madden <drt@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e966de19
    • Sukadev Bhattiprolu's avatar
      ibmvnic: init ->running_cap_crqs early · 539ac94e
      Sukadev Bhattiprolu authored
      [ Upstream commit 151b6a5c ]
      
      We use ->running_cap_crqs to determine when the ibmvnic_tasklet() should
      send out the next protocol message type. i.e when we get back responses
      to all our QUERY_CAPABILITY CRQs we send out REQUEST_CAPABILITY crqs.
      Similiary, when we get responses to all the REQUEST_CAPABILITY crqs, we
      send out the QUERY_IP_OFFLOAD CRQ.
      
      We currently increment ->running_cap_crqs as we send out each CRQ and
      have the ibmvnic_tasklet() send out the next message type, when this
      running_cap_crqs count drops to 0.
      
      This assumes that all the CRQs of the current type were sent out before
      the count drops to 0. However it is possible that we send out say 6 CRQs,
      get preempted and receive all the 6 responses before we send out the
      remaining CRQs. This can result in ->running_cap_crqs count dropping to
      zero before all messages of the current type were sent and we end up
      sending the next protocol message too early.
      
      Instead initialize the ->running_cap_crqs upfront so the tasklet will
      only send the next protocol message after all responses are received.
      
      Use the cap_reqs local variable to also detect any discrepancy (either
      now or in future) in the number of capability requests we actually send.
      
      Currently only send_query_cap() is affected by this behavior (of sending
      next message early) since it is called from the worker thread (during
      reset) and from application thread (during ->ndo_open()) and they can be
      preempted. send_request_cap() is only called from the tasklet  which
      processes CRQ responses sequentially, is not be affected.  But to
      maintain the existing symmtery with send_query_capability() we update
      send_request_capability() also.
      
      Fixes: 249168ad
      
       ("ibmvnic: Make CRQ interrupt tasklet wait for all capabilities crqs")
      Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Reviewed-by: default avatarDany Madden <drt@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      539ac94e
    • Marek Behún's avatar
      phylib: fix potential use-after-free · 67d27176
      Marek Behún authored
      [ Upstream commit cbda1b16 ]
      
      Commit bafbdd52 ("phylib: Add device reset GPIO support") added call
      to phy_device_reset(phydev) after the put_device() call in phy_detach().
      
      The comment before the put_device() call says that the phydev might go
      away with put_device().
      
      Fix potential use-after-free by calling phy_device_reset() before
      put_device().
      
      Fixes: bafbdd52
      
       ("phylib: Add device reset GPIO support")
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Link: https://lore.kernel.org/r/20220119162748.32418-1-kabel@kernel.org
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      67d27176
    • Trond Myklebust's avatar
      NFS: Ensure the server has an up to date ctime before renaming · 8b5c9de1
      Trond Myklebust authored
      [ Upstream commit 6ff9d99b ]
      
      Renaming a file is required by POSIX to update the file ctime, so
      ensure that the file data is synced to disk so that we don't clobber the
      updated ctime by writing back after creating the hard link.
      
      Fixes: f2c2c552
      
       ("NFS: Move delegation recall into the NFSv4 callback for rename_setup()")
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8b5c9de1
    • Trond Myklebust's avatar
      NFS: Ensure the server has an up to date ctime before hardlinking · ddeea000
      Trond Myklebust authored
      [ Upstream commit 20497503 ]
      
      Creating a hard link is required by POSIX to update the file ctime, so
      ensure that the file data is synced to disk so that we don't clobber the
      updated ctime by writing back after creating the hard link.
      
      Fixes: 9f768272
      
       ("NFS: Move the delegation return down into nfs4_proc_link()")
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ddeea000
    • Eric Dumazet's avatar
      ipv6: annotate accesses to fn->fn_sernum · 243e8984
      Eric Dumazet authored
      commit aafc2e32 upstream.
      
      struct fib6_node's fn_sernum field can be
      read while other threads change it.
      
      Add READ_ONCE()/WRITE_ONCE() annotations.
      
      Do not change existing smp barriers in fib6_get_cookie_safe()
      and __fib6_update_sernum_upto_root()
      
      syzbot reported:
      
      BUG: KCSAN: data-race in fib6_clean_node / inet6_csk_route_socket
      
      write to 0xffff88813df62e2c of 4 bytes by task 1920 on cpu 1:
       fib6_clean_node+0xc2/0x260 net/ipv6/ip6_fib.c:2178
       fib6_walk_continue+0x38e/0x430 net/ipv6/ip6_fib.c:2112
       fib6_walk net/ipv6/ip6_fib.c:2160 [inline]
       fib6_clean_tree net/ipv6/ip6_fib.c:2240 [inline]
       __fib6_clean_all+0x1a9/0x2e0 net/ipv6/ip6_fib.c:2256
       fib6_flush_trees+0x6c/0x80 net/ipv6/ip6_fib.c:2281
       rt_genid_bump_ipv6 include/net/net_namespace.h:488 [inline]
       addrconf_dad_completed+0x57f/0x870 net/ipv6/addrconf.c:4230
       addrconf_dad_work+0x908/0x1170
       process_one_work+0x3f6/0x960 kernel/workqueue.c:2307
       worker_thread+0x616/0xa70 kernel/workqueue.c:2454
       kthread+0x1bf/0x1e0 kernel/kthread.c:359
       ret_from_fork+0x1f/0x30
      
      read to 0xffff88813df62e2c of 4 bytes by task 15701 on cpu 0:
       fib6_get_cookie_safe include/net/ip6_fib.h:285 [inline]
       rt6_get_cookie include/net/ip6_fib.h:306 [inline]
       ip6_dst_store include/net/ip6_route.h:234 [inline]
       inet6_csk_route_socket+0x352/0x3c0 net/ipv6/inet6_connection_sock.c:109
       inet6_csk_xmit+0x91/0x1e0 net/ipv6/inet6_connection_sock.c:121
       __tcp_transmit_skb+0x1323/0x1840 net/ipv4/tcp_output.c:1402
       tcp_transmit_skb net/ipv4/tcp_output.c:1420 [inline]
       tcp_write_xmit+0x1450/0x4460 net/ipv4/tcp_output.c:2680
       __tcp_push_pending_frames+0x68/0x1c0 net/ipv4/tcp_output.c:2864
       tcp_push+0x2d9/0x2f0 net/ipv4/tcp.c:725
       mptcp_push_release net/mptcp/protocol.c:1491 [inline]
       __mptcp_push_pending+0x46c/0x490 net/mptcp/protocol.c:1578
       mptcp_sendmsg+0x9ec/0xa50 net/mptcp/protocol.c:1764
       inet6_sendmsg+0x5f/0x80 net/ipv6/af_inet6.c:643
       sock_sendmsg_nosec net/socket.c:705 [inline]
       sock_sendmsg net/socket.c:725 [inline]
       kernel_sendmsg+0x97/0xd0 net/socket.c:745
       sock_no_sendpage+0x84/0xb0 net/core/sock.c:3086
       inet_sendpage+0x9d/0xc0 net/ipv4/af_inet.c:834
       kernel_sendpage+0x187/0x200 net/socket.c:3492
       sock_sendpage+0x5a/0x70 net/socket.c:1007
       pipe_to_sendpage+0x128/0x160 fs/splice.c:364
       splice_from_pipe_feed fs/splice.c:418 [inline]
       __splice_from_pipe+0x207/0x500 fs/splice.c:562
       splice_from_pipe fs/splice.c:597 [inline]
       generic_splice_sendpage+0x94/0xd0 fs/splice.c:746
       do_splice_from fs/splice.c:767 [inline]
       direct_splice_actor+0x80/0xa0 fs/splice.c:936
       splice_direct_to_actor+0x345/0x650 fs/splice.c:891
       do_splice_direct+0x106/0x190 fs/splice.c:979
       do_sendfile+0x675/0xc40 fs/read_write.c:1245
       __do_sys_sendfile64 fs/read_write.c:1310 [inline]
       __se_sys_sendfile64 fs/read_write.c:1296 [inline]
       __x64_sys_sendfile64+0x102/0x140 fs/read_write.c:1296
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      value changed: 0x0000026f -> 0x00000271
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 0 PID: 15701 Comm: syz-executor.2 Not tainted 5.16.0-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      
      The Fixes tag I chose is probably arbitrary, I do not think
      we need to backport this patch to older kernels.
      
      Fixes: c5cff856
      
       ("ipv6: add rcu grace period before freeing fib6_node")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Link: https://lore.kernel.org/r/20220120174112.1126644-1-eric.dumazet@gmail.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      243e8984
    • José Expósito's avatar
      drm/msm/dsi: invalid parameter check in msm_dsi_phy_enable · ca63eeb7
      José Expósito authored
      commit 5e761a22 upstream.
      
      The function performs a check on the "phy" input parameter, however, it
      is used before the check.
      
      Initialize the "dev" variable after the sanity check to avoid a possible
      NULL pointer dereference.
      
      Fixes: 5c829028
      
       ("drm/msm/dsi: Split PHY drivers to separate files")
      Addresses-Coverity-ID: 1493860 ("Null pointer dereference")
      Signed-off-by: default avatarJosé Expósito <jose.exposito89@gmail.com>
      Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Link: https://lore.kernel.org/r/20220116181844.7400-1-jose.exposito89@gmail.com
      Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca63eeb7
    • Xianting Tian's avatar
      drm/msm: Fix wrong size calculation · 5467ff88
      Xianting Tian authored
      commit 0a727b45
      
       upstream.
      
      For example, memory-region in .dts as below,
      	reg = <0x0 0x50000000 0x0 0x20000000>
      
      We can get below values,
      struct resource r;
      r.start = 0x50000000;
      r.end	= 0x6fffffff;
      
      So the size should be:
      size = r.end - r.start + 1 = 0x20000000
      
      Signed-off-by: default avatarXianting Tian <xianting.tian@linux.alibaba.com>
      Fixes: 072f1f91
      
       ("drm/msm: add support for "stolen" mem")
      Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Link: https://lore.kernel.org/r/20220112123334.749776-1-xianting.tian@linux.alibaba.com
      Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5467ff88
    • Jianguo Wu's avatar
      net-procfs: show net devices bound packet types · 4be8f4cd
      Jianguo Wu authored
      commit 1d10f8a1 upstream.
      
      After commit:7866a621 ("dev: add per net_device packet type chains"),
      we can not get packet types that are bound to a specified net device by
      /proc/net/ptype, this patch fix the regression.
      
      Run "tcpdump -i ens192 udp -nns0" Before and after apply this patch:
      
      Before:
        [root@localhost ~]# cat /proc/net/ptype
        Type Device      Function
        0800          ip_rcv
        0806          arp_rcv
        86dd          ipv6_rcv
      
      After:
        [root@localhost ~]# cat /proc/net/ptype
        Type Device      Function
        ALL  ens192   tpacket_rcv
        0800          ip_rcv
        0806          arp_rcv
        86dd          ipv6_rcv
      
      v1 -> v2:
        - fix the regression rather than adding new /proc API as
          suggested by Stephen Hemminger.
      
      Fixes: 7866a621
      
       ("dev: add per net_device packet type chains")
      Signed-off-by: default avatarJianguo Wu <wujianguo@chinatelecom.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4be8f4cd
    • Trond Myklebust's avatar
      NFSv4: nfs_atomic_open() can race when looking up a non-regular file · 07a970dd
      Trond Myklebust authored
      commit 1751fc1d upstream.
      
      If the file type changes back to being a regular file on the server
      between the failed OPEN and our LOOKUP, then we need to re-run the OPEN.
      
      Fixes: 0dd2b474
      
       ("nfs: implement i_op->atomic_open()")
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      07a970dd
    • Trond Myklebust's avatar
      NFSv4: Handle case where the lookup of a directory fails · b00b4c6f
      Trond Myklebust authored
      commit ac795161
      
       upstream.
      
      If the application sets the O_DIRECTORY flag, and tries to open a
      regular file, nfs_atomic_open() will punt to doing a regular lookup.
      If the server then returns a regular file, we will happily return a
      file descriptor with uninitialised open state.
      
      The fix is to return the expected ENOTDIR error in these cases.
      
      Reported-by: default avatarLyu Tao <tao.lyu@epfl.ch>
      Fixes: 0dd2b474
      
       ("nfs: implement i_op->atomic_open()")
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b00b4c6f
    • Guenter Roeck's avatar
      hwmon: (lm90) Reduce maximum conversion rate for G781 · e3e20f10
      Guenter Roeck authored
      [ Upstream commit a66c5ed5 ]
      
      According to its datasheet, G781 supports a maximum conversion rate value
      of 8 (62.5 ms). However, chips labeled G781 and G780 were found to only
      support a maximum conversion rate value of 7 (125 ms). On the other side,
      chips labeled G781-1 and G784 were found to support a conversion rate value
      of 8. There is no known means to distinguish G780 from G781 or G784; all
      chips report the same manufacturer ID and chip revision.
      Setting the conversion rate register value to 8 on chips not supporting
      it causes unexpected behavior since the real conversion rate is set to 0
      (16 seconds) if a value of 8 is written into the conversion rate register.
      Limit the conversion rate register value to 7 for all G78x chips to avoid
      the problem.
      
      Fixes: ae544f64
      
       ("hwmon: (lm90) Add support for GMT G781")
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e3e20f10
    • Eric Dumazet's avatar
      ipv4: avoid using shared IP generator for connected sockets · eb04c6d1
      Eric Dumazet authored
      commit 23f57406 upstream.
      
      ip_select_ident_segs() has been very conservative about using
      the connected socket private generator only for packets with IP_DF
      set, claiming it was needed for some VJ compression implementations.
      
      As mentioned in this referenced document, this can be abused.
      (Ref: Off-Path TCP Exploits of the Mixed IPID Assignment)
      
      Before switching to pure random IPID generation and possibly hurt
      some workloads, lets use the private inet socket generator.
      
      Not only this will remove one vulnerability, this will also
      improve performance of TCP flows using pmtudisc==IP_PMTUDISC_DONT
      
      Fixes: 73f156a6
      
       ("inetpeer: get rid of ip_id_count")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reported-by: default avatarRay Che <xijiache@gmail.com>
      Cc: Willy Tarreau <w@1wt.eu>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eb04c6d1
    • Xin Long's avatar
      ping: fix the sk_bound_dev_if match in ping_lookup · a9215078
      Xin Long authored
      commit 2afc3b5a upstream.
      
      When 'ping' changes to use PING socket instead of RAW socket by:
      
         # sysctl -w net.ipv4.ping_group_range="0 100"
      
      the selftests 'router_broadcast.sh' will fail, as such command
      
        # ip vrf exec vrf-h1 ping -I veth0 198.51.100.255 -b
      
      can't receive the response skb by the PING socket. It's caused by mismatch
      of sk_bound_dev_if and dif in ping_rcv() when looking up the PING socket,
      as dif is vrf-h1 if dif's master was set to vrf-h1.
      
      This patch is to fix this regression by also checking the sk_bound_dev_if
      against sdif so that the packets can stil be received even if the socket
      is not bound to the vrf device but to the real iif.
      
      Fixes: c319b4d7
      
       ("net: ipv4: add IPPROTO_ICMP socket kind")
      Reported-by: default avatarHangbin Liu <liuhangbin@gmail.com>
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a9215078
    • Congyu Liu's avatar
      net: fix information leakage in /proc/net/ptype · b67ad617
      Congyu Liu authored
      commit 47934e06 upstream.
      
      In one net namespace, after creating a packet socket without binding
      it to a device, users in other net namespaces can observe the new
      `packet_type` added by this packet socket by reading `/proc/net/ptype`
      file. This is minor information leakage as packet socket is
      namespace aware.
      
      Add a net pointer in `packet_type` to keep the net namespace of
      of corresponding packet socket. In `ptype_seq_show`, this net pointer
      must be checked when it is not NULL.
      
      Fixes: 2feb27db
      
       ("[NETNS]: Minor information leak via /proc/net/ptype file.")
      Signed-off-by: default avatarCongyu Liu <liu3101@purdue.edu>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b67ad617
    • Ido Schimmel's avatar
      ipv6_tunnel: Rate limit warning messages · e3e01ed7
      Ido Schimmel authored
      commit 6cee105e upstream.
      
      The warning messages can be invoked from the data path for every packet
      transmitted through an ip6gre netdev, leading to high CPU utilization.
      
      Fix that by rate limiting the messages.
      
      Fixes: 09c6bbf0
      
       ("[IPV6]: Do mandatory IPv6 tunnel endpoint checks in realtime")
      Reported-by: default avatarMaksym Yaremchuk <maksymy@nvidia.com>
      Tested-by: default avatarMaksym Yaremchuk <maksymy@nvidia.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Reviewed-by: default avatarAmit Cohen <amcohen@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e3e01ed7
    • John Meneghini's avatar
      scsi: bnx2fc: Flush destroy_work queue before calling bnx2fc_interface_put() · de6336b1
      John Meneghini authored
      commit 847f9ea4 upstream.
      
      The bnx2fc_destroy() functions are removing the interface before calling
      destroy_work. This results multiple WARNings from sysfs_remove_group() as
      the controller rport device attributes are removed too early.
      
      Replace the fcoe_port's destroy_work queue. It's not needed.
      
      The problem is easily reproducible with the following steps.
      
      Example:
      
        $ dmesg -w &
        $ systemctl enable --now fcoe
        $ fipvlan -s -c ens2f1
        $ fcoeadm -d ens2f1.802
        [  583.464488] host2: libfc: Link down on port (7500a1)
        [  583.472651] bnx2fc: 7500a1 - rport not created Yet!!
        [  583.490468] ------------[ cut here ]------------
        [  583.538725] sysfs group 'power' not found for kobject 'rport-2:0-0'
        [  583.568814] WARNING: CPU: 3 PID: 192 at fs/sysfs/group.c:279 sysfs_remove_group+0x6f/0x80
        [  583.607130] Modules linked in: dm_service_time 8021q garp mrp stp llc bnx2fc cnic uio rpcsec_gss_krb5 auth_rpcgss nfsv4 ...
        [  583.942994] CPU: 3 PID: 192 Comm: kworker/3:2 Kdump: loaded Not tainted 5.14.0-39.el9.x86_64 #1
        [  583.984105] Hardware name: HP ProLiant DL120 G7, BIOS J01 07/01/2013
        [  584.016535] Workqueue: fc_wq_2 fc_rport_final_delete [scsi_transport_fc]
        [  584.050691] RIP: 0010:sysfs_remove_group+0x6f/0x80
        [  584.074725] Code: ff 5b 48 89 ef 5d 41 5c e9 ee c0 ff ff 48 89 ef e8 f6 b8 ff ff eb d1 49 8b 14 24 48 8b 33 48 c7 c7 ...
        [  584.162586] RSP: 0018:ffffb567c15afdc0 EFLAGS: 00010282
        [  584.188225] RAX: 0000000000000000 RBX: ffffffff8eec4220 RCX: 0000000000000000
        [  584.221053] RDX: ffff8c1586ce84c0 RSI: ffff8c1586cd7cc0 RDI: ffff8c1586cd7cc0
        [  584.255089] RBP: 0000000000000000 R08: 0000000000000000 R09: ffffb567c15afc00
        [  584.287954] R10: ffffb567c15afbf8 R11: ffffffff8fbe7f28 R12: ffff8c1486326400
        [  584.322356] R13: ffff8c1486326480 R14: ffff8c1483a4a000 R15: 0000000000000004
        [  584.355379] FS:  0000000000000000(0000) GS:ffff8c1586cc0000(0000) knlGS:0000000000000000
        [  584.394419] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [  584.421123] CR2: 00007fe95a6f7840 CR3: 0000000107674002 CR4: 00000000000606e0
        [  584.454888] Call Trace:
        [  584.466108]  device_del+0xb2/0x3e0
        [  584.481701]  device_unregister+0x13/0x60
        [  584.501306]  bsg_unregister_queue+0x5b/0x80
        [  584.522029]  bsg_remove_queue+0x1c/0x40
        [  584.541884]  fc_rport_final_delete+0xf3/0x1d0 [scsi_transport_fc]
        [  584.573823]  process_one_work+0x1e3/0x3b0
        [  584.592396]  worker_thread+0x50/0x3b0
        [  584.609256]  ? rescuer_thread+0x370/0x370
        [  584.628877]  kthread+0x149/0x170
        [  584.643673]  ? set_kthread_struct+0x40/0x40
        [  584.662909]  ret_from_fork+0x22/0x30
        [  584.680002] ---[ end trace 53575ecefa942ece ]---
      
      Link: https://lore.kernel.org/r/20220115040044.1013475-1-jmeneghi@redhat.com
      Fixes: 0cbf32e1
      
       ("[SCSI] bnx2fc: Avoid calling bnx2fc_if_destroy with unnecessary locks")
      Tested-by: default avatarGuangwu Zhang <guazhang@redhat.com>
      Co-developed-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
      Signed-off-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
      Signed-off-by: default avatarJohn Meneghini <jmeneghi@redhat.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de6336b1
    • Matthias Kaehlcke's avatar
      rpmsg: char: Fix race between the release of rpmsg_eptdev and cdev · 4305697d
      Matthias Kaehlcke authored
      commit 7a534ae8 upstream.
      
      struct rpmsg_eptdev contains a struct cdev. The current code frees
      the rpmsg_eptdev struct in rpmsg_eptdev_destroy(), but the cdev is
      a managed object, therefore its release is not predictable and the
      rpmsg_eptdev could be freed before the cdev is entirely released.
      
      The cdev_device_add/del() API was created to address this issue
      (see commit '233ed09d ("chardev: add helper function to register
      char devs with a struct device")'), use it instead of cdev add/del().
      
      Fixes: c0cdc19f
      
       ("rpmsg: Driver for user space endpoint interface")
      Suggested-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Signed-off-by: default avatarMatthias Kaehlcke <mka@chromium.org>
      Reviewed-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
      Reviewed-by: default avatarStephen Boyd <swboyd@chromium.org>
      Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Link: https://lore.kernel.org/r/20220110104706.v6.2.Idde68b05b88d4a2e6e54766c653f3a6d9e419ce6@changeid
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4305697d
    • Sujit Kautkar's avatar
      rpmsg: char: Fix race between the release of rpmsg_ctrldev and cdev · 70cb4295
      Sujit Kautkar authored
      commit b7fb2dad upstream.
      
      struct rpmsg_ctrldev contains a struct cdev. The current code frees
      the rpmsg_ctrldev struct in rpmsg_ctrldev_release_device(), but the
      cdev is a managed object, therefore its release is not predictable
      and the rpmsg_ctrldev could be freed before the cdev is entirely
      released, as in the backtrace below.
      
      [   93.625603] ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x7c
      [   93.636115] WARNING: CPU: 0 PID: 12 at lib/debugobjects.c:488 debug_print_object+0x13c/0x1b0
      [   93.644799] Modules linked in: veth xt_cgroup xt_MASQUERADE rfcomm algif_hash algif_skcipher af_alg uinput ip6table_nat fuse uvcvideo videobuf2_vmalloc venus_enc venus_dec videobuf2_dma_contig hci_uart btandroid btqca snd_soc_rt5682_i2c bluetooth qcom_spmi_temp_alarm snd_soc_rt5682v
      [   93.715175] CPU: 0 PID: 12 Comm: kworker/0:1 Tainted: G    B             5.4.163-lockdep #26
      [   93.723855] Hardware name: Google Lazor (rev3 - 8) with LTE (DT)
      [   93.730055] Workqueue: events kobject_delayed_cleanup
      [   93.735271] pstate: 60c00009 (nZCv daif +PAN +UAO)
      [   93.740216] pc : debug_print_object+0x13c/0x1b0
      [   93.744890] lr : debug_print_object+0x13c/0x1b0
      [   93.749555] sp : ffffffacf5bc7940
      [   93.752978] x29: ffffffacf5bc7940 x28: dfffffd000000000
      [   93.758448] x27: ffffffacdb11a800 x26: dfffffd000000000
      [   93.763916] x25: ffffffd0734f856c x24: dfffffd000000000
      [   93.769389] x23: 0000000000000000 x22: ffffffd0733c35b0
      [   93.774860] x21: ffffffd0751994a0 x20: ffffffd075ec27c0
      [   93.780338] x19: ffffffd075199100 x18: 00000000000276e0
      [   93.785814] x17: 0000000000000000 x16: dfffffd000000000
      [   93.791291] x15: ffffffffffffffff x14: 6e6968207473696c
      [   93.796768] x13: 0000000000000000 x12: ffffffd075e2b000
      [   93.802244] x11: 0000000000000001 x10: 0000000000000000
      [   93.807723] x9 : d13400dff1921900 x8 : d13400dff1921900
      [   93.813200] x7 : 0000000000000000 x6 : 0000000000000000
      [   93.818676] x5 : 0000000000000080 x4 : 0000000000000000
      [   93.824152] x3 : ffffffd0732a0fa4 x2 : 0000000000000001
      [   93.829628] x1 : ffffffacf5bc7580 x0 : 0000000000000061
      [   93.835104] Call trace:
      [   93.837644]  debug_print_object+0x13c/0x1b0
      [   93.841963]  __debug_check_no_obj_freed+0x25c/0x3c0
      [   93.846987]  debug_check_no_obj_freed+0x18/0x20
      [   93.851669]  slab_free_freelist_hook+0xbc/0x1e4
      [   93.856346]  kfree+0xfc/0x2f4
      [   93.859416]  rpmsg_ctrldev_release_device+0x78/0xb8
      [   93.864445]  device_release+0x84/0x168
      [   93.868310]  kobject_cleanup+0x12c/0x298
      [   93.872356]  kobject_delayed_cleanup+0x10/0x18
      [   93.876948]  process_one_work+0x578/0x92c
      [   93.881086]  worker_thread+0x804/0xcf8
      [   93.884963]  kthread+0x2a8/0x314
      [   93.888303]  ret_from_fork+0x10/0x18
      
      The cdev_device_add/del() API was created to address this issue (see
      commit '233ed09d ("chardev: add helper function to register char
      devs with a struct device")'), use it instead of cdev add/del().
      
      Fixes: c0cdc19f
      
       ("rpmsg: Driver for user space endpoint interface")
      Signed-off-by: default avatarSujit Kautkar <sujitka@chromium.org>
      Signed-off-by: default avatarMatthias Kaehlcke <mka@chromium.org>
      Reviewed-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
      Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Reviewed-by: default avatarStephen Boyd <swboyd@chromium.org>
      Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Link: https://lore.kernel.org/r/20220110104706.v6.1.Iaac908f3e3149a89190ce006ba166e2d3fd247a3@changeid
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70cb4295
    • Joe Damato's avatar
      i40e: fix unsigned stat widths · e8549592
      Joe Damato authored
      commit 3b8428b8 upstream.
      
      Change i40e_update_vsi_stats and struct i40e_vsi to use u64 fields to match
      the width of the stats counters in struct i40e_rx_queue_stats.
      
      Update debugfs code to use the correct format specifier for u64.
      
      Fixes: 41c445ff
      
       ("i40e: main driver core")
      Signed-off-by: default avatarJoe Damato <jdamato@fastly.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Tested-by: default avatarGurucharan G <gurucharanx.g@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e8549592
    • Sylwester Dziedziuch's avatar
      i40e: Fix queues reservation for XDP · d46fa4ea
      Sylwester Dziedziuch authored
      commit 92947844 upstream.
      
      When XDP was configured on a system with large number of CPUs
      and X722 NIC there was a call trace with NULL pointer dereference.
      
      i40e 0000:87:00.0: failed to get tracking for 256 queues for VSI 0 err -12
      i40e 0000:87:00.0: setup of MAIN VSI failed
      
      BUG: kernel NULL pointer dereference, address: 0000000000000000
      RIP: 0010:i40e_xdp+0xea/0x1b0 [i40e]
      Call Trace:
      ? i40e_reconfig_rss_queues+0x130/0x130 [i40e]
      dev_xdp_install+0x61/0xe0
      dev_xdp_attach+0x18a/0x4c0
      dev_change_xdp_fd+0x1e6/0x220
      do_setlink+0x616/0x1030
      ? ahci_port_stop+0x80/0x80
      ? ata_qc_issue+0x107/0x1e0
      ? lock_timer_base+0x61/0x80
      ? __mod_timer+0x202/0x380
      rtnl_setlink+0xe5/0x170
      ? bpf_lsm_binder_transaction+0x10/0x10
      ? security_capable+0x36/0x50
      rtnetlink_rcv_msg+0x121/0x350
      ? rtnl_calcit.isra.0+0x100/0x100
      netlink_rcv_skb+0x50/0xf0
      netlink_unicast+0x1d3/0x2a0
      netlink_sendmsg+0x22a/0x440
      sock_sendmsg+0x5e/0x60
      __sys_sendto+0xf0/0x160
      ? __sys_getsockname+0x7e/0xc0
      ? _copy_from_user+0x3c/0x80
      ? __sys_setsockopt+0xc8/0x1a0
      __x64_sys_sendto+0x20/0x30
      do_syscall_64+0x33/0x40
      entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x7f83fa7a39e0
      
      This was caused by PF queue pile fragmentation due to
      flow director VSI queue being placed right after main VSI.
      Because of this main VSI was not able to resize its
      queue allocation for XDP resulting in no queues allocated
      for main VSI when XDP was turned on.
      
      Fix this by always allocating last queue in PF queue pile
      for a flow director VSI.
      
      Fixes: 41c445ff ("i40e: main driver core")
      Fixes: 74608d17
      
       ("i40e: add support for XDP_TX action")
      Signed-off-by: default avatarSylwester Dziedziuch <sylwesterx.dziedziuch@intel.com>
      Signed-off-by: default avatarMateusz Palczewski <mateusz.palczewski@intel.com>
      Reviewed-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
      Tested-by: default avatarKiran Bhandare <kiranx.bhandare@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d46fa4ea
    • Jedrzej Jagielski's avatar
      i40e: Fix issue when maximum queues is exceeded · 8783ee71
      Jedrzej Jagielski authored
      commit d701658a upstream.
      
      Before this patch VF interface vanished when
      maximum queue number was exceeded. Driver tried
      to add next queues even if there was not enough
      space. PF sent incorrect number of queues to
      the VF when there were not enough of them.
      
      Add an additional condition introduced to check
      available space in 'qp_pile' before proceeding.
      This condition makes it impossible to add queues
      if they number is greater than the number resulting
      from available space.
      Also add the search for free space in PF queue
      pair piles.
      
      Without this patch VF interfaces are not seen
      when available space for queues has been
      exceeded and following logs appears permanently
      in dmesg:
      "Unable to get VF config (-32)".
      "VF 62 failed opcode 3, retval: -5"
      "Unable to get VF config due to PF error condition, not retrying"
      
      Fixes: 7daa6bf3 ("i40e: driver core headers")
      Fixes: 41c445ff
      
       ("i40e: main driver core")
      Signed-off-by: default avatarJaroslaw Gawin <jaroslawx.gawin@intel.com>
      Signed-off-by: default avatarSlawomir Laba <slawomirx.laba@intel.com>
      Signed-off-by: default avatarJedrzej Jagielski <jedrzej.jagielski@intel.com>
      Tested-by: default avatarKonrad Jankowski <konrad0.jankowski@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8783ee71
    • Jedrzej Jagielski's avatar
      i40e: Increase delay to 1 s after global EMP reset · 866028ed
      Jedrzej Jagielski authored
      commit 9b13bd53 upstream.
      
      Recently simplified i40e_rebuild causes that FW sometimes
      is not ready after NVM update, the ping does not return.
      
      Increase the delay in case of EMP reset.
      Old delay of 300 ms was introduced for specific cards for 710 series.
      Now it works for all the cards and delay was increased.
      
      Fixes: 1fa51a65
      
       ("i40e: Add delay after EMP reset for firmware to recover")
      Signed-off-by: default avatarArkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
      Signed-off-by: default avatarJedrzej Jagielski <jedrzej.jagielski@intel.com>
      Tested-by: default avatarGurucharan G <gurucharanx.g@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      866028ed
    • Christophe Leroy's avatar
      powerpc/32: Fix boot failure with GCC latent entropy plugin · 49678489
      Christophe Leroy authored
      commit bba49665 upstream.
      
      Boot fails with GCC latent entropy plugin enabled.
      
      This is due to early boot functions trying to access 'latent_entropy'
      global data while the kernel is not relocated at its final
      destination yet.
      
      As there is no way to tell GCC to use PTRRELOC() to access it,
      disable latent entropy plugin in early_32.o and feature-fixups.o and
      code-patching.o
      
      Fixes: 38addce8
      
       ("gcc-plugins: Add latent_entropy plugin")
      Cc: stable@vger.kernel.org # v4.9+
      Reported-by: default avatarErhard Furtner <erhard_f@mailbox.org>
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215217
      Link: https://lore.kernel.org/r/2bac55483b8daf5b1caa163a45fa5f9cdbe18be4.1640178426.git.christophe.leroy@csgroup.eu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      49678489
    • Marek Behún's avatar
      net: sfp: ignore disabled SFP node · f5b894ae
      Marek Behún authored
      commit 2148927e upstream.
      
      Commit ce0aa27f ("sfp: add sfp-bus to bridge between network devices
      and sfp cages") added code which finds SFP bus DT node even if the node
      is disabled with status = "disabled". Because of this, when phylink is
      created, it ends with non-null .sfp_bus member, even though the SFP
      module is not probed (because the node is disabled).
      
      We need to ignore disabled SFP bus node.
      
      Fixes: ce0aa27f
      
       ("sfp: add sfp-bus to bridge between network devices and sfp cages")
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org # 2203cbf2
      
       ("net: sfp: move fwnode parsing into sfp-bus layer")
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [ backport to 4.19 ]
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f5b894ae
    • Badhri Jagan Sridharan's avatar
      usb: typec: tcpm: Do not disconnect while receiving VBUS off · e7a56e4d
      Badhri Jagan Sridharan authored
      commit 90b8aa9f upstream.
      
      With some chargers, vbus might momentarily raise above VSAFE5V and fall
      back to 0V before tcpm gets to read port->tcpc->get_vbus. This will
      will report a VBUS off event causing TCPM to transition to
      SNK_UNATTACHED where it should be waiting in either SNK_ATTACH_WAIT
      or SNK_DEBOUNCED state. This patch makes TCPM avoid vbus off events
      while in SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
      
      Stub from the spec:
          "4.5.2.2.4.2 Exiting from AttachWait.SNK State
          A Sink shall transition to Unattached.SNK when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
          A DRP shall transition to Unattached.SRC when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."
      
      [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
      [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
      [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
      [23.300579] VBUS off
      [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
      [23.301014] VBUS VSAFE0V
      [23.301111] Start toggling
      
      Fixes: f0690a25
      
       ("staging: typec: USB Type-C Port Manager (tcpm)")
      Cc: stable@vger.kernel.org
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarBadhri Jagan Sridharan <badhri@google.com>
      Link: https://lore.kernel.org/r/20220122015520.332507-1-badhri@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e7a56e4d
    • Alan Stern's avatar
      USB: core: Fix hang in usb_kill_urb by adding memory barriers · 5904dfd3
      Alan Stern authored
      commit 26fbe977
      
       upstream.
      
      The syzbot fuzzer has identified a bug in which processes hang waiting
      for usb_kill_urb() to return.  It turns out the issue is not unlinking
      the URB; that works just fine.  Rather, the problem arises when the
      wakeup notification that the URB has completed is not received.
      
      The reason is memory-access ordering on SMP systems.  In outline form,
      usb_kill_urb() and __usb_hcd_giveback_urb() operating concurrently on
      different CPUs perform the following actions:
      
      CPU 0					CPU 1
      ----------------------------		---------------------------------
      usb_kill_urb():				__usb_hcd_giveback_urb():
        ...					  ...
        atomic_inc(&urb->reject);		  atomic_dec(&urb->use_count);
        ...					  ...
        wait_event(usb_kill_urb_queue,
      	atomic_read(&urb->use_count) == 0);
      					  if (atomic_read(&urb->reject))
      						wake_up(&usb_kill_urb_queue);
      
      Confining your attention to urb->reject and urb->use_count, you can
      see that the overall pattern of accesses on CPU 0 is:
      
      	write urb->reject, then read urb->use_count;
      
      whereas the overall pattern of accesses on CPU 1 is:
      
      	write urb->use_count, then read urb->reject.
      
      This pattern is referred to in memory-model circles as SB (for "Store
      Buffering"), and it is well known that without suitable enforcement of
      the desired order of accesses -- in the form of memory barriers -- it
      is entirely possible for one or both CPUs to execute their reads ahead
      of their writes.  The end result will be that sometimes CPU 0 sees the
      old un-decremented value of urb->use_count while CPU 1 sees the old
      un-incremented value of urb->reject.  Consequently CPU 0 ends up on
      the wait queue and never gets woken up, leading to the observed hang
      in usb_kill_urb().
      
      The same pattern of accesses occurs in usb_poison_urb() and the
      failure pathway of usb_hcd_submit_urb().
      
      The problem is fixed by adding suitable memory barriers.  To provide
      proper memory-access ordering in the SB pattern, a full barrier is
      required on both CPUs.  The atomic_inc() and atomic_dec() accesses
      themselves don't provide any memory ordering, but since they are
      present, we can use the optimized smp_mb__after_atomic() memory
      barrier in the various routines to obtain the desired effect.
      
      This patch adds the necessary memory barriers.
      
      CC: <stable@vger.kernel.org>
      Reported-and-tested-by: default avatar <syzbot+76629376e06e2c2ad626@syzkaller.appspotmail.com>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/Ye8K0QYee0Q0Nna2@rowland.harvard.edu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5904dfd3
    • Pavankumar Kondeti's avatar
      usb: gadget: f_sourcesink: Fix isoc transfer for USB_SPEED_SUPER_PLUS · 2ad9bf96
      Pavankumar Kondeti authored
      commit 904edf8a upstream.
      
      Currently when gadget enumerates in super speed plus, the isoc
      endpoint request buffer size is not calculated correctly. Fix
      this by checking the gadget speed against USB_SPEED_SUPER_PLUS
      and update the request buffer size.
      
      Fixes: 90c4d057
      
       ("usb: fix various gadgets null ptr deref on 10gbps cabling.")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarPavankumar Kondeti <quic_pkondeti@quicinc.com>
      Link: https://lore.kernel.org/r/1642820602-20619-1-git-send-email-quic_pkondeti@quicinc.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2ad9bf96
    • Jon Hunter's avatar
      usb: common: ulpi: Fix crash in ulpi_match() · 901a7d44
      Jon Hunter authored
      commit 2e3dd4a6 upstream.
      
      Commit 7495af93 ("ARM: multi_v7_defconfig: Enable drivers for
      DragonBoard 410c") enables the CONFIG_PHY_QCOM_USB_HS for the ARM
      multi_v7_defconfig. Enabling this Kconfig is causing the kernel to crash
      on the Tegra20 Ventana platform in the ulpi_match() function.
      
      The Qualcomm USB HS PHY driver that is enabled by CONFIG_PHY_QCOM_USB_HS,
      registers a ulpi_driver but this driver does not provide an 'id_table',
      so when ulpi_match() is called on the Tegra20 Ventana platform, it
      crashes when attempting to deference the id_table pointer which is not
      valid. The Qualcomm USB HS PHY driver uses device-tree for matching the
      ULPI driver with the device and so fix this crash by using device-tree
      for matching if the id_table is not valid.
      
      Fixes: ef6a7bcf
      
       ("usb: ulpi: Support device discovery via DT")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Link: https://lore.kernel.org/r/20220117150039.44058-1-jonathanh@nvidia.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      901a7d44
    • Alan Stern's avatar
      usb-storage: Add unusual-devs entry for VL817 USB-SATA bridge · 3093ce1f
      Alan Stern authored
      commit 5b67b315
      
       upstream.
      
      Two people have reported (and mentioned numerous other reports on the
      web) that VIA's VL817 USB-SATA bridge does not work with the uas
      driver.  Typical log messages are:
      
      [ 3606.232149] sd 14:0:0:0: [sdg] tag#2 uas_zap_pending 0 uas-tag 1 inflight: CMD
      [ 3606.232154] sd 14:0:0:0: [sdg] tag#2 CDB: Write(16) 8a 00 00 00 00 00 18 0c c9 80 00 00 00 80 00 00
      [ 3606.306257] usb 4-4.4: reset SuperSpeed Plus Gen 2x1 USB device number 11 using xhci_hcd
      [ 3606.328584] scsi host14: uas_eh_device_reset_handler success
      
      Surprisingly, the devices do seem to work okay for some other people.
      The cause of the differing behaviors is not known.
      
      In the hope of getting the devices to work for the most users, even at
      the possible cost of degraded performance for some, this patch adds an
      unusual_devs entry for the VL817 to block it from binding to the uas
      driver by default.  Users will be able to override this entry by means
      of a module parameter, if they want.
      
      CC: <stable@vger.kernel.org>
      Reported-by: default avatarDocMAX <mail@vacharakis.de>
      Reported-and-tested-by: default avatarThomas Weißschuh <linux@weissschuh.net>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/Ye8IsK2sjlEv1rqU@rowland.harvard.edu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3093ce1f
    • Cameron Williams's avatar
      tty: Add support for Brainboxes UC cards. · 9c50f7ed
      Cameron Williams authored
      commit 152d1afa
      
       upstream.
      
      This commit adds support for the some of the Brainboxes PCI range of
      cards, including the UC-101, UC-235/246, UC-257, UC-268, UC-275/279,
      UC-302, UC-310, UC-313, UC-320/324, UC-346, UC-357, UC-368
      and UC-420/431.
      
      Signed-off-by: default avatarCameron Williams <cang1@live.co.uk>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/AM5PR0202MB2564688493F7DD9B9C610827C45E9@AM5PR0202MB2564.eurprd02.prod.outlook.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9c50f7ed
    • daniel.starke@siemens.com's avatar
      tty: n_gsm: fix SW flow control encoding/handling · 47bc9be8
      daniel.starke@siemens.com authored
      commit 8838b2af upstream.
      
      n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010.
      See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516
      The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to
      the newer 27.010 here. Chapter 5.2.7.3 states that DC1 (XON) and DC3 (XOFF)
      are the control characters defined in ISO/IEC 646. These shall be quoted if
      seen in the data stream to avoid interpretation as flow control characters.
      
      ISO/IEC 646 refers to the set of ISO standards described as the ISO
      7-bit coded character set for information interchange. Its final version
      is also known as ITU T.50.
      See https://www.itu.int/rec/T-REC-T.50-199209-I/en
      
      To abide the standard it is needed to quote DC1 and DC3 correctly if these
      are seen as data bytes and not as control characters. The current
      implementation already tries to enforce this but fails to catch all
      defined cases. 3GPP 27.010 chapter 5.2.7.3 clearly states that the most
      significant bit shall be ignored for DC1 and DC3 handling. The current
      implementation handles only the case with the most significant bit set 0.
      Cases in which DC1 and DC3 have the most significant bit set 1 are left
      unhandled.
      
      This patch fixes this by masking the data bytes with ISO_IEC_646_MASK (only
      the 7 least significant bits set 1) before comparing them with XON
      (a.k.a. DC1) and XOFF (a.k.a. DC3) when testing which byte values need
      quotation via byte stuffing.
      
      Fixes: e1eaea46
      
       ("tty: n_gsm line discipline")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDaniel Starke <daniel.starke@siemens.com>
      Link: https://lore.kernel.org/r/20220120101857.2509-1-daniel.starke@siemens.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      47bc9be8
    • Valentin Caron's avatar
      serial: stm32: fix software flow control transfer · a41398a5
      Valentin Caron authored
      commit 037b91ec upstream.
      
      x_char is ignored by stm32_usart_start_tx() when xmit buffer is empty.
      
      Fix start_tx condition to allow x_char to be sent.
      
      Fixes: 48a6092f
      
       ("serial: stm32-usart: Add STM32 USART Driver")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarErwan Le Ray <erwan.leray@foss.st.com>
      Signed-off-by: default avatarValentin Caron <valentin.caron@foss.st.com>
      Link: https://lore.kernel.org/r/20220111164441.6178-3-valentin.caron@foss.st.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a41398a5
    • Robert Hancock's avatar
      serial: 8250: of: Fix mapped region size when using reg-offset property · ff6cb8fc
      Robert Hancock authored
      commit d06b1cf2 upstream.
      
      8250_of supports a reg-offset property which is intended to handle
      cases where the device registers start at an offset inside the region
      of memory allocated to the device. The Xilinx 16550 UART, for which this
      support was initially added, requires this. However, the code did not
      adjust the overall size of the mapped region accordingly, causing the
      driver to request an area of memory past the end of the device's
      allocation. For example, if the UART was allocated an address of
      0xb0130000, size of 0x10000 and reg-offset of 0x1000 in the device
      tree, the region of memory reserved was b0131000-b0140fff, which caused
      the driver for the region starting at b0140000 to fail to probe.
      
      Fix this by subtracting reg-offset from the mapped region size.
      
      Fixes: b912b5e2
      
       ([POWERPC] Xilinx: of_serial support for Xilinx uart 16550.)
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarRobert Hancock <robert.hancock@calian.com>
      Link: https://lore.kernel.org/r/20220112194214.881844-1-robert.hancock@calian.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ff6cb8fc
    • Pablo Neira Ayuso's avatar
      netfilter: nft_payload: do not update layer 4 checksum when mangling fragments · a622b1fd
      Pablo Neira Ayuso authored
      commit 4e1860a3 upstream.
      
      IP fragments do not come with the transport header, hence skip bogus
      layer 4 checksum updates.
      
      Fixes: 18140969
      
       ("netfilter: nft_payload: layer 4 checksum adjustment for pseudoheader fields")
      Reported-and-tested-by: default avatarSteffen Weinreich <steve@weinreich.org>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a622b1fd