Skip to content
  1. Aug 11, 2020
    • Lorenzo Bianconi's avatar
      net: gre: recompute gre csum for sctp over gre tunnels · 786a9368
      Lorenzo Bianconi authored
      [ Upstream commit 622e32b7 ]
      
      The GRE tunnel can be used to transport traffic that does not rely on a
      Internet checksum (e.g. SCTP). The issue can be triggered creating a GRE
      or GRETAP tunnel and transmitting SCTP traffic ontop of it where CRC
      offload has been disabled. In order to fix the issue we need to
      recompute the GRE csum in gre_gso_segment() not relying on the inner
      checksum.
      The issue is still present when we have the CRC offload enabled.
      In this case we need to disable the CRC offload if we require GRE
      checksum since otherwise skb_checksum() will report a wrong value.
      
      Fixes: 90017acc
      
       ("sctp: Add GSO support")
      Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
      Reviewed-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      786a9368
    • Stephen Hemminger's avatar
      hv_netvsc: do not use VF device if link is down · 5d791d36
      Stephen Hemminger authored
      [ Upstream commit 7c9864bb
      
       ]
      
      If the accelerated networking SRIOV VF device has lost carrier
      use the synthetic network device which is available as backup
      path. This is a rare case since if VF link goes down, normally
      the VMBus device will also loose external connectivity as well.
      But if the communication is between two VM's on the same host
      the VMBus device will still work.
      
      Reported-by: default avatar"Shah, Ashish N" <ashish.n.shah@intel.com>
      Fixes: 0c195567
      
       ("netvsc: transparent VF management")
      Signed-off-by: default avatarStephen Hemminger <stephen@networkplumber.org>
      Reviewed-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5d791d36
    • YueHaibing's avatar
      dpaa2-eth: Fix passing zero to 'PTR_ERR' warning · 3a82f4bf
      YueHaibing authored
      [ Upstream commit 02afa9c6 ]
      
      Fix smatch warning:
      
      drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:2419
       alloc_channel() warn: passing zero to 'ERR_PTR'
      
      setup_dpcon() should return ERR_PTR(err) instead of zero in error
      handling case.
      
      Fixes: d7f5a9d8
      
       ("dpaa2-eth: defer probe on object allocate")
      Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3a82f4bf
    • Vincent Duvert's avatar
      appletalk: Fix atalk_proc_init() return path · 5a963aa7
      Vincent Duvert authored
      [ Upstream commit d0f6ba2e ]
      
      Add a missing return statement to atalk_proc_init so it doesn't return
      -ENOMEM when successful.  This allows the appletalk module to load
      properly.
      
      Fixes: e2bcd8b0
      
       ("appletalk: use remove_proc_subtree to simplify procfs code")
      Link: https://www.downtowndougbrown.com/2020/08/hacking-up-a-fix-for-the-broken-appletalk-kernel-module-in-linux-5-1-and-newer/
      Reported-by: default avatarChristopher KOBAYASHI <chris@disavowed.jp>
      Reported-by: default avatarDoug Brown <doug@downtowndougbrown.com>
      Signed-off-by: default avatarVincent Duvert <vincent.ldev@duvert.net>
      [lukas: add missing tags]
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Cc: stable@vger.kernel.org # v5.1+
      Cc: Yue Haibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5a963aa7
    • Johan Hovold's avatar
      net: lan78xx: replace bogus endpoint lookup · 3787b5a3
      Johan Hovold authored
      [ Upstream commit ea060b35
      
       ]
      
      Drop the bogus endpoint-lookup helper which could end up accepting
      interfaces based on endpoints belonging to unrelated altsettings.
      
      Note that the returned bulk pipes and interrupt endpoint descriptor
      were never actually used. Instead the bulk-endpoint numbers are
      hardcoded to 1 and 2 (matching the specification), while the interrupt-
      endpoint descriptor was assumed to be the third descriptor created by
      USB core.
      
      Try to bring some order to this by dropping the bogus lookup helper and
      adding the missing endpoint sanity checks while keeping the interrupt-
      descriptor assumption for now.
      
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3787b5a3
    • Ido Schimmel's avatar
      vxlan: Ensure FDB dump is performed under RCU · 31489ed8
      Ido Schimmel authored
      [ Upstream commit b5141915 ]
      
      The commit cited below removed the RCU read-side critical section from
      rtnl_fdb_dump() which means that the ndo_fdb_dump() callback is invoked
      without RCU protection.
      
      This results in the following warning [1] in the VXLAN driver, which
      relied on the callback being invoked from an RCU read-side critical
      section.
      
      Fix this by calling rcu_read_lock() in the VXLAN driver, as already done
      in the bridge driver.
      
      [1]
      WARNING: suspicious RCU usage
      5.8.0-rc4-custom-01521-g481007553ce6 #29 Not tainted
      -----------------------------
      drivers/net/vxlan.c:1379 RCU-list traversed in non-reader section!!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      1 lock held by bridge/166:
       #0: ffffffff85a27850 (rtnl_mutex){+.+.}-{3:3}, at: netlink_dump+0xea/0x1090
      
      stack backtrace:
      CPU: 1 PID: 166 Comm: bridge Not tainted 5.8.0-rc4-custom-01521-g481007553ce6 #29
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-2.fc32 04/01/2014
      Call Trace:
       dump_stack+0x100/0x184
       lockdep_rcu_suspicious+0x153/0x15d
       vxlan_fdb_dump+0x51e/0x6d0
       rtnl_fdb_dump+0x4dc/0xad0
       netlink_dump+0x540/0x1090
       __netlink_dump_start+0x695/0x950
       rtnetlink_rcv_msg+0x802/0xbd0
       netlink_rcv_skb+0x17a/0x480
       rtnetlink_rcv+0x22/0x30
       netlink_unicast+0x5ae/0x890
       netlink_sendmsg+0x98a/0xf40
       __sys_sendto+0x279/0x3b0
       __x64_sys_sendto+0xe6/0x1a0
       do_syscall_64+0x54/0xa0
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x7fe14fa2ade0
      Code: Bad RIP value.
      RSP: 002b:00007fff75bb5b88 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
      RAX: ffffffffffffffda RBX: 00005614b1ba0020 RCX: 00007fe14fa2ade0
      RDX: 000000000000011c RSI: 00007fff75bb5b90 RDI: 0000000000000003
      RBP: 00007fff75bb5b90 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 00005614b1b89160
      R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
      
      Fixes: 5e6d2435
      
       ("bridge: netlink dump interface at par with brctl")
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      31489ed8
    • David Howells's avatar
      rxrpc: Fix race between recvmsg and sendmsg on immediate call failure · 106b415d
      David Howells authored
      [ Upstream commit 65550098 ]
      
      There's a race between rxrpc_sendmsg setting up a call, but then failing to
      send anything on it due to an error, and recvmsg() seeing the call
      completion occur and trying to return the state to the user.
      
      An assertion fails in rxrpc_recvmsg() because the call has already been
      released from the socket and is about to be released again as recvmsg deals
      with it.  (The recvmsg_q queue on the socket holds a ref, so there's no
      problem with use-after-free.)
      
      We also have to be careful not to end up reporting an error twice, in such
      a way that both returns indicate to userspace that the user ID supplied
      with the call is no longer in use - which could cause the client to
      malfunction if it recycles the user ID fast enough.
      
      Fix this by the following means:
      
       (1) When sendmsg() creates a call after the point that the call has been
           successfully added to the socket, don't return any errors through
           sendmsg(), but rather complete the call and let recvmsg() retrieve
           them.  Make sendmsg() return 0 at this point.  Further calls to
           sendmsg() for that call will fail with ESHUTDOWN.
      
           Note that at this point, we haven't send any packets yet, so the
           server doesn't yet know about the call.
      
       (2) If sendmsg() returns an error when it was expected to create a new
           call, it means that the user ID wasn't used.
      
       (3) Mark the call disconnected before marking it completed to prevent an
           oops in rxrpc_release_call().
      
       (4) recvmsg() will then retrieve the error and set MSG_EOR to indicate
           that the user ID is no longer known by the kernel.
      
      An oops like the following is produced:
      
      	kernel BUG at net/rxrpc/recvmsg.c:605!
      	...
      	RIP: 0010:rxrpc_recvmsg+0x256/0x5ae
      	...
      	Call Trace:
      	 ? __init_waitqueue_head+0x2f/0x2f
      	 ____sys_recvmsg+0x8a/0x148
      	 ? import_iovec+0x69/0x9c
      	 ? copy_msghdr_from_user+0x5c/0x86
      	 ___sys_recvmsg+0x72/0xaa
      	 ? __fget_files+0x22/0x57
      	 ? __fget_light+0x46/0x51
      	 ? fdget+0x9/0x1b
      	 do_recvmmsg+0x15e/0x232
      	 ? _raw_spin_unlock+0xa/0xb
      	 ? vtime_delta+0xf/0x25
      	 __x64_sys_recvmmsg+0x2c/0x2f
      	 do_syscall_64+0x4c/0x78
      	 entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: 357f5ef6
      
       ("rxrpc: Call rxrpc_release_call() on error in rxrpc_new_client_call()")
      Reported-by: default avatar <syzbot+b54969381df354936d96@syzkaller.appspotmail.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarMarc Dionne <marc.dionne@auristor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      106b415d
    • Landen Chao's avatar
      net: ethernet: mtk_eth_soc: fix MTU warnings · 6f935470
      Landen Chao authored
      [ Upstream commit 555a8933 ]
      
      in recent kernel versions there are warnings about incorrect MTU size
      like these:
      
      eth0: mtu greater than device maximum
      mtk_soc_eth 1b100000.ethernet eth0: error -22 setting MTU to include DSA overhead
      
      Fixes: bfcb8132 ("net: dsa: configure the MTU for switch ports")
      Fixes: 72579e14 ("net: dsa: don't fail to probe if we couldn't set the MTU")
      Fixes: 7a4c53be
      
       ("net: report invalid mtu value via netlink extack")
      Signed-off-by: default avatarLanden Chao <landen.chao@mediatek.com>
      Signed-off-by: default avatarFrank Wunderlich <frank-w@public-files.de>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f935470
    • Xiyu Yang's avatar
      ipv6: Fix nexthop refcnt leak when creating ipv6 route info · bd68177f
      Xiyu Yang authored
      [ Upstream commit 706ec919 ]
      
      ip6_route_info_create() invokes nexthop_get(), which increases the
      refcount of the "nh".
      
      When ip6_route_info_create() returns, local variable "nh" becomes
      invalid, so the refcount should be decreased to keep refcount balanced.
      
      The reference counting issue happens in one exception handling path of
      ip6_route_info_create(). When nexthops can not be used with source
      routing, the function forgets to decrease the refcnt increased by
      nexthop_get(), causing a refcnt leak.
      
      Fix this issue by pulling up the error source routing handling when
      nexthops can not be used with source routing.
      
      Fixes: f88d8ea6
      
       ("ipv6: Plumb support for nexthop object in a fib6_info")
      Signed-off-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: default avatarXin Tan <tanxin.ctf@gmail.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd68177f
    • Cong Wang's avatar
      ipv6: fix memory leaks on IPV6_ADDRFORM path · 89c12bc3
      Cong Wang authored
      [ Upstream commit 8c0de6e9
      
       ]
      
      IPV6_ADDRFORM causes resource leaks when converting an IPv6 socket
      to IPv4, particularly struct ipv6_ac_socklist. Similar to
      struct ipv6_mc_socklist, we should just close it on this path.
      
      This bug can be easily reproduced with the following C program:
      
        #include <stdio.h>
        #include <string.h>
        #include <sys/types.h>
        #include <sys/socket.h>
        #include <arpa/inet.h>
      
        int main()
        {
          int s, value;
          struct sockaddr_in6 addr;
          struct ipv6_mreq m6;
      
          s = socket(AF_INET6, SOCK_DGRAM, 0);
          addr.sin6_family = AF_INET6;
          addr.sin6_port = htons(5000);
          inet_pton(AF_INET6, "::ffff:192.168.122.194", &addr.sin6_addr);
          connect(s, (struct sockaddr *)&addr, sizeof(addr));
      
          inet_pton(AF_INET6, "fe80::AAAA", &m6.ipv6mr_multiaddr);
          m6.ipv6mr_interface = 5;
          setsockopt(s, SOL_IPV6, IPV6_JOIN_ANYCAST, &m6, sizeof(m6));
      
          value = AF_INET;
          setsockopt(s, SOL_IPV6, IPV6_ADDRFORM, &value, sizeof(value));
      
          close(s);
          return 0;
        }
      
      Reported-by: default avatar <ch3332xr@gmail.com>
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89c12bc3
    • Ido Schimmel's avatar
      ipv4: Silence suspicious RCU usage warning · 9b37a7bc
      Ido Schimmel authored
      [ Upstream commit 83f35228 ]
      
      fib_trie_unmerge() is called with RTNL held, but not from an RCU
      read-side critical section. This leads to the following warning [1] when
      the FIB alias list in a leaf is traversed with
      hlist_for_each_entry_rcu().
      
      Since the function is always called with RTNL held and since
      modification of the list is protected by RTNL, simply use
      hlist_for_each_entry() and silence the warning.
      
      [1]
      WARNING: suspicious RCU usage
      5.8.0-rc4-custom-01520-gc1f937f3f83b #30 Not tainted
      -----------------------------
      net/ipv4/fib_trie.c:1867 RCU-list traversed in non-reader section!!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      1 lock held by ip/164:
       #0: ffffffff85a27850 (rtnl_mutex){+.+.}-{3:3}, at: rtnetlink_rcv_msg+0x49a/0xbd0
      
      stack backtrace:
      CPU: 0 PID: 164 Comm: ip Not tainted 5.8.0-rc4-custom-01520-gc1f937f3f83b #30
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-2.fc32 04/01/2014
      Call Trace:
       dump_stack+0x100/0x184
       lockdep_rcu_suspicious+0x153/0x15d
       fib_trie_unmerge+0x608/0xdb0
       fib_unmerge+0x44/0x360
       fib4_rule_configure+0xc8/0xad0
       fib_nl_newrule+0x37a/0x1dd0
       rtnetlink_rcv_msg+0x4f7/0xbd0
       netlink_rcv_skb+0x17a/0x480
       rtnetlink_rcv+0x22/0x30
       netlink_unicast+0x5ae/0x890
       netlink_sendmsg+0x98a/0xf40
       ____sys_sendmsg+0x879/0xa00
       ___sys_sendmsg+0x122/0x190
       __sys_sendmsg+0x103/0x1d0
       __x64_sys_sendmsg+0x7d/0xb0
       do_syscall_64+0x54/0xa0
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x7fc80a234e97
      Code: Bad RIP value.
      RSP: 002b:00007ffef8b66798 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fc80a234e97
      RDX: 0000000000000000 RSI: 00007ffef8b66800 RDI: 0000000000000003
      RBP: 000000005f141b1c R08: 0000000000000001 R09: 0000000000000000
      R10: 00007fc80a2a8ac0 R11: 0000000000000246 R12: 0000000000000001
      R13: 0000000000000000 R14: 00007ffef8b67008 R15: 0000556fccb10020
      
      Fixes: 0ddcf43d
      
       ("ipv4: FIB Local/MAIN table collapse")
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9b37a7bc
    • Nicolas Chauvet's avatar
      PCI: tegra: Revert tegra124 raw_violation_fixup · 4913f71e
      Nicolas Chauvet authored
      commit e7b856df upstream.
      
      As reported in https://bugzilla.kernel.org/206217 , raw_violation_fixup
      is causing more harm than good in some common use-cases.
      
      This patch is a partial revert of commit:
      
      191cd6fb ("PCI: tegra: Add SW fixup for RAW violations")
      
      and fixes the following regression since then.
      
      * Description:
      
      When both the NIC and MMC are used one can see the following message:
      
        NETDEV WATCHDOG: enp1s0 (r8169): transmit queue 0 timed out
      
      and
      
        pcieport 0000:00:02.0: AER: Uncorrected (Non-Fatal) error received: 0000:01:00.0
        r8169 0000:01:00.0: AER: PCIe Bus Error: severity=Uncorrected (Non-Fatal), type=Transaction Layer, (Requester ID)
        r8169 0000:01:00.0: AER:   device [10ec:8168] error status/mask=00004000/00400000
        r8169 0000:01:00.0: AER:    [14] CmpltTO                (First)
        r8169 0000:01:00.0: AER: can't recover (no error_detected callback)
        pcieport 0000:00:02.0: AER: device recovery failed
      
      After that, the ethernet NIC is not functional anymore even after
      reloading the r8169 module. After a reboot, this is reproducible by
      copying a large file over the NIC to the MMC.
      
      For some reason this is not reproducible when files are copied to a tmpfs.
      
      * Little background on the fixup, by Manikanta Maddireddy:
        "In the internal testing with dGPU on Tegra124, CmplTO is reported by
      dGPU. This happened because FIFO queue in AFI(AXI to PCIe) module
      get full by upstream posted writes. Back to back upstream writes
      interleaved with infrequent reads, triggers RAW violation and CmpltTO.
      This is fixed by reducing the posted write credits and by changing
      updateFC timer frequency. These settings are fixed after stress test.
      
      In the current case, RTL NIC is also reporting CmplTO. These settings
      seems to be aggravating the issue instead of fixing it."
      
      Link: https://lore.kernel.org/r/20200718100710.15398-1-kwizart@gmail.com
      Fixes: 191cd6fb
      
       ("PCI: tegra: Add SW fixup for RAW violations")
      Signed-off-by: default avatarNicolas Chauvet <kwizart@gmail.com>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarManikanta Maddireddy <mmaddireddy@nvidia.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4913f71e
    • Christophe Leroy's avatar
      Revert "powerpc/kasan: Fix shadow pages allocation failure" · ceff42e6
      Christophe Leroy authored
      commit b506923e upstream.
      
      This reverts commit d2a91cef.
      
      This commit moved too much work in kasan_init(). The allocation
      of shadow pages has to be moved for the reason explained in that
      patch, but the allocation of page tables still need to be done
      before switching to the final hash table.
      
      First revert the incorrect commit, following patch redoes it
      properly.
      
      Fixes: d2a91cef
      
       ("powerpc/kasan: Fix shadow pages allocation failure")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarErhard F. <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=208181
      Link: https://lore.kernel.org/r/3667deb0911affbf999b99f87c31c77d5e870cd2.1593690707.git.christophe.leroy@csgroup.eu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ceff42e6
    • Frank van der Linden's avatar
      xattr: break delegations in {set,remove}xattr · 11e64146
      Frank van der Linden authored
      commit 08b5d501
      
       upstream.
      
      set/removexattr on an exported filesystem should break NFS delegations.
      This is true in general, but also for the upcoming support for
      RFC 8726 (NFSv4 extended attribute support). Make sure that they do.
      
      Additionally, they need to grow a _locked variant, since callers might
      call this with i_rwsem held (like the NFS server code).
      
      Cc: stable@vger.kernel.org # v4.9+
      Cc: linux-fsdevel@vger.kernel.org
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarFrank van der Linden <fllinden@amazon.com>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11e64146
    • Dexuan Cui's avatar
      Drivers: hv: vmbus: Ignore CHANNELMSG_TL_CONNECT_RESULT(23) · 6059000e
      Dexuan Cui authored
      [ Upstream commit ddc9d357
      
       ]
      
      When a Linux hv_sock app tries to connect to a Service GUID on which no
      host app is listening, a recent host (RS3+) sends a
      CHANNELMSG_TL_CONNECT_RESULT (23) message to Linux and this triggers such
      a warning:
      
      unknown msgtype=23
      WARNING: CPU: 2 PID: 0 at drivers/hv/vmbus_drv.c:1031 vmbus_on_msg_dpc
      
      Actually Linux can safely ignore the message because the Linux app's
      connect() will time out in 2 seconds: see VSOCK_DEFAULT_CONNECT_TIMEOUT
      and vsock_stream_connect(). We don't bother to make use of the message
      because: 1) it's only supported on recent hosts; 2) a non-trivial effort
      is required to use the message in Linux, but the benefit is small.
      
      So, let's not see the warning by silently ignoring the message.
      
      Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
      Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6059000e
    • Philippe Duplessis-Guindon's avatar
      tools lib traceevent: Fix memory leak in process_dynamic_array_len · 34295790
      Philippe Duplessis-Guindon authored
      [ Upstream commit e24c6447
      
       ]
      
      I compiled with AddressSanitizer and I had these memory leaks while I
      was using the tep_parse_format function:
      
          Direct leak of 28 byte(s) in 4 object(s) allocated from:
              #0 0x7fb07db49ffe in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dffe)
              #1 0x7fb07a724228 in extend_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:985
              #2 0x7fb07a724c21 in __read_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1140
              #3 0x7fb07a724f78 in read_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1206
              #4 0x7fb07a725191 in __read_expect_type /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1291
              #5 0x7fb07a7251df in read_expect_type /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1299
              #6 0x7fb07a72e6c8 in process_dynamic_array_len /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:2849
              #7 0x7fb07a7304b8 in process_function /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3161
              #8 0x7fb07a730900 in process_arg_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3207
              #9 0x7fb07a727c0b in process_arg /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1786
              #10 0x7fb07a731080 in event_read_print_args /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3285
              #11 0x7fb07a731722 in event_read_print /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3369
              #12 0x7fb07a740054 in __tep_parse_format /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6335
              #13 0x7fb07a74047a in __parse_event /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6389
              #14 0x7fb07a740536 in tep_parse_format /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6431
              #15 0x7fb07a785acf in parse_event ../../../src/fs-src/fs.c:251
              #16 0x7fb07a785ccd in parse_systems ../../../src/fs-src/fs.c:284
              #17 0x7fb07a786fb3 in read_metadata ../../../src/fs-src/fs.c:593
              #18 0x7fb07a78760e in ftrace_fs_source_init ../../../src/fs-src/fs.c:727
              #19 0x7fb07d90c19c in add_component_with_init_method_data ../../../../src/lib/graph/graph.c:1048
              #20 0x7fb07d90c87b in add_source_component_with_initialize_method_data ../../../../src/lib/graph/graph.c:1127
              #21 0x7fb07d90c92a in bt_graph_add_source_component ../../../../src/lib/graph/graph.c:1152
              #22 0x55db11aa632e in cmd_run_ctx_create_components_from_config_components ../../../src/cli/babeltrace2.c:2252
              #23 0x55db11aa6fda in cmd_run_ctx_create_components ../../../src/cli/babeltrace2.c:2347
              #24 0x55db11aa780c in cmd_run ../../../src/cli/babeltrace2.c:2461
              #25 0x55db11aa8a7d in main ../../../src/cli/babeltrace2.c:2673
              #26 0x7fb07d5460b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
      
      The token variable in the process_dynamic_array_len function is
      allocated in the read_expect_type function, but is not freed before
      calling the read_token function.
      
      Free the token variable before calling read_token in order to plug the
      leak.
      
      Signed-off-by: default avatarPhilippe Duplessis-Guindon <pduplessis@efficios.com>
      Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Link: https://lore.kernel.org/linux-trace-devel/20200730150236.5392-1-pduplessis@efficios.com
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      34295790
    • Xin Xiong's avatar
      atm: fix atm_dev refcnt leaks in atmtcp_remove_persistent · 414f1053
      Xin Xiong authored
      [ Upstream commit 51875dad
      
       ]
      
      atmtcp_remove_persistent() invokes atm_dev_lookup(), which returns a
      reference of atm_dev with increased refcount or NULL if fails.
      
      The refcount leaks issues occur in two error handling paths. If
      dev_data->persist is zero or PRIV(dev)->vcc isn't NULL, the function
      returns 0 without decreasing the refcount kept by a local variable,
      resulting in refcount leaks.
      
      Fix the issue by adding atm_dev_put() before returning 0 both when
      dev_data->persist is zero or PRIV(dev)->vcc isn't NULL.
      
      Signed-off-by: default avatarXin Xiong <xiongx18@fudan.edu.cn>
      Signed-off-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: default avatarXin Tan <tanxin.ctf@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      414f1053
    • Francesco Ruggeri's avatar
      igb: reinit_locked() should be called with rtnl_lock · 5414f270
      Francesco Ruggeri authored
      [ Upstream commit 024a8168 ]
      
      We observed two panics involving races with igb_reset_task.
      The first panic is caused by this race condition:
      
      	kworker			reboot -f
      
      	igb_reset_task
      	igb_reinit_locked
      	igb_down
      	napi_synchronize
      				__igb_shutdown
      				igb_clear_interrupt_scheme
      				igb_free_q_vectors
      				igb_free_q_vector
      				adapter->q_vector[v_idx] = NULL;
      	napi_disable
      	Panics trying to access
      	adapter->q_vector[v_idx].napi_state
      
      The second panic (a divide error) is caused by this race:
      
      kworker		reboot -f	tx packet
      
      igb_reset_task
      		__igb_shutdown
      		rtnl_lock()
      		...
      		igb_clear_interrupt_scheme
      		igb_free_q_vectors
      		adapter->num_tx_queues = 0
      		...
      		rtnl_unlock()
      rtnl_lock()
      igb_reinit_locked
      igb_down
      igb_up
      netif_tx_start_all_queues
      				dev_hard_start_xmit
      				igb_xmit_frame
      				igb_tx_queue_mapping
      				Panics on
      				r_idx % adapter->num_tx_queues
      
      This commit applies to igb_reset_task the same changes that
      were applied to ixgbe in commit 2f90b865 ("ixgbe: this patch
      adds support for DCB to the kernel and ixgbe driver"),
      commit 8f4c5c9f ("ixgbe: reinit_locked() should be called with
      rtnl_lock") and commit 88adce4e
      
       ("ixgbe: fix possible race in
      reset subtask").
      
      Signed-off-by: default avatarFrancesco Ruggeri <fruggeri@arista.com>
      Tested-by: default avatarAaron Brown <aaron.f.brown@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5414f270
    • Julian Squires's avatar
      cfg80211: check vendor command doit pointer before use · 7c8a863b
      Julian Squires authored
      [ Upstream commit 4052d3d2
      
       ]
      
      In the case where a vendor command does not implement doit, and has no
      flags set, doit would not be validated and a NULL pointer dereference
      would occur, for example when invoking the vendor command via iw.
      
      I encountered this while developing new vendor commands.  Perhaps in
      practice it is advisable to always implement doit along with dumpit,
      but it seems reasonable to me to always check doit anyway, not just
      when NEED_WDEV.
      
      Signed-off-by: default avatarJulian Squires <julian@cipht.net>
      Link: https://lore.kernel.org/r/20200706211353.2366470-1-julian@cipht.net
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7c8a863b
    • Qiushi Wu's avatar
      firmware: Fix a reference count leak. · 83ea6370
      Qiushi Wu authored
      [ Upstream commit fe3c6068
      
       ]
      
      kobject_init_and_add() takes reference even when it fails.
      If this function returns an error, kobject_put() must be called to
      properly clean up the memory associated with the object.
      Callback function fw_cfg_sysfs_release_entry() in kobject_put()
      can handle the pointer "entry" properly.
      
      Signed-off-by: default avatarQiushi Wu <wu000273@umn.edu>
      Link: https://lore.kernel.org/r/20200613190533.15712-1-wu000273@umn.edu
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      83ea6370
    • Ranjani Sridharan's avatar
      ALSA: hda: fix NULL pointer dereference during suspend · 01fdcb84
      Ranjani Sridharan authored
      [ Upstream commit 7fcd9bb5
      
       ]
      
      When the ASoC card registration fails and the codec component driver
      never probes, the codec device is not initialized and therefore
      memory for codec->wcaps is not allocated. This results in a NULL pointer
      dereference when the codec driver suspend callback is invoked during
      system suspend. Fix this by returning without performing any actions
      during codec suspend/resume if the card was not registered successfully.
      
      Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
      Signed-off-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
      Link: https://lore.kernel.org/r/20200728231011.1454066-1-ranjani.sridharan@linux.intel.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      01fdcb84
    • René van Dorst's avatar
      net: ethernet: mtk_eth_soc: Always call mtk_gmac0_rgmii_adjust() for mt7623 · eb96e4f7
      René van Dorst authored
      [ Upstream commit 19016d93
      
       ]
      
      Modify mtk_gmac0_rgmii_adjust() so it can always be called.
      mtk_gmac0_rgmii_adjust() sets-up the TRGMII clocks.
      
      Signed-off-by: default avatarRené van Dorst <opensource@vdorst.com>
      Signed-off-By: default avatarDavid Woodhouse <dwmw2@infradead.org>
      Tested-by: default avatarFrank Wunderlich <frank-w@public-files.de>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      eb96e4f7
    • Rustam Kovhaev's avatar
      usb: hso: check for return value in hso_serial_common_create() · fd601f38
      Rustam Kovhaev authored
      [ Upstream commit e911e99a
      
       ]
      
      in case of an error tty_register_device_attr() returns ERR_PTR(),
      add IS_ERR() check
      
      Reported-and-tested-by: default avatar <syzbot+67b2bd0e34f952d0321e@syzkaller.appspotmail.com>
      Link: https://syzkaller.appspot.com/bug?extid=67b2bd0e34f952d0321e
      Signed-off-by: default avatarRustam Kovhaev <rkovhaev@gmail.com>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fd601f38
    • Wolfram Sang's avatar
      i2c: slave: add sanity check when unregistering · 871b5a5a
      Wolfram Sang authored
      [ Upstream commit 8808981b
      
       ]
      
      Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
      Reviewed-by: default avatarAlain Volmat <alain.volmat@st.com>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      871b5a5a
    • Wolfram Sang's avatar
      i2c: slave: improve sanity check when registering · fa0195d8
      Wolfram Sang authored
      [ Upstream commit 1b1be3bf
      
       ]
      
      Add check for ERR_PTR and simplify code while here.
      
      Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
      Reviewed-by: default avatarAlain Volmat <alain.volmat@st.com>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fa0195d8
    • Sam Ravnborg's avatar
      drm/drm_fb_helper: fix fbdev with sparc64 · 4bba72b7
      Sam Ravnborg authored
      [ Upstream commit 2a1658bf ]
      
      Recent kernels have been reported to panic using the bochs_drm
      framebuffer under qemu-system-sparc64 which was bisected to
      commit 7a0483ac
      
       ("drm/bochs: switch to generic drm fbdev emulation").
      
      The backtrace indicates that the shadow framebuffer copy in
      drm_fb_helper_dirty_blit_real() is trying to access the real
      framebuffer using a virtual address rather than use an IO access
      typically implemented using a physical (ASI_PHYS) access on SPARC.
      
      The fix is to replace the memcpy with memcpy_toio() from io.h.
      
      memcpy_toio() uses writeb() where the original fbdev code
      used sbus_memcpy_toio(). The latter uses sbus_writeb().
      
      The difference between writeb() and sbus_memcpy_toio() is
      that writeb() writes bytes in little-endian, where sbus_writeb() writes
      bytes in big-endian. As endian does not matter for byte writes they are
      the same. So we can safely use memcpy_toio() here.
      
      Note that this only fixes bochs, in general fbdev helpers still have
      issues with mixing up system memory and __iomem space. Fixing that will
      require a lot more work.
      
      v3:
        - Improved changelog (Daniel)
        - Added FIXME to fbdev_use_iomem (Daniel)
      
      v2:
        - Added missing __iomem cast (kernel test robot)
        - Made changelog readable and fix typos (Mark)
        - Add flag to select iomem - and set it in the bochs driver
      
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Reported-by: default avatarMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Tested-by: default avatarMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
      Cc: Thomas Zimmermann <tzimmermann@suse.de>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: sparclinux@vger.kernel.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20200709193016.291267-1-sam@ravnborg.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20200725191012.GA434957@ravnborg.org
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4bba72b7
    • Kai-Heng Feng's avatar
      nvme-pci: prevent SK hynix PC400 from using Write Zeroes command · 8e6af828
      Kai-Heng Feng authored
      [ Upstream commit 5611ec2b ]
      
      After commit 6e02318e
      
       ("nvme: add support for the Write Zeroes
      command"), SK hynix PC400 becomes very slow with the following error
      message:
      
      [  224.567695] blk_update_request: operation not supported error, dev nvme1n1, sector 499384320 op 0x9:(WRITE_ZEROES) flags 0x1000000 phys_seg 0 prio class 0]
      
      SK Hynix PC400 has a buggy firmware that treats NLB as max value instead
      of a range, so the NLB passed isn't a valid value to the firmware.
      
      According to SK hynix there are three commands are affected:
      - Write Zeroes
      - Compare
      - Write Uncorrectable
      
      Right now only Write Zeroes is implemented, so disable it completely on
      SK hynix PC400.
      
      BugLink: https://bugs.launchpad.net/bugs/1872383
      Cc: kyounghwan sohn <kyounghwan.sohn@sk.com>
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8e6af828
    • Ben Skeggs's avatar
      drm/nouveau/fbcon: zero-initialise the mode_cmd2 structure · 802df1e3
      Ben Skeggs authored
      [ Upstream commit 15fbc3b9
      
       ]
      
      This is tripping up the format modifier patches.
      
      Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      802df1e3
    • Ben Skeggs's avatar
      drm/nouveau/fbcon: fix module unload when fbcon init has failed for some reason · 5955ccb5
      Ben Skeggs authored
      [ Upstream commit 498595ab
      
       ]
      
      Stale pointer was tripping up the unload path.
      
      Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5955ccb5
    • Christoph Hellwig's avatar
      net/9p: validate fds in p9_fd_open · e0c47a51
      Christoph Hellwig authored
      [ Upstream commit a39c4606
      
       ]
      
      p9_fd_open just fgets file descriptors passed in from userspace, but
      doesn't verify that they are valid for read or writing.  This gets
      cought down in the VFS when actually attempting a read or write, but
      a new warning added in linux-next upsets syzcaller.
      
      Fix this by just verifying the fds early on.
      
      Link: http://lkml.kernel.org/r/20200710085722.435850-1-hch@lst.de
      Reported-by: default avatar <syzbot+e6f77e16ff68b2434a2c@syzkaller.appspotmail.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      [Dominique: amend goto as per Doug Nazar's review]
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e0c47a51
    • Johan Hovold's avatar
      leds: 88pm860x: fix use-after-free on unbind · fe6402e0
      Johan Hovold authored
      commit eca21c2d upstream.
      
      Several MFD child drivers register their class devices directly under
      the parent device. This means you cannot blindly do devres conversions
      so that deregistration ends up being tied to the parent device,
      something which leads to use-after-free on driver unbind when the class
      device is released while still being registered.
      
      Fixes: 375446df
      
       ("leds: 88pm860x: Use devm_led_classdev_register")
      Cc: stable <stable@vger.kernel.org>     # 4.6
      Cc: Amitoj Kaur Chawla <amitoj1606@gmail.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe6402e0
    • Johan Hovold's avatar
      leds: lm3533: fix use-after-free on unbind · 3564cdde
      Johan Hovold authored
      commit d584221e upstream.
      
      Several MFD child drivers register their class devices directly under
      the parent device. This means you cannot blindly do devres conversions
      so that deregistration ends up being tied to the parent device,
      something which leads to use-after-free on driver unbind when the class
      device is released while still being registered.
      
      Fixes: 50154e29
      
       ("leds: lm3533: Use devm_led_classdev_register")
      Cc: stable <stable@vger.kernel.org>     # 4.6
      Cc: Amitoj Kaur Chawla <amitoj1606@gmail.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3564cdde
    • Johan Hovold's avatar
      leds: da903x: fix use-after-free on unbind · 385c1ae9
      Johan Hovold authored
      commit 6f4aa357 upstream.
      
      Several MFD child drivers register their class devices directly under
      the parent device. This means you cannot blindly do devres conversions
      so that deregistration ends up being tied to the parent device,
      something which leads to use-after-free on driver unbind when the class
      device is released while still being registered.
      
      Fixes: eed16255
      
       ("leds: da903x: Use devm_led_classdev_register")
      Cc: stable <stable@vger.kernel.org>     # 4.6
      Cc: Amitoj Kaur Chawla <amitoj1606@gmail.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      385c1ae9
    • Johan Hovold's avatar
      leds: lm36274: fix use-after-free on unbind · bde8f23c
      Johan Hovold authored
      commit a0972fff upstream.
      
      Several MFD child drivers register their class devices directly under
      the parent device. This means you cannot use devres so that
      deregistration ends up being tied to the parent device, something which
      leads to use-after-free on driver unbind when the class device is
      released while still being registered.
      
      Fixes: 11e1bbc1
      
       ("leds: lm36274: Introduce the TI LM36274 LED driver")
      Cc: stable <stable@vger.kernel.org>     # 5.3
      Cc: Dan Murphy <dmurphy@ti.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bde8f23c
    • Johan Hovold's avatar
      leds: wm831x-status: fix use-after-free on unbind · 635f8fcc
      Johan Hovold authored
      commit 47a459ec upstream.
      
      Several MFD child drivers register their class devices directly under
      the parent device. This means you cannot blindly do devres conversions
      so that deregistration ends up being tied to the parent device,
      something which leads to use-after-free on driver unbind when the class
      device is released while still being registered.
      
      Fixes: 8d3b6a40
      
       ("leds: wm831x-status: Use devm_led_classdev_register")
      Cc: stable <stable@vger.kernel.org>     # 4.6
      Cc: Amitoj Kaur Chawla <amitoj1606@gmail.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      635f8fcc
    • Greg Kroah-Hartman's avatar
      mtd: properly check all write ioctls for permissions · 9a53e8bd
      Greg Kroah-Hartman authored
      commit f7e6b19b
      
       upstream.
      
      When doing a "write" ioctl call, properly check that we have permissions
      to do so before copying anything from userspace or anything else so we
      can "fail fast".  This includes also covering the MEMWRITE ioctl which
      previously missed checking for this.
      
      Cc: Miquel Raynal <miquel.raynal@bootlin.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Vignesh Raghavendra <vigneshr@ti.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      [rw: Fixed locking issue]
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9a53e8bd
    • Yunhai Zhang's avatar
      vgacon: Fix for missing check in scrollback handling · 8c3215a0
      Yunhai Zhang authored
      commit ebfdfeea
      
       upstream.
      
      vgacon_scrollback_update() always leaves enbough room in the scrollback
      buffer for the next call, but if the console size changed that room
      might not actually be enough, and so we need to re-check.
      
      The check should be in the loop since vgacon_scrollback_cur->tail is
      updated in the loop and count may be more than 1 when triggered by CSI M,
      as Jiri's PoC:
      #include <stdio.h>
      #include <stdlib.h>
      #include <unistd.h>
      #include <sys/types.h>
      #include <sys/stat.h>
      #include <sys/ioctl.h>
      #include <fcntl.h>
      
      int main(int argc, char** argv)
      {
              int fd = open("/dev/tty1", O_RDWR);
              unsigned short size[3] = {25, 200, 0};
              ioctl(fd, 0x5609, size); // VT_RESIZE
      
              write(fd, "\e[1;1H", 6);
              for (int i = 0; i < 30; i++)
                      write(fd, "\e[10M", 5);
      }
      
      It leads to various crashes as vgacon_scrollback_update writes out of
      the buffer:
       BUG: unable to handle page fault for address: ffffc900001752a0
       #PF: supervisor write access in kernel mode
       #PF: error_code(0x0002) - not-present page
       RIP: 0010:mutex_unlock+0x13/0x30
      ...
       Call Trace:
        n_tty_write+0x1a0/0x4d0
        tty_write+0x1a0/0x2e0
      
      Or to KASAN reports:
      BUG: KASAN: slab-out-of-bounds in vgacon_scroll+0x57a/0x8ed
      
      This fixes CVE-2020-14331.
      
      Reported-by: default avatar张云海 <zhangyunhai@nsfocus.com>
      Reported-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reported-by: default avatarKyungtae Kim <kt0755@gmail.com>
      Fixes: 15bdab95
      
       ([PATCH] vgacon: Add support for soft scrollback)
      Cc: stable@vger.kernel.org
      Cc: linux-fbdev@vger.kernel.org
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Solar Designer <solar@openwall.com>
      Cc: "Srivatsa S. Bhat" <srivatsa@csail.mit.edu>
      Cc: Anthony Liguori <aliguori@amazon.com>
      Cc: Yang Yingliang <yangyingliang@huawei.com>
      Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Cc: Jiri Slaby <jirislaby@kernel.org>
      Signed-off-by: default avatarYunhai Zhang <zhangyunhai@nsfocus.com>
      Link: https://lore.kernel.org/r/9fb43895-ca91-9b07-ebfd-808cf854ca95@nsfocus.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8c3215a0
    • Matthias Maennich's avatar
      scripts: add dummy report mode to add_namespace.cocci · 1ae21e97
      Matthias Maennich authored
      commit 55c75498
      
       upstream.
      
      When running `make coccicheck` in report mode using the
      add_namespace.cocci file, it will fail for files that contain
      MODULE_LICENSE. Those match the replacement precondition, but spatch
      errors out as virtual.ns is not set.
      
      In order to fix that, add the virtual rule nsdeps and only do search and
      replace if that rule has been explicitly requested.
      
      In order to make spatch happy in report mode, we also need a dummy rule,
      as otherwise it errors out with "No rules apply". Using a script:python
      rule appears unrelated and odd, but this is the shortest I could come up
      with.
      
      Adjust scripts/nsdeps accordingly to set the nsdeps rule when run trough
      `make nsdeps`.
      
      Suggested-by: default avatarJulia Lawall <julia.lawall@inria.fr>
      Fixes: c7c4e29f
      
       ("scripts: add_namespace: Fix coccicheck failed")
      Cc: YueHaibing <yuehaibing@huawei.com>
      Cc: jeyu@kernel.org
      Cc: cocci@systeme.lip6.fr
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMatthias Maennich <maennich@google.com>
      Reported-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Acked-by: default avatarJulia Lawall <julia.lawall@inria.fr>
      Link: https://lore.kernel.org/r/20200604164145.173925-1-maennich@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ae21e97
    • Eric Biggers's avatar
      Smack: fix use-after-free in smk_write_relabel_self() · 5f5fb7ce
      Eric Biggers authored
      commit beb4ee67
      
       upstream.
      
      smk_write_relabel_self() frees memory from the task's credentials with
      no locking, which can easily cause a use-after-free because multiple
      tasks can share the same credentials structure.
      
      Fix this by using prepare_creds() and commit_creds() to correctly modify
      the task's credentials.
      
      Reproducer for "BUG: KASAN: use-after-free in smk_write_relabel_self":
      
      	#include <fcntl.h>
      	#include <pthread.h>
      	#include <unistd.h>
      
      	static void *thrproc(void *arg)
      	{
      		int fd = open("/sys/fs/smackfs/relabel-self", O_WRONLY);
      		for (;;) write(fd, "foo", 3);
      	}
      
      	int main()
      	{
      		pthread_t t;
      		pthread_create(&t, NULL, thrproc, NULL);
      		thrproc(NULL);
      	}
      
      Reported-by: default avatar <syzbot+e6416dabb497a650da40@syzkaller.appspotmail.com>
      Fixes: 38416e53
      
       ("Smack: limited capability for changing process label")
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5f5fb7ce
    • Jann Horn's avatar
      binder: Prevent context manager from incrementing ref 0 · c5665caf
      Jann Horn authored
      commit 4b836a14 upstream.
      
      Binder is designed such that a binder_proc never has references to
      itself. If this rule is violated, memory corruption can occur when a
      process sends a transaction to itself; see e.g.
      <https://syzkaller.appspot.com/bug?extid=09e05aba06723a94d43d>.
      
      There is a remaining edgecase through which such a transaction-to-self
      can still occur from the context of a task with BINDER_SET_CONTEXT_MGR
      access:
      
       - task A opens /dev/binder twice, creating binder_proc instances P1
         and P2
       - P1 becomes context manager
       - P2 calls ACQUIRE on the magic handle 0, allocating index 0 in its
         handle table
       - P1 dies (by closing the /dev/binder fd and waiting a bit)
       - P2 becomes context manager
       - P2 calls ACQUIRE on the magic handle 0, allocating index 1 in its
         handle table
         [this triggers a warning: "binder: 1974:1974 tried to acquire
         reference to desc 0, got 1 instead"]
       - task B opens /dev/binder once, creating binder_proc instance P3
       - P3 calls P2 (via magic handle 0) with (void*)1 as argument (two-way
         transaction)
       - P2 receives the handle and uses it to call P3 (two-way transaction)
       - P3 calls P2 (via magic handle 0) (two-way transaction)
       - P2 calls P2 (via handle 1) (two-way transaction)
      
      And then, if P2 does *NOT* accept the incoming transaction work, but
      instead closes the binder fd, we get a crash.
      
      Solve it by preventing the context manager from using ACQUIRE on ref 0.
      There shouldn't be any legitimate reason for the context manager to do
      that.
      
      Additionally, print a warning if someone manages to find another way to
      trigger a transaction-to-self bug in the future.
      
      Cc: stable@vger.kernel.org
      Fixes: 457b9a6f
      
       ("Staging: android: add binder driver")
      Acked-by: default avatarTodd Kjos <tkjos@google.com>
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Reviewed-by: default avatarMartijn Coenen <maco@android.com>
      Link: https://lore.kernel.org/r/20200727120424.1627555-1-jannh@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c5665caf