Skip to content
  1. Dec 14, 2022
    • Haiyang Zhang's avatar
      net: mana: Fix race on per-CQ variable napi work_done · fe50a9bb
      Haiyang Zhang authored
      commit 18010ff7 upstream.
      
      After calling napi_complete_done(), the NAPIF_STATE_SCHED bit may be
      cleared, and another CPU can start napi thread and access per-CQ variable,
      cq->work_done. If the other thread (for example, from busy_poll) sets
      it to a value >= budget, this thread will continue to run when it should
      stop, and cause memory corruption and panic.
      
      To fix this issue, save the per-CQ work_done variable in a local variable
      before napi_complete_done(), so it won't be corrupted by a possible
      concurrent thread after napi_complete_done().
      
      Also, add a flag bit to advertise to the NIC firmware: the NAPI work_done
      variable race is fixed, so the driver is able to reliably support features
      like busy_poll.
      
      Cc: stable@vger.kernel.org
      Fixes: e1b5683f
      
       ("net: mana: Move NAPI from EQ to CQ")
      Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
      Link: https://lore.kernel.org/r/1670010190-28595-1-git-send-email-haiyangz@microsoft.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe50a9bb
    • Luiz Augusto von Dentz's avatar
      Bluetooth: Fix crash when replugging CSR fake controllers · a49894a5
      Luiz Augusto von Dentz authored
      commit b5ca3387
      
       upstream.
      
      It seems fake CSR 5.0 clones can cause the suspend notifier to be
      registered twice causing the following kernel panic:
      
      [   71.986122] Call Trace:
      [   71.986124]  <TASK>
      [   71.986125]  blocking_notifier_chain_register+0x33/0x60
      [   71.986130]  hci_register_dev+0x316/0x3d0 [bluetooth 99b5497ea3d09708fa1366c1dc03288bf3cca8da]
      [   71.986154]  btusb_probe+0x979/0xd85 [btusb e1e0605a4f4c01984a4b9c8ac58c3666ae287477]
      [   71.986159]  ? __pm_runtime_set_status+0x1a9/0x300
      [   71.986162]  ? ktime_get_mono_fast_ns+0x3e/0x90
      [   71.986167]  usb_probe_interface+0xe3/0x2b0
      [   71.986171]  really_probe+0xdb/0x380
      [   71.986174]  ? pm_runtime_barrier+0x54/0x90
      [   71.986177]  __driver_probe_device+0x78/0x170
      [   71.986180]  driver_probe_device+0x1f/0x90
      [   71.986183]  __device_attach_driver+0x89/0x110
      [   71.986186]  ? driver_allows_async_probing+0x70/0x70
      [   71.986189]  bus_for_each_drv+0x8c/0xe0
      [   71.986192]  __device_attach+0xb2/0x1e0
      [   71.986195]  bus_probe_device+0x92/0xb0
      [   71.986198]  device_add+0x422/0x9a0
      [   71.986201]  ? sysfs_merge_group+0xd4/0x110
      [   71.986205]  usb_set_configuration+0x57a/0x820
      [   71.986208]  usb_generic_driver_probe+0x4f/0x70
      [   71.986211]  usb_probe_device+0x3a/0x110
      [   71.986213]  really_probe+0xdb/0x380
      [   71.986216]  ? pm_runtime_barrier+0x54/0x90
      [   71.986219]  __driver_probe_device+0x78/0x170
      [   71.986221]  driver_probe_device+0x1f/0x90
      [   71.986224]  __device_attach_driver+0x89/0x110
      [   71.986227]  ? driver_allows_async_probing+0x70/0x70
      [   71.986230]  bus_for_each_drv+0x8c/0xe0
      [   71.986232]  __device_attach+0xb2/0x1e0
      [   71.986235]  bus_probe_device+0x92/0xb0
      [   71.986237]  device_add+0x422/0x9a0
      [   71.986239]  ? _dev_info+0x7d/0x98
      [   71.986242]  ? blake2s_update+0x4c/0xc0
      [   71.986246]  usb_new_device.cold+0x148/0x36d
      [   71.986250]  hub_event+0xa8a/0x1910
      [   71.986255]  process_one_work+0x1c4/0x380
      [   71.986259]  worker_thread+0x51/0x390
      [   71.986262]  ? rescuer_thread+0x3b0/0x3b0
      [   71.986264]  kthread+0xdb/0x110
      [   71.986266]  ? kthread_complete_and_exit+0x20/0x20
      [   71.986268]  ret_from_fork+0x1f/0x30
      [   71.986273]  </TASK>
      [   71.986274] ---[ end trace 0000000000000000 ]---
      [   71.986284] btusb: probe of 2-1.6:1.0 failed with error -17
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216683
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Tested-by: default avatarLeonardo Eugênio <lelgenio@disroot.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a49894a5
    • Ismael Ferreras Morezuelas's avatar
      Bluetooth: btusb: Add debug message for CSR controllers · 1dee2b50
      Ismael Ferreras Morezuelas authored
      commit 955aebd4
      
       upstream.
      
      The rationale of showing this is that it's potentially critical
      information to diagnose and find more CSR compatibility bugs in the
      future and it will save a lot of headaches.
      
      Given that clones come from a wide array of vendors (some are actually
      Barrot, some are something else) and these numbers are what let us find
      differences between actual and fake ones, it will be immensely helpful
      to scour the Internet looking for this pattern and building an actual
      database to find correlations and improve the checks.
      
      Cc: stable@vger.kernel.org
      Cc: Hans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarIsmael Ferreras Morezuelas <swyterzone@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1dee2b50
    • John Starks's avatar
      mm/gup: fix gup_pud_range() for dax · 3ac29732
      John Starks authored
      commit fcd0ccd8 upstream.
      
      For dax pud, pud_huge() returns true on x86. So the function works as long
      as hugetlb is configured. However, dax doesn't depend on hugetlb.
      Commit 414fd080 ("mm/gup: fix gup_pmd_range() for dax") fixed
      devmap-backed huge PMDs, but missed devmap-backed huge PUDs. Fix this as
      well.
      
      This fixes the below kernel panic:
      
      general protection fault, probably for non-canonical address 0x69e7c000cc478: 0000 [#1] SMP
      	< snip >
      Call Trace:
      <TASK>
      get_user_pages_fast+0x1f/0x40
      iov_iter_get_pages+0xc6/0x3b0
      ? mempool_alloc+0x5d/0x170
      bio_iov_iter_get_pages+0x82/0x4e0
      ? bvec_alloc+0x91/0xc0
      ? bio_alloc_bioset+0x19a/0x2a0
      blkdev_direct_IO+0x282/0x480
      ? __io_complete_rw_common+0xc0/0xc0
      ? filemap_range_has_page+0x82/0xc0
      generic_file_direct_write+0x9d/0x1a0
      ? inode_update_time+0x24/0x30
      __generic_file_write_iter+0xbd/0x1e0
      blkdev_write_iter+0xb4/0x150
      ? io_import_iovec+0x8d/0x340
      io_write+0xf9/0x300
      io_issue_sqe+0x3c3/0x1d30
      ? sysvec_reschedule_ipi+0x6c/0x80
      __io_queue_sqe+0x33/0x240
      ? fget+0x76/0xa0
      io_submit_sqes+0xe6a/0x18d0
      ? __fget_light+0xd1/0x100
      __x64_sys_io_uring_enter+0x199/0x880
      ? __context_tracking_enter+0x1f/0x70
      ? irqentry_exit_to_user_mode+0x24/0x30
      ? irqentry_exit+0x1d/0x30
      ? __context_tracking_exit+0xe/0x70
      do_syscall_64+0x3b/0x90
      entry_SYSCALL_64_after_hwframe+0x61/0xcb
      RIP: 0033:0x7fc97c11a7be
      	< snip >
      </TASK>
      ---[ end trace 48b2e0e67debcaeb ]---
      RIP: 0010:internal_get_user_pages_fast+0x340/0x990
      	< snip >
      Kernel panic - not syncing: Fatal exception
      Kernel Offset: disabled
      
      Link: https://lkml.kernel.org/r/1670392853-28252-1-git-send-email-ssengar@linux.microsoft.com
      Fixes: 414fd080
      
       ("mm/gup: fix gup_pmd_range() for dax")
      Signed-off-by: default avatarJohn Starks <jostarks@microsoft.com>
      Signed-off-by: default avatarSaurabh Sengar <ssengar@linux.microsoft.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Yu Zhao <yuzhao@google.com>
      Cc: Jason Gunthorpe <jgg@nvidia.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Alistair Popple <apopple@nvidia.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ac29732
    • Tejun Heo's avatar
      memcg: fix possible use-after-free in memcg_write_event_control() · aad8bbd1
      Tejun Heo authored
      commit 4a7ba45b upstream.
      
      memcg_write_event_control() accesses the dentry->d_name of the specified
      control fd to route the write call.  As a cgroup interface file can't be
      renamed, it's safe to access d_name as long as the specified file is a
      regular cgroup file.  Also, as these cgroup interface files can't be
      removed before the directory, it's safe to access the parent too.
      
      Prior to 347c4a87 ("memcg: remove cgroup_event->cft"), there was a
      call to __file_cft() which verified that the specified file is a regular
      cgroupfs file before further accesses.  The cftype pointer returned from
      __file_cft() was no longer necessary and the commit inadvertently dropped
      the file type check with it allowing any file to slip through.  With the
      invarients broken, the d_name and parent accesses can now race against
      renames and removals of arbitrary files and cause use-after-free's.
      
      Fix the bug by resurrecting the file type check in __file_cft().  Now that
      cgroupfs is implemented through kernfs, checking the file operations needs
      to go through a layer of indirection.  Instead, let's check the superblock
      and dentry type.
      
      Link: https://lkml.kernel.org/r/Y5FRm/cfcKPGzWwl@slm.duckdns.org
      Fixes: 347c4a87
      
       ("memcg: remove cgroup_event->cft")
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: Shakeel Butt <shakeelb@google.com>
      Cc: <stable@vger.kernel.org>	[3.14+]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aad8bbd1
    • Hans Verkuil's avatar
      media: v4l2-dv-timings.c: fix too strict blanking sanity checks · 6fb8bc29
      Hans Verkuil authored
      commit 5eef2141
      
       upstream.
      
      Sanity checks were added to verify the v4l2_bt_timings blanking fields
      in order to avoid integer overflows when userspace passes weird values.
      
      But that assumed that userspace would correctly fill in the front porch,
      backporch and sync values, but sometimes all you know is the total
      blanking, which is then assigned to just one of these fields.
      
      And that can fail with these checks.
      
      So instead set a maximum for the total horizontal and vertical
      blanking and check that each field remains below that.
      
      That is still sufficient to avoid integer overflows, but it also
      allows for more flexibility in how userspace fills in these fields.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Fixes: 4b6d66a4
      
       ("media: v4l2-dv-timings: add sanity checks for blanking values")
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6fb8bc29
    • Francesco Dolcini's avatar
      Revert "ARM: dts: imx7: Fix NAND controller size-cells" · a4c57554
      Francesco Dolcini authored
      commit ef19964d upstream.
      
      This reverts commit 753395ea.
      
      It introduced a boot regression on colibri-imx7, and potentially any
      other i.MX7 boards with MTD partition list generated into the fdt by
      U-Boot.
      
      While the commit we are reverting here is not obviously wrong, it fixes
      only a dt binding checker warning that is non-functional, while it
      introduces a boot regression and there is no obvious fix ready.
      
      Fixes: 753395ea
      
       ("ARM: dts: imx7: Fix NAND controller size-cells")
      Signed-off-by: default avatarFrancesco Dolcini <francesco.dolcini@toradex.com>
      Reviewed-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Acked-by: default avatarMarek Vasut <marex@denx.de>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/all/Y4dgBTGNWpM6SQXI@francesco-nb.int.toradex.com/
      Link: https://lore.kernel.org/all/20221205144917.6514168a@xps-13/
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a4c57554
    • Sjoerd Simons's avatar
      soundwire: intel: Initialize clock stop timeout · 28abc114
      Sjoerd Simons authored
      commit 13c30a75 upstream.
      
      The bus->clk_stop_timeout member is only initialized to a non-zero value
      during the codec driver probe. This can lead to corner cases where this
      value remains pegged at zero when the bus suspends, which results in an
      endless loop in sdw_bus_wait_for_clk_prep_deprep().
      
      Corner cases include configurations with no codecs described in the
      firmware, or delays in probing codec drivers.
      
      Initializing the default timeout to the smallest non-zero value avoid this
      problem and allows for the existing logic to be preserved: the
      bus->clk_stop_timeout is set as the maximum required by all codecs
      connected on the bus.
      
      Fixes: 1f2dcf3a
      
       ("soundwire: intel: set dev_num_ida_min")
      Signed-off-by: default avatarSjoerd Simons <sjoerd@collabora.com>
      Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
      Reviewed-by: default avatarChao Song <chao.song@intel.com>
      Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
      Link: https://lore.kernel.org/r/20221020015624.1703950-1-yung-chuan.liao@linux.intel.com
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      28abc114
    • Hans Verkuil's avatar
      media: videobuf2-core: take mmap_lock in vb2_get_unmapped_area() · 22d800b3
      Hans Verkuil authored
      [ Upstream commit 098e5edc ]
      
      While vb2_mmap took the mmap_lock mutex, vb2_get_unmapped_area didn't.
      Add this.
      
      Also take this opportunity to move the 'q->memory != VB2_MEMORY_MMAP'
      check and vb2_fileio_is_active() check into __find_plane_by_offset() so
      both vb2_mmap and vb2_get_unmapped_area do the same checks.
      
      Since q->memory is checked while mmap_lock is held, also take that lock
      in reqbufs and create_bufs when it is set, and set it back to
      MEMORY_UNKNOWN on error.
      
      Fixes: f035eb4e
      
       ("[media] videobuf2: fix lockdep warning")
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Acked-by: default avatarTomasz Figa <tfiga@chromium.org>
      Reviewed-by: default avatarRicardo Ribalda <ribalda@chromium.org>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      22d800b3
    • Juergen Gross's avatar
      xen/netback: don't call kfree_skb() with interrupts disabled · 5d0fa6fc
      Juergen Gross authored
      [ Upstream commit 74e7e1ef ]
      
      It is not allowed to call kfree_skb() from hardware interrupt
      context or with interrupts being disabled. So remove kfree_skb()
      from the spin_lock_irqsave() section and use the already existing
      "drop" label in xenvif_start_xmit() for dropping the SKB. At the
      same time replace the dev_kfree_skb() call there with a call of
      dev_kfree_skb_any(), as xenvif_start_xmit() can be called with
      disabled interrupts.
      
      This is XSA-424 / CVE-2022-42328 / CVE-2022-42329.
      
      Fixes: be81992f
      
       ("xen/netback: don't queue unlimited number of packages")
      Reported-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Reviewed-by: default avatarJan Beulich <jbeulich@suse.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5d0fa6fc
    • Juergen Gross's avatar
      xen/netback: do some code cleanup · 4422241c
      Juergen Gross authored
      [ Upstream commit 5834e72e
      
       ]
      
      Remove some unused macros and functions, make local functions static.
      
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Acked-by: default avatarWei Liu <wei.liu@kernel.org>
      Link: https://lore.kernel.org/r/20220608043726.9380-1-jgross@suse.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: 74e7e1ef
      
       ("xen/netback: don't call kfree_skb() with interrupts disabled")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4422241c
    • Ross Lagerwall's avatar
      xen/netback: Ensure protocol headers don't fall in the non-linear area · 0fe29bd9
      Ross Lagerwall authored
      [ Upstream commit ad7f402a ]
      
      In some cases, the frontend may send a packet where the protocol headers
      are spread across multiple slots. This would result in netback creating
      an skb where the protocol headers spill over into the non-linear area.
      Some drivers and NICs don't handle this properly resulting in an
      interface reset or worse.
      
      This issue was introduced by the removal of an unconditional skb pull in
      the tx path to improve performance.  Fix this without reintroducing the
      pull by setting up grant copy ops for as many slots as needed to reach
      the XEN_NETBACK_TX_COPY_LEN size. Adjust the rest of the code to handle
      multiple copy operations per skb.
      
      This is XSA-423 / CVE-2022-3643.
      
      Fixes: 7e5d7753
      
       ("xen-netback: remove unconditional __pskb_pull_tail() in guest Tx path")
      Signed-off-by: default avatarRoss Lagerwall <ross.lagerwall@citrix.com>
      Reviewed-by: default avatarPaul Durrant <paul@xen.org>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0fe29bd9
    • Hsin-Yi Wang's avatar
      drm/bridge: anx7625: Fix edid_read break case in sp_tx_edid_read() · f01677be
      Hsin-Yi Wang authored
      [ Upstream commit 0bae5687 ]
      
      edid_read() was assumed to return 0 on success. After commit
      7f16d0f3("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()"),
      the function will return > 0 for successful case, representing the i2c
      read bytes. Otherwise -EIO on failure cases. Update the g_edid_break
      break condition accordingly.
      
      Fixes: 7f16d0f3
      
      ("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()")
      Signed-off-by: default avatarHsin-Yi Wang <hsinyi@chromium.org>
      Reviewed-by: default avatarRobert Foss <robert.foss@linaro.org>
      Reviewed-by: default avatarXin Ji <xji@analogixsemi.com>
      Signed-off-by: default avatarRobert Foss <robert.foss@linaro.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/20211118193002.407168-1-hsinyi@chromium.org
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f01677be
    • Zeng Heng's avatar
      cifs: fix use-after-free caused by invalid pointer `hostname` · ee253683
      Zeng Heng authored
      [ Upstream commit 153695d3 ]
      
      `hostname` needs to be set as null-pointer after free in
      `cifs_put_tcp_session` function, or when `cifsd` thread attempts
      to resolve hostname and reconnect the host, the thread would deref
      the invalid pointer.
      
      Here is one of practical backtrace examples as reference:
      
      Task 477
      ---------------------------
       do_mount
        path_mount
         do_new_mount
          vfs_get_tree
           smb3_get_tree
            smb3_get_tree_common
             cifs_smb3_do_mount
              cifs_mount
               mount_put_conns
                cifs_put_tcp_session
                --> kfree(server->hostname)
      
      cifsd
      ---------------------------
       kthread
        cifs_demultiplex_thread
         cifs_reconnect
          reconn_set_ipaddr_from_hostname
          --> if (!server->hostname)
          --> if (server->hostname[0] == '\0')  // !! UAF fault here
      
      CIFS: VFS: cifs_mount failed w/return code = -112
      mount error(112): Host is down
      BUG: KASAN: use-after-free in reconn_set_ipaddr_from_hostname+0x2ba/0x310
      Read of size 1 at addr ffff888108f35380 by task cifsd/480
      CPU: 2 PID: 480 Comm: cifsd Not tainted 6.1.0-rc2-00106-gf705792f89dd-dirty #25
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x68/0x85
       print_report+0x16c/0x4a3
       kasan_report+0x95/0x190
       reconn_set_ipaddr_from_hostname+0x2ba/0x310
       __cifs_reconnect.part.0+0x241/0x800
       cifs_reconnect+0x65f/0xb60
       cifs_demultiplex_thread+0x1570/0x2570
       kthread+0x2c5/0x380
       ret_from_fork+0x22/0x30
       </TASK>
      Allocated by task 477:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       __kasan_kmalloc+0x7e/0x90
       __kmalloc_node_track_caller+0x52/0x1b0
       kstrdup+0x3b/0x70
       cifs_get_tcp_session+0xbc/0x19b0
       mount_get_conns+0xa9/0x10c0
       cifs_mount+0xdf/0x1970
       cifs_smb3_do_mount+0x295/0x1660
       smb3_get_tree+0x352/0x5e0
       vfs_get_tree+0x8e/0x2e0
       path_mount+0xf8c/0x1990
       do_mount+0xee/0x110
       __x64_sys_mount+0x14b/0x1f0
       do_syscall_64+0x3b/0x90
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      Freed by task 477:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       kasan_save_free_info+0x2a/0x50
       __kasan_slab_free+0x10a/0x190
       __kmem_cache_free+0xca/0x3f0
       cifs_put_tcp_session+0x30c/0x450
       cifs_mount+0xf95/0x1970
       cifs_smb3_do_mount+0x295/0x1660
       smb3_get_tree+0x352/0x5e0
       vfs_get_tree+0x8e/0x2e0
       path_mount+0xf8c/0x1990
       do_mount+0xee/0x110
       __x64_sys_mount+0x14b/0x1f0
       do_syscall_64+0x3b/0x90
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      The buggy address belongs to the object at ffff888108f35380
       which belongs to the cache kmalloc-16 of size 16
      The buggy address is located 0 bytes inside of
       16-byte region [ffff888108f35380, ffff888108f35390)
      The buggy address belongs to the physical page:
      page:00000000333f8e58 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888108f350e0 pfn:0x108f35
      flags: 0x200000000000200(slab|node=0|zone=2)
      raw: 0200000000000200 0000000000000000 dead000000000122 ffff8881000423c0
      raw: ffff888108f350e0 000000008080007a 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      Memory state around the buggy address:
       ffff888108f35280: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
       ffff888108f35300: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
      >ffff888108f35380: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
                         ^
       ffff888108f35400: fa fb fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       ffff888108f35480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      
      Fixes: 7be3248f
      
       ("cifs: To match file servers, make sure the server hostname matches")
      Signed-off-by: default avatarZeng Heng <zengheng4@huawei.com>
      Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ee253683
    • Mateusz Jończyk's avatar
      rtc: cmos: avoid UIP when reading alarm time · dc62f05f
      Mateusz Jończyk authored
      [ Upstream commit cdedc45c
      
       ]
      
      Some Intel chipsets disconnect the time and date RTC registers when the
      clock update is in progress: during this time reads may return bogus
      values and writes fail silently. This includes the RTC alarm registers.
      [1]
      
      cmos_read_alarm() did not take account for that, which caused alarm time
      reads to sometimes return bogus values. This can be shown with a test
      patch that I am attaching to this patch series.
      
      Fix this, by using mc146818_avoid_UIP().
      
      [1] 7th Generation Intel ® Processor Family I/O for U/Y Platforms [...]
      Datasheet, Volume 1 of 2 (Intel's Document Number: 334658-006)
      Page 208
      https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/7th-and-8th-gen-core-family-mobile-u-y-processor-lines-i-o-datasheet-vol-1.pdf
              "If a RAM read from the ten time and date bytes is attempted
              during an update cycle, the value read do not necessarily
              represent the true contents of those locations. Any RAM writes
              under the same conditions are ignored."
      
      Signed-off-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
      Cc: Alessandro Zummo <a.zummo@towertech.it>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20211210200131.153887-9-mat.jonczyk@o2.pl
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dc62f05f
    • Mateusz Jończyk's avatar
      rtc: cmos: avoid UIP when writing alarm time · 48ea4199
      Mateusz Jończyk authored
      [ Upstream commit cd17420e
      
       ]
      
      Some Intel chipsets disconnect the time and date RTC registers when the
      clock update is in progress: during this time reads may return bogus
      values and writes fail silently. This includes the RTC alarm registers.
      [1]
      
      cmos_set_alarm() did not take account for that, fix it.
      
      [1] 7th Generation Intel ® Processor Family I/O for U/Y Platforms [...]
      Datasheet, Volume 1 of 2 (Intel's Document Number: 334658-006)
      Page 208
      https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/7th-and-8th-gen-core-family-mobile-u-y-processor-lines-i-o-datasheet-vol-1.pdf
              "If a RAM read from the ten time and date bytes is attempted
              during an update cycle, the value read do not necessarily
              represent the true contents of those locations. Any RAM writes
              under the same conditions are ignored."
      
      Signed-off-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
      Cc: Alessandro Zummo <a.zummo@towertech.it>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20211210200131.153887-10-mat.jonczyk@o2.pl
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      48ea4199
    • Mateusz Jończyk's avatar
      rtc: mc146818-lib: extract mc146818_avoid_UIP · 3f52afc6
      Mateusz Jończyk authored
      [ Upstream commit ec5895c0
      
       ]
      
      Function mc146818_get_time() contains an elaborate mechanism of reading
      the RTC time while no RTC update is in progress. It turns out that
      reading the RTC alarm clock also requires avoiding the RTC update.
      Therefore, the mechanism in mc146818_get_time() should be reused - so
      extract it into a separate function.
      
      The logic in mc146818_avoid_UIP() is same as in mc146818_get_time()
      except that after every
      
              if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) {
      
      there is now "mdelay(1)".
      
      To avoid producing a very unreadable patch, mc146818_get_time() will be
      refactored to use mc146818_avoid_UIP() in the next patch.
      
      Signed-off-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
      Cc: Alessandro Zummo <a.zummo@towertech.it>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20211210200131.153887-6-mat.jonczyk@o2.pl
      Stable-dep-of: cd17420e
      
       ("rtc: cmos: avoid UIP when writing alarm time")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3f52afc6
    • Jann Horn's avatar
      mm/khugepaged: invoke MMU notifiers in shmem/file collapse paths · 1a3f8c6c
      Jann Horn authored
      commit f268f6cf upstream.
      
      Any codepath that zaps page table entries must invoke MMU notifiers to
      ensure that secondary MMUs (like KVM) don't keep accessing pages which
      aren't mapped anymore.  Secondary MMUs don't hold their own references to
      pages that are mirrored over, so failing to notify them can lead to page
      use-after-free.
      
      I'm marking this as addressing an issue introduced in commit f3f0e1d2
      ("khugepaged: add support of collapse for tmpfs/shmem pages"), but most of
      the security impact of this only came in commit 27e1f827 ("khugepaged:
      enable collapse pmd for pte-mapped THP"), which actually omitted flushes
      for the removal of present PTEs, not just for the removal of empty page
      tables.
      
      Link: https://lkml.kernel.org/r/20221129154730.2274278-3-jannh@google.com
      Link: https://lkml.kernel.org/r/20221128180252.1684965-3-jannh@google.com
      Link: https://lkml.kernel.org/r/20221125213714.4115729-3-jannh@google.com
      Fixes: f3f0e1d2
      
       ("khugepaged: add support of collapse for tmpfs/shmem pages")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Reviewed-by: default avatarYang Shi <shy828301@gmail.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      [manual backport: this code was refactored from two copies into a common
      helper between 5.15 and 6.0]
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1a3f8c6c
    • Jann Horn's avatar
      mm/khugepaged: fix GUP-fast interaction by sending IPI · 79ad784c
      Jann Horn authored
      commit 2ba99c5e upstream.
      
      Since commit 70cbc3cc ("mm: gup: fix the fast GUP race against THP
      collapse"), the lockless_pages_from_mm() fastpath rechecks the pmd_t to
      ensure that the page table was not removed by khugepaged in between.
      
      However, lockless_pages_from_mm() still requires that the page table is
      not concurrently freed.  Fix it by sending IPIs (if the architecture uses
      semi-RCU-style page table freeing) before freeing/reusing page tables.
      
      Link: https://lkml.kernel.org/r/20221129154730.2274278-2-jannh@google.com
      Link: https://lkml.kernel.org/r/20221128180252.1684965-2-jannh@google.com
      Link: https://lkml.kernel.org/r/20221125213714.4115729-2-jannh@google.com
      Fixes: ba76149f
      
       ("thp: khugepaged")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Reviewed-by: default avatarYang Shi <shy828301@gmail.com>
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      [manual backport: two of the three places in khugepaged that can free
      ptes were refactored into a common helper between 5.15 and 6.0]
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      79ad784c
    • Jann Horn's avatar
      mm/khugepaged: take the right locks for page table retraction · d15cd6de
      Jann Horn authored
      commit 8d3c106e upstream.
      
      pagetable walks on address ranges mapped by VMAs can be done under the
      mmap lock, the lock of an anon_vma attached to the VMA, or the lock of the
      VMA's address_space.  Only one of these needs to be held, and it does not
      need to be held in exclusive mode.
      
      Under those circumstances, the rules for concurrent access to page table
      entries are:
      
       - Terminal page table entries (entries that don't point to another page
         table) can be arbitrarily changed under the page table lock, with the
         exception that they always need to be consistent for
         hardware page table walks and lockless_pages_from_mm().
         This includes that they can be changed into non-terminal entries.
       - Non-terminal page table entries (which point to another page table)
         can not be modified; readers are allowed to READ_ONCE() an entry, verify
         that it is non-terminal, and then assume that its value will stay as-is.
      
      Retracting a page table involves modifying a non-terminal entry, so
      page-table-level locks are insufficient to protect against concurrent page
      table traversal; it requires taking all the higher-level locks under which
      it is possible to start a page walk in the relevant range in exclusive
      mode.
      
      The collapse_huge_page() path for anonymous THP already follows this rule,
      but the shmem/file THP path was getting it wrong, making it possible for
      concurrent rmap-based operations to cause corruption.
      
      Link: https://lkml.kernel.org/r/20221129154730.2274278-1-jannh@google.com
      Link: https://lkml.kernel.org/r/20221128180252.1684965-1-jannh@google.com
      Link: https://lkml.kernel.org/r/20221125213714.4115729-1-jannh@google.com
      Fixes: 27e1f827
      
       ("khugepaged: enable collapse pmd for pte-mapped THP")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Reviewed-by: default avatarYang Shi <shy828301@gmail.com>
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      [manual backport: this code was refactored from two copies into a common
      helper between 5.15 and 6.0]
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d15cd6de
    • Davide Tronchin's avatar
      net: usb: qmi_wwan: add u-blox 0x1342 composition · 26f084e5
      Davide Tronchin authored
      [ Upstream commit a487069e
      
       ]
      
      Add RmNet support for LARA-L6.
      
      LARA-L6 module can be configured (by AT interface) in three different
      USB modes:
      * Default mode (Vendor ID: 0x1546 Product ID: 0x1341) with 4 serial
      interfaces
      * RmNet mode (Vendor ID: 0x1546 Product ID: 0x1342) with 4 serial
      interfaces and 1 RmNet virtual network interface
      * CDC-ECM mode (Vendor ID: 0x1546 Product ID: 0x1343) with 4 serial
      interface and 1 CDC-ECM virtual network interface
      
      In RmNet mode LARA-L6 exposes the following interfaces:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: AT parset/alternative functions
      If 4: RMNET interface
      
      Signed-off-by: default avatarDavide Tronchin <davide.tronchin.94@gmail.com>
      Acked-by: default avatarBjørn Mork <bjorn@mork.no>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      26f084e5
    • Dominique Martinet's avatar
      9p/xen: check logical size for buffer size · 029a7f1c
      Dominique Martinet authored
      [ Upstream commit 391c18cf
      
       ]
      
      trans_xen did not check the data fits into the buffer before copying
      from the xen ring, but we probably should.
      Add a check that just skips the request and return an error to
      userspace if it did not fit
      
      Tested-by: default avatarStefano Stabellini <sstabellini@kernel.org>
      Reviewed-by: default avatarChristian Schoenebeck <linux_oss@crudebyte.com>
      Link: https://lkml.kernel.org/r/20221118135542.63400-1-asmadeus@codewreck.org
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      029a7f1c
    • Thinh Nguyen's avatar
      usb: dwc3: gadget: Disable GUSB2PHYCFG.SUSPHY for End Transfer · b3988328
      Thinh Nguyen authored
      [ Upstream commit 3aa07f72
      
       ]
      
      If there's a disconnection while operating in eSS, there may be a delay
      in VBUS drop response from the connector. In that case, the internal
      link state may drop to operate in usb2 speed while the controller thinks
      the VBUS is still high. The driver must make sure to disable
      GUSB2PHYCFG.SUSPHY when sending endpoint command while in usb2 speed.
      The End Transfer command may be called, and only that command needs to
      go through at this point. Let's keep it simple and unconditionally
      disable GUSB2PHYCFG.SUSPHY whenever we issue the command.
      
      This scenario is not seen in real hardware. In a rare case, our
      prototype type-c controller/interface may have a slow response
      triggerring this issue.
      
      Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
      Link: https://lore.kernel.org/r/5651117207803c26e2f22ddf4e5ce9e865dcf7c7.1668045468.git.Thinh.Nguyen@synopsys.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b3988328
    • Tetsuo Handa's avatar
      fbcon: Use kzalloc() in fbcon_prepare_logo() · e70a5724
      Tetsuo Handa authored
      [ Upstream commit a6a00d7e
      
       ]
      
      A kernel built with syzbot's config file reported that
      
        scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2))
      
      causes uninitialized "save" to be copied.
      
        ----------
        [drm] Initialized vgem 1.0.0 20120112 for vgem on minor 0
        [drm] Initialized vkms 1.0.0 20180514 for vkms on minor 1
        Console: switching to colour frame buffer device 128x48
        =====================================================
        BUG: KMSAN: uninit-value in do_update_region+0x4b8/0xba0
         do_update_region+0x4b8/0xba0
         update_region+0x40d/0x840
         fbcon_switch+0x3364/0x35e0
         redraw_screen+0xae3/0x18a0
         do_bind_con_driver+0x1cb3/0x1df0
         do_take_over_console+0x11cb/0x13f0
         fbcon_fb_registered+0xacc/0xfd0
         register_framebuffer+0x1179/0x1320
         __drm_fb_helper_initial_config_and_unlock+0x23ad/0x2b40
         drm_fbdev_client_hotplug+0xbea/0xda0
         drm_fbdev_generic_setup+0x65e/0x9d0
         vkms_init+0x9f3/0xc76
         (...snipped...)
      
        Uninit was stored to memory at:
         fbcon_prepare_logo+0x143b/0x1940
         fbcon_init+0x2c1b/0x31c0
         visual_init+0x3e7/0x820
         do_bind_con_driver+0x14a4/0x1df0
         do_take_over_console+0x11cb/0x13f0
         fbcon_fb_registered+0xacc/0xfd0
         register_framebuffer+0x1179/0x1320
         __drm_fb_helper_initial_config_and_unlock+0x23ad/0x2b40
         drm_fbdev_client_hotplug+0xbea/0xda0
         drm_fbdev_generic_setup+0x65e/0x9d0
         vkms_init+0x9f3/0xc76
         (...snipped...)
      
        Uninit was created at:
         __kmem_cache_alloc_node+0xb69/0x1020
         __kmalloc+0x379/0x680
         fbcon_prepare_logo+0x704/0x1940
         fbcon_init+0x2c1b/0x31c0
         visual_init+0x3e7/0x820
         do_bind_con_driver+0x14a4/0x1df0
         do_take_over_console+0x11cb/0x13f0
         fbcon_fb_registered+0xacc/0xfd0
         register_framebuffer+0x1179/0x1320
         __drm_fb_helper_initial_config_and_unlock+0x23ad/0x2b40
         drm_fbdev_client_hotplug+0xbea/0xda0
         drm_fbdev_generic_setup+0x65e/0x9d0
         vkms_init+0x9f3/0xc76
         (...snipped...)
      
        CPU: 2 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc4-00356-g8f2975c2bb4c #924
        Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
        ----------
      
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/cad03d25-0ea0-32c4-8173-fd1895314bce@I-love.SAKURA.ne.jp
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e70a5724
    • Andreas Kemnade's avatar
      regulator: twl6030: fix get status of twl6032 regulators · fd376859
      Andreas Kemnade authored
      [ Upstream commit 31a6297b
      
       ]
      
      Status is reported as always off in the 6032 case. Status
      reporting now matches the logic in the setters. Once of
      the differences to the 6030 is that there are no groups,
      therefore the state needs to be read out in the lower bits.
      
      Signed-off-by: default avatarAndreas Kemnade <andreas@kemnade.info>
      Link: https://lore.kernel.org/r/20221120221208.3093727-3-andreas@kemnade.info
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fd376859
    • Srinivasa Rao Mandadapu's avatar
      ASoC: soc-pcm: Add NULL check in BE reparenting · 9f74b9aa
      Srinivasa Rao Mandadapu authored
      [ Upstream commit db8f91d4
      
       ]
      
      Add NULL check in dpcm_be_reparent API, to handle
      kernel NULL pointer dereference error.
      The issue occurred in fuzzing test.
      
      Signed-off-by: default avatarSrinivasa Rao Mandadapu <quic_srivasam@quicinc.com>
      Link: https://lore.kernel.org/r/1669098673-29703-1-git-send-email-quic_srivasam@quicinc.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9f74b9aa
    • Filipe Manana's avatar
      btrfs: send: avoid unaligned encoded writes when attempting to clone range · dae93f41
      Filipe Manana authored
      [ Upstream commit a11452a3
      
       ]
      
      When trying to see if we can clone a file range, there are cases where we
      end up sending two write operations in case the inode from the source root
      has an i_size that is not sector size aligned and the length from the
      current offset to its i_size is less than the remaining length we are
      trying to clone.
      
      Issuing two write operations when we could instead issue a single write
      operation is not incorrect. However it is not optimal, specially if the
      extents are compressed and the flag BTRFS_SEND_FLAG_COMPRESSED was passed
      to the send ioctl. In that case we can end up sending an encoded write
      with an offset that is not sector size aligned, which makes the receiver
      fallback to decompressing the data and writing it using regular buffered
      IO (so re-compressing the data in case the fs is mounted with compression
      enabled), because encoded writes fail with -EINVAL when an offset is not
      sector size aligned.
      
      The following example, which triggered a bug in the receiver code for the
      fallback logic of decompressing + regular buffer IO and is fixed by the
      patchset referred in a Link at the bottom of this changelog, is an example
      where we have the non-optimal behaviour due to an unaligned encoded write:
      
         $ cat test.sh
         #!/bin/bash
      
         DEV=/dev/sdj
         MNT=/mnt/sdj
      
         mkfs.btrfs -f $DEV > /dev/null
         mount -o compress $DEV $MNT
      
         # File foo has a size of 33K, not aligned to the sector size.
         xfs_io -f -c "pwrite -S 0xab 0 33K" $MNT/foo
      
         xfs_io -f -c "pwrite -S 0xcd 0 64K" $MNT/bar
      
         # Now clone the first 32K of file bar into foo at offset 0.
         xfs_io -c "reflink $MNT/bar 0 0 32K" $MNT/foo
      
         # Snapshot the default subvolume and create a full send stream (v2).
         btrfs subvolume snapshot -r $MNT $MNT/snap
      
         btrfs send --compressed-data -f /tmp/test.send $MNT/snap
      
         echo -e "\nFile bar in the original filesystem:"
         od -A d -t x1 $MNT/snap/bar
      
         umount $MNT
         mkfs.btrfs -f $DEV > /dev/null
         mount $DEV $MNT
      
         echo -e "\nReceiving stream in a new filesystem..."
         btrfs receive -f /tmp/test.send $MNT
      
         echo -e "\nFile bar in the new filesystem:"
         od -A d -t x1 $MNT/snap/bar
      
         umount $MNT
      
      Before this patch, the send stream included one regular write and one
      encoded write for file 'bar', with the later being not sector size aligned
      and causing the receiver to fallback to decompression + buffered writes.
      The output of the btrfs receive command in verbose mode (-vvv):
      
         (...)
         mkfile o258-7-0
         rename o258-7-0 -> bar
         utimes
         clone bar - source=foo source offset=0 offset=0 length=32768
         write bar - offset=32768 length=1024
         encoded_write bar - offset=33792, len=4096, unencoded_offset=33792, unencoded_file_len=31744, unencoded_len=65536, compression=1, encryption=0
         encoded_write bar - falling back to decompress and write due to errno 22 ("Invalid argument")
         (...)
      
      This patch avoids the regular write followed by an unaligned encoded write
      so that we end up sending a single encoded write that is aligned. So after
      this patch the stream content is (output of btrfs receive -vvv):
      
         (...)
         mkfile o258-7-0
         rename o258-7-0 -> bar
         utimes
         clone bar - source=foo source offset=0 offset=0 length=32768
         encoded_write bar - offset=32768, len=4096, unencoded_offset=32768, unencoded_file_len=32768, unencoded_len=65536, compression=1, encryption=0
         (...)
      
      So we get more optimal behaviour and avoid the silent data loss bug in
      versions of btrfs-progs affected by the bug referred by the Link tag
      below (btrfs-progs v5.19, v5.19.1, v6.0 and v6.0.1).
      
      Link: https://lore.kernel.org/linux-btrfs/cover.1668529099.git.fdmanana@suse.com/
      Reviewed-by: default avatarBoris Burkov <boris@bur.io>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dae93f41
    • Daniel Díaz's avatar
      selftests/net: Find nettest in current directory · f54e1edf
      Daniel Díaz authored
      [ Upstream commit bd5e1e42
      
       ]
      
      The `nettest` binary, built from `selftests/net/nettest.c`,
      was expected to be found in the path during test execution of
      `fcnal-test.sh` and `pmtu.sh`, leading to tests getting
      skipped when the binary is not installed in the system, as can
      be seen in these logs found in the wild [1]:
      
        # TEST: vti4: PMTU exceptions                                         [SKIP]
        [  350.600250] IPv6: ADDRCONF(NETDEV_CHANGE): veth_b: link becomes ready
        [  350.607421] IPv6: ADDRCONF(NETDEV_CHANGE): veth_a: link becomes ready
        # 'nettest' command not found; skipping tests
        #   xfrm6udp not supported
        # TEST: vti6: PMTU exceptions (ESP-in-UDP)                            [SKIP]
        [  351.605102] IPv6: ADDRCONF(NETDEV_CHANGE): veth_b: link becomes ready
        [  351.612243] IPv6: ADDRCONF(NETDEV_CHANGE): veth_a: link becomes ready
        # 'nettest' command not found; skipping tests
        #   xfrm4udp not supported
      
      The `unicast_extensions.sh` tests also rely on `nettest`, but
      it runs fine there because it looks for the binary in the
      current working directory [2]:
      
      The same mechanism that works for the Unicast extensions tests
      is here copied over to the PMTU and functional tests.
      
      [1] https://lkft.validation.linaro.org/scheduler/job/5839508#L6221
      [2] https://lkft.validation.linaro.org/scheduler/job/5839508#L7958
      
      Signed-off-by: default avatarDaniel Díaz <daniel.diaz@linaro.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f54e1edf
    • Kees Cook's avatar
      ALSA: seq: Fix function prototype mismatch in snd_seq_expand_var_event · fccd4541
      Kees Cook authored
      [ Upstream commit 05530ef7
      
       ]
      
      With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG),
      indirect call targets are validated against the expected function
      pointer prototype to make sure the call target is valid to help mitigate
      ROP attacks. If they are not identical, there is a failure at run time,
      which manifests as either a kernel panic or thread getting killed.
      
      seq_copy_in_user() and seq_copy_in_kernel() did not have prototypes
      matching snd_seq_dump_func_t. Adjust this and remove the casts. There
      are not resulting binary output differences.
      
      This was found as a result of Clang's new -Wcast-function-type-strict
      flag, which is more sensitive than the simpler -Wcast-function-type,
      which only checks for type width mismatches.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Link: https://lore.kernel.org/lkml/202211041527.HD8TLSE1-lkp@intel.com
      Cc: Jaroslav Kysela <perex@perex.cz>
      Cc: Takashi Iwai <tiwai@suse.com>
      Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
      Cc: alsa-devel@alsa-project.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20221118232346.never.380-kees@kernel.org
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fccd4541
    • Konrad Dybcio's avatar
      regulator: slg51000: Wait after asserting CS pin · 542a563b
      Konrad Dybcio authored
      [ Upstream commit 0b24dfa5
      
       ]
      
      Sony's downstream driver [1], among some other changes, adds a
      seemingly random 10ms usleep_range, which turned out to be necessary
      for the hardware to function properly on at least Sony Xperia 1 IV.
      Without this, I2C transactions with the SLG51000 straight up fail.
      
      Relax (10-10ms -> 10-11ms) and add the aforementioned sleep to make
      sure the hardware has some time to wake up.
      
      (nagara-2.0.0-mlc/vendor/semc/hardware/camera-kernel-module/)
      [1] https://developer.sony.com/file/download/open-source-archive-for-64-0-m-4-29/
      
      Signed-off-by: default avatarKonrad Dybcio <konrad.dybcio@linaro.org>
      Link: https://lore.kernel.org/r/20221118131035.54874-1-konrad.dybcio@linaro.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      542a563b
    • GUO Zihua's avatar
      9p/fd: Use P9_HDRSZ for header size · 3d1b5fde
      GUO Zihua authored
      [ Upstream commit 6854fadb
      
       ]
      
      Cleanup hardcoded header sizes to use P9_HDRSZ instead of '7'
      
      Link: https://lkml.kernel.org/r/20221117091159.31533-4-guozihua@huawei.com
      Signed-off-by: default avatarGUO Zihua <guozihua@huawei.com>
      Reviewed-by: default avatarChristian Schoenebeck <linux_oss@crudebyte.com>
      [Dominique: commit message adjusted to make sense after offset size
      adjustment got removed]
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3d1b5fde
    • Shuming Fan's avatar
      ASoC: rt711-sdca: fix the latency time of clock stop prepare state machine transitions · fe2d44e8
      Shuming Fan authored
      [ Upstream commit c7d7d4e7
      
       ]
      
      Due to the hardware behavior, it takes some time for CBJ detection/impedance sensing/de-bounce.
      The ClockStop_NotFinished flag will be raised until these functions are completed.
      In ClockStopMode0 mode case, the SdW controller might check this flag from D3 to D0 when the
      jack detection interrupt happened.
      
      Signed-off-by: default avatarShuming Fan <shumingf@realtek.com>
      Link: https://lore.kernel.org/r/20221116090318.5017-1-shumingf@realtek.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fe2d44e8
    • Johan Jonker's avatar
      ARM: dts: rockchip: disable arm_global_timer on rk3066 and rk3188 · e945f3d8
      Johan Jonker authored
      [ Upstream commit da74858a
      
       ]
      
      The clock source and the sched_clock provided by the arm_global_timer
      on Rockchip rk3066a/rk3188 are quite unstable because their rates
      depend on the CPU frequency.
      
      Recent changes to the arm_global_timer driver makes it impossible to use.
      
      On the other side, the arm_global_timer has a higher rating than the
      ROCKCHIP_TIMER, it will be selected by default by the time framework
      while we want to use the stable Rockchip clock source.
      
      Keep the arm_global_timer disabled in order to have the
      DW_APB_TIMER (rk3066a) or ROCKCHIP_TIMER (rk3188) selected by default.
      
      Signed-off-by: default avatarJohan Jonker <jbx6244@gmail.com>
      Link: https://lore.kernel.org/r/f275ca8d-fd0a-26e5-b978-b7f3df815e0a@gmail.com
      Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e945f3d8
    • Zhichao Liu's avatar
      spi: mediatek: Fix DEVAPC Violation at KO Remove · c3b818c9
      Zhichao Liu authored
      [ Upstream commit 0d10e90c
      
       ]
      
      A DEVAPC violation occurs when removing the module
      due to accessing HW registers without base clock.
      To fix this bug, the correct method is:
      1. Call the runtime resume function to enable the
         clock;
      2. Operate the registers to reset the HW;
      3. Turn off the clocks and disable the device
         RPM mechanism.
      
      Signed-off-by: default avatarZhichao Liu <zhichao.liu@mediatek.com>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Link: https://lore.kernel.org/r/20221110072839.30961-1-zhichao.liu@mediatek.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c3b818c9
    • Chancel Liu's avatar
      ASoC: wm8962: Wait for updated value of WM8962_CLOCKING1 register · d9f0107b
      Chancel Liu authored
      [ Upstream commit 3ca507bf
      
       ]
      
      DSPCLK_DIV field in WM8962_CLOCKING1 register is used to generate
      correct frequency of LRCLK and BCLK. Sometimes the read-only value
      can't be updated timely after enabling SYSCLK. This results in wrong
      calculation values. Delay is introduced here to wait for newest value
      from register. The time of the delay should be at least 500~1000us
      according to test.
      
      Signed-off-by: default avatarChancel Liu <chancel.liu@nxp.com>
      Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Link: https://lore.kernel.org/r/20221109121354.123958-1-chancel.liu@nxp.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d9f0107b
    • Giulio Benetti's avatar
      ARM: 9266/1: mm: fix no-MMU ZERO_PAGE() implementation · 7ae02627
      Giulio Benetti authored
      [ Upstream commit 340a9828 ]
      
      Actually in no-MMU SoCs(i.e. i.MXRT) ZERO_PAGE(vaddr) expands to
      ```
      virt_to_page(0)
      ```
      that in order expands to:
      ```
      pfn_to_page(virt_to_pfn(0))
      ```
      and then virt_to_pfn(0) to:
      ```
              ((((unsigned long)(0) - PAGE_OFFSET) >> PAGE_SHIFT) +
               PHYS_PFN_OFFSET)
      ```
      where PAGE_OFFSET and PHYS_PFN_OFFSET are the DRAM offset(0x80000000) and
      PAGE_SHIFT is 12. This way we obtain 16MB(0x01000000) summed to the base of
      DRAM(0x80000000).
      When ZERO_PAGE(0) is then used, for example in bio_add_page(), the page
      gets an address that is out of DRAM bounds.
      So instead of using fake virtual page 0 let's allocate a dedicated
      zero_page during paging_init() and assign it to a global 'struct page *
      empty_zero_page' the same way mmu.c does and it's the same approach used
      in m68k with commit dc068f46
      
       as discussed here[0]. Then let's move
      ZERO_PAGE() definition to the top of pgtable.h to be in common between
      mmu.c and nommu.c.
      
      [0]: https://lore.kernel.org/linux-m68k/2a462b23-5b8e-bbf4-ec7d-778434a3b9d7@google.com/T/#m1266ceb63
      ad140743174d6b3070364d3c9a5179b
      
      Signed-off-by: default avatarGiulio Benetti <giulio.benetti@benettiengineering.com>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7ae02627
    • Tomislav Novak's avatar
      ARM: 9251/1: perf: Fix stacktraces for tracepoint events in THUMB2 kernels · d81c62e3
      Tomislav Novak authored
      [ Upstream commit 612695bc
      
       ]
      
      Store the frame address where arm_get_current_stackframe() looks for it
      (ARM_r7 instead of ARM_fp if CONFIG_THUMB2_KERNEL=y). Otherwise frame->fp
      gets set to 0, causing unwind_frame() to fail.
      
        # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
        Attaching 1 probe...
        @[
            __schedule+1059
        ]: 1
      
      A typical first unwind instruction is 0x97 (SP = R7), so after executing
      it SP ends up being 0 and -URC_FAILURE is returned.
      
        unwind_frame(pc = ac9da7d7 lr = 00000000 sp = c69bdda0 fp = 00000000)
        unwind_find_idx(ac9da7d7)
        unwind_exec_insn: insn = 00000097
        unwind_exec_insn: fp = 00000000 sp = 00000000 lr = 00000000 pc = 00000000
      
      With this patch:
      
        # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
        Attaching 1 probe...
        @[
            __schedule+1059
            __schedule+1059
            schedule+79
            schedule_hrtimeout_range_clock+163
            schedule_hrtimeout_range+17
            ep_poll+471
            SyS_epoll_wait+111
            sys_epoll_pwait+231
            __ret_fast_syscall+1
        ]: 1
      
      Link: https://lore.kernel.org/r/20220920230728.2617421-1-tnovak@fb.com/
      
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarTomislav Novak <tnovak@fb.com>
      Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d81c62e3
    • Jann Horn's avatar
      fs: use acquire ordering in __fget_light() · 66717ad0
      Jann Horn authored
      [ Upstream commit 7ee47dcf
      
       ]
      
      We must prevent the CPU from reordering the files->count read with the
      FD table access like this, on architectures where read-read reordering is
      possible:
      
          files_lookup_fd_raw()
                                        close_fd()
                                        put_files_struct()
          atomic_read(&files->count)
      
      I would like to mark this for stable, but the stable rules explicitly say
      "no theoretical races", and given that the FD table pointer and
      files->count are explicitly stored in the same cacheline, this sort of
      reordering seems quite unlikely in practice...
      
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      66717ad0
    • Johan Jonker's avatar
      ARM: dts: rockchip: rk3188: fix lcdc1-rgb24 node name · 1222e236
      Johan Jonker authored
      [ Upstream commit 11871e20
      
       ]
      
      The lcdc1-rgb24 node name is out of line with the rest
      of the rk3188 lcdc1 node, so fix it.
      
      Signed-off-by: default avatarJohan Jonker <jbx6244@gmail.com>
      Link: https://lore.kernel.org/r/7b9c0a6f-626b-07e8-ae74-7e0f08b8d241@gmail.com
      Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1222e236
    • Johan Jonker's avatar
      arm64: dts: rockchip: fix ir-receiver node names · 996fb29b
      Johan Jonker authored
      [ Upstream commit de0d04b9
      
       ]
      
      Fix ir-receiver node names on Rockchip boards,
      so that they match with regex: '^ir(-receiver)?(@[a-f0-9]+)?$'
      
      Signed-off-by: default avatarJohan Jonker <jbx6244@gmail.com>
      Link: https://lore.kernel.org/r/e9764253-8ce8-150b-4820-41f03f845469@gmail.com
      Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      996fb29b