Skip to content
  1. Aug 10, 2021
  2. Aug 08, 2021
    • Greg Kroah-Hartman's avatar
    • Ziyang Xuan's avatar
      can: raw: raw_setsockopt(): fix raw_rcv panic for sock UAF · 19a3982a
      Ziyang Xuan authored
      commit 54f93336 upstream.
      
      We get a bug during ltp can_filter test as following.
      
      ===========================================
      [60919.264984] BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
      [60919.265223] PGD 8000003dda726067 P4D 8000003dda726067 PUD 3dda727067 PMD 0
      [60919.265443] Oops: 0000 [#1] SMP PTI
      [60919.265550] CPU: 30 PID: 3638365 Comm: can_filter Kdump: loaded Tainted: G        W         4.19.90+ #1
      [60919.266068] RIP: 0010:selinux_socket_sock_rcv_skb+0x3e/0x200
      [60919.293289] RSP: 0018:ffff8d53bfc03cf8 EFLAGS: 00010246
      [60919.307140] RAX: 0000000000000000 RBX: 000000000000001d RCX: 0000000000000007
      [60919.320756] RDX: 0000000000000001 RSI: ffff8d5104a8ed00 RDI: ffff8d53bfc03d30
      [60919.334319] RBP: ffff8d9338056800 R08: ffff8d53bfc29d80 R09: 0000000000000001
      [60919.347969] R10: ffff8d53bfc03ec0 R11: ffffb8526ef47c98 R12: ffff8d53bfc03d30
      [60919.350320] perf: interrupt took too long (3063 > 2500), lowering kernel.perf_event_max_sample_rate to 65000
      [60919.361148] R13: 0000000000000001 R14: ffff8d53bcf90000 R15: 0000000000000000
      [60919.361151] FS:  00007fb78b6b3600(0000) GS:ffff8d53bfc00000(0000) knlGS:0000000000000000
      [60919.400812] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [60919.413730] CR2: 0000000000000010 CR3: 0000003e3f784006 CR4: 00000000007606e0
      [60919.426479] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [60919.439339] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [60919.451608] PKRU: 55555554
      [60919.463622] Call Trace:
      [60919.475617]  <IRQ>
      [60919.487122]  ? update_load_avg+0x89/0x5d0
      [60919.498478]  ? update_load_avg+0x89/0x5d0
      [60919.509822]  ? account_entity_enqueue+0xc5/0xf0
      [60919.520709]  security_sock_rcv_skb+0x2a/0x40
      [60919.531413]  sk_filter_trim_cap+0x47/0x1b0
      [60919.542178]  ? kmem_cache_alloc+0x38/0x1b0
      [60919.552444]  sock_queue_rcv_skb+0x17/0x30
      [60919.562477]  raw_rcv+0x110/0x190 [can_raw]
      [60919.572539]  can_rcv_filter+0xbc/0x1b0 [can]
      [60919.582173]  can_receive+0x6b/0xb0 [can]
      [60919.591595]  can_rcv+0x31/0x70 [can]
      [60919.600783]  __netif_receive_skb_one_core+0x5a/0x80
      [60919.609864]  process_backlog+0x9b/0x150
      [60919.618691]  net_rx_action+0x156/0x400
      [60919.627310]  ? sched_clock_cpu+0xc/0xa0
      [60919.635714]  __do_softirq+0xe8/0x2e9
      [60919.644161]  do_softirq_own_stack+0x2a/0x40
      [60919.652154]  </IRQ>
      [60919.659899]  do_softirq.part.17+0x4f/0x60
      [60919.667475]  __local_bh_enable_ip+0x60/0x70
      [60919.675089]  __dev_queue_xmit+0x539/0x920
      [60919.682267]  ? finish_wait+0x80/0x80
      [60919.689218]  ? finish_wait+0x80/0x80
      [60919.695886]  ? sock_alloc_send_pskb+0x211/0x230
      [60919.702395]  ? can_send+0xe5/0x1f0 [can]
      [60919.708882]  can_send+0xe5/0x1f0 [can]
      [60919.715037]  raw_sendmsg+0x16d/0x268 [can_raw]
      
      It's because raw_setsockopt() concurrently with
      unregister_netdevice_many(). Concurrent scenario as following.
      
      	cpu0						cpu1
      raw_bind
      raw_setsockopt					unregister_netdevice_many
      						unlist_netdevice
      dev_get_by_index				raw_notifier
      raw_enable_filters				......
      can_rx_register
      can_rcv_list_find(..., net->can.rx_alldev_list)
      
      ......
      
      sock_close
      raw_release(sock_a)
      
      ......
      
      can_receive
      can_rcv_filter(net->can.rx_alldev_list, ...)
      raw_rcv(skb, sock_a)
      BUG
      
      After unlist_netdevice(), dev_get_by_index() return NULL in
      raw_setsockopt(). Function raw_enable_filters() will add sock
      and can_filter to net->can.rx_alldev_list. Then the sock is closed.
      Followed by, we sock_sendmsg() to a new vcan device use the same
      can_filter. Protocol stack match the old receiver whose sock has
      been released on net->can.rx_alldev_list in can_rcv_filter().
      Function raw_rcv() uses the freed sock. UAF BUG is triggered.
      
      We can find that the key issue is that net_device has not been
      protected in raw_setsockopt(). Use rtnl_lock to protect net_device
      in raw_setsockopt().
      
      Fixes: c18ce101 ("[CAN]: Add raw protocol")
      Link: https://lore.kernel.org/r/20210722070819.1048263-1-william.xuanziyang@huawei.com
      
      
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: default avatarZiyang Xuan <william.xuanziyang@huawei.com>
      Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      19a3982a
    • Greg Kroah-Hartman's avatar
      Revert "Bluetooth: Shutdown controller after workqueues are flushed or cancelled" · d992022d
      Greg Kroah-Hartman authored
      This reverts commit 5d16a828 which is
      commit 0ea9fd00 upstream.
      
      It has been reported to have problems:
      	https://lore.kernel.org/linux-bluetooth/8735ryk0o7.fsf@baylibre.com/
      
      
      
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Cc: Kai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: Marcel Holtmann <marcel@holtmann.org>
      Cc: Sasha Levin <sashal@kernel.org>
      Link: https://lore.kernel.org/r/efee3a58-a4d2-af22-0931-e81b877ab539@roeck-us.net
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d992022d
    • Pravin B Shelar's avatar
      net: Fix zero-copy head len calculation. · 1fb80d62
      Pravin B Shelar authored
      [ Upstream commit a17ad096
      
       ]
      
      In some cases skb head could be locked and entire header
      data is pulled from skb. When skb_zerocopy() called in such cases,
      following BUG is triggered. This patch fixes it by copying entire
      skb in such cases.
      This could be optimized incase this is performance bottleneck.
      
      ---8<---
      kernel BUG at net/core/skbuff.c:2961!
      invalid opcode: 0000 [#1] SMP PTI
      CPU: 2 PID: 0 Comm: swapper/2 Tainted: G           OE     5.4.0-77-generic #86-Ubuntu
      Hardware name: OpenStack Foundation OpenStack Nova, BIOS 1.13.0-1ubuntu1.1 04/01/2014
      RIP: 0010:skb_zerocopy+0x37a/0x3a0
      RSP: 0018:ffffbcc70013ca38 EFLAGS: 00010246
      Call Trace:
       <IRQ>
       queue_userspace_packet+0x2af/0x5e0 [openvswitch]
       ovs_dp_upcall+0x3d/0x60 [openvswitch]
       ovs_dp_process_packet+0x125/0x150 [openvswitch]
       ovs_vport_receive+0x77/0xd0 [openvswitch]
       netdev_port_receive+0x87/0x130 [openvswitch]
       netdev_frame_hook+0x4b/0x60 [openvswitch]
       __netif_receive_skb_core+0x2b4/0xc90
       __netif_receive_skb_one_core+0x3f/0xa0
       __netif_receive_skb+0x18/0x60
       process_backlog+0xa9/0x160
       net_rx_action+0x142/0x390
       __do_softirq+0xe1/0x2d6
       irq_exit+0xae/0xb0
       do_IRQ+0x5a/0xf0
       common_interrupt+0xf/0xf
      
      Code that triggered BUG:
      int
      skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
      {
              int i, j = 0;
              int plen = 0; /* length of skb->head fragment */
              int ret;
              struct page *page;
              unsigned int offset;
      
              BUG_ON(!from->head_frag && !hlen);
      
      Signed-off-by: default avatarPravin B Shelar <pshelar@ovn.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1fb80d62
    • Takashi Iwai's avatar
      r8152: Fix potential PM refcount imbalance · ac5008a0
      Takashi Iwai authored
      [ Upstream commit 9c23aa51 ]
      
      rtl8152_close() takes the refcount via usb_autopm_get_interface() but
      it doesn't release when RTL8152_UNPLUG test hits.  This may lead to
      the imbalance of PM refcount.  This patch addresses it.
      
      Link: https://bugzilla.suse.com/show_bug.cgi?id=1186194
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ac5008a0
    • Axel Lin's avatar
      regulator: rt5033: Fix n_voltages settings for BUCK and LDO · 225f3fed
      Axel Lin authored
      [ Upstream commit 6549c46a
      
       ]
      
      For linear regulators, the n_voltages should be (max - min) / step + 1.
      
      Buck voltage from 1v to 3V, per step 100mV, and vout mask is 0x1f.
      If value is from 20 to 31, the voltage will all be fixed to 3V.
      And LDO also, just vout range is different from 1.2v to 3v, step is the
      same. If value is from 18 to 31, the voltage will also be fixed to 3v.
      
      Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
      Reviewed-by: default avatarChiYuan Huang <cy_huang@richtek.com>
      Link: https://lore.kernel.org/r/20210627080418.1718127-1-axel.lin@ingics.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      225f3fed
    • Goldwyn Rodrigues's avatar
      btrfs: mark compressed range uptodate only if all bio succeed · 2714679a
      Goldwyn Rodrigues authored
      [ Upstream commit 240246f6
      
       ]
      
      In compression write endio sequence, the range which the compressed_bio
      writes is marked as uptodate if the last bio of the compressed (sub)bios
      is completed successfully. There could be previous bio which may
      have failed which is recorded in cb->errors.
      
      Set the writeback range as uptodate only if cb->errors is zero, as opposed
      to checking only the last bio's status.
      
      Backporting notes: in all versions up to 4.4 the last argument is always
      replaced by "!cb->errors".
      
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2714679a
  3. Aug 04, 2021
    • Greg Kroah-Hartman's avatar
    • Wang Hai's avatar
      sis900: Fix missing pci_disable_device() in probe and remove · b27b5486
      Wang Hai authored
      [ Upstream commit 89fb62fd ]
      
      Replace pci_enable_device() with pcim_enable_device(),
      pci_disable_device() and pci_release_regions() will be
      called in release automatically.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b27b5486
    • Wang Hai's avatar
      tulip: windbond-840: Fix missing pci_disable_device() in probe and remove · 4f362e8b
      Wang Hai authored
      [ Upstream commit 76a16be0 ]
      
      Replace pci_enable_device() with pcim_enable_device(),
      pci_disable_device() and pci_release_regions() will be
      called in release automatically.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4f362e8b
    • Pavel Skripkin's avatar
      net: llc: fix skb_over_panic · 84dd1190
      Pavel Skripkin authored
      [ Upstream commit c7c9d210 ]
      
      Syzbot reported skb_over_panic() in llc_pdu_init_as_xid_cmd(). The
      problem was in wrong LCC header manipulations.
      
      Syzbot's reproducer tries to send XID packet. llc_ui_sendmsg() is
      doing following steps:
      
      	1. skb allocation with size = len + header size
      		len is passed from userpace and header size
      		is 3 since addr->sllc_xid is set.
      
      	2. skb_reserve() for header_len = 3
      	3. filling all other space with memcpy_from_msg()
      
      Ok, at this moment we have fully loaded skb, only headers needs to be
      filled.
      
      Then code comes to llc_sap_action_send_xid_c(). This function pushes 3
      bytes for LLC PDU header and initializes it. Then comes
      llc_pdu_init_as_xid_cmd(). It initalizes next 3 bytes *AFTER* LLC PDU
      header and call skb_push(skb, 3). This looks wrong for 2 reasons:
      
      	1. Bytes rigth after LLC header are user data, so this function
      	   was overwriting payload.
      
      	2. skb_push(skb, 3) call can cause skb_over_panic() since
      	   all free space was filled in llc_ui_sendmsg(). (This can
      	   happen is user passed 686 len: 686 + 14 (eth header) + 3 (LLC
      	   header) = 703. SKB_DATA_ALIGN(703) = 704)
      
      So, in this patch I added 2 new private constansts: LLC_PDU_TYPE_U_XID
      and LLC_PDU_LEN_U_XID. LLC_PDU_LEN_U_XID is used to correctly reserve
      header size to handle LLC + XID case. LLC_PDU_TYPE_U_XID is used by
      llc_pdu_header_init() function to push 6 bytes instead of 3. And finally
      I removed skb_push() call from llc_pdu_init_as_xid_cmd().
      
      This changes should not affect other parts of LLC, since after
      all steps we just transmit buffer.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reported-and-tested-by: default avatar <syzbot+5e5a981ad7cc54c4b2b4@syzkaller.appspotmail.com>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      84dd1190
    • Jiapeng Chong's avatar
      mlx4: Fix missing error code in mlx4_load_one() · 87c5d1bb
      Jiapeng Chong authored
      [ Upstream commit 7e4960b3
      
       ]
      
      The error code is missing in this code scenario, add the error code
      '-EINVAL' to the return value 'err'.
      
      Eliminate the follow smatch warning:
      
      drivers/net/ethernet/mellanox/mlx4/main.c:3538 mlx4_load_one() warn:
      missing error code 'err'.
      
      Reported-by: default avatarAbaci Robot <abaci@linux.alibaba.com>
      Fixes: 7ae0e400
      
       ("net/mlx4_core: Flexible (asymmetric) allocation of EQs and MSI-X vectors for PF/VFs")
      Signed-off-by: default avatarJiapeng Chong <jiapeng.chong@linux.alibaba.com>
      Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      87c5d1bb
    • Hoang Le's avatar
      tipc: fix sleeping in tipc accept routine · e4bee8d2
      Hoang Le authored
      [ Upstream commit d237a7f1 ]
      
      The release_sock() is blocking function, it would change the state
      after sleeping. In order to evaluate the stated condition outside
      the socket lock context, switch to use wait_woken() instead.
      
      Fixes: 6398e23c
      
       ("tipc: standardize accept routine")
      Acked-by: default avatarJon Maloy <jmaloy@redhat.com>
      Signed-off-by: default avatarHoang Le <hoang.h.le@dektech.com.au>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e4bee8d2
    • Pablo Neira Ayuso's avatar
      netfilter: nft_nat: allow to specify layer 4 protocol NAT only · 0df650d5
      Pablo Neira Ayuso authored
      [ Upstream commit a33f387e ]
      
      nft_nat reports a bogus EAFNOSUPPORT if no layer 3 information is specified.
      
      Fixes: d07db988
      
       ("netfilter: nf_tables: introduce nft_validate_register_load()")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0df650d5
    • Nguyen Dinh Phi's avatar
      cfg80211: Fix possible memory leak in function cfg80211_bss_update · 744a3144
      Nguyen Dinh Phi authored
      commit f9a5c358
      
       upstream.
      
      When we exceed the limit of BSS entries, this function will free the
      new entry, however, at this time, it is the last door to access the
      inputed ies, so these ies will be unreferenced objects and cause memory
      leak.
      Therefore we should free its ies before deallocating the new entry, beside
      of dropping it from hidden_list.
      
      Signed-off-by: default avatarNguyen Dinh Phi <phind.uet@gmail.com>
      Link: https://lore.kernel.org/r/20210628132334.851095-1-phind.uet@gmail.com
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      744a3144
    • Jan Kiszka's avatar
      x86/asm: Ensure asm/proto.h can be included stand-alone · f9dc6deb
      Jan Kiszka authored
      [ Upstream commit f7b21a0e
      
       ]
      
      Fix:
      
        ../arch/x86/include/asm/proto.h:14:30: warning: ‘struct task_struct’ declared \
          inside parameter list will not be visible outside of this definition or declaration
        long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2);
                                     ^~~~~~~~~~~
      
        .../arch/x86/include/asm/proto.h:40:34: warning: ‘struct task_struct’ declared \
          inside parameter list will not be visible outside of this definition or declaration
         long do_arch_prctl_common(struct task_struct *task, int option,
                                          ^~~~~~~~~~~
      
      if linux/sched.h hasn't be included previously. This fixes a build error
      when this header is used outside of the kernel tree.
      
       [ bp: Massage commit message. ]
      
      Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Link: https://lkml.kernel.org/r/b76b4be3-cf66-f6b2-9a6c-3e7ef54f9845@web.de
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f9dc6deb
    • Paul Jakma's avatar
      NIU: fix incorrect error return, missed in previous revert · e281c718
      Paul Jakma authored
      commit 15bbf8bb upstream.
      
      Commit 7930742d, reverting 26fd962b, missed out on reverting an incorrect
      change to a return value.  The niu_pci_vpd_scan_props(..) == 1 case appears
      to be a normal path - treating it as an error and return -EINVAL was
      breaking VPD_SCAN and causing the driver to fail to load.
      
      Fix, so my Neptune card works again.
      
      Cc: Kangjie Lu <kjlu@umn.edu>
      Cc: Shannon Nelson <shannon.lee.nelson@gmail.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable <stable@vger.kernel.org>
      Fixes: 7930742d
      
       ('Revert "niu: fix missing checks of niu_pci_eeprom_read"')
      Signed-off-by: default avatarPaul Jakma <paul@jakma.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e281c718
    • Pavel Skripkin's avatar
      can: esd_usb2: fix memory leak · ae4b78ef
      Pavel Skripkin authored
      commit 928150fa upstream.
      
      In esd_usb2_setup_rx_urbs() MAX_RX_URBS coherent buffers are allocated
      and there is nothing, that frees them:
      
      1) In callback function the urb is resubmitted and that's all
      2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
         is not set (see esd_usb2_setup_rx_urbs) and this flag cannot be used
         with coherent buffers.
      
      So, all allocated buffers should be freed with usb_free_coherent()
      explicitly.
      
      Side note: This code looks like a copy-paste of other can drivers. The
      same patch was applied to mcba_usb driver and it works nice with real
      hardware. There is no change in functionality, only clean-up code for
      coherent buffers.
      
      Fixes: 96d8e903 ("can: Add driver for esd CAN-USB/2 device")
      Link: https://lore.kernel.org/r/b31b096926dcb35998ad0271aac4b51770ca7cc8.1627404470.git.paskripkin@gmail.com
      
      
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ae4b78ef
    • Pavel Skripkin's avatar
      can: ems_usb: fix memory leak · 2b04b7b1
      Pavel Skripkin authored
      commit 9969e3c5 upstream.
      
      In ems_usb_start() MAX_RX_URBS coherent buffers are allocated and
      there is nothing, that frees them:
      
      1) In callback function the urb is resubmitted and that's all
      2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
         is not set (see ems_usb_start) and this flag cannot be used with
         coherent buffers.
      
      So, all allocated buffers should be freed with usb_free_coherent()
      explicitly.
      
      Side note: This code looks like a copy-paste of other can drivers. The
      same patch was applied to mcba_usb driver and it works nice with real
      hardware. There is no change in functionality, only clean-up code for
      coherent buffers.
      
      Fixes: 702171ad ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
      Link: https://lore.kernel.org/r/59aa9fbc9a8cbf9af2bbd2f61a659c480b415800.1627404470.git.paskripkin@gmail.com
      
      
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b04b7b1
    • Pavel Skripkin's avatar
      can: usb_8dev: fix memory leak · 2fe5187d
      Pavel Skripkin authored
      commit 0e865f0c upstream.
      
      In usb_8dev_start() MAX_RX_URBS coherent buffers are allocated and
      there is nothing, that frees them:
      
      1) In callback function the urb is resubmitted and that's all
      2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
         is not set (see usb_8dev_start) and this flag cannot be used with
         coherent buffers.
      
      So, all allocated buffers should be freed with usb_free_coherent()
      explicitly.
      
      Side note: This code looks like a copy-paste of other can drivers. The
      same patch was applied to mcba_usb driver and it works nice with real
      hardware. There is no change in functionality, only clean-up code for
      coherent buffers.
      
      Fixes: 0024d8ad ("can: usb_8dev: Add support for USB2CAN interface from 8 devices")
      Link: https://lore.kernel.org/r/d39b458cd425a1cf7f512f340224e6e9563b07bd.1627404470.git.paskripkin@gmail.com
      
      
      Cc: linux-stable <stable@vger.kernel.org>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2fe5187d
    • Junxiao Bi's avatar
      ocfs2: issue zeroout to EOF blocks · cd98ef88
      Junxiao Bi authored
      commit 9449ad33 upstream.
      
      For punch holes in EOF blocks, fallocate used buffer write to zero the
      EOF blocks in last cluster.  But since ->writepage will ignore EOF
      pages, those zeros will not be flushed.
      
      This "looks" ok as commit 6bba4471 ("ocfs2: fix data corruption by
      fallocate") will zero the EOF blocks when extend the file size, but it
      isn't.  The problem happened on those EOF pages, before writeback, those
      pages had DIRTY flag set and all buffer_head in them also had DIRTY flag
      set, when writeback run by write_cache_pages(), DIRTY flag on the page
      was cleared, but DIRTY flag on the buffer_head not.
      
      When next write happened to those EOF pages, since buffer_head already
      had DIRTY flag set, it would not mark page DIRTY again.  That made
      writeback ignore them forever.  That will cause data corruption.  Even
      directio write can't work because it will fail when trying to drop pages
      caches before direct io, as it found the buffer_head for those pages
      still had DIRTY flag set, then it will fall back to buffer io mode.
      
      To make a summary of the issue, as writeback ingores EOF pages, once any
      EOF page is generated, any write to it will only go to the page cache,
      it will never be flushed to disk even file size extends and that page is
      not EOF page any more.  The fix is to avoid zero EOF blocks with buffer
      write.
      
      The following code snippet from qemu-img could trigger the corruption.
      
        656   open("6b3711ae-3306-4bdd-823c-cf1c0060a095.conv.2", O_RDWR|O_DIRECT|O_CLOEXEC) = 11
        ...
        660   fallocate(11, FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE, 2275868672, 327680 <unfinished ...>
        660   fallocate(11, 0, 2275868672, 327680) = 0
        658   pwrite64(11, "
      
      Link: https://lkml.kernel.org/r/20210722054923.24389-2-junxiao.bi@oracle.com
      
      
      Signed-off-by: default avatarJunxiao Bi <junxiao.bi@oracle.com>
      Reviewed-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Jun Piao <piaojun@huawei.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cd98ef88
    • Junxiao Bi's avatar
      ocfs2: fix zero out valid data · 61b1d20e
      Junxiao Bi authored
      commit f267aeb6 upstream.
      
      If append-dio feature is enabled, direct-io write and fallocate could
      run in parallel to extend file size, fallocate used "orig_isize" to
      record i_size before taking "ip_alloc_sem", when
      ocfs2_zeroout_partial_cluster() zeroout EOF blocks, i_size maybe already
      extended by ocfs2_dio_end_io_write(), that will cause valid data zeroed
      out.
      
      Link: https://lkml.kernel.org/r/20210722054923.24389-1-junxiao.bi@oracle.com
      Fixes: 6bba4471
      
       ("ocfs2: fix data corruption by fallocate")
      Signed-off-by: default avatarJunxiao Bi <junxiao.bi@oracle.com>
      Reviewed-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Jun Piao <piaojun@huawei.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      61b1d20e
    • Russell King's avatar
      ARM: ensure the signal page contains defined contents · 8db77dca
      Russell King authored
      commit 9c698bff
      
       upstream.
      
      Ensure that the signal page contains our poison instruction to increase
      the protection against ROP attacks and also contains well defined
      contents.
      
      Acked-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarNobuhiro Iwamatsu (CIP) <nobuhiro1.iwamatsu@toshiba.co.jp>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8db77dca
    • Matthew Wilcox's avatar
      lib/string.c: add multibyte memset functions · 5ed05c55
      Matthew Wilcox authored
      commit 3b3c4bab upstream.
      
      Patch series "Multibyte memset variations", v4.
      
      A relatively common idiom we're missing is a function to fill an area of
      memory with a pattern which is larger than a single byte.  I first
      noticed this with a zram patch which wanted to fill a page with an
      'unsigned long' value.  There turn out to be quite a few places in the
      kernel which can benefit from using an optimised function rather than a
      loop; sometimes text size, sometimes speed, and sometimes both.  The
      optimised PowerPC version (not included here) improves performance by
      about 30% on POWER8 on just the raw memset_l().
      
      Most of the extra lines of code come from the three testcases I added.
      
      This patch (of 8):
      
      memset16(), memset32() and memset64() are like memset(), but allow the
      caller to fill the destination with a value larger than a single byte.
      memset_l() and memset_p() allow the caller to use unsigned long and
      pointer values respectively.
      
      Link: http://lkml.kernel.org/r/20170720184539.31609-2-willy@infradead.org
      
      
      Signed-off-by: default avatarMatthew Wilcox <mawilcox@microsoft.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: David Miller <davem@davemloft.net>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
      Cc: Matt Turner <mattst88@gmail.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Russell King <rmk+kernel@armlinux.org.uk>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarNobuhiro Iwamatsu (CIP) <nobuhiro1.iwamatsu@toshiba.co.jp>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ed05c55
    • Sudeep Holla's avatar
      ARM: dts: versatile: Fix up interrupt controller node names · 9789810f
      Sudeep Holla authored
      [ Upstream commit 82a1c675
      
       ]
      
      Once the new schema interrupt-controller/arm,vic.yaml is added, we get
      the below warnings:
      
              arch/arm/boot/dts/versatile-ab.dt.yaml:
              intc@10140000: $nodename:0: 'intc@10140000' does not match
              '^interrupt-controller(@[0-9a-f,]+)*$'
      
      	arch/arm/boot/dts/versatile-ab.dt.yaml:
      	intc@10140000: 'clear-mask' does not match any of the regexes
      
      Fix the node names for the interrupt controller to conform
      to the standard node name interrupt-controller@.. Also drop invalid
      clear-mask property.
      
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Link: https://lore.kernel.org/r/20210701132118.759454-1-sudeep.holla@arm.com
      
      '
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9789810f
    • Desmond Cheong Zhi Xi's avatar
      hfs: add lock nesting notation to hfs_find_init · b81e38f9
      Desmond Cheong Zhi Xi authored
      [ Upstream commit b3b2177a ]
      
      Syzbot reports a possible recursive lock in [1].
      
      This happens due to missing lock nesting information.  From the logs, we
      see that a call to hfs_fill_super is made to mount the hfs filesystem.
      While searching for the root inode, the lock on the catalog btree is
      grabbed.  Then, when the parent of the root isn't found, a call to
      __hfs_bnode_create is made to create the parent of the root.  This
      eventually leads to a call to hfs_ext_read_extent which grabs a lock on
      the extents btree.
      
      Since the order of locking is catalog btree -> extents btree, this lock
      hierarchy does not lead to a deadlock.
      
      To tell lockdep that this locking is safe, we add nesting notation to
      distinguish between catalog btrees, extents btrees, and attributes
      btrees (for HFS+).  This has already been done in hfsplus.
      
      Link: https://syzkaller.appspot.com/bug?id=f007ef1d7a31a469e3be7aeb0fde0769b18585db [1]
      Link: https://lkml.kernel.org/r/20210701030756.58760-4-desmondcheongzx@gmail.com
      
      
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reported-by: default avatar <syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com>
      Tested-by: default avatar <syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b81e38f9
    • Desmond Cheong Zhi Xi's avatar
      hfs: fix high memory mapping in hfs_bnode_read · 6c2803d4
      Desmond Cheong Zhi Xi authored
      [ Upstream commit 54a5ead6 ]
      
      Pages that we read in hfs_bnode_read need to be kmapped into kernel
      address space.  However, currently only the 0th page is kmapped.  If the
      given offset + length exceeds this 0th page, then we have an invalid
      memory access.
      
      To fix this, we kmap relevant pages one by one and copy their relevant
      portions of data.
      
      An example of invalid memory access occurring without this fix can be seen
      in the following crash report:
      
        ==================================================================
        BUG: KASAN: use-after-free in memcpy include/linux/fortify-string.h:191 [inline]
        BUG: KASAN: use-after-free in hfs_bnode_read+0xc4/0xe0 fs/hfs/bnode.c:26
        Read of size 2 at addr ffff888125fdcffe by task syz-executor5/4634
      
        CPU: 0 PID: 4634 Comm: syz-executor5 Not tainted 5.13.0-syzkaller #0
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
        Call Trace:
         __dump_stack lib/dump_stack.c:79 [inline]
         dump_stack+0x195/0x1f8 lib/dump_stack.c:120
         print_address_description.constprop.0+0x1d/0x110 mm/kasan/report.c:233
         __kasan_report mm/kasan/report.c:419 [inline]
         kasan_report.cold+0x7b/0xd4 mm/kasan/report.c:436
         check_region_inline mm/kasan/generic.c:180 [inline]
         kasan_check_range+0x154/0x1b0 mm/kasan/generic.c:186
         memcpy+0x24/0x60 mm/kasan/shadow.c:65
         memcpy include/linux/fortify-string.h:191 [inline]
         hfs_bnode_read+0xc4/0xe0 fs/hfs/bnode.c:26
         hfs_bnode_read_u16 fs/hfs/bnode.c:34 [inline]
         hfs_bnode_find+0x880/0xcc0 fs/hfs/bnode.c:365
         hfs_brec_find+0x2d8/0x540 fs/hfs/bfind.c:126
         hfs_brec_read+0x27/0x120 fs/hfs/bfind.c:165
         hfs_cat_find_brec+0x19a/0x3b0 fs/hfs/catalog.c:194
         hfs_fill_super+0xc13/0x1460 fs/hfs/super.c:419
         mount_bdev+0x331/0x3f0 fs/super.c:1368
         hfs_mount+0x35/0x40 fs/hfs/super.c:457
         legacy_get_tree+0x10c/0x220 fs/fs_context.c:592
         vfs_get_tree+0x93/0x300 fs/super.c:1498
         do_new_mount fs/namespace.c:2905 [inline]
         path_mount+0x13f5/0x20e0 fs/namespace.c:3235
         do_mount fs/namespace.c:3248 [inline]
         __do_sys_mount fs/namespace.c:3456 [inline]
         __se_sys_mount fs/namespace.c:3433 [inline]
         __x64_sys_mount+0x2b8/0x340 fs/namespace.c:3433
         do_syscall_64+0x37/0xc0 arch/x86/entry/common.c:47
         entry_SYSCALL_64_after_hwframe+0x44/0xae
        RIP: 0033:0x45e63a
        Code: 48 c7 c2 bc ff ff ff f7 d8 64 89 02 b8 ff ff ff ff eb d2 e8 88 04 00 00 0f 1f 84 00 00 00 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
        RSP: 002b:00007f9404d410d8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
        RAX: ffffffffffffffda RBX: 0000000020000248 RCX: 000000000045e63a
        RDX: 0000000020000000 RSI: 0000000020000100 RDI: 00007f9404d41120
        RBP: 00007f9404d41120 R08: 00000000200002c0 R09: 0000000020000000
        R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
        R13: 0000000000000003 R14: 00000000004ad5d8 R15: 0000000000000000
      
        The buggy address belongs to the page:
        page:00000000dadbcf3e refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x125fdc
        flags: 0x2fffc0000000000(node=0|zone=2|lastcpupid=0x3fff)
        raw: 02fffc0000000000 ffffea000497f748 ffffea000497f6c8 0000000000000000
        raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
        page dumped because: kasan: bad access detected
      
        Memory state around the buggy address:
         ffff888125fdce80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff888125fdcf00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        >ffff888125fdcf80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                                                        ^
         ffff888125fdd000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff888125fdd080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        ==================================================================
      
      Link: https://lkml.kernel.org/r/20210701030756.58760-3-desmondcheongzx@gmail.com
      
      
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6c2803d4
    • Desmond Cheong Zhi Xi's avatar
      hfs: add missing clean-up in hfs_fill_super · 540544cd
      Desmond Cheong Zhi Xi authored
      [ Upstream commit 16ee572e ]
      
      Patch series "hfs: fix various errors", v2.
      
      This series ultimately aims to address a lockdep warning in
      hfs_find_init reported by Syzbot [1].
      
      The work done for this led to the discovery of another bug, and the
      Syzkaller repro test also reveals an invalid memory access error after
      clearing the lockdep warning.  Hence, this series is broken up into
      three patches:
      
      1. Add a missing call to hfs_find_exit for an error path in
         hfs_fill_super
      
      2. Fix memory mapping in hfs_bnode_read by fixing calls to kmap
      
      3. Add lock nesting notation to tell lockdep that the observed locking
         hierarchy is safe
      
      This patch (of 3):
      
      Before exiting hfs_fill_super, the struct hfs_find_data used in
      hfs_find_init should be passed to hfs_find_exit to be cleaned up, and to
      release the lock held on the btree.
      
      The call to hfs_find_exit is missing from an error path.  We add it back
      in by consolidating calls to hfs_find_exit for error paths.
      
      Link: https://syzkaller.appspot.com/bug?id=f007ef1d7a31a469e3be7aeb0fde0769b18585db [1]
      Link: https://lkml.kernel.org/r/20210701030756.58760-1-desmondcheongzx@gmail.com
      Link: https://lkml.kernel.org/r/20210701030756.58760-2-desmondcheongzx@gmail.com
      
      
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      540544cd
    • Xin Long's avatar
      sctp: move 198 addresses from unusable to private scope · 615595fa
      Xin Long authored
      [ Upstream commit 1d11fa23
      
       ]
      
      The doc draft-stewart-tsvwg-sctp-ipv4-00 that restricts 198 addresses
      was never published. These addresses as private addresses should be
      allowed to use in SCTP.
      
      As Michael Tuexen suggested, this patch is to move 198 addresses from
      unusable to private scope.
      
      Reported-by: default avatarSérgio <surkamp@gmail.com>
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Acked-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      615595fa
    • Yang Yingliang's avatar
      net/802/garp: fix memleak in garp_request_join() · eef8786a
      Yang Yingliang authored
      [ Upstream commit 42ca63f9
      
       ]
      
      I got kmemleak report when doing fuzz test:
      
      BUG: memory leak
      unreferenced object 0xffff88810c909b80 (size 64):
        comm "syz", pid 957, jiffies 4295220394 (age 399.090s)
        hex dump (first 32 bytes):
          01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 08 00 00 00 01 02 00 04  ................
        backtrace:
          [<00000000ca1f2e2e>] garp_request_join+0x285/0x3d0
          [<00000000bf153351>] vlan_gvrp_request_join+0x15b/0x190
          [<0000000024005e72>] vlan_dev_open+0x706/0x980
          [<00000000dc20c4d4>] __dev_open+0x2bb/0x460
          [<0000000066573004>] __dev_change_flags+0x501/0x650
          [<0000000035b42f83>] rtnl_configure_link+0xee/0x280
          [<00000000a5e69de0>] __rtnl_newlink+0xed5/0x1550
          [<00000000a5258f4a>] rtnl_newlink+0x66/0x90
          [<00000000506568ee>] rtnetlink_rcv_msg+0x439/0xbd0
          [<00000000b7eaeae1>] netlink_rcv_skb+0x14d/0x420
          [<00000000c373ce66>] netlink_unicast+0x550/0x750
          [<00000000ec74ce74>] netlink_sendmsg+0x88b/0xda0
          [<00000000381ff246>] sock_sendmsg+0xc9/0x120
          [<000000008f6a2db3>] ____sys_sendmsg+0x6e8/0x820
          [<000000008d9c1735>] ___sys_sendmsg+0x145/0x1c0
          [<00000000aa39dd8b>] __sys_sendmsg+0xfe/0x1d0
      
      Calling garp_request_leave() after garp_request_join(), the attr->state
      is set to GARP_APPLICANT_VO, garp_attr_destroy() won't be called in last
      transmit event in garp_uninit_applicant(), the attr of applicant will be
      leaked. To fix this leak, iterate and free each attr of applicant before
      rerturning from garp_uninit_applicant().
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      eef8786a
    • Yang Yingliang's avatar
      net/802/mrp: fix memleak in mrp_request_join() · d9917f12
      Yang Yingliang authored
      [ Upstream commit 996af621
      
       ]
      
      I got kmemleak report when doing fuzz test:
      
      BUG: memory leak
      unreferenced object 0xffff88810c239500 (size 64):
      comm "syz-executor940", pid 882, jiffies 4294712870 (age 14.631s)
      hex dump (first 32 bytes):
      01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
      00 00 00 00 00 00 00 00 01 00 00 00 01 02 00 04 ................
      backtrace:
      [<00000000a323afa4>] slab_alloc_node mm/slub.c:2972 [inline]
      [<00000000a323afa4>] slab_alloc mm/slub.c:2980 [inline]
      [<00000000a323afa4>] __kmalloc+0x167/0x340 mm/slub.c:4130
      [<000000005034ca11>] kmalloc include/linux/slab.h:595 [inline]
      [<000000005034ca11>] mrp_attr_create net/802/mrp.c:276 [inline]
      [<000000005034ca11>] mrp_request_join+0x265/0x550 net/802/mrp.c:530
      [<00000000fcfd81f3>] vlan_mvrp_request_join+0x145/0x170 net/8021q/vlan_mvrp.c:40
      [<000000009258546e>] vlan_dev_open+0x477/0x890 net/8021q/vlan_dev.c:292
      [<0000000059acd82b>] __dev_open+0x281/0x410 net/core/dev.c:1609
      [<000000004e6dc695>] __dev_change_flags+0x424/0x560 net/core/dev.c:8767
      [<00000000471a09af>] rtnl_configure_link+0xd9/0x210 net/core/rtnetlink.c:3122
      [<0000000037a4672b>] __rtnl_newlink+0xe08/0x13e0 net/core/rtnetlink.c:3448
      [<000000008d5d0fda>] rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3488
      [<000000004882fe39>] rtnetlink_rcv_msg+0x369/0xa10 net/core/rtnetlink.c:5552
      [<00000000907e6c54>] netlink_rcv_skb+0x134/0x3d0 net/netlink/af_netlink.c:2504
      [<00000000e7d7a8c4>] netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
      [<00000000e7d7a8c4>] netlink_unicast+0x4a0/0x6a0 net/netlink/af_netlink.c:1340
      [<00000000e0645d50>] netlink_sendmsg+0x78e/0xc90 net/netlink/af_netlink.c:1929
      [<00000000c24559b7>] sock_sendmsg_nosec net/socket.c:654 [inline]
      [<00000000c24559b7>] sock_sendmsg+0x139/0x170 net/socket.c:674
      [<00000000fc210bc2>] ____sys_sendmsg+0x658/0x7d0 net/socket.c:2350
      [<00000000be4577b5>] ___sys_sendmsg+0xf8/0x170 net/socket.c:2404
      
      Calling mrp_request_leave() after mrp_request_join(), the attr->state
      is set to MRP_APPLICANT_VO, mrp_attr_destroy() won't be called in last
      TX event in mrp_uninit_applicant(), the attr of applicant will be leaked.
      To fix this leak, iterate and free each attr of applicant before rerturning
      from mrp_uninit_applicant().
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d9917f12
    • Yang Yingliang's avatar
      workqueue: fix UAF in pwq_unbound_release_workfn() · 4be0584e
      Yang Yingliang authored
      commit b42b0bdd upstream.
      
      I got a UAF report when doing fuzz test:
      
      [  152.880091][ T8030] ==================================================================
      [  152.881240][ T8030] BUG: KASAN: use-after-free in pwq_unbound_release_workfn+0x50/0x190
      [  152.882442][ T8030] Read of size 4 at addr ffff88810d31bd00 by task kworker/3:2/8030
      [  152.883578][ T8030]
      [  152.883932][ T8030] CPU: 3 PID: 8030 Comm: kworker/3:2 Not tainted 5.13.0+ #249
      [  152.885014][ T8030] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      [  152.886442][ T8030] Workqueue: events pwq_unbound_release_workfn
      [  152.887358][ T8030] Call Trace:
      [  152.887837][ T8030]  dump_stack_lvl+0x75/0x9b
      [  152.888525][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.889371][ T8030]  print_address_description.constprop.10+0x48/0x70
      [  152.890326][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.891163][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.891999][ T8030]  kasan_report.cold.15+0x82/0xdb
      [  152.892740][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.893594][ T8030]  __asan_load4+0x69/0x90
      [  152.894243][ T8030]  pwq_unbound_release_workfn+0x50/0x190
      [  152.895057][ T8030]  process_one_work+0x47b/0x890
      [  152.895778][ T8030]  worker_thread+0x5c/0x790
      [  152.896439][ T8030]  ? process_one_work+0x890/0x890
      [  152.897163][ T8030]  kthread+0x223/0x250
      [  152.897747][ T8030]  ? set_kthread_struct+0xb0/0xb0
      [  152.898471][ T8030]  ret_from_fork+0x1f/0x30
      [  152.899114][ T8030]
      [  152.899446][ T8030] Allocated by task 8884:
      [  152.900084][ T8030]  kasan_save_stack+0x21/0x50
      [  152.900769][ T8030]  __kasan_kmalloc+0x88/0xb0
      [  152.901416][ T8030]  __kmalloc+0x29c/0x460
      [  152.902014][ T8030]  alloc_workqueue+0x111/0x8e0
      [  152.902690][ T8030]  __btrfs_alloc_workqueue+0x11e/0x2a0
      [  152.903459][ T8030]  btrfs_alloc_workqueue+0x6d/0x1d0
      [  152.904198][ T8030]  scrub_workers_get+0x1e8/0x490
      [  152.904929][ T8030]  btrfs_scrub_dev+0x1b9/0x9c0
      [  152.905599][ T8030]  btrfs_ioctl+0x122c/0x4e50
      [  152.906247][ T8030]  __x64_sys_ioctl+0x137/0x190
      [  152.906916][ T8030]  do_syscall_64+0x34/0xb0
      [  152.907535][ T8030]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  152.908365][ T8030]
      [  152.908688][ T8030] Freed by task 8884:
      [  152.909243][ T8030]  kasan_save_stack+0x21/0x50
      [  152.909893][ T8030]  kasan_set_track+0x20/0x30
      [  152.910541][ T8030]  kasan_set_free_info+0x24/0x40
      [  152.911265][ T8030]  __kasan_slab_free+0xf7/0x140
      [  152.911964][ T8030]  kfree+0x9e/0x3d0
      [  152.912501][ T8030]  alloc_workqueue+0x7d7/0x8e0
      [  152.913182][ T8030]  __btrfs_alloc_workqueue+0x11e/0x2a0
      [  152.913949][ T8030]  btrfs_alloc_workqueue+0x6d/0x1d0
      [  152.914703][ T8030]  scrub_workers_get+0x1e8/0x490
      [  152.915402][ T8030]  btrfs_scrub_dev+0x1b9/0x9c0
      [  152.916077][ T8030]  btrfs_ioctl+0x122c/0x4e50
      [  152.916729][ T8030]  __x64_sys_ioctl+0x137/0x190
      [  152.917414][ T8030]  do_syscall_64+0x34/0xb0
      [  152.918034][ T8030]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  152.918872][ T8030]
      [  152.919203][ T8030] The buggy address belongs to the object at ffff88810d31bc00
      [  152.919203][ T8030]  which belongs to the cache kmalloc-512 of size 512
      [  152.921155][ T8030] The buggy address is located 256 bytes inside of
      [  152.921155][ T8030]  512-byte region [ffff88810d31bc00, ffff88810d31be00)
      [  152.922993][ T8030] The buggy address belongs to the page:
      [  152.923800][ T8030] page:ffffea000434c600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10d318
      [  152.925249][ T8030] head:ffffea000434c600 order:2 compound_mapcount:0 compound_pincount:0
      [  152.926399][ T8030] flags: 0x57ff00000010200(slab|head|node=1|zone=2|lastcpupid=0x7ff)
      [  152.927515][ T8030] raw: 057ff00000010200 dead000000000100 dead000000000122 ffff888009c42c80
      [  152.928716][ T8030] raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
      [  152.929890][ T8030] page dumped because: kasan: bad access detected
      [  152.930759][ T8030]
      [  152.931076][ T8030] Memory state around the buggy address:
      [  152.931851][ T8030]  ffff88810d31bc00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.932967][ T8030]  ffff88810d31bc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.934068][ T8030] >ffff88810d31bd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.935189][ T8030]                    ^
      [  152.935763][ T8030]  ffff88810d31bd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.936847][ T8030]  ffff88810d31be00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  152.937940][ T8030] ==================================================================
      
      If apply_wqattrs_prepare() fails in alloc_workqueue(), it will call put_pwq()
      which invoke a work queue to call pwq_unbound_release_workfn() and use the 'wq'.
      The 'wq' allocated in alloc_workqueue() will be freed in error path when
      apply_wqattrs_prepare() fails. So it will lead a UAF.
      
      CPU0                                          CPU1
      alloc_workqueue()
      alloc_and_link_pwqs()
      apply_wqattrs_prepare() fails
      apply_wqattrs_cleanup()
      schedule_work(&pwq->unbound_release_work)
      kfree(wq)
                                                    worker_thread()
                                                    pwq_unbound_release_workfn() <- trigger uaf here
      
      If apply_wqattrs_prepare() fails, the new pwq are not linked, it doesn't
      hold any reference to the 'wq', 'wq' is invalid to access in the worker,
      so add check pwq if linked to fix this.
      
      Fixes: 2d5f0764
      
       ("workqueue: split apply_workqueue_attrs() into 3 stages")
      Cc: stable@vger.kernel.org # v4.2+
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Suggested-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
      Tested-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4be0584e