1. 27 Apr, 2022 40 commits
    • Theodore Ts'o's avatar
      ext4: fix overhead calculation to account for the reserved gdt blocks · df602c1d
      Theodore Ts'o authored
      commit 10b01ee9
      
       upstream.
      
      The kernel calculation was underestimating the overhead by not taking
      into account the reserved gdt blocks.  With this change, the overhead
      calculated by the kernel matches the overhead calculation in mke2fs.
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df602c1d
    • wangjianjian (C)'s avatar
      ext4, doc: fix incorrect h_reserved size · 5be6d3a6
      wangjianjian (C) authored
      commit 7102ffe4
      
       upstream.
      
      According to document and code, ext4_xattr_header's size is 32 bytes, so
      h_reserved size should be 3.
      Signed-off-by: default avatarWang Jianjian <wangjianjian3@huawei.com>
      Link: https://lore.kernel.org/r/92fcc3a6-7d77-8c09-4126-377fcb4c46a5@huawei.com
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5be6d3a6
    • Tadeusz Struk's avatar
      ext4: limit length to bitmap_maxbytes - blocksize in punch_hole · 46d6a646
      Tadeusz Struk authored
      commit 2da37622 upstream.
      
      Syzbot found an issue [1] in ext4_fallocate().
      The C reproducer [2] calls fallocate(), passing size 0xffeffeff000ul,
      and offset 0x1000000ul, which, when added together exceed the
      bitmap_maxbytes for the inode. This triggers a BUG in
      ext4_ind_remove_space(). According to the comments in this function
      the 'end' parameter needs to be one block after the last block to be
      removed. In the case when the BUG is triggered it points to the last
      block. Modify the ext4_punch_hole() function and add constraint that
      caps the length to satisfy the one before laster block requirement.
      
      LINK: [1] https://syzkaller.appspot.com/bug?id=b80bd9cf348aac724a4f4dff251800106d721331
      LINK: [2] https://syzkaller.appspot.com/text?tag=ReproC&x=14ba0238700000
      
      Fixes: a4bb6b64
      
       ("ext4: enable "punch hole" functionality")
      Reported-by: syzbot+7a806094edd5d07ba029@syzkaller.appspotmail.com
      Signed-off-by: default avatarTadeusz Struk <tadeusz.struk@linaro.org>
      Link: https://lore.kernel.org/r/20220331200515.153214-1-tadeusz.struk@linaro.org
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46d6a646
    • Ye Bin's avatar
      ext4: fix use-after-free in ext4_search_dir · 105c3c3a
      Ye Bin authored
      commit c186f088
      
       upstream.
      
      We got issue as follows:
      EXT4-fs (loop0): mounted filesystem without journal. Opts: ,errors=continue
      ==================================================================
      BUG: KASAN: use-after-free in ext4_search_dir fs/ext4/namei.c:1394 [inline]
      BUG: KASAN: use-after-free in search_dirblock fs/ext4/namei.c:1199 [inline]
      BUG: KASAN: use-after-free in __ext4_find_entry+0xdca/0x1210 fs/ext4/namei.c:1553
      Read of size 1 at addr ffff8881317c3005 by task syz-executor117/2331
      
      CPU: 1 PID: 2331 Comm: syz-executor117 Not tainted 5.10.0+ #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
      Call Trace:
       __dump_stack lib/dump_stack.c:83 [inline]
       dump_stack+0x144/0x187 lib/dump_stack.c:124
       print_address_description+0x7d/0x630 mm/kasan/report.c:387
       __kasan_report+0x132/0x190 mm/kasan/report.c:547
       kasan_report+0x47/0x60 mm/kasan/report.c:564
       ext4_search_dir fs/ext4/namei.c:1394 [inline]
       search_dirblock fs/ext4/namei.c:1199 [inline]
       __ext4_find_entry+0xdca/0x1210 fs/ext4/namei.c:1553
       ext4_lookup_entry fs/ext4/namei.c:1622 [inline]
       ext4_lookup+0xb8/0x3a0 fs/ext4/namei.c:1690
       __lookup_hash+0xc5/0x190 fs/namei.c:1451
       do_rmdir+0x19e/0x310 fs/namei.c:3760
       do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x445e59
      Code: 4d c7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 1b c7 fb ff c3 66 2e 0f 1f 84 00 00 00 00
      RSP: 002b:00007fff2277fac8 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
      RAX: ffffffffffffffda RBX: 0000000000400280 RCX: 0000000000445e59
      RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000200000c0
      RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000002
      R10: 00007fff2277f990 R11: 0000000000000246 R12: 0000000000000000
      R13: 431bde82d7b634db R14: 0000000000000000 R15: 0000000000000000
      
      The buggy address belongs to the page:
      page:0000000048cd3304 refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x1317c3
      flags: 0x200000000000000()
      raw: 0200000000000000 ffffea0004526588 ffffea0004528088 0000000000000000
      raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff8881317c2f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
       ffff8881317c2f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      >ffff8881317c3000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                         ^
       ffff8881317c3080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
       ffff8881317c3100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
      ==================================================================
      
      ext4_search_dir:
        ...
        de = (struct ext4_dir_entry_2 *)search_buf;
        dlimit = search_buf + buf_size;
        while ((char *) de < dlimit) {
        ...
          if ((char *) de + de->name_len <= dlimit &&
      	 ext4_match(dir, fname, de)) {
      	    ...
          }
        ...
          de_len = ext4_rec_len_from_disk(de->rec_len, dir->i_sb->s_blocksize);
          if (de_len <= 0)
            return -1;
          offset += de_len;
          de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
        }
      
      Assume:
      de=0xffff8881317c2fff
      dlimit=0x0xffff8881317c3000
      
      If read 'de->name_len' which address is 0xffff8881317c3005, obviously is
      out of range, then will trigger use-after-free.
      To solve this issue, 'dlimit' must reserve 8 bytes, as we will read
      'de->name_len' to judge if '(char *) de + de->name_len' out of range.
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20220324064816.1209985-1-yebin10@huawei.com
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      105c3c3a
    • Ye Bin's avatar
      ext4: fix symlink file size not match to file content · 4e7d8c5c
      Ye Bin authored
      commit a2b0b205
      
       upstream.
      
      We got issue as follows:
      [home]# fsck.ext4  -fn  ram0yb
      e2fsck 1.45.6 (20-Mar-2020)
      Pass 1: Checking inodes, blocks, and sizes
      Pass 2: Checking directory structure
      Symlink /p3/d14/d1a/l3d (inode #3494) is invalid.
      Clear? no
      Entry 'l3d' in /p3/d14/d1a (3383) has an incorrect filetype (was 7, should be 0).
      Fix? no
      
      As the symlink file size does not match the file content. If the writeback
      of the symlink data block failed, ext4_finish_bio() handles the end of IO.
      However this function fails to mark the buffer with BH_write_io_error and
      so when unmount does journal checkpoint it cannot detect the writeback
      error and will cleanup the journal. Thus we've lost the correct data in the
      journal area. To solve this issue, mark the buffer as BH_write_io_error in
      ext4_finish_bio().
      
      Cc: stable@kernel.org
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20220321144438.201685-1-yebin10@huawei.com
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e7d8c5c
    • Darrick J. Wong's avatar
      ext4: fix fallocate to use file_modified to update permissions consistently · 9799392a
      Darrick J. Wong authored
      commit ad5cd4f4
      
       upstream.
      
      Since the initial introduction of (posix) fallocate back at the turn of
      the century, it has been possible to use this syscall to change the
      user-visible contents of files.  This can happen by extending the file
      size during a preallocation, or through any of the newer modes (punch,
      zero, collapse, insert range).  Because the call can be used to change
      file contents, we should treat it like we do any other modification to a
      file -- update the mtime, and drop set[ug]id privileges/capabilities.
      
      The VFS function file_modified() does all this for us if pass it a
      locked inode, so let's make fallocate drop permissions correctly.
      Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Link: https://lore.kernel.org/r/20220308185043.GA117678@magnolia
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9799392a
    • Mingwei Zhang's avatar
      KVM: SVM: Flush when freeing encrypted pages even on SME_COHERENT CPUs · b5296f09
      Mingwei Zhang authored
      commit d45829b3 upstream.
      
      Use clflush_cache_range() to flush the confidential memory when
      SME_COHERENT is supported in AMD CPU. Cache flush is still needed since
      SME_COHERENT only support cache invalidation at CPU side. All confidential
      cache lines are still incoherent with DMA devices.
      
      Cc: stable@vger.kerel.org
      
      Fixes: add5e2f0
      
       ("KVM: SVM: Add support for the SEV-ES VMSA")
      Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarMingwei Zhang <mizhang@google.com>
      Message-Id: <20220421031407.2516575-3-mizhang@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b5296f09
    • Sean Christopherson's avatar
      KVM: SVM: Simplify and harden helper to flush SEV guest page(s) · 5ecee7fc
      Sean Christopherson authored
      commit 4bbef7e8
      
       upstream.
      
      Rework sev_flush_guest_memory() to explicitly handle only a single page,
      and harden it to fall back to WBINVD if VM_PAGE_FLUSH fails.  Per-page
      flushing is currently used only to flush the VMSA, and in its current
      form, the helper is completely broken with respect to flushing actual
      guest memory, i.e. won't work correctly for an arbitrary memory range.
      
      VM_PAGE_FLUSH takes a host virtual address, and is subject to normal page
      walks, i.e. will fault if the address is not present in the host page
      tables or does not have the correct permissions.  Current AMD CPUs also
      do not honor SMAP overrides (undocumented in kernel versions of the APM),
      so passing in a userspace address is completely out of the question.  In
      other words, KVM would need to manually walk the host page tables to get
      the pfn, ensure the pfn is stable, and then use the direct map to invoke
      VM_PAGE_FLUSH.  And the latter might not even work, e.g. if userspace is
      particularly evil/clever and backs the guest with Secret Memory (which
      unmaps memory from the direct map).
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      Fixes: add5e2f0
      
       ("KVM: SVM: Add support for the SEV-ES VMSA")
      Reported-by: default avatarMingwei Zhang <mizhang@google.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMingwei Zhang <mizhang@google.com>
      Message-Id: <20220421031407.2516575-2-mizhang@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      5ecee7fc
    • Sean Christopherson's avatar
      KVM: nVMX: Defer APICv updates while L2 is active until L1 is active · 246b862c
      Sean Christopherson authored
      commit 7c69661e
      
       upstream.
      
      Defer APICv updates that occur while L2 is active until nested VM-Exit,
      i.e. until L1 regains control.  vmx_refresh_apicv_exec_ctrl() assumes L1
      is active and (a) stomps all over vmcs02 and (b) neglects to ever updated
      vmcs01.  E.g. if vmcs12 doesn't enable the TPR shadow for L2 (and thus no
      APICv controls), L1 performs nested VM-Enter APICv inhibited, and APICv
      becomes unhibited while L2 is active, KVM will set various APICv controls
      in vmcs02 and trigger a failed VM-Entry.  The kicker is that, unless
      running with nested_early_check=1, KVM blames L1 and chaos ensues.
      
      In all cases, ignoring vmcs02 and always deferring the inhibition change
      to vmcs01 is correct (or at least acceptable).  The ABSENT and DISABLE
      inhibitions cannot truly change while L2 is active (see below).
      
      IRQ_BLOCKING can change, but it is firmly a best effort debug feature.
      Furthermore, only L2's APIC is accelerated/virtualized to the full extent
      possible, e.g. even if L1 passes through its APIC to L2, normal MMIO/MSR
      interception will apply to the virtual APIC managed by KVM.
      The exception is the SELF_IPI register when x2APIC is enabled, but that's
      an acceptable hole.
      
      Lastly, Hyper-V's Auto EOI can technically be toggled if L1 exposes the
      MSRs to L2, but for that to work in any sane capacity, L1 would need to
      pass through IRQs to L2 as well, and IRQs must be intercepted to enable
      virtual interrupt delivery.  I.e. exposing Auto EOI to L2 and enabling
      VID for L2 are, for all intents and purposes, mutually exclusive.
      
      Lack of dynamic toggling is also why this scenario is all but impossible
      to encounter in KVM's current form.  But a future patch will pend an
      APICv update request _during_ vCPU creation to plug a race where a vCPU
      that's being created doesn't get included in the "all vCPUs request"
      because it's not yet visible to other vCPUs.  If userspaces restores L2
      after VM creation (hello, KVM selftests), the first KVM_RUN will occur
      while L2 is active and thus service the APICv update request made during
      VM creation.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220420013732.3308816-3-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      246b862c
    • Sean Christopherson's avatar
      KVM: x86: Pend KVM_REQ_APICV_UPDATE during vCPU creation to fix a race · c66bd1dd
      Sean Christopherson authored
      commit 423ecfea
      
       upstream.
      
      Make a KVM_REQ_APICV_UPDATE request when creating a vCPU with an
      in-kernel local APIC and APICv enabled at the module level.  Consuming
      kvm_apicv_activated() and stuffing vcpu->arch.apicv_active directly can
      race with __kvm_set_or_clear_apicv_inhibit(), as vCPU creation happens
      before the vCPU is fully onlined, i.e. it won't get the request made to
      "all" vCPUs.  If APICv is globally inhibited between setting apicv_active
      and onlining the vCPU, the vCPU will end up running with APICv enabled
      and trigger KVM's sanity check.
      
      Mark APICv as active during vCPU creation if APICv is enabled at the
      module level, both to be optimistic about it's final state, e.g. to avoid
      additional VMWRITEs on VMX, and because there are likely bugs lurking
      since KVM checks apicv_active in multiple vCPU creation paths.  While
      keeping the current behavior of consuming kvm_apicv_activated() is
      arguably safer from a regression perspective, force apicv_active so that
      vCPU creation runs with deterministic state and so that if there are bugs,
      they are found sooner than later, i.e. not when some crazy race condition
      is hit.
      
        WARNING: CPU: 0 PID: 484 at arch/x86/kvm/x86.c:9877 vcpu_enter_guest+0x2ae3/0x3ee0 arch/x86/kvm/x86.c:9877
        Modules linked in:
        CPU: 0 PID: 484 Comm: syz-executor361 Not tainted 5.16.13 #2
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1~cloud0 04/01/2014
        RIP: 0010:vcpu_enter_guest+0x2ae3/0x3ee0 arch/x86/kvm/x86.c:9877
        Call Trace:
         <TASK>
         vcpu_run arch/x86/kvm/x86.c:10039 [inline]
         kvm_arch_vcpu_ioctl_run+0x337/0x15e0 arch/x86/kvm/x86.c:10234
         kvm_vcpu_ioctl+0x4d2/0xc80 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3727
         vfs_ioctl fs/ioctl.c:51 [inline]
         __do_sys_ioctl fs/ioctl.c:874 [inline]
         __se_sys_ioctl fs/ioctl.c:860 [inline]
         __x64_sys_ioctl+0x16d/0x1d0 fs/ioctl.c:860
         do_syscall_x64 arch/x86/entry/common.c:50 [inline]
         do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80
         entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      The bug was hit by a syzkaller spamming VM creation with 2 vCPUs and a
      call to KVM_SET_GUEST_DEBUG.
      
        r0 = openat$kvm(0xffffffffffffff9c, &(0x7f0000000000), 0x0, 0x0)
        r1 = ioctl$KVM_CREATE_VM(r0, 0xae01, 0x0)
        ioctl$KVM_CAP_SPLIT_IRQCHIP(r1, 0x4068aea3, &(0x7f0000000000)) (async)
        r2 = ioctl$KVM_CREATE_VCPU(r1, 0xae41, 0x0) (async)
        r3 = ioctl$KVM_CREATE_VCPU(r1, 0xae41, 0x400000000000002)
        ioctl$KVM_SET_GUEST_DEBUG(r3, 0x4048ae9b, &(0x7f00000000c0)={0x5dda9c14aa95f5c5})
        ioctl$KVM_RUN(r2, 0xae80, 0x0)
      Reported-by: default avatarGaoning Pan <pgn@zju.edu.cn>
      Reported-by: default avatarYongkang Jia <kangel@zju.edu.cn>
      Fixes: 8df14af4
      
       ("kvm: x86: Add support for dynamic APICv activation")
      Cc: stable@vger.kernel.org
      Cc: Maxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Message-Id: <20220420013732.3308816-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c66bd1dd
    • Sean Christopherson's avatar
      KVM: x86: Don't re-acquire SRCU lock in complete_emulated_io() · daa3f16e
      Sean Christopherson authored
      commit 2d089356 upstream.
      
      Don't re-acquire SRCU in complete_emulated_io() now that KVM acquires the
      lock in kvm_arch_vcpu_ioctl_run().  More importantly, don't overwrite
      vcpu->srcu_idx.  If the index acquired by complete_emulated_io() differs
      from the one acquired by kvm_arch_vcpu_ioctl_run(), KVM will effectively
      leak a lock and hang if/when synchronize_srcu() is invoked for the
      relevant grace period.
      
      Fixes: 8d25b7be
      
       ("KVM: x86: pull kvm->srcu read-side to kvm_arch_vcpu_ioctl_run")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Message-Id: <20220415004343.2203171-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      daa3f16e
    • Like Xu's avatar
      KVM: x86/pmu: Update AMD PMC sample period to fix guest NMI-watchdog · 3a59b94b
      Like Xu authored
      commit 75189d1d upstream.
      
      NMI-watchdog is one of the favorite features of kernel developers,
      but it does not work in AMD guest even with vPMU enabled and worse,
      the system misrepresents this capability via /proc.
      
      This is a PMC emulation error. KVM does not pass the latest valid
      value to perf_event in time when guest NMI-watchdog is running, thus
      the perf_event corresponding to the watchdog counter will enter the
      old state at some point after the first guest NMI injection, forcing
      the hardware register PMC0 to be constantly written to 0x800000000001.
      
      Meanwhile, the running counter should accurately reflect its new value
      based on the latest coordinated pmc->counter (from vPMC's point of view)
      rather than the value written directly by the guest.
      
      Fixes: 168d918f
      
       ("KVM: x86: Adjust counter sample period after a wrmsr")
      Reported-by: default avatarDongli Cao <caodongli@kingsoft.com>
      Signed-off-by: default avatarLike Xu <likexu@tencent.com>
      Reviewed-by: default avatarYanan Wang <wangyanan55@huawei.com>
      Tested-by: default avatarYanan Wang <wangyanan55@huawei.com>
      Reviewed-by: default avatarJim Mattson <jmattson@google.com>
      Message-Id: <20220409015226.38619-1-likexu@tencent.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3a59b94b
    • Rob Herring's avatar
      arm_pmu: Validate single/group leader events · 7f99e9d6
      Rob Herring authored
      commit e5c23779
      
       upstream.
      
      In the case where there is only a cycle counter available (i.e.
      PMCR_EL0.N is 0) and an event other than CPU cycles is opened, the open
      should fail as the event can never possibly be scheduled. However, the
      event validation when an event is opened is skipped when the group
      leader is opened. Fix this by always validating the group leader events.
      Reported-by: default avatarAl Grant <al.grant@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
      Link: https://lore.kernel.org/r/20220408203330.4014015-1-robh@kernel.org
      
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f99e9d6
    • Zack Rusin's avatar
      drm/vmwgfx: Fix gem refcounting and memory evictions · cff5f3b5
      Zack Rusin authored
      commit 298799a2
      
       upstream.
      
      v2: Add the last part of the ref count fix which was spotted by
      Philipp Sieweck where the ref count of cpu writers is off due to
      ERESTARTSYS or EBUSY during bo waits.
      
      The initial GEM port broke refcounting on shareable (prime) surfaces and
      memory evictions. The prime surfaces broke because the parent surfaces
      weren't increasing the ref count on GEM surfaces, which meant that
      the memory backing textures could have been deleted while the texture
      was still accessible. The evictions broke due to a typo, the code was
      supposed to exit if the passed buffers were not vmw_buffer_object
      not if they were. They're tied because the evictions depend on having
      memory to actually evict.
      
      This fixes crashes with XA state tracker which is used for xrender
      acceleration on xf86-video-vmware, apps/tests which use a lot of
      memory (a good test being the piglit's streaming-texture-leak) and
      desktops.
      Signed-off-by: default avatarZack Rusin <zackr@vmware.com>
      Fixes: 8afa13a0
      
       ("drm/vmwgfx: Implement DRIVER_GEM")
      Reported-by: default avatarPhilipp Sieweck <psi@informatik.uni-kiel.de>
      Cc: <stable@vger.kernel.org> # v5.17+
      Reviewed-by: default avatarMaaz Mombasawala <mombasawalam@vmware.com>
      Reviewed-by: default avatarMartin Krastev <krastevm@vmware.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220420040328.1007409-1-zack@kde.org
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cff5f3b5
    • Sergey Matyukevich's avatar
      ARC: entry: fix syscall_trace_exit argument · 74364b41
      Sergey Matyukevich authored
      commit b1c6ecfd
      
       upstream.
      
      Function syscall_trace_exit expects pointer to pt_regs. However
      r0 is also used to keep syscall return value. Restore pointer
      to pt_regs before calling syscall_trace_exit.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarSergey Matyukevich <sergey.matyukevich@synopsys.com>
      Signed-off-by: default avatarVineet Gupta <vgupta@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      74364b41
    • Xiaomeng Tong's avatar
      codecs: rt5682s: fix an incorrect NULL check on list iterator · f13ab82a
      Xiaomeng Tong authored
      commit acc72863 upstream.
      
      The bug is here:
                  if (!dai) {
      
      The list iterator value 'dai' will *always* be set and non-NULL
      by for_each_component_dais(), so it is incorrect to assume that
      the iterator value will be NULL if the list is empty or no element
      is found (In fact, it will be a bogus pointer to an invalid struct
      object containing the HEAD). Otherwise it will bypass the check
      'if (!dai) {' (never call dev_err() and never return -ENODEV;)
      and lead to invalid memory access lately when calling
      'rt5682s_set_bclk1_ratio(dai, factor);'.
      
      To fix the bug, just return rt5682s_set_bclk1_ratio(dai, factor);
      when found the 'dai', otherwise dev_err() and return -ENODEV;
      
      Cc: stable@vger.kernel.org
      Fixes: bdd229ab
      
       ("ASoC: rt5682s: Add driver for ALC5682I-VS codec")
      Signed-off-by: default avatarXiaomeng Tong <xiam0nd.tong@gmail.com>
      Link: https://lore.kernel.org/r/20220327081300.12962-1-xiam0nd.tong@gmail.com
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f13ab82a
    • Sasha Neftin's avatar
      e1000e: Fix possible overflow in LTR decoding · 4250fca5
      Sasha Neftin authored
      commit 04ebaa1c upstream.
      
      When we decode the latency and the max_latency, u16 value may not fit
      the required size and could lead to the wrong LTR representation.
      
      Scaling is represented as:
      scale 0 - 1         (2^(5*0)) = 2^0
      scale 1 - 32        (2^(5 *1))= 2^5
      scale 2 - 1024      (2^(5 *2)) =2^10
      scale 3 - 32768     (2^(5 *3)) =2^15
      scale 4 - 1048576   (2^(5 *4)) = 2^20
      scale 5 - 33554432  (2^(5 *4)) = 2^25
      scale 4 and scale 5 required 20 and 25 bits respectively.
      scale 6 reserved.
      
      Replace the u16 type with the u32 type and allow corrected LTR
      representation.
      
      Cc: stable@vger.kernel.org
      Fixes: 44a13a5d
      
       ("e1000e: Fix the max snoop/no-snoop latency for 10M")
      Reported-by: default avatarJames Hutchinson <jahutchinson99@googlemail.com>
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215689
      
      Suggested-by: default avatarDima Ruinskiy <dima.ruinskiy@intel.com>
      Signed-off-by: default avatarSasha Neftin <sasha.neftin@intel.com>
      Tested-by: default avatarNaama Meir <naamax.meir@linux.intel.com>
      Tested-by: default avatarJames Hutchinson <jahutchinson99@googlemail.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4250fca5
    • Xiaomeng Tong's avatar
      ASoC: soc-dapm: fix two incorrect uses of list iterator · 8b5513f4
      Xiaomeng Tong authored
      commit f730a46b upstream.
      
      These two bug are here:
      	list_for_each_entry_safe_continue(w, n, list,
      					power_list);
      	list_for_each_entry_safe_continue(w, n, list,
      					power_list);
      
      After the list_for_each_entry_safe_continue() exits, the list iterator
      will always be a bogus pointer which point to an invalid struct objdect
      containing HEAD member. The funciton poniter 'w->event' will be a
      invalid value which can lead to a control-flow hijack if the 'w' can be
      controlled.
      
      The original intention was to continue the outer list_for_each_entry_safe()
      loop with the same entry if w->event is NULL, but misunderstanding the
      meaning of list_for_each_entry_safe_continue().
      
      So just add a 'continue;' to fix the bug.
      
      Cc: stable@vger.kernel.org
      Fixes: 163cac06
      
       ("ASoC: Factor out DAPM sequence execution")
      Signed-off-by: default avatarXiaomeng Tong <xiam0nd.tong@gmail.com>
      Link: https://lore.kernel.org/r/20220329012134.9375-1-xiam0nd.tong@gmail.com
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b5513f4
    • Xiaomeng Tong's avatar
      ASoC: rt5682: fix an incorrect NULL check on list iterator · a5402d05
      Xiaomeng Tong authored
      commit c8618d65 upstream.
      
      The bug is here:
      	if (!dai) {
      
      The list iterator value 'dai' will *always* be set and non-NULL
      by for_each_component_dais(), so it is incorrect to assume that
      the iterator value will be NULL if the list is empty or no element
      is found (In fact, it will be a bogus pointer to an invalid struct
      object containing the HEAD). Otherwise it will bypass the check
      'if (!dai) {' (never call dev_err() and never return -ENODEV;)
      and lead to invalid memory access lately when calling
      'rt5682_set_bclk1_ratio(dai, factor);'.
      
      To fix the bug, just return rt5682_set_bclk1_ratio(dai, factor);
      when found the 'dai', otherwise dev_err() and return -ENODEV;
      
      Cc: stable@vger.kernel.org
      Fixes: ebbfabc1
      
       ("ASoC: rt5682: Add CCF usage for providing I2S clks")
      Signed-off-by: default avatarXiaomeng Tong <xiam0nd.tong@gmail.com>
      Link: https://lore.kernel.org/r/20220327081002.12684-1-xiam0nd.tong@gmail.com
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a5402d05
    • Mario Limonciello's avatar
      gpio: Request interrupts after IRQ is initialized · d3f54679
      Mario Limonciello authored
      commit 06fb4ecf upstream.
      
      Commit 5467801f ("gpio: Restrict usage of GPIO chip irq members
      before initialization") attempted to fix a race condition that lead to a
      NULL pointer, but in the process caused a regression for _AEI/_EVT
      declared GPIOs.
      
      This manifests in messages showing deferred probing while trying to
      allocate IRQs like so:
      
        amd_gpio AMDI0030:00: Failed to translate GPIO pin 0x0000 to IRQ, err -517
        amd_gpio AMDI0030:00: Failed to translate GPIO pin 0x002C to IRQ, err -517
        amd_gpio AMDI0030:00: Failed to translate GPIO pin 0x003D to IRQ, err -517
        [ .. more of the same .. ]
      
      The code for walking _AEI doesn't handle deferred probing and so this
      leads to non-functional GPIO interrupts.
      
      Fix this issue by moving the call to `acpi_gpiochip_request_interrupts`
      to occur after gc->irc.initialized is set.
      
      Fixes: 5467801f ("gpio: Restrict usage of GPIO chip irq members before initialization")
      Link: https://lore.kernel.org/linux-gpio/BL1PR12MB51577A77F000A008AA694675E2EF9@BL1PR12MB5157.namprd12.prod.outlook.com/
      Link: https://bugzilla.suse.com/show_bug.cgi?id=1198697
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215850
      Link: https://gitlab.freedesktop.org/drm/amd/-/issues/1979
      Link: https://gitlab.freedesktop.org/drm/amd/-/issues/1976
      
      Reported-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Reviewed-by: default avatarShreeya Patel <shreeya.patel@collabora.com>
      Tested-By: default avatarSamuel Čavoj <samuel@cavoj.net>
      Tested-By: lukeluk498@gmail.com Link:
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Reviewed-and-tested-by: default avatarTakashi Iwai <tiwai@suse.de>
      Cc: Shreeya Patel <shreeya.patel@collabora.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d3f54679
    • Paolo Valerio's avatar
      openvswitch: fix OOB access in reserve_sfa_size() · 24f0f311
      Paolo Valerio authored
      commit cefa91b2 upstream.
      
      Given a sufficiently large number of actions, while copying and
      reserving memory for a new action of a new flow, if next_offset is
      greater than MAX_ACTIONS_BUFSIZE, the function reserve_sfa_size() does
      not return -EMSGSIZE as expected, but it allocates MAX_ACTIONS_BUFSIZE
      bytes increasing actions_len by req_size. This can then lead to an OOB
      write access, especially when further actions need to be copied.
      
      Fix it by rearranging the flow action size check.
      
      KASAN splat below:
      
      ==================================================================
      BUG: KASAN: slab-out-of-bounds in reserve_sfa_size+0x1ba/0x380 [openvswitch]
      Write of size 65360 at addr ffff888147e4001c by task handler15/836
      
      CPU: 1 PID: 836 Comm: handler15 Not tainted 5.18.0-rc1+ #27
      ...
      Call Trace:
       <TASK>
       dump_stack_lvl+0x45/0x5a
       print_report.cold+0x5e/0x5db
       ? __lock_text_start+0x8/0x8
       ? reserve_sfa_size+0x1ba/0x380 [openvswitch]
       kasan_report+0xb5/0x130
       ? reserve_sfa_size+0x1ba/0x380 [openvswitch]
       kasan_check_range+0xf5/0x1d0
       memcpy+0x39/0x60
       reserve_sfa_size+0x1ba/0x380 [openvswitch]
       __add_action+0x24/0x120 [openvswitch]
       ovs_nla_add_action+0xe/0x20 [openvswitch]
       ovs_ct_copy_action+0x29d/0x1130 [openvswitch]
       ? __kernel_text_address+0xe/0x30
       ? unwind_get_return_address+0x56/0xa0
       ? create_prof_cpu_mask+0x20/0x20
       ? ovs_ct_verify+0xf0/0xf0 [openvswitch]
       ? prep_compound_page+0x198/0x2a0
       ? __kasan_check_byte+0x10/0x40
       ? kasan_unpoison+0x40/0x70
       ? ksize+0x44/0x60
       ? reserve_sfa_size+0x75/0x380 [openvswitch]
       __ovs_nla_copy_actions+0xc26/0x2070 [openvswitch]
       ? __zone_watermark_ok+0x420/0x420
       ? validate_set.constprop.0+0xc90/0xc90 [openvswitch]
       ? __alloc_pages+0x1a9/0x3e0
       ? __alloc_pages_slowpath.constprop.0+0x1da0/0x1da0
       ? unwind_next_frame+0x991/0x1e40
       ? __mod_node_page_state+0x99/0x120
       ? __mod_lruvec_page_state+0x2e3/0x470
       ? __kasan_kmalloc_large+0x90/0xe0
       ovs_nla_copy_actions+0x1b4/0x2c0 [openvswitch]
       ovs_flow_cmd_new+0x3cd/0xb10 [openvswitch]
       ...
      
      Cc: stable@vger.kernel.org
      Fixes: f28cd2af
      
       ("openvswitch: fix flow actions reallocation")
      Signed-off-by: default avatarPaolo Valerio <pvalerio@redhat.com>
      Acked-by: default avatarEelco Chaudron <echaudro@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      24f0f311
    • Max Filippov's avatar
      xtensa: fix a7 clobbering in coprocessor context load/store · cd4ada44
      Max Filippov authored
      commit 839769c3 upstream.
      
      Fast coprocessor exception handler saves a3..a6, but coprocessor context
      load/store code uses a4..a7 as temporaries, potentially clobbering a7.
      'Potentially' because coprocessor state load/store macros may not use
      all four temporary registers (and neither FPU nor HiFi macros do).
      Use a3..a6 as intended.
      
      Cc: stable@vger.kernel.org
      Fixes: c658eac6
      
       ("[XTENSA] Add support for configurable registers and coprocessors")
      Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cd4ada44
    • Guo Ren's avatar
      xtensa: patch_text: Fixup last cpu should be master · 37ce27cb
      Guo Ren authored
      commit ee69d4be upstream.
      
      These patch_text implementations are using stop_machine_cpuslocked
      infrastructure with atomic cpu_count. The original idea: When the
      master CPU patch_text, the others should wait for it. But current
      implementation is using the first CPU as master, which couldn't
      guarantee the remaining CPUs are waiting. This patch changes the
      last CPU as the master to solve the potential risk.
      
      Fixes: 64711f9a
      
       ("xtensa: implement jump_label support")
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Signed-off-by: default avatarGuo Ren <guoren@kernel.org>
      Reviewed-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: <stable@vger.kernel.org>
      Message-Id: <20220407073323.743224-4-guoren@kernel.org>
      Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      37ce27cb
    • Paulo Alcantara's avatar
      cifs: use correct lock type in cifs_reconnect() · a6b48566
      Paulo Alcantara authored
      commit cd70a3e8
      
       upstream.
      
      TCP_Server_Info::origin_fullpath and TCP_Server_Info::leaf_fullpath
      are protected by refpath_lock mutex and not cifs_tcp_ses_lock
      spinlock.
      Signed-off-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a6b48566
    • Paulo Alcantara's avatar
      cifs: fix NULL ptr dereference in refresh_mounts() · 8d59b668
      Paulo Alcantara authored
      commit 41f10081
      
       upstream.
      
      Either mount(2) or automount might not have server->origin_fullpath
      set yet while refresh_cache_worker() is attempting to refresh DFS
      referrals.  Add missing NULL check and locking around it.
      
      This fixes bellow crash:
      
      [ 1070.276835] general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN NOPTI
      [ 1070.277676] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
      [ 1070.278219] CPU: 1 PID: 8506 Comm: kworker/u8:1 Not tainted 5.18.0-rc3 #10
      [ 1070.278701] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.15.0-0-g2dd4b9b-rebuilt.opensuse.org 04/01/2014
      [ 1070.279495] Workqueue: cifs-dfscache refresh_cache_worker [cifs]
      [ 1070.280044] RIP: 0010:strcasecmp+0x34/0x150
      [ 1070.280359] Code: 00 00 00 fc ff df 41 54 55 48 89 fd 53 48 83 ec 10 eb 03 4c 89 fe 48 89 ef 48 83 c5 01 48 89 f8 48 89 fa 48 c1 e8 03 83 e2 07 <42> 0f b6 04 28 38 d0 7f 08 84 c0 0f 85 bc 00 00 00 0f b6 45 ff 44
      [ 1070.281729] RSP: 0018:ffffc90008367958 EFLAGS: 00010246
      [ 1070.282114] RAX: 0000000000000000 RBX: dffffc0000000000 RCX: 0000000000000000
      [ 1070.282691] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
      [ 1070.283273] RBP: 0000000000000001 R08: 0000000000000000 R09: ffffffff873eda27
      [ 1070.283857] R10: ffffc900083679a0 R11: 0000000000000001 R12: ffff88812624c000
      [ 1070.284436] R13: dffffc0000000000 R14: ffff88810e6e9a88 R15: ffff888119bb9000
      [ 1070.284990] FS:  0000000000000000(0000) GS:ffff888151200000(0000) knlGS:0000000000000000
      [ 1070.285625] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1070.286100] CR2: 0000561a4d922418 CR3: 000000010aecc000 CR4: 0000000000350ee0
      [ 1070.286683] Call Trace:
      [ 1070.286890]  <TASK>
      [ 1070.287070]  refresh_cache_worker+0x895/0xd20 [cifs]
      [ 1070.287475]  ? __refresh_tcon.isra.0+0xfb0/0xfb0 [cifs]
      [ 1070.287905]  ? __lock_acquire+0xcd1/0x6960
      [ 1070.288247]  ? is_dynamic_key+0x1a0/0x1a0
      [ 1070.288591]  ? lockdep_hardirqs_on_prepare+0x410/0x410
      [ 1070.289012]  ? lock_downgrade+0x6f0/0x6f0
      [ 1070.289318]  process_one_work+0x7bd/0x12d0
      [ 1070.289637]  ? worker_thread+0x160/0xec0
      [ 1070.289970]  ? pwq_dec_nr_in_flight+0x230/0x230
      [ 1070.290318]  ? _raw_spin_lock_irq+0x5e/0x90
      [ 1070.290619]  worker_thread+0x5ac/0xec0
      [ 1070.290891]  ? process_one_work+0x12d0/0x12d0
      [ 1070.291199]  kthread+0x2a5/0x350
      [ 1070.291430]  ? kthread_complete_and_exit+0x20/0x20
      [ 1070.291770]  ret_from_fork+0x22/0x30
      [ 1070.292050]  </TASK>
      [ 1070.292223] Modules linked in: bpfilter cifs cifs_arc4 cifs_md4
      [ 1070.292765] ---[ end trace 0000000000000000 ]---
      [ 1070.293108] RIP: 0010:strcasecmp+0x34/0x150
      [ 1070.293471] Code: 00 00 00 fc ff df 41 54 55 48 89 fd 53 48 83 ec 10 eb 03 4c 89 fe 48 89 ef 48 83 c5 01 48 89 f8 48 89 fa 48 c1 e8 03 83 e2 07 <42> 0f b6 04 28 38 d0 7f 08 84 c0 0f 85 bc 00 00 00 0f b6 45 ff 44
      [ 1070.297718] RSP: 0018:ffffc90008367958 EFLAGS: 00010246
      [ 1070.298622] RAX: 0000000000000000 RBX: dffffc0000000000 RCX: 0000000000000000
      [ 1070.299428] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
      [ 1070.300296] RBP: 0000000000000001 R08: 0000000000000000 R09: ffffffff873eda27
      [ 1070.301204] R10: ffffc900083679a0 R11: 0000000000000001 R12: ffff88812624c000
      [ 1070.301932] R13: dffffc0000000000 R14: ffff88810e6e9a88 R15: ffff888119bb9000
      [ 1070.302645] FS:  0000000000000000(0000) GS:ffff888151200000(0000) knlGS:0000000000000000
      [ 1070.303462] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1070.304131] CR2: 0000561a4d922418 CR3: 000000010aecc000 CR4: 0000000000350ee0
      [ 1070.305004] Kernel panic - not syncing: Fatal exception
      [ 1070.305711] Kernel Offset: disabled
      [ 1070.305971] ---[ end Kernel panic - not syncing: Fatal exception ]---
      Signed-off-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8d59b668
    • Christian Brauner's avatar
      fs: fix acl translation · f518e2e7
      Christian Brauner authored
      commit 705191b0 upstream.
      
      Last cycle we extended the idmapped mounts infrastructure to support
      idmapped mounts of idmapped filesystems (No such filesystem yet exist.).
      Since then, the meaning of an idmapped mount is a mount whose idmapping
      is different from the filesystems idmapping.
      
      While doing that work we missed to adapt the acl translation helpers.
      They still assume that checking for the identity mapping is enough.  But
      they need to use the no_idmapping() helper instead.
      
      Note, POSIX ACLs are always translated right at the userspace-kernel
      boundary using the caller's current idmapping and the initial idmapping.
      The order depends on whether we're coming from or going to userspace.
      The filesystem's idmapping doesn't matter at the border.
      
      Consequently, if a non-idmapped mount is passed we need to make sure to
      always pass the initial idmapping as the mount's idmapping and not the
      filesystem idmapping.  Since it's irrelevant here it would yield invalid
      ids and prevent setting acls for filesystems that are mountable in a
      userns and support posix acls (tmpfs and fuse).
      
      I verified the regression reported in [1] and verified that this patch
      fixes it.  A regression test will be added to xfstests in parallel.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215849 [1]
      Fixes: bd303368
      
       ("fs: support mapped mounts of mapped filesystems")
      Cc: Seth Forshee <sforshee@digitalocean.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: <stable@vger.kernel.org> # 5.17
      Cc: <regressions@lists.linux.dev>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f518e2e7
    • Leo Yan's avatar
      perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event · 516a9b74
      Leo Yan authored
      [ Upstream commit ccb17cae ]
      
      Since commit bb30acae ("perf report: Bail out --mem-mode if mem
      info is not available") "perf mem report" and "perf report --mem-mode"
      don't report result if the PERF_SAMPLE_DATA_SRC bit is missed in sample
      type.
      
      The commit ffab4870 ("perf: arm-spe: Fix perf report
      --mem-mode") partially fixes the issue.  It adds PERF_SAMPLE_DATA_SRC
      bit for Arm SPE event, this allows the perf data file generated by
      kernel v5.18-rc1 or later version can be reported properly.
      
      On the other hand, perf tool still fails to be backward compatibility
      for a data file recorded by an older version's perf which contains Arm
      SPE trace data.  This patch is a workaround in reporting phase, when
      detects ARM SPE PMU event and without PERF_SAMPLE_DATA_SRC bit, it will
      force to set the bit in the sample type and give a warning info.
      
      Fixes: bb30acae
      
       ("perf report: Bail out --mem-mode if mem info is not available")
      Reviewed-by: default avatarJames Clark <james.clark@arm.com>
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Tested-by: default avatarGerman Gomez <german.gomez@arm.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
      Link: https://lore.kernel.org/r/20220414123201.842754-1-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      516a9b74
    • Leo Yan's avatar
      perf script: Always allow field 'data_src' for auxtrace · 3992e509
      Leo Yan authored
      [ Upstream commit c6d8df01 ]
      
      If use command 'perf script -F,+data_src' to dump memory samples with
      Arm SPE trace data, it reports error:
      
        # perf script -F,+data_src
        Samples for 'dummy:u' event do not have DATA_SRC attribute set. Cannot print 'data_src' field.
      
      This is because the 'dummy:u' event is absent DATA_SRC bit in its sample
      type, so if a file contains AUX area tracing data then always allow
      field 'data_src' to be selected as an option for perf script.
      
      Fixes: e55ed342
      
       ("perf arm-spe: Synthesize memory event")
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20220417114837.839896-1-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3992e509
    • Miaoqian Lin's avatar
      arm/xen: Fix some refcount leaks · bbcd0267
      Miaoqian Lin authored
      [ Upstream commit 533bec14 ]
      
      The of_find_compatible_node() function returns a node pointer with
      refcount incremented, We should use of_node_put() on it when done
      Add the missing of_node_put() to release the refcount.
      
      Fixes: 9b08aaa3 ("ARM: XEN: Move xen_early_init() before efi_init()")
      Fixes: b2371587
      
       ("arm/xen: Read extended regions from DT and init Xen resource")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
      Signed-off-by: default avatarStefano Stabellini <stefano.stabellini@xilinx.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bbcd0267
    • Athira Rajeev's avatar
      powerpc/perf: Fix power10 event alternatives · 9b6308dc
      Athira Rajeev authored
      [ Upstream commit c6cc9a85 ]
      
      When scheduling a group of events, there are constraint checks done to
      make sure all events can go in a group. Example, one of the criteria is
      that events in a group cannot use the same PMC. But platform specific
      PMU supports alternative event for some of the event codes. During
      perf_event_open(), if any event group doesn't match constraint check
      criteria, further lookup is done to find alternative event.
      
      By current design, the array of alternatives events in PMU code is
      expected to be sorted by column 0. This is because in
      find_alternative() the return criteria is based on event code
      comparison. ie. "event < ev_alt[i][0])". This optimisation is there
      since find_alternative() can be called multiple times. In power10 PMU
      code, the alternative event array is not sorted properly and hence there
      is breakage in finding alternative event.
      
      To work with existing logic, fix the alternative event array to be
      sorted by column 0 for power10-pmu.c
      
      Results:
      
      In case where an alternative event is not chosen when we could, events
      will be multiplexed. ie, time sliced where it could actually run
      concurrently.
      
      Example, in power10 PM_INST_CMPL_ALT(0x00002) has alternative event,
      PM_INST_CMPL(0x500fa). Without the fix, if a group of events with PMC1
      to PMC4 is used along with PM_INST_CMPL_ALT, it will be time sliced
      since all programmable PMC's are consumed already. But with the fix,
      when it picks alternative event on PMC5, all events will run
      concurrently.
      
      Before:
      
       # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc
      
       Performance counter stats for 'system wide':
      
               328668935      r00002               (79.94%)
                56501024      r100fc               (79.95%)
                49564238      r200fa               (79.95%)
                     376      r300fc               (80.19%)
                     660      r400fc               (79.97%)
      
             4.039150522 seconds time elapsed
      
      With the fix, since alternative event is chosen to run on PMC6, events
      will be run concurrently.
      
      After:
      
       # perf stat -e r00002,r100fc,r200fa,r300fc,r400fc
      
       Performance counter stats for 'system wide':
      
                23596607      r00002
                 4907738      r100fc
                 2283608      r200fa
                     135      r300fc
                     248      r400fc
      
             1.664671390 seconds time elapsed
      
      Fixes: a64e697c
      
       ("powerpc/perf: power10 Performance Monitoring support")
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20220419114828.89843-2-atrajeev@linux.vnet.ibm.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9b6308dc
    • Athira Rajeev's avatar
      powerpc/perf: Fix power9 event alternatives · a1ca0cbb
      Athira Rajeev authored
      [ Upstream commit 0dcad700 ]
      
      When scheduling a group of events, there are constraint checks done to
      make sure all events can go in a group. Example, one of the criteria is
      that events in a group cannot use the same PMC. But platform specific
      PMU supports alternative event for some of the event codes. During
      perf_event_open(), if any event group doesn't match constraint check
      criteria, further lookup is done to find alternative event.
      
      By current design, the array of alternatives events in PMU code is
      expected to be sorted by column 0. This is because in
      find_alternative() the return criteria is based on event code
      comparison. ie. "event < ev_alt[i][0])". This optimisation is there
      since find_alternative() can be called multiple times. In power9 PMU
      code, the alternative event array is not sorted properly and hence there
      is breakage in finding alternative events.
      
      To work with existing logic, fix the alternative event array to be
      sorted by column 0 for power9-pmu.c
      
      Results:
      
      With alternative events, multiplexing can be avoided. That is, for
      example, in power9 PM_LD_MISS_L1 (0x3e054) has alternative event,
      PM_LD_MISS_L1_ALT (0x400f0). This is an identical event which can be
      programmed in a different PMC.
      
      Before:
      
       # perf stat -e r3e054,r300fc
      
       Performance counter stats for 'system wide':
      
                 1057860      r3e054              (50.21%)
                     379      r300fc              (49.79%)
      
             0.944329741 seconds time elapsed
      
      Since both the events are using PMC3 in this case, they are
      multiplexed here.
      
      After:
      
       # perf stat -e r3e054,r300fc
      
       Performance counter stats for 'system wide':
      
                 1006948      r3e054
                     182      r300fc
      
      Fixes: 91e0bd1e
      
       ("powerpc/perf: Add PM_LD_MISS_L1 and PM_BR_2PATH to power9 event list")
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20220419114828.89843-1-atrajeev@linux.vnet.ibm.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a1ca0cbb
    • Miaoqian Lin's avatar
      drm/vc4: Use pm_runtime_resume_and_get to fix pm_runtime_get_sync() usage · 6796aad6
      Miaoqian Lin authored
      [ Upstream commit 3d0b93d9 ]
      
      If the device is already in a runtime PM enabled state
      pm_runtime_get_sync() will return 1.
      
      Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
      fails, so use pm_runtime_resume_and_get() instead. this function
      will handle this.
      
      Fixes: 4078f575
      
       ("drm/vc4: Add DSI driver")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220420135008.2757-1-linmq006@gmail.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6796aad6
    • Alexey Kardashevskiy's avatar
      KVM: PPC: Fix TCE handling for VFIO · aa918a1e
      Alexey Kardashevskiy authored
      [ Upstream commit 26a62b75 ]
      
      The LoPAPR spec defines a guest visible IOMMU with a variable page size.
      Currently QEMU advertises 4K, 64K, 2M, 16MB pages, a Linux VM picks
      the biggest (16MB). In the case of a passed though PCI device, there is
      a hardware IOMMU which does not support all pages sizes from the above -
      P8 cannot do 2MB and P9 cannot do 16MB. So for each emulated
      16M IOMMU page we may create several smaller mappings ("TCEs") in
      the hardware IOMMU.
      
      The code wrongly uses the emulated TCE index instead of hardware TCE
      index in error handling. The problem is easier to see on POWER8 with
      multi-level TCE tables (when only the first level is preallocated)
      as hash mode uses real mode TCE hypercalls handlers.
      The kernel starts using indirect tables when VMs get bigger than 128GB
      (depends on the max page order).
      The very first real mode hcall is going to fail with H_TOO_HARD as
      in the real mode we cannot allocate memory for TCEs (we can in the virtual
      mode) but on the way out the code attempts to clear hardware TCEs using
      emulated TCE indexes which corrupts random kernel memory because
      it_offset==1<<59 is subtracted from those indexes and the resulting index
      is out of the TCE table bounds.
      
      This fixes kvmppc_clear_tce() to use the correct TCE indexes.
      
      While at it, this fixes TCE cache invalidation which uses emulated TCE
      indexes instead of the hardware ones. This went unnoticed as 64bit DMA
      is used these days and VMs map all RAM in one go and only then do DMA
      and this is when the TCE cache gets populated.
      
      Potentially this could slow down mapping, however normally 16MB
      emulated pages are backed by 64K hardware pages so it is one write to
      the "TCE Kill" per 256 updates which is not that bad considering the size
      of the cache (1024 TCEs or so).
      
      Fixes: ca1fc489
      
       ("KVM: PPC: Book3S: Allow backing bigger guest IOMMU pages with smaller physical pages")
      Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Tested-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      Reviewed-by: default avatarFrederic Barrat <fbarrat@linux.ibm.com>
      Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20220420050840.328223-1-aik@ozlabs.ru
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aa918a1e
    • Michael Ellerman's avatar
      powerpc/time: Always set decrementer in timer_interrupt() · d0f75b88
      Michael Ellerman authored
      [ Upstream commit d2b9be1f ]
      
      This is a partial revert of commit 0faf20a1 ("powerpc/64s/interrupt:
      Don't enable MSR[EE] in irq handlers unless perf is in use").
      
      Prior to that commit, we always set the decrementer in
      timer_interrupt(), to clear the timer interrupt. Otherwise we could end
      up continuously taking timer interrupts.
      
      When high res timers are enabled there is no problem seen with leaving
      the decrementer untouched in timer_interrupt(), because it will be
      programmed via hrtimer_interrupt() -> tick_program_event() ->
      clockevents_program_event() -> decrementer_set_next_event().
      
      However with CONFIG_HIGH_RES_TIMERS=n or booting with highres=off, we
      see a stall/lockup, because tick_nohz_handler() does not cause a
      reprogram of the decrementer, leading to endless timer interrupts.
      Example trace:
      
        [    1.898617][    T7] Freeing initrd memory: 2624K^M
        [   22.680919][    C1] rcu: INFO: rcu_sched detected stalls on CPUs/tasks:^M
        [   22.682281][    C1] rcu:     0-....: (25 ticks this GP) idle=073/0/0x1 softirq=10/16 fqs=1050 ^M
        [   22.682851][    C1]  (detected by 1, t=2102 jiffies, g=-1179, q=476)^M
        [   22.683649][    C1] Sending NMI from CPU 1 to CPUs 0:^M
        [   22.685252][    C0] NMI backtrace for cpu 0^M
        [   22.685649][    C0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-rc2-00185-g0faf20a1 #145^M
        [   22.686393][    C0] NIP:  c000000000016d64 LR: c000000000f6cca4 CTR: c00000000019c6e0^M
        [   22.686774][    C0] REGS: c000000002833590 TRAP: 0500   Not tainted  (5.16.0-rc2-00185-g0faf20a1)^M
        [   22.687222][    C0] MSR:  8000000000009033 <SF,EE,ME,IR,DR,RI,LE>  CR: 24000222  XER: 00000000^M
        [   22.688297][    C0] CFAR: c00000000000c854 IRQMASK: 0 ^M
        ...
        [   22.692637][    C0] NIP [c000000000016d64] arch_local_irq_restore+0x174/0x250^M
        [   22.694443][    C0] LR [c000000000f6cca4] __do_softirq+0xe4/0x3dc^M
        [   22.695762][    C0] Call Trace:^M
        [   22.696050][    C0] [c000000002833830] [c000000000f6cc80] __do_softirq+0xc0/0x3dc (unreliable)^M
        [   22.697377][    C0] [c000000002833920] [c000000000151508] __irq_exit_rcu+0xd8/0x130^M
        [   22.698739][    C0] [c000000002833950] [c000000000151730] irq_exit+0x20/0x40^M
        [   22.699938][    C0] [c000000002833970] [c000000000027f40] timer_interrupt+0x270/0x460^M
        [   22.701119][    C0] [c0000000028339d0] [c0000000000099a8] decrementer_common_virt+0x208/0x210^M
      
      Possibly this should be fixed in the lowres timing code, but that would
      be a generic change and could take some time and may not backport
      easily, so for now make the programming of the decrementer unconditional
      again in timer_interrupt() to avoid the stall/lockup.
      
      Fixes: 0faf20a1
      
       ("powerpc/64s/interrupt: Don't enable MSR[EE] in irq handlers unless perf is in use")
      Reported-by: default avatarMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Reviewed-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Link: https://lore.kernel.org/r/20220420141657.771442-1-mpe@ellerman.id.au
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d0f75b88
    • Dave Stevenson's avatar
      drm/panel/raspberrypi-touchscreen: Initialise the bridge in prepare · adb710ca
      Dave Stevenson authored
      [ Upstream commit 5f18c078 ]
      
      The panel has a prepare call which is before video starts, and an
      enable call which is after.
      The Toshiba bridge should be configured before video, so move
      the relevant power and initialisation calls to prepare.
      
      Fixes: 2f733d61
      
       ("drm/panel: Add support for the Raspberry Pi 7" Touchscreen.")
      Signed-off-by: default avatarDave Stevenson <dave.stevenson@raspberrypi.com>
      Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220415162513.42190-3-stefan.wahren@i2se.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      adb710ca
    • Dave Stevenson's avatar
      drm/panel/raspberrypi-touchscreen: Avoid NULL deref if not initialised · 0a3599df
      Dave Stevenson authored
      [ Upstream commit f92055ae ]
      
      If a call to rpi_touchscreen_i2c_write from rpi_touchscreen_probe
      fails before mipi_dsi_device_register_full is called, then
      in trying to log the error message if uses ts->dsi->dev when
      it is still NULL.
      
      Use ts->i2c->dev instead, which is initialised earlier in probe.
      
      Fixes: 2f733d61
      
       ("drm/panel: Add support for the Raspberry Pi 7" Touchscreen.")
      Signed-off-by: default avatarDave Stevenson <dave.stevenson@raspberrypi.com>
      Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220415162513.42190-2-stefan.wahren@i2se.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0a3599df
    • Zhipeng Xie's avatar
      perf/core: Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled · 9c7fd841
      Zhipeng Xie authored
      [ Upstream commit 60490e79 ]
      
      This problem can be reproduced with CONFIG_PERF_USE_VMALLOC enabled on
      both x86_64 and aarch64 arch when using sysdig -B(using ebpf)[1].
      sysdig -B works fine after rebuilding the kernel with
      CONFIG_PERF_USE_VMALLOC disabled.
      
      I tracked it down to the if condition event->rb->nr_pages != nr_pages
      in perf_mmap is true when CONFIG_PERF_USE_VMALLOC is enabled where
      event->rb->nr_pages = 1 and nr_pages = 2048 resulting perf_mmap to
      return -EINVAL. This is because when CONFIG_PERF_USE_VMALLOC is
      enabled, rb->nr_pages is always equal to 1.
      
      Arch with CONFIG_PERF_USE_VMALLOC enabled by default:
      	arc/arm/csky/mips/sh/sparc/xtensa
      
      Arch with CONFIG_PERF_USE_VMALLOC disabled by default:
      	x86_64/aarch64/...
      
      Fix this problem by using data_page_nr()
      
      [1] https://github.com/draios/sysdig
      
      Fixes: 906010b2
      
       ("perf_event: Provide vmalloc() based mmap() backing")
      Signed-off-by: default avatarZhipeng Xie <xiezhipeng1@huawei.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/20220209145417.6495-1-xiezhipeng1@huawei.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9c7fd841
    • kuyo chang's avatar
      sched/pelt: Fix attach_entity_load_avg() corner case · cce88434
      kuyo chang authored
      [ Upstream commit 40f5aa4c ]
      
      The warning in cfs_rq_is_decayed() triggered:
      
          SCHED_WARN_ON(cfs_rq->avg.load_avg ||
      		  cfs_rq->avg.util_avg ||
      		  cfs_rq->avg.runnable_avg)
      
      There exists a corner case in attach_entity_load_avg() which will
      cause load_sum to be zero while load_avg will not be.
      
      Consider se_weight is 88761 as per the sched_prio_to_weight[] table.
      Further assume the get_pelt_divider() is 47742, this gives:
      se->avg.load_avg is 1.
      
      However, calculating load_sum:
      
        se->avg.load_sum = div_u64(se->avg.load_avg * se->avg.load_sum, se_weight(se));
        se->avg.load_sum = 1*47742/88761 = 0.
      
      Then enqueue_load_avg() adds this to the cfs_rq totals:
      
        cfs_rq->avg.load_avg += se->avg.load_avg;
        cfs_rq->avg.load_sum += se_weight(se) * se->avg.load_sum;
      
      Resulting in load_avg being 1 with load_sum is 0, which will trigger
      the WARN.
      
      Fixes: f207934f
      
       ("sched/fair: Align PELT windows between cfs_rq and its se")
      Signed-off-by: default avatarkuyo chang <kuyo.chang@mediatek.com>
      [peterz: massage changelog]
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Reviewed-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
      Tested-by: default avatarDietmar Eggemann <dietmar.eggemann@arm.com>
      Link: https://lkml.kernel.org/r/20220414090229.342-1-kuyo.chang@mediatek.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cce88434
    • Tom Rix's avatar
      scsi: sr: Do not leak information in ioctl · d4f8bb41
      Tom Rix authored
      [ Upstream commit faad6ceb ]
      
      sr_ioctl.c uses this pattern:
      
        result = sr_do_ioctl(cd, &cgc);
        to-user = buffer[];
        kfree(buffer);
        return result;
      
      Use of a buffer without checking leaks information. Check result and jump
      over the use of buffer if there is an error.
      
        result = sr_do_ioctl(cd, &cgc);
        if (result)
          goto err;
        to-user = buffer[];
      err:
        kfree(buffer);
        return result;
      
      Additionally, initialize the buffer to zero.
      
      This problem can be seen in the 2.4.0 kernel.
      
      Link: https://lore.kernel.org/r/20220411174756.2418435-1-trix@redhat.com
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d4f8bb41
    • Miaoqian Lin's avatar
      Input: omap4-keypad - fix pm_runtime_get_sync() error checking · 69eeaa61
      Miaoqian Lin authored
      [ Upstream commit 81022a17 ]
      
      If the device is already in a runtime PM enabled state
      pm_runtime_get_sync() will return 1, so a test for negative
      value should be used to check for errors.
      
      Fixes: f77621cc
      
       ("Input: omap-keypad - dynamically handle register offsets")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Link: https://lore.kernel.org/r/20220412070131.19848-1-linmq006@gmail.com
      
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      69eeaa61