Skip to content
Snippets Groups Projects
  1. Dec 05, 2024
    • Jann Horn's avatar
      fsnotify: Fix ordering of iput() and watched_objects decrement · 83af1cfa
      Jann Horn authored
      
      commit 21d1b618b6b9da46c5116c640ac4b1cc8d40d63a upstream.
      
      Ensure the superblock is kept alive until we're done with iput().
      Holding a reference to an inode is not allowed unless we ensure the
      superblock stays alive, which fsnotify does by keeping the
      watched_objects count elevated, so iput() must happen before the
      watched_objects decrement.
      This can lead to a UAF of something like sb->s_fs_info in tmpfs, but the
      UAF is hard to hit because race orderings that oops are more likely, thanks
      to the CHECK_DATA_CORRUPTION() block in generic_shutdown_super().
      
      Also, ensure that fsnotify_put_sb_watched_objects() doesn't call
      fsnotify_sb_watched_objects() on a superblock that may have already been
      freed, which would cause a UAF read of sb->s_fsnotify_info.
      
      Cc: stable@kernel.org
      Fixes: d2f277e2 ("fsnotify: rename fsnotify_{get,put}_sb_connectors()")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      83af1cfa
    • Amir Goldstein's avatar
      fsnotify: fix sending inotify event with unexpected filename · a6b28352
      Amir Goldstein authored
      
      commit aa52c54da40d9eee3ba87c05cdcb0cd07c04fa13 upstream.
      
      We got a report that adding a fanotify filsystem watch prevents tail -f
      from receiving events.
      
      Reproducer:
      
      1. Create 3 windows / login sessions. Become root in each session.
      2. Choose a mounted filesystem that is pretty quiet; I picked /boot.
      3. In the first window, run: fsnotifywait -S -m /boot
      4. In the second window, run: echo data >> /boot/foo
      5. In the third window, run: tail -f /boot/foo
      6. Go back to the second window and run: echo more data >> /boot/foo
      7. Observe that the tail command doesn't show the new data.
      8. In the first window, hit control-C to interrupt fsnotifywait.
      9. In the second window, run: echo still more data >> /boot/foo
      10. Observe that the tail command in the third window has now printed
      the missing data.
      
      When stracing tail, we observed that when fanotify filesystem mark is
      set, tail does get the inotify event, but the event is receieved with
      the filename:
      
      read(4, "\1\0\0\0\2\0\0\0\0\0\0\0\20\0\0\0foo\0\0\0\0\0\0\0\0\0\0\0\0\0",
      50) = 32
      
      This is unexpected, because tail is watching the file itself and not its
      parent and is inconsistent with the inotify event received by tail when
      fanotify filesystem mark is not set:
      
      read(4, "\1\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0", 50) = 16
      
      The inteference between different fsnotify groups was caused by the fact
      that the mark on the sb requires the filename, so the filename is passed
      to fsnotify().  Later on, fsnotify_handle_event() tries to take care of
      not passing the filename to groups (such as inotify) that are interested
      in the filename only when the parent is watching.
      
      But the logic was incorrect for the case that no group is watching the
      parent, some groups are watching the sb and some watching the inode.
      
      Reported-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
      Fixes: 7372e79c ("fanotify: fix logic of reporting name info with watched parent")
      Cc: stable@vger.kernel.org # 5.10+
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a6b28352
    • Gustavo A. R. Silva's avatar
      clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access · 1bf88771
      Gustavo A. R. Silva authored
      
      commit 02fb4f0084331ef72c28d0c70fcb15d1bea369ec upstream.
      
      Flexible-array member `hws` in `struct clk_hw_onecell_data` is annotated
      with the `counted_by()` attribute. This means that when memory is
      allocated for this array, the _counter_, which in this case is member
      `num` in the flexible structure, should be set to the maximum number of
      elements the flexible array can contain, or fewer.
      
      In this case, the total number of elements for the flexible array is
      determined by variable `clks_num` when allocating heap space via
      `devm_kzalloc()`, as shown below:
      
      289         struct loongson2_clk_provider *clp;
      	...
      296         for (p = data; p->name; p++)
      297                 clks_num++;
      298
      299         clp = devm_kzalloc(dev, struct_size(clp, clk_data.hws, clks_num),
      300                            GFP_KERNEL);
      
      So, `clp->clk_data.num` should be set to `clks_num` or less, and not
      exceed `clks_num`, as is currently the case. Otherwise, if data is
      written into `clp->clk_data.hws[clks_num]`, the instrumentation
      provided by the compiler won't detect the overflow, leading to a
      memory corruption bug at runtime.
      
      Fix this issue by setting `clp->clk_data.num` to `clks_num`.
      
      Fixes: 9796ec0b ("clk: clk-loongson2: Refactor driver for adding new platforms")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Link: https://lore.kernel.org/r/ZzaN5MpmMr0hwHw9@kspp
      
      
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1bf88771
    • Gustavo A. R. Silva's avatar
      clk: clk-loongson2: Fix memory corruption bug in struct loongson2_clk_provider · 145de180
      Gustavo A. R. Silva authored
      
      commit 6e4bf018bb040955da53dae9f8628ef8fcec2dbe upstream.
      
      Some heap space is allocated for the flexible structure `struct
      clk_hw_onecell_data` and its flexible-array member `hws` through
      the composite structure `struct loongson2_clk_provider` in function
      `loongson2_clk_probe()`, as shown below:
      
      289         struct loongson2_clk_provider *clp;
      	...
      296         for (p = data; p->name; p++)
      297                 clks_num++;
      298
      299         clp = devm_kzalloc(dev, struct_size(clp, clk_data.hws, clks_num),
      300                            GFP_KERNEL);
      
      Then some data is written into the flexible array:
      
      350                 clp->clk_data.hws[p->id] = hw;
      
      This corrupts `clk_lock`, which is the spinlock variable immediately
      following the `clk_data` member in `struct loongson2_clk_provider`:
      
      struct loongson2_clk_provider {
      	void __iomem *base;
      	struct device *dev;
      	struct clk_hw_onecell_data clk_data;
      	spinlock_t clk_lock;	/* protect access to DIV registers */
      };
      
      The problem is that the flexible structure is currently placed in the
      middle of `struct loongson2_clk_provider` instead of at the end.
      
      Fix this by moving `struct clk_hw_onecell_data clk_data;` to the end of
      `struct loongson2_clk_provider`. Also, add a code comment to help
      prevent this from happening again in case new members are added to the
      structure in the future.
      
      This change also fixes the following -Wflex-array-member-not-at-end
      warning:
      
      drivers/clk/clk-loongson2.c:32:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      
      Fixes: 9796ec0b ("clk: clk-loongson2: Refactor driver for adding new platforms")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Link: https://lore.kernel.org/r/ZzZ-cd_EFXs6qFaH@kspp
      
      
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      145de180
    • Huacai Chen's avatar
      LoongArch: Explicitly specify code model in Makefile · 7b3a7918
      Huacai Chen authored
      
      commit e67e0eb6a98b261caf45048f9eb95fd7609289c0 upstream.
      
      LoongArch's toolchain may change the default code model from normal to
      medium. This is unnecessary for kernel, and generates some relocations
      which cannot be handled by the module loader. So explicitly specify the
      code model to normal in Makefile (for Rust 'normal' is 'small').
      
      Cc: stable@vger.kernel.org
      Tested-by: default avatarHaiyong Sun <sunhaiyong@loongson.cn>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7b3a7918
    • Lukas Wunner's avatar
      PCI: Fix use-after-free of slot->bus on hot remove · 69d2ceac
      Lukas Wunner authored
      commit c7acef99642b763ba585f4a43af999fcdbcc3dc4 upstream.
      
      Dennis reports a boot crash on recent Lenovo laptops with a USB4 dock.
      
      Since commit 0fc70886 ("thunderbolt: Reset USB4 v2 host router") and
      commit 59a54c5f ("thunderbolt: Reset topology created by the boot
      firmware"), USB4 v2 and v1 Host Routers are reset on probe of the
      thunderbolt driver.
      
      The reset clears the Presence Detect State and Data Link Layer Link Active
      bits at the USB4 Host Router's Root Port and thus causes hot removal of the
      dock.
      
      The crash occurs when pciehp is unbound from one of the dock's Downstream
      Ports:  pciehp creates a pci_slot on bind and destroys it on unbind.  The
      pci_slot contains a pointer to the pci_bus below the Downstream Port, but
      a reference on that pci_bus is never acquired.  The pci_bus is destroyed
      before the pci_slot, so a use-after-free ensues when pci_slot_release()
      accesses slot->bus.
      
      In principle this should not happen because pci_stop_bus_device() unbinds
      pciehp (and therefore destroys the pci_slot) before the pci_bus is
      destroyed by pci_remove_bus_device().
      
      However the stacktrace provided by Dennis shows that pciehp is unbound from
      pci_remove_bus_device() instead of pci_stop_bus_device().  To understand
      the significance of this, one needs to know that the PCI core uses a two
      step process to remove a portion of the hierarchy:  It first unbinds all
      drivers in the sub-hierarchy in pci_stop_bus_device() and then actually
      removes the devices in pci_remove_bus_device().  There is no precaution to
      prevent driver binding in-between pci_stop_bus_device() and
      pci_remove_bus_device().
      
      In Dennis' case, it seems removal of the hierarchy by pciehp races with
      driver binding by pci_bus_add_devices().  pciehp is bound to the
      Downstream Port after pci_stop_bus_device() has run, so it is unbound by
      pci_remove_bus_device() instead of pci_stop_bus_device().  Because the
      pci_bus has already been destroyed at that point, accesses to it result in
      a use-after-free.
      
      One might conclude that driver binding needs to be prevented after
      pci_stop_bus_device() has run.  However it seems risky that pci_slot points
      to pci_bus without holding a reference.  Solely relying on correct ordering
      of driver unbind versus pci_bus destruction is certainly not defensive
      programming.
      
      If pci_slot has a need to access data in pci_bus, it ought to acquire a
      reference.  Amend pci_create_slot() accordingly.  Dennis reports that the
      crash is not reproducible with this change.
      
      Abridged stacktrace:
      
        pcieport 0000:00:07.0: PME: Signaling with IRQ 156
        pcieport 0000:00:07.0: pciehp: Slot #12 AttnBtn- PwrCtrl- MRL- AttnInd- PwrInd- HotPlug+ Surprise+ Interlock- NoCompl+ IbPresDis- LLActRep+
        pci_bus 0000:20: dev 00, created physical slot 12
        pcieport 0000:00:07.0: pciehp: Slot(12): Card not present
        ...
        pcieport 0000:21:02.0: pciehp: pcie_disable_notification: SLOTCTRL d8 write cmd 0
        Oops: general protection fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b: 0000 [#1] PREEMPT SMP NOPTI
        CPU: 13 UID: 0 PID: 134 Comm: irq/156-pciehp Not tainted 6.11.0-devel+ #1
        RIP: 0010:dev_driver_string+0x12/0x40
        pci_destroy_slot
        pciehp_remove
        pcie_port_remove_service
        device_release_driver_internal
        bus_remove_device
        device_del
        device_unregister
        remove_iter
        device_for_each_child
        pcie_portdrv_remove
        pci_device_remove
        device_release_driver_internal
        bus_remove_device
        device_del
        pci_remove_bus_device (recursive invocation)
        pci_remove_bus_device
        pciehp_unconfigure_device
        pciehp_disable_slot
        pciehp_handle_presence_or_link_change
        pciehp_ist
      
      Link: https://lore.kernel.org/r/4bfd4c0e976c1776cd08e76603903b338cf25729.1728579288.git.lukas@wunner.de
      
      
      Reported-by: default avatarDennis Wassenberg <Dennis.Wassenberg@secunet.com>
      Closes: https://lore.kernel.org/r/6de4b45ff2b32dd91a805ec02ec8ec73ef411bf6.camel@secunet.com/
      
      
      Tested-by: default avatarDennis Wassenberg <Dennis.Wassenberg@secunet.com>
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69d2ceac
    • Jan Hendrik Farr's avatar
      Compiler Attributes: disable __counted_by for clang < 19.1.3 · e46d4caa
      Jan Hendrik Farr authored
      commit f06e108a3dc53c0f5234d18de0bd224753db5019 upstream.
      
      This patch disables __counted_by for clang versions < 19.1.3 because
      of the two issues listed below. It does this by introducing
      CONFIG_CC_HAS_COUNTED_BY.
      
      1. clang < 19.1.2 has a bug that can lead to __bdos returning 0:
      https://github.com/llvm/llvm-project/pull/110497
      
      2. clang < 19.1.3 has a bug that can lead to __bdos being off by 4:
      https://github.com/llvm/llvm-project/pull/112636
      
      
      
      Fixes: c8248faf ("Compiler Attributes: counted_by: Adjust name and identifier expansion")
      Cc: stable@vger.kernel.org # 6.6.x: 16c31dd7: Compiler Attributes: counted_by: bump min gcc version
      Cc: stable@vger.kernel.org # 6.6.x: 2993eb7a: Compiler Attributes: counted_by: fixup clang URL
      Cc: stable@vger.kernel.org # 6.6.x: 231dc3f0: lkdtm/bugs: Improve warning message for compilers without counted_by support
      Cc: stable@vger.kernel.org # 6.6.x
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Closes: https://lore.kernel.org/all/20240913164630.GA4091534@thelio-3990X/
      
      
      Reported-by: default avatarkernel test robot <oliver.sang@intel.com>
      Closes: https://lore.kernel.org/oe-lkp/202409260949.a1254989-oliver.sang@intel.com
      Link: https://lore.kernel.org/all/Zw8iawAF5W2uzGuh@archlinux/T/#m204c09f63c076586a02d194b87dffc7e81b8de7b
      
      
      Suggested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarJan Hendrik Farr <kernel@jfarr.cc>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      Reviewed-by: default avatarThorsten Blum <thorsten.blum@linux.dev>
      Link: https://lore.kernel.org/r/20241029140036.577804-2-kernel@jfarr.cc
      
      
      Signed-off-by: default avatarKees Cook <kees@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e46d4caa
    • Kunkun Jiang's avatar
      KVM: arm64: vgic-its: Clear DTE when MAPD unmaps a device · 1059f1e5
      Kunkun Jiang authored
      
      commit e9649129d33dca561305fc590a7c4ba8c3e5675a upstream.
      
      vgic_its_save_device_tables will traverse its->device_list to
      save DTE for each device. vgic_its_restore_device_tables will
      traverse each entry of device table and check if it is valid.
      Restore if valid.
      
      But when MAPD unmaps a device, it does not invalidate the
      corresponding DTE. In the scenario of continuous saves
      and restores, there may be a situation where a device's DTE
      is not saved but is restored. This is unreasonable and may
      cause restore to fail. This patch clears the corresponding
      DTE when MAPD unmaps a device.
      
      Cc: stable@vger.kernel.org
      Fixes: 57a9a117 ("KVM: arm64: vgic-its: Device table save/restore")
      Co-developed-by: default avatarShusen Li <lishusen2@huawei.com>
      Signed-off-by: default avatarShusen Li <lishusen2@huawei.com>
      Signed-off-by: default avatarKunkun Jiang <jiangkunkun@huawei.com>
      [Jing: Update with entry write helper]
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20241107214137.428439-5-jingzhangos@google.com
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1059f1e5
    • Jing Zhang's avatar
      KVM: arm64: vgic-its: Add a data length check in vgic_its_save_* · 46018a04
      Jing Zhang authored
      
      commit 7fe28d7e68f92cc3d0668b8f2fbdf5c303ac3022 upstream.
      
      In all the vgic_its_save_*() functinos, they do not check whether
      the data length is 8 bytes before calling vgic_write_guest_lock.
      This patch adds the check. To prevent the kernel from being blown up
      when the fault occurs, KVM_BUG_ON() is used. And the other BUG_ON()s
      are replaced together.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarKunkun Jiang <jiangkunkun@huawei.com>
      [Jing: Update with the new entry read/write helpers]
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20241107214137.428439-4-jingzhangos@google.com
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46018a04
    • Raghavendra Rao Ananta's avatar
      KVM: arm64: Get rid of userspace_irqchip_in_use · fe425d52
      Raghavendra Rao Ananta authored
      
      commit 38d7aacca09230fdb98a34194fec2af597e8e20d upstream.
      
      Improper use of userspace_irqchip_in_use led to syzbot hitting the
      following WARN_ON() in kvm_timer_update_irq():
      
      WARNING: CPU: 0 PID: 3281 at arch/arm64/kvm/arch_timer.c:459
      kvm_timer_update_irq+0x21c/0x394
      Call trace:
        kvm_timer_update_irq+0x21c/0x394 arch/arm64/kvm/arch_timer.c:459
        kvm_timer_vcpu_reset+0x158/0x684 arch/arm64/kvm/arch_timer.c:968
        kvm_reset_vcpu+0x3b4/0x560 arch/arm64/kvm/reset.c:264
        kvm_vcpu_set_target arch/arm64/kvm/arm.c:1553 [inline]
        kvm_arch_vcpu_ioctl_vcpu_init arch/arm64/kvm/arm.c:1573 [inline]
        kvm_arch_vcpu_ioctl+0x112c/0x1b3c arch/arm64/kvm/arm.c:1695
        kvm_vcpu_ioctl+0x4ec/0xf74 virt/kvm/kvm_main.c:4658
        vfs_ioctl fs/ioctl.c:51 [inline]
        __do_sys_ioctl fs/ioctl.c:907 [inline]
        __se_sys_ioctl fs/ioctl.c:893 [inline]
        __arm64_sys_ioctl+0x108/0x184 fs/ioctl.c:893
        __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
        invoke_syscall+0x78/0x1b8 arch/arm64/kernel/syscall.c:49
        el0_svc_common+0xe8/0x1b0 arch/arm64/kernel/syscall.c:132
        do_el0_svc+0x40/0x50 arch/arm64/kernel/syscall.c:151
        el0_svc+0x54/0x14c arch/arm64/kernel/entry-common.c:712
        el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730
        el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598
      
      The following sequence led to the scenario:
       - Userspace creates a VM and a vCPU.
       - The vCPU is initialized with KVM_ARM_VCPU_PMU_V3 during
         KVM_ARM_VCPU_INIT.
       - Without any other setup, such as vGIC or vPMU, userspace issues
         KVM_RUN on the vCPU. Since the vPMU is requested, but not setup,
         kvm_arm_pmu_v3_enable() fails in kvm_arch_vcpu_run_pid_change().
         As a result, KVM_RUN returns after enabling the timer, but before
         incrementing 'userspace_irqchip_in_use':
         kvm_arch_vcpu_run_pid_change()
             ret = kvm_arm_pmu_v3_enable()
                 if (!vcpu->arch.pmu.created)
                     return -EINVAL;
             if (ret)
                 return ret;
             [...]
             if (!irqchip_in_kernel(kvm))
                 static_branch_inc(&userspace_irqchip_in_use);
       - Userspace ignores the error and issues KVM_ARM_VCPU_INIT again.
         Since the timer is already enabled, control moves through the
         following flow, ultimately hitting the WARN_ON():
         kvm_timer_vcpu_reset()
             if (timer->enabled)
                kvm_timer_update_irq()
                    if (!userspace_irqchip())
                        ret = kvm_vgic_inject_irq()
                            ret = vgic_lazy_init()
                                if (unlikely(!vgic_initialized(kvm)))
                                    if (kvm->arch.vgic.vgic_model !=
                                        KVM_DEV_TYPE_ARM_VGIC_V2)
                                            return -EBUSY;
                        WARN_ON(ret);
      
      Theoretically, since userspace_irqchip_in_use's functionality can be
      simply replaced by '!irqchip_in_kernel()', get rid of the static key
      to avoid the mismanagement, which also helps with the syzbot issue.
      
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Suggested-by: default avatarMarc Zyngier <maz@kernel.org>
      Signed-off-by: default avatarRaghavendra Rao Ananta <rananta@google.com>
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe425d52
    • Kunkun Jiang's avatar
      KVM: arm64: vgic-its: Clear ITE when DISCARD frees an ITE · eabd7ef1
      Kunkun Jiang authored
      
      commit 7602ffd1d5e8927fadd5187cb4aed2fdc9c47143 upstream.
      
      When DISCARD frees an ITE, it does not invalidate the
      corresponding ITE. In the scenario of continuous saves and
      restores, there may be a situation where an ITE is not saved
      but is restored. This is unreasonable and may cause restore
      to fail. This patch clears the corresponding ITE when DISCARD
      frees an ITE.
      
      Cc: stable@vger.kernel.org
      Fixes: eff484e0 ("KVM: arm64: vgic-its: ITT save and restore")
      Signed-off-by: default avatarKunkun Jiang <jiangkunkun@huawei.com>
      [Jing: Update with entry write helper]
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20241107214137.428439-6-jingzhangos@google.com
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eabd7ef1
    • Oliver Upton's avatar
      KVM: arm64: Don't retire aborted MMIO instruction · d0571c3a
      Oliver Upton authored
      
      commit e735a5da64420a86be370b216c269b5dd8e830e2 upstream.
      
      Returning an abort to the guest for an unsupported MMIO access is a
      documented feature of the KVM UAPI. Nevertheless, it's clear that this
      plumbing has seen limited testing, since userspace can trivially cause a
      WARN in the MMIO return:
      
        WARNING: CPU: 0 PID: 30558 at arch/arm64/include/asm/kvm_emulate.h:536 kvm_handle_mmio_return+0x46c/0x5c4 arch/arm64/include/asm/kvm_emulate.h:536
        Call trace:
         kvm_handle_mmio_return+0x46c/0x5c4 arch/arm64/include/asm/kvm_emulate.h:536
         kvm_arch_vcpu_ioctl_run+0x98/0x15b4 arch/arm64/kvm/arm.c:1133
         kvm_vcpu_ioctl+0x75c/0xa78 virt/kvm/kvm_main.c:4487
         __do_sys_ioctl fs/ioctl.c:51 [inline]
         __se_sys_ioctl fs/ioctl.c:893 [inline]
         __arm64_sys_ioctl+0x14c/0x1c8 fs/ioctl.c:893
         __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
         invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
         el0_svc_common+0x1e0/0x23c arch/arm64/kernel/syscall.c:132
         do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
         el0_svc+0x38/0x68 arch/arm64/kernel/entry-common.c:712
         el0t_64_sync_handler+0x90/0xfc arch/arm64/kernel/entry-common.c:730
         el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598
      
      The splat is complaining that KVM is advancing PC while an exception is
      pending, i.e. that KVM is retiring the MMIO instruction despite a
      pending synchronous external abort. Womp womp.
      
      Fix the glaring UAPI bug by skipping over all the MMIO emulation in
      case there is a pending synchronous exception. Note that while userspace
      is capable of pending an asynchronous exception (SError, IRQ, or FIQ),
      it is still safe to retire the MMIO instruction in this case as (1) they
      are by definition asynchronous, and (2) KVM relies on hardware support
      for pending/delivering these exceptions instead of the software state
      machine for advancing PC.
      
      Cc: stable@vger.kernel.org
      Fixes: da345174 ("KVM: arm/arm64: Allow user injection of external data aborts")
      Reported-by: default avatarAlexander Potapenko <glider@google.com>
      Reviewed-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20241025203106.3529261-2-oliver.upton@linux.dev
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d0571c3a
    • Sean Christopherson's avatar
      Revert "KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()" · f3c6fa7c
      Sean Christopherson authored
      commit 85434c3c73fcad58870016ddfe5eaa5036672675 upstream.
      
      Revert back to clearing VM_{ENTRY,EXIT}_LOAD_IA32_PERF_GLOBAL_CTRL in KVM's
      golden VMCS config, as applying the workaround during vCPU creation is
      pointless and broken.  KVM *unconditionally* clears the controls in the
      values returned by vmx_vmentry_ctrl() and vmx_vmexit_ctrl(), as KVM loads
      PERF_GLOBAL_CTRL if and only if its necessary to do so.  E.g. if KVM wants
      to run the guest with the same PERF_GLOBAL_CTRL as the host, then there's
      no need to re-load the MSR on entry and exit.
      
      Even worse, the buggy commit failed to apply the erratum where it's
      actually needed, add_atomic_switch_msr().  As a result, KVM completely
      ignores the erratum for all intents and purposes, i.e. uses the flawed
      VMCS controls to load PERF_GLOBAL_CTRL.
      
      To top things off, the patch was intended to be dropped, as the premise
      of an L1 VMM being able to pivot on FMS is flawed, and KVM can (and now
      does) fully emulate the controls in software.  Simply revert the commit,
      as all upstream supported kernels that have the buggy commit should also
      have commit f4c93d1a ("KVM: nVMX: Always emulate PERF_GLOBAL_CTRL
      VM-Entry/VM-Exit controls"), i.e. the (likely theoretical) live migration
      concern is a complete non-issue.
      
      Opportunistically drop the manual "kvm: " scope from the warning about
      the erratum, as KVM now uses pr_fmt() to provide the correct scope (v6.1
      kernels and earlier don't, but the erratum only applies to CPUs that are
      15+ years old; it's not worth a separate patch).
      
      This reverts commit 9d78d6fb.
      
      Link: https://lore.kernel.org/all/YtnZmCutdd5tpUmz@google.com
      
      
      Fixes: 9d78d6fb ("KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()")
      Cc: stable@vger.kernel.org
      Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
      Cc: Maxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-ID: <20241119011433.1797921-1-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f3c6fa7c
    • Raghavendra Rao Ananta's avatar
      KVM: arm64: Ignore PMCNTENSET_EL0 while checking for overflow status · 8b6916f4
      Raghavendra Rao Ananta authored
      commit 54bbee190d42166209185d89070c58a343bf514b upstream.
      
      DDI0487K.a D13.3.1 describes the PMU overflow condition, which evaluates
      to true if any counter's global enable (PMCR_EL0.E), overflow flag
      (PMOVSSET_EL0[n]), and interrupt enable (PMINTENSET_EL1[n]) are all 1.
      Of note, this does not require a counter to be enabled
      (i.e. PMCNTENSET_EL0[n] = 1) to generate an overflow.
      
      Align kvm_pmu_overflow_status() with the reality of the architecture
      and stop using PMCNTENSET_EL0 as part of the overflow condition. The
      bug was discovered while running an SBSA PMU test [*], which only sets
      PMCR.E, PMOVSSET<0>, PMINTENSET<0>, and expects an overflow interrupt.
      
      Cc: stable@vger.kernel.org
      Fixes: 76d883c4 ("arm64: KVM: Add access handler for PMOVSSET and PMOVSCLR register")
      Link: https://github.com/ARM-software/sbsa-acs/blob/master/test_pool/pmu/operating_system/test_pmu001.c
      
      
      Signed-off-by: default avatarRaghavendra Rao Ananta <rananta@google.com>
      [ oliver: massaged changelog ]
      Reviewed-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20241120005230.2335682-2-oliver.upton@linux.dev
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b6916f4
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Sanitise guest writes to GICR_INVLPIR · f594a568
      Marc Zyngier authored
      
      commit d561491ba927cb5634094ff311795e9d618e9b86 upstream.
      
      Make sure we filter out non-LPI invalidation when handling writes
      to GICR_INVLPIR.
      
      Fixes: 4645d11f ("KVM: arm64: vgic-v3: Implement MMIO-based LPI invalidation")
      Reported-by: default avatarAlexander Potapenko <glider@google.com>
      Tested-by: default avatarAlexander Potapenko <glider@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20241117165757.247686-2-maz@kernel.org
      
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f594a568
    • Gautam Menghani's avatar
      powerpc/pseries: Fix KVM guest detection for disabling hardlockup detector · 58d64730
      Gautam Menghani authored
      
      commit 44e5d21e6d3fd2a1fed7f0327cf72e99397e2eaf upstream.
      
      As per the kernel documentation[1], hardlockup detector should
      be disabled in KVM guests as it may give false positives. On
      PPC, hardlockup detector is enabled inside KVM guests because
      disable_hardlockup_detector() is marked as early_initcall and it
      relies on kvm_guest static key (is_kvm_guest()) which is initialized
      later during boot by check_kvm_guest(), which is a core_initcall.
      check_kvm_guest() is also called in pSeries_smp_probe(), which is called
      before initcalls, but it is skipped if KVM guest does not have doorbell
      support or if the guest is launched with SMT=1.
      
      Call check_kvm_guest() in disable_hardlockup_detector() so that
      is_kvm_guest() check goes through fine and hardlockup detector can be
      disabled inside the KVM guest.
      
      [1]: Documentation/admin-guide/sysctl/kernel.rst
      
      Fixes: 633c8e98 ("powerpc/pseries: Enable hardlockup watchdog for PowerVM partitions")
      Cc: stable@vger.kernel.org # v5.14+
      Signed-off-by: default avatarGautam Menghani <gautam@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://patch.msgid.link/20241108094839.33084-1-gautam@linux.ibm.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      58d64730
    • Sean Christopherson's avatar
      KVM: x86: Break CONFIG_KVM_X86's direct dependency on KVM_INTEL || KVM_AMD · 952741d5
      Sean Christopherson authored
      
      commit 9ee62c33c0fe017ee02501a877f6f562363122fa upstream.
      
      Rework CONFIG_KVM_X86's dependency to only check if KVM_INTEL or KVM_AMD
      is selected, i.e. not 'n'.  Having KVM_X86 depend directly on the vendor
      modules results in KVM_X86 being set to 'm' if at least one of KVM_INTEL
      or KVM_AMD is enabled, but neither is 'y', regardless of the value of KVM
      itself.
      
      The documentation for def_tristate doesn't explicitly state that this is
      the intended behavior, but it does clearly state that the "if" section is
      parsed as a dependency, i.e. the behavior is consistent with how tristate
      dependencies are handled in general.
      
        Optionally dependencies for this default value can be added with "if".
      
      Fixes: ea4290d7 ("KVM: x86: leave kvm.ko out of the build if no vendor module is requested")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-ID: <20241118172002.1633824-3-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      952741d5
    • Arnd Bergmann's avatar
      KVM: x86: add back X86_LOCAL_APIC dependency · b44026c0
      Arnd Bergmann authored
      
      commit 1331343af6f502aecd274d522dd34bf7c965f484 upstream.
      
      Enabling KVM now causes a build failure on x86-32 if X86_LOCAL_APIC
      is disabled:
      
      arch/x86/kvm/svm/svm.c: In function 'svm_emergency_disable_virtualization_cpu':
      arch/x86/kvm/svm/svm.c:597:9: error: 'kvm_rebooting' undeclared (first use in this function); did you mean 'kvm_irq_routing'?
        597 |         kvm_rebooting = true;
            |         ^~~~~~~~~~~~~
            |         kvm_irq_routing
      arch/x86/kvm/svm/svm.c:597:9: note: each undeclared identifier is reported only once for each function it appears in
      make[6]: *** [scripts/Makefile.build:221: arch/x86/kvm/svm/svm.o] Error 1
      In file included from include/linux/rculist.h:11,
                       from include/linux/hashtable.h:14,
                       from arch/x86/kvm/svm/avic.c:18:
      arch/x86/kvm/svm/avic.c: In function 'avic_pi_update_irte':
      arch/x86/kvm/svm/avic.c:909:38: error: 'struct kvm' has no member named 'irq_routing'
        909 |         irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu);
            |                                      ^~
      include/linux/rcupdate.h:538:17: note: in definition of macro '__rcu_dereference_check'
        538 |         typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
      
      Move the dependency to the same place as before.
      
      Fixes: ea4290d7 ("KVM: x86: leave kvm.ko out of the build if no vendor module is requested")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Closes: https://lore.kernel.org/oe-kbuild-all/202410060426.e9Xsnkvi-lkp@intel.com/
      
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: default avatarSean Christopherson <seanjc@google.com>
      [sean: add Cc to stable, tweak shortlog scope]
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-ID: <20241118172002.1633824-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b44026c0
    • Sean Christopherson's avatar
      KVM: x86/mmu: Skip the "try unsync" path iff the old SPTE was a leaf SPTE · cb02ac15
      Sean Christopherson authored
      
      commit 2867eb782cf7f64c2ac427596133b6f9c3f64b7a upstream.
      
      Apply make_spte()'s optimization to skip trying to unsync shadow pages if
      and only if the old SPTE was a leaf SPTE, as non-leaf SPTEs in direct MMUs
      are always writable, i.e. could trigger a false positive and incorrectly
      lead to KVM creating a SPTE without write-protecting or marking shadow
      pages unsync.
      
      This bug only affects the TDP MMU, as the shadow MMU only overwrites a
      shadow-present SPTE when synchronizing SPTEs (and only 4KiB SPTEs can be
      unsync).  Specifically, mmu_set_spte() drops any non-leaf SPTEs *before*
      calling make_spte(), whereas the TDP MMU can do a direct replacement of a
      page table with the leaf SPTE.
      
      Opportunistically update the comment to explain why skipping the unsync
      stuff is safe, as opposed to simply saying "it's someone else's problem".
      
      Cc: stable@vger.kernel.org
      Tested-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Tested-by: default avatarDmitry Osipenko <dmitry.osipenko@collabora.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-ID: <20241010182427.1434605-5-seanjc@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb02ac15
    • Paolo Bonzini's avatar
      KVM: x86: switch hugepage recovery thread to vhost_task · 91248a2e
      Paolo Bonzini authored
      
      commit d96c77bd4eeba469bddbbb14323d2191684da82a upstream.
      
      kvm_vm_create_worker_thread() is meant to be used for kthreads that
      can consume significant amounts of CPU time on behalf of a VM or in
      response to how the VM behaves (for example how it accesses its memory).
      Therefore it wants to charge the CPU time consumed by that work to
      the VM's container.
      
      However, because of these threads, cgroups which have kvm instances
      inside never complete freezing.  This can be trivially reproduced:
      
        root@test ~# mkdir /sys/fs/cgroup/test
        root@test ~# echo $$ > /sys/fs/cgroup/test/cgroup.procs
        root@test ~# qemu-system-x86_64 -nographic -enable-kvm
      
      and in another terminal:
      
        root@test ~# echo 1 > /sys/fs/cgroup/test/cgroup.freeze
        root@test ~# cat /sys/fs/cgroup/test/cgroup.events
        populated 1
        frozen 0
      
      The cgroup freezing happens in the signal delivery path but
      kvm_nx_huge_page_recovery_worker, while joining non-root cgroups, never
      calls into the signal delivery path and thus never gets frozen. Because
      the cgroup freezer determines whether a given cgroup is frozen by
      comparing the number of frozen threads to the total number of threads
      in the cgroup, the cgroup never becomes frozen and users waiting for
      the state transition may hang indefinitely.
      
      Since the worker kthread is tied to a user process, it's better if
      it behaves similarly to user tasks as much as possible, including
      being able to send SIGSTOP and SIGCONT.  In fact, vhost_task is all
      that kvm_vm_create_worker_thread() wanted to be and more: not only it
      inherits the userspace process's cgroups, it has other niceties like
      being parented properly in the process tree.  Use it instead of the
      homegrown alternative.
      
      Incidentally, the new code is also better behaved when you flip recovery
      back and forth to disabled and back to enabled.  If your recovery period
      is 1 minute, it will run the next recovery after 1 minute independent
      of how many times you flipped the parameter.
      
      (Commit message based on emails from Tejun).
      
      Reported-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarLuca Boccassi <bluca@debian.org>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Tested-by: default avatarLuca Boccassi <bluca@debian.org>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      91248a2e
    • Eric Biggers's avatar
      crypto: x86/aegis128 - access 32-bit arguments as 32-bit · d6933f2e
      Eric Biggers authored
      
      commit 3b2f2d22fb424e9bebda4dbf6676cbfc7f9f62cd upstream.
      
      Fix the AEGIS assembly code to access 'unsigned int' arguments as 32-bit
      values instead of 64-bit, since the upper bits of the corresponding
      64-bit registers are not guaranteed to be zero.
      
      Note: there haven't been any reports of this bug actually causing
      incorrect behavior.  Neither gcc nor clang guarantee zero-extension to
      64 bits, but zero-extension is likely to happen in practice because most
      instructions that operate on 32-bit registers zero-extend to 64 bits.
      
      Fixes: 1d373d4e ("crypto: x86 - Add optimized AEGIS implementations")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d6933f2e
    • Adrian Hunter's avatar
      perf/x86/intel/pt: Fix buffer full but size is 0 case · bc9b40fa
      Adrian Hunter authored
      
      commit 5b590160d2cf776b304eb054afafea2bd55e3620 upstream.
      
      If the trace data buffer becomes full, a truncated flag [T] is reported
      in PERF_RECORD_AUX.  In some cases, the size reported is 0, even though
      data must have been added to make the buffer full.
      
      That happens when the buffer fills up from empty to full before the
      Intel PT driver has updated the buffer position.  Then the driver
      calculates the new buffer position before calculating the data size.
      If the old and new positions are the same, the data size is reported
      as 0, even though it is really the whole buffer size.
      
      Fix by detecting when the buffer position is wrapped, and adjust the
      data size calculation accordingly.
      
      Example
      
        Use a very small buffer size (8K) and observe the size of truncated [T]
        data. Before the fix, it is possible to see records of 0 size.
      
        Before:
      
          $ perf record -m,8K -e intel_pt// uname
          Linux
          [ perf record: Woken up 2 times to write data ]
          [ perf record: Captured and wrote 0.105 MB perf.data ]
          $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
          Warning:
          AUX data lost 2 times out of 3!
      
          5 19462712368111 0x19710 [0x40]: PERF_RECORD_AUX offset: 0 size: 0 flags: 0x1 [T]
          5 19462712700046 0x19ba8 [0x40]: PERF_RECORD_AUX offset: 0x170 size: 0xe90 flags: 0x1 [T]
      
       After:
      
          $ perf record -m,8K -e intel_pt// uname
          Linux
          [ perf record: Woken up 3 times to write data ]
          [ perf record: Captured and wrote 0.040 MB perf.data ]
          $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
          Warning:
          AUX data lost 2 times out of 3!
      
          1 113720802995 0x4948 [0x40]: PERF_RECORD_AUX offset: 0 size: 0x2000 flags: 0x1 [T]
          1 113720979812 0x6b10 [0x40]: PERF_RECORD_AUX offset: 0x2000 size: 0x2000 flags: 0x1 [T]
      
      Fixes: 52ca9ced ("perf/x86/intel/pt: Add Intel PT PMU driver")
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/20241022155920.17511-2-adrian.hunter@intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bc9b40fa
    • Claudiu Beznea's avatar
      ASoC: da7213: Populate max_register to regmap_config · b09a655d
      Claudiu Beznea authored
      
      commit 9d4f9f6a7bb1afbde57d08c98f2db4ff019ee19d upstream.
      
      On the Renesas RZ/G3S SMARC Carrier II board having a DA7212 codec (using
      da7213 driver) connected to one SSIF-2 available on the Renesas RZ/G3S SoC
      it has been discovered that using the runtime PM API for suspend/resume
      (as will be proposed in the following commits) leads to the codec not
      being propertly initialized after resume. This is because w/o
      max_register populated to regmap_config the regcache_rbtree_sync()
      breaks on base_reg > max condition and the regcache_sync_block() call is
      skipped.
      
      Fixes: ef5c2eba ("ASoC: codecs: Add da7213 codec")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
      Link: https://patch.msgid.link/20241106081826.1211088-23-claudiu.beznea.uj@bp.renesas.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b09a655d
    • Qiu-ji Chen's avatar
      ASoC: codecs: Fix atomicity violation in snd_soc_component_get_drvdata() · b5bcf578
      Qiu-ji Chen authored
      
      commit 1157733344651ca505e259d6554591ff156922fa upstream.
      
      An atomicity violation occurs when the validity of the variables
      da7219->clk_src and da7219->mclk_rate is being assessed. Since the entire
      assessment is not protected by a lock, the da7219 variable might still be
      in flux during the assessment, rendering this check invalid.
      
      To fix this issue, we recommend adding a lock before the block
      if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) so that
      the legitimacy check for da7219->clk_src and da7219->mclk_rate is
      protected by the lock, ensuring the validity of the check.
      
      This possible bug is found by an experimental static analysis tool
      developed by our team. This tool analyzes the locking APIs
      to extract function pairs that can be concurrently executed, and then
      analyzes the instructions in the paired functions to identify possible
      concurrency bugs including data races and atomicity violations.
      
      Fixes: 6d817c0e ("ASoC: codecs: Add da7219 codec driver")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarQiu-ji Chen <chenqiuji666@gmail.com>
      Link: https://patch.msgid.link/20240930101216.23723-1-chenqiuji666@gmail.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b5bcf578
    • Ilya Zverev's avatar
      ASoC: amd: yc: Add a quirk for microfone on Lenovo ThinkPad P14s Gen 5 21MES00B00 · 9ab9a7fa
      Ilya Zverev authored
      commit b682aa788e5f9f1ddacdfbb453e49fd3f4e83721 upstream.
      
      New ThinkPads need new quirk entries. Ilya has tested this one.
      Laptop product id is 21MES00B00, though the shorthand 21ME works.
      
      Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219533
      
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarIlya Zverev <ilya@zverev.info>
      Link: https://patch.msgid.link/20241127134420.14471-1-ilya@zverev.info
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ab9a7fa
    • Artem Sadovnikov's avatar
      jfs: xattr: check invalid xattr size more strictly · 8c505ebe
      Artem Sadovnikov authored
      
      commit d9f9d96136cba8fedd647d2c024342ce090133c2 upstream.
      
      Commit 7c55b788 ("jfs: xattr: fix buffer overflow for invalid xattr")
      also addresses this issue but it only fixes it for positive values, while
      ea_size is an integer type and can take negative values, e.g. in case of
      a corrupted filesystem. This still breaks validation and would overflow
      because of implicit conversion from int to size_t in print_hex_dump().
      
      Fix this issue by clamping the ea_size value instead.
      
      Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarArtem Sadovnikov <ancowi69@gmail.com>
      Signed-off-by: default avatarDave Kleikamp <dave.kleikamp@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8c505ebe
    • Mauro Carvalho Chehab's avatar
      docs: media: update location of the media patches · a7f28636
      Mauro Carvalho Chehab authored
      
      commit 72ad4ff638047bbbdf3232178fea4bec1f429319 upstream.
      
      Due to recent changes on the way we're maintaining media, the
      location of the main tree was updated.
      
      Change docs accordingly.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Reviewed-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7f28636
    • Mauro Carvalho Chehab's avatar
      MAINTAINERS: update location of media main tree · 6f9be323
      Mauro Carvalho Chehab authored
      commit dc51b3cc9d4d2a04bdbfe34f7746fc9122cc3f49 upstream.
      
      There were some recent changes on the way we're handling
      media patches. Now, the official tree is located at:
      
      	https://git.linuxtv.org/media.git/
      
      
      
      Update it at MAINTAINERS file.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Reviewed-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f9be323
    • Theodore Ts'o's avatar
      ext4: fix FS_IOC_GETFSMAP handling · ad34d9c7
      Theodore Ts'o authored
      
      commit 4a622e4d477bb12ad5ed4abbc7ad1365de1fa347 upstream.
      
      The original implementation ext4's FS_IOC_GETFSMAP handling only
      worked when the range of queried blocks included at least one free
      (unallocated) block range.  This is because how the metadata blocks
      were emitted was as a side effect of ext4_mballoc_query_range()
      calling ext4_getfsmap_datadev_helper(), and that function was only
      called when a free block range was identified.  As a result, this
      caused generic/365 to fail.
      
      Fix this by creating a new function ext4_getfsmap_meta_helper() which
      gets called so that blocks before the first free block range in a
      block group can get properly reported.
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ad34d9c7
    • Jeongjun Park's avatar
      ext4: supress data-race warnings in ext4_free_inodes_{count,set}() · ec56ada6
      Jeongjun Park authored
      
      commit 902cc179c931a033cd7f4242353aa2733bf8524c upstream.
      
      find_group_other() and find_group_orlov() read *_lo, *_hi with
      ext4_free_inodes_count without additional locking. This can cause
      data-race warning, but since the lock is held for most writes and free
      inodes value is generally not a problem even if it is incorrect, it is
      more appropriate to use READ_ONCE()/WRITE_ONCE() than to add locking.
      
      ==================================================================
      BUG: KCSAN: data-race in ext4_free_inodes_count / ext4_free_inodes_set
      
      write to 0xffff88810404300e of 2 bytes by task 6254 on cpu 1:
       ext4_free_inodes_set+0x1f/0x80 fs/ext4/super.c:405
       __ext4_new_inode+0x15ca/0x2200 fs/ext4/ialloc.c:1216
       ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
       vfs_symlink+0xca/0x1d0 fs/namei.c:4615
       do_symlinkat+0xe3/0x340 fs/namei.c:4641
       __do_sys_symlinkat fs/namei.c:4657 [inline]
       __se_sys_symlinkat fs/namei.c:4654 [inline]
       __x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4654
       x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      read to 0xffff88810404300e of 2 bytes by task 6257 on cpu 0:
       ext4_free_inodes_count+0x1c/0x80 fs/ext4/super.c:349
       find_group_other fs/ext4/ialloc.c:594 [inline]
       __ext4_new_inode+0x6ec/0x2200 fs/ext4/ialloc.c:1017
       ext4_symlink+0x242/0x5a0 fs/ext4/namei.c:3391
       vfs_symlink+0xca/0x1d0 fs/namei.c:4615
       do_symlinkat+0xe3/0x340 fs/namei.c:4641
       __do_sys_symlinkat fs/namei.c:4657 [inline]
       __se_sys_symlinkat fs/namei.c:4654 [inline]
       __x64_sys_symlinkat+0x5e/0x70 fs/namei.c:4654
       x64_sys_call+0x1dda/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:267
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0x54/0x120 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJeongjun Park <aha310510@gmail.com>
      Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
      Link: https://patch.msgid.link/20241003125337.47283-1-aha310510@gmail.com
      
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ec56ada6
    • Darrick J. Wong's avatar
      xfs: fix simplify extent lookup in xfs_can_free_eofblocks · 66b60629
      Darrick J. Wong authored
      
      commit 62027820eb4486f075b89ec31c1548c6cb1bb13f upstream.
      
      In commit 11f4c3a5, we tried to simplify the extent lookup in
      xfs_can_free_eofblocks so that it doesn't incur the overhead of all the
      extra stuff that xfs_bmapi_read does around the iext lookup.
      
      Unfortunately, this causes regressions on generic/603, xfs/108,
      generic/219, xfs/173, generic/694, xfs/052, generic/230, and xfs/441
      when always_cow is turned on.  In all cases, the regressions take the
      form of alwayscow files consuming rather more space than the golden
      output is expecting.  I observed that in all these cases, the cause of
      the excess space usage was due to CoW fork delalloc reservations that go
      beyond EOF.
      
      For alwayscow files we allow posteof delalloc CoW reservations because
      all writes go through the CoW fork.  Recall that all extents in the CoW
      fork are accounted for via i_delayed_blks, which means that prior to
      this patch, we'd invoke xfs_free_eofblocks on first close if anything
      was in the CoW fork.  Now we don't do that.
      
      Fix the problem by reverting the removal of the i_delayed_blks check.
      
      Cc: <stable@vger.kernel.org> # v6.12-rc1
      Fixes: 11f4c3a5 ("xfs: simplify extent lookup in xfs_can_free_eofblocks")
      Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      66b60629
    • Dmitry Baryshkov's avatar
      usb: typec: ucsi: glink: fix off-by-one in connector_status · 6ba6f7f2
      Dmitry Baryshkov authored
      
      commit 4a22918810980897393fa1776ea3877e4baf8cca upstream.
      
      UCSI connector's indices start from 1 up to 3, PMIC_GLINK_MAX_PORTS.
      Correct the condition in the pmic_glink_ucsi_connector_status()
      callback, fixing Type-C orientation reporting for the third USB-C
      connector.
      
      Fixes: 76716fd5 ("usb: typec: ucsi: glink: move GPIO reading into connector_status callback")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarAbel Vesa <abel.vesa@linaro.org>
      Reviewed-by: default avatarNeil Armstrong <neil.armstrong@linaro.org>
      Reviewed-by: default avatarJohan Hovold <johan+linaro@kernel.org>
      Tested-by: default avatarJohan Hovold <johan+linaro@kernel.org>
      Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Link: https://lore.kernel.org/r/20241109-ucsi-glue-fixes-v2-1-8b21ff4f9fbe@linaro.org
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6ba6f7f2
    • Vitalii Mordan's avatar
      usb: ehci-spear: fix call balance of sehci clk handling routines · a3245450
      Vitalii Mordan authored
      
      commit 40c974826734836402abfd44efbf04f63a2cc1c1 upstream.
      
      If the clock sehci->clk was not enabled in spear_ehci_hcd_drv_probe,
      it should not be disabled in any path.
      
      Conversely, if it was enabled in spear_ehci_hcd_drv_probe, it must be disabled
      in all error paths to ensure proper cleanup.
      
      Found by Linux Verification Center (linuxtesting.org) with Klever.
      
      Fixes: 7675d6ba ("USB: EHCI: make ehci-spear a separate driver")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarVitalii Mordan <mordan@ispras.ru>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/20241114230310.432213-1-mordan@ispras.ru
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a3245450
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix out of bounds reads when finding clock sources · 096bb5b4
      Takashi Iwai authored
      
      commit a3dd4d63eeb452cfb064a13862fb376ab108f6a6 upstream.
      
      The current USB-audio driver code doesn't check bLength of each
      descriptor at traversing for clock descriptors.  That is, when a
      device provides a bogus descriptor with a shorter bLength, the driver
      might hit out-of-bounds reads.
      
      For addressing it, this patch adds sanity checks to the validator
      functions for the clock descriptor traversal.  When the descriptor
      length is shorter than expected, it's skipped in the loop.
      
      For the clock source and clock multiplier descriptors, we can just
      check bLength against the sizeof() of each descriptor type.
      OTOH, the clock selector descriptor of UAC2 and UAC3 has an array
      of bNrInPins elements and two more fields at its tail, hence those
      have to be checked in addition to the sizeof() check.
      
      Reported-by: default avatarBenoît Sevens <bsevens@google.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/20241121140613.3651-1-bsevens@google.com
      Link: https://patch.msgid.link/20241125144629.20757-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      096bb5b4
    • Benoît Sevens's avatar
      ALSA: usb-audio: Fix potential out-of-bound accesses for Extigy and Mbox devices · b521b53a
      Benoît Sevens authored
      
      commit b909df18ce2a998afef81d58bbd1a05dc0788c40 upstream.
      
      A bogus device can provide a bNumConfigurations value that exceeds the
      initial value used in usb_get_configuration for allocating dev->config.
      
      This can lead to out-of-bounds accesses later, e.g. in
      usb_destroy_configuration.
      
      Signed-off-by: default avatarBenoît Sevens <bsevens@google.com>
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Cc: stable@kernel.org
      Link: https://patch.msgid.link/20241120124144.3814457-1-bsevens@google.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b521b53a
    • Qiu-ji Chen's avatar
      xen: Fix the issue of resource not being properly released in xenbus_dev_probe() · 2f977a4c
      Qiu-ji Chen authored
      
      commit afc545da381ba0c651b2658966ac737032676f01 upstream.
      
      This patch fixes an issue in the function xenbus_dev_probe(). In the
      xenbus_dev_probe() function, within the if (err) branch at line 313, the
      program incorrectly returns err directly without releasing the resources
      allocated by err = drv->probe(dev, id). As the return value is non-zero,
      the upper layers assume the processing logic has failed. However, the probe
      operation was performed earlier without a corresponding remove operation.
      Since the probe actually allocates resources, failing to perform the remove
      operation could lead to problems.
      
      To fix this issue, we followed the resource release logic of the
      xenbus_dev_remove() function by adding a new block fail_remove before the
      fail_put block. After entering the branch if (err) at line 313, the
      function will use a goto statement to jump to the fail_remove block,
      ensuring that the previously acquired resources are correctly released,
      thus preventing the reference count leak.
      
      This bug was identified by an experimental static analysis tool developed
      by our team. The tool specializes in analyzing reference count operations
      and detecting potential issues where resources are not properly managed.
      In this case, the tool flagged the missing release operation as a
      potential problem, which led to the development of this patch.
      
      Fixes: 4bac07c9 ("xen: add the Xenbus sysfs and virtual device hotplug driver")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarQiu-ji Chen <chenqiuji666@gmail.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20241105130919.4621-1-chenqiuji666@gmail.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f977a4c
    • Jakub Kicinski's avatar
      net_sched: sch_fq: don't follow the fast path if Tx is behind now · d716851d
      Jakub Kicinski authored
      
      commit 122aba8c80618eca904490b1733af27fb8f07528 upstream.
      
      Recent kernels cause a lot of TCP retransmissions
      
      [ ID] Interval           Transfer     Bitrate         Retr  Cwnd
      [  5]   0.00-1.00   sec  2.24 GBytes  19.2 Gbits/sec  2767    442 KBytes
      [  5]   1.00-2.00   sec  2.23 GBytes  19.1 Gbits/sec  2312    350 KBytes
                                                            ^^^^
      
      Replacing the qdisc with pfifo makes retransmissions go away.
      
      It appears that a flow may have a delayed packet with a very near
      Tx time. Later, we may get busy processing Rx and the target Tx time
      will pass, but we won't service Tx since the CPU is busy with Rx.
      If Rx sees an ACK and we try to push more data for the delayed flow
      we may fastpath the skb, not realizing that there are already "ready
      to send" packets for this flow sitting in the qdisc.
      
      Don't trust the fastpath if we are "behind" according to the projected
      Tx time for next flow waiting in the Qdisc. Because we consider anything
      within the offload window to be okay for fastpath we must consider
      the entire offload window as "now".
      
      Qdisc config:
      
      qdisc fq 8001: dev eth0 parent 1234:1 limit 10000p flow_limit 100p \
        buckets 32768 orphan_mask 1023 bands 3 \
        priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 \
        weights 589824 196608 65536 quantum 3028b initial_quantum 15140b \
        low_rate_threshold 550Kbit \
        refill_delay 40ms timer_slack 10us horizon 10s horizon_drop
      
      For iperf this change seems to do fine, the reordering is gone.
      The fastpath still gets used most of the time:
      
        gc 0 highprio 0 fastpath 142614 throttled 418309 latency 19.1us
         xx_behind 2731
      
      where "xx_behind" counts how many times we hit the new "return false".
      
      CC: stable@vger.kernel.org
      Fixes: 076433bd ("net_sched: sch_fq: add fast path for mostly idle qdisc")
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://patch.msgid.link/20241124022148.3126719-1-kuba@kernel.org
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      [stable: drop the offload horizon, it's not supported / 0]
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d716851d
    • Xiuhong Wang's avatar
      f2fs: fix fiemap failure issue when page size is 16KB · 98b87256
      Xiuhong Wang authored
      
      commit a7a7c1d423a6351a6541e95c797da5358e5ad1ea upstream.
      
      After enable 16K page size, an infinite loop may occur in
      fiemap (fm_length=UINT64_MAX) on a file, such as the 16KB
      scratch.img during the remount operation in Android.
      
      The condition for whether fiemap continues to map is to check
      whether the number of bytes corresponding to the next map.m_lblk
      exceeds blks_to_bytes(inode,max_inode_blocks(inode)) if there are HOLE.
      The latter does not take into account the maximum size of a file with 16KB
      page size, so the loop cannot be jumped out.
      
      The following is the fail trace:
      When f2fs_map_blocks reaches map.m_lblk=3936, it needs to go to the
      first direct node block, so the map is 3936 + 4090 = 8026,
      The next map is the second direct node block, that is,
      8026 + 4090 = 12116,
      The next map is the first indirect node block, that is,
      12116 + 4090 * 4090 = 16740216,
      The next map is the second indirect node block, that is,
      16740216 + 4090 * 4090 = 33468316,
      The next map is the first double indirect node block, that is,
      33468316 + 4090 * 4090 * 4090 = 68451397316
      Since map.m_lblk represents the address of a block, which is 32
      bits, truncation will occur, that is, 68451397316 becomes
      4026887876, and the number of bytes corresponding to the block
      number does not exceed blks_to_bytes(inode,max_inode_blocks(inode)),
      so the loop will not be jumped out.
      The next time, it will be considered that it should still be a
      double indirect node block, that is,
      4026887876 + 4090 * 4090 * 4090 = 72444816876, which will be
      truncated to 3725340140, and the loop will not be jumped out.
      
      156.374871: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 0, start blkaddr = 0x8e00, len = 0x200, flags = 2,seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.374916: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 512, start blkaddr = 0x0, len = 0x0, flags = 0 , seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.374920: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 513, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      ......
      156.385747: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 3935, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385752: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 3936, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385755: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 8026, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385758: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 12116, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385761: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 16740216, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385764: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 33468316, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385767: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 4026887876, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385770: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 3725340140, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385772: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 4026887876, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      156.385775: f2fs_map_blocks: dev = (254,57), ino = 7449, file offset = 3725340140, start blkaddr = 0x0, len = 0x0, flags = 0, seg_type = 8, may_create = 0, multidevice = 0, flag = 1, err = 0
      
      Commit a6a010f5 ("f2fs: Restrict max filesize for 16K f2fs")
      has set the maximum allowed file size to (U32_MAX + 1) * F2FS_BLKSIZE,
      so max_file_blocks should be used here to limit it, that is,
      maxbytes defined above. And the max_inode_blocks function is not
      called by other functions except here, so cleanup it.
      
      Signed-off-by: default avatarXiuhong Wang <xiuhong.wang@unisoc.com>
      Signed-off-by: default avatarZhiguo Niu <zhiguo.niu@unisoc.com>
      Reviewed-by: default avatarChao Yu <chao@kernel.org>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      Cc: Daniel Rosenberg <drosen@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      98b87256
    • Niklas Schnelle's avatar
      s390/pci: Fix potential double remove of hotplug slot · 371bd905
      Niklas Schnelle authored
      
      [ Upstream commit c4a585e952ca403a370586d3f16e8331a7564901 ]
      
      In commit 6ee600bf ("s390/pci: remove hotplug slot when releasing the
      device") the zpci_exit_slot() was moved from zpci_device_reserved() to
      zpci_release_device() with the intention of keeping the hotplug slot
      around until the device is actually removed.
      
      Now zpci_release_device() is only called once all references are
      dropped. Since the zPCI subsystem only drops its reference once the
      device is in the reserved state it follows that zpci_release_device()
      must only deal with devices in the reserved state. Despite that it
      contains code to tear down from both configured and standby state. For
      the standby case this already includes the removal of the hotplug slot
      so would cause a double removal if a device was ever removed in
      either configured or standby state.
      
      Instead of causing a potential double removal in a case that should
      never happen explicitly WARN_ON() if a device in non-reserved state is
      released and get rid of the dead code cases.
      
      Fixes: 6ee600bf ("s390/pci: remove hotplug slot when releasing the device")
      Reviewed-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
      Reviewed-by: default avatarGerd Bayer <gbayer@linux.ibm.com>
      Tested-by: default avatarGerd Bayer <gbayer@linux.ibm.com>
      Signed-off-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      371bd905
    • Nícolas F. R. A. Prado's avatar
      ASoC: mediatek: Check num_codecs is not zero to avoid panic during probe · 55027944
      Nícolas F. R. A. Prado authored
      
      [ Upstream commit 2f2020327cc8561d7c520d2f2d9acea84fa7b3a3 ]
      
      Following commit 13f58267 ("ASoC: soc.h: don't create dummy
      Component via COMP_DUMMY()"), COMP_DUMMY() became an array with zero
      length, and only gets populated with the dummy struct after the card is
      registered. Since the sound card driver's probe happens before the card
      registration, accessing any of the members of a dummy component during
      probe will result in undefined behavior.
      
      This can be observed in the mt8188 and mt8195 machine sound drivers. By
      omitting a dai link subnode in the sound card's node in the Devicetree,
      the default uninitialized dummy codec is used, and when its dai_name
      pointer gets passed to strcmp() it results in a null pointer dereference
      and a kernel panic.
      
      In addition to that, set_card_codec_info() in the generic helpers file,
      mtk-soundcard-driver.c, will populate a dai link with a dummy codec when
      a dai link node is present in DT but with no codec property.
      
      The result is that at probe time, a dummy codec can either be
      uninitialized with num_codecs = 0, or be an initialized dummy codec,
      with num_codecs = 1 and dai_name = "snd-soc-dummy-dai". In order to
      accommodate for both situations, check that num_codecs is not zero
      before accessing the codecs' fields but still check for the codec's dai
      name against "snd-soc-dummy-dai" as needed.
      
      While at it, also drop the check that dai_name is not null in the mt8192
      driver, introduced in commit 4d4e1b63 ("ASoC: mediatek: mt8192:
      Check existence of dai_name before dereferencing"), as it is actually
      redundant given the preceding num_codecs != 0 check.
      
      Fixes: 13f58267 ("ASoC: soc.h: don't create dummy Component via COMP_DUMMY()")
      Signed-off-by: default avatarNícolas F. R. A. Prado <nfraprado@collabora.com>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Acked-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
      Reviewed-by: default avatarFei Shao <fshao@chromium.org>
      Acked-by: default avatarTrevor Wu <trevor.wu@mediatek.com>
      Link: https://patch.msgid.link/20241126-asoc-mtk-dummy-panic-v1-1-42d53e168d2e@collabora.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      55027944
Loading