Skip to content
  1. Aug 04, 2021
    • Junxiao Bi's avatar
      ocfs2: fix zero out valid data · eaaa4284
      Junxiao Bi authored
      commit f267aeb6 upstream.
      
      If append-dio feature is enabled, direct-io write and fallocate could
      run in parallel to extend file size, fallocate used "orig_isize" to
      record i_size before taking "ip_alloc_sem", when
      ocfs2_zeroout_partial_cluster() zeroout EOF blocks, i_size maybe already
      extended by ocfs2_dio_end_io_write(), that will cause valid data zeroed
      out.
      
      Link: https://lkml.kernel.org/r/20210722054923.24389-1-junxiao.bi@oracle.com
      Fixes: 6bba4471
      
       ("ocfs2: fix data corruption by fallocate")
      Signed-off-by: default avatarJunxiao Bi <junxiao.bi@oracle.com>
      Reviewed-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Jun Piao <piaojun@huawei.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eaaa4284
    • Paolo Bonzini's avatar
      KVM: add missing compat KVM_CLEAR_DIRTY_LOG · 9bd10921
      Paolo Bonzini authored
      commit 8750f9bb upstream.
      
      The arguments to the KVM_CLEAR_DIRTY_LOG ioctl include a pointer,
      therefore it needs a compat ioctl implementation.  Otherwise,
      32-bit userspace fails to invoke it on 64-bit kernels; for x86
      it might work fine by chance if the padding is zero, but not
      on big-endian architectures.
      
      Reported-by: Thomas Sattler
      Cc: stable@vger.kernel.org
      Fixes: 2a31b9db
      
       ("kvm: introduce manual dirty log reprotect")
      Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9bd10921
    • Juergen Gross's avatar
      x86/kvm: fix vcpu-id indexed array sizes · 7a94dfe5
      Juergen Gross authored
      commit 76b4f357
      
       upstream.
      
      KVM_MAX_VCPU_ID is the maximum vcpu-id of a guest, and not the number
      of vcpu-ids. Fix array indexed by vcpu-id to have KVM_MAX_VCPU_ID+1
      elements.
      
      Note that this is currently no real problem, as KVM_MAX_VCPU_ID is
      an odd number, resulting in always enough padding being available at
      the end of those arrays.
      
      Nevertheless this should be fixed in order to avoid rare problems in
      case someone is using an even number for KVM_MAX_VCPU_ID.
      
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Message-Id: <20210701154105.23215-2-jgross@suse.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>
      7a94dfe5
    • Hui Wang's avatar
      Revert "ACPI: resources: Add checks for ACPI IRQ override" · 2dc29158
      Hui Wang authored
      commit e0eef369 upstream.
      
      The commit 0ec4e55e ("ACPI: resources: Add checks for ACPI IRQ
      override") introduces regression on some platforms, at least it makes
      the UART can't get correct irq setting on two different platforms,
      and it makes the kernel can't bootup on these two platforms.
      
      This reverts commit 0ec4e55e
      
      .
      
      Regression-discuss: https://bugzilla.kernel.org/show_bug.cgi?id=213031
      Reported-by: default avatarPGNd <pgnet.dev@gmail.com>
      Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
      Signed-off-by: default avatarHui Wang <hui.wang@canonical.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2dc29158
    • Goldwyn Rodrigues's avatar
      btrfs: mark compressed range uptodate only if all bio succeed · a8eec697
      Goldwyn Rodrigues authored
      commit 240246f6
      
       upstream.
      
      In compression write endio sequence, the range which the compressed_bio
      writes is marked as uptodate if the last bio of the compressed (sub)bios
      is completed successfully. There could be previous bio which may
      have failed which is recorded in cb->errors.
      
      Set the writeback range as uptodate only if cb->errors is zero, as opposed
      to checking only the last bio's status.
      
      Backporting notes: in all versions up to 4.4 the last argument is always
      replaced by "!cb->errors".
      
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a8eec697
    • Desmond Cheong Zhi Xi's avatar
      btrfs: fix rw device counting in __btrfs_free_extra_devids · 57429c1e
      Desmond Cheong Zhi Xi authored
      commit b2a61667 upstream.
      
      When removing a writeable device in __btrfs_free_extra_devids, the rw
      device count should be decremented.
      
      This error was caught by Syzbot which reported a warning in
      close_fs_devices:
      
        WARNING: CPU: 1 PID: 9355 at fs/btrfs/volumes.c:1168 close_fs_devices+0x763/0x880 fs/btrfs/volumes.c:1168
        Modules linked in:
        CPU: 0 PID: 9355 Comm: syz-executor552 Not tainted 5.13.0-rc1-syzkaller #0
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
        RIP: 0010:close_fs_devices+0x763/0x880 fs/btrfs/volumes.c:1168
        RSP: 0018:ffffc9000333f2f0 EFLAGS: 00010293
        RAX: ffffffff8365f5c3 RBX: 0000000000000001 RCX: ffff888029afd4c0
        RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000
        RBP: ffff88802846f508 R08: ffffffff8365f525 R09: ffffed100337d128
        R10: ffffed100337d128 R11: 0000000000000000 R12: dffffc0000000000
        R13: ffff888019be8868 R14: 1ffff1100337d10d R15: 1ffff1100337d10a
        FS:  00007f6f53828700(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000
        CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        CR2: 000000000047c410 CR3: 00000000302a6000 CR4: 00000000001506f0
        DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        Call Trace:
         btrfs_close_devices+0xc9/0x450 fs/btrfs/volumes.c:1180
         open_ctree+0x8e1/0x3968 fs/btrfs/disk-io.c:3693
         btrfs_fill_super fs/btrfs/super.c:1382 [inline]
         btrfs_mount_root+0xac5/0xc60 fs/btrfs/super.c:1749
         legacy_get_tree+0xea/0x180 fs/fs_context.c:592
         vfs_get_tree+0x86/0x270 fs/super.c:1498
         fc_mount fs/namespace.c:993 [inline]
         vfs_kern_mount+0xc9/0x160 fs/namespace.c:1023
         btrfs_mount+0x3d3/0xb50 fs/btrfs/super.c:1809
         legacy_get_tree+0xea/0x180 fs/fs_context.c:592
         vfs_get_tree+0x86/0x270 fs/super.c:1498
         do_new_mount fs/namespace.c:2905 [inline]
         path_mount+0x196f/0x2be0 fs/namespace.c:3235
         do_mount fs/namespace.c:3248 [inline]
         __do_sys_mount fs/namespace.c:3456 [inline]
         __se_sys_mount+0x2f9/0x3b0 fs/namespace.c:3433
         do_syscall_64+0x3f/0xb0 arch/x86/entry/common.c:47
         entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      Because fs_devices->rw_devices was not 0 after
      closing all devices. Here is the call trace that was observed:
      
        btrfs_mount_root():
          btrfs_scan_one_device():
            device_list_add();   <---------------- device added
          btrfs_open_devices():
            open_fs_devices():
              btrfs_open_one_device();   <-------- writable device opened,
      	                                     rw device count ++
          btrfs_fill_super():
            open_ctree():
              btrfs_free_extra_devids():
      	  __btrfs_free_extra_devids();  <--- writable device removed,
      	                              rw device count not decremented
      	  fail_tree_roots:
      	    btrfs_close_devices():
      	      close_fs_devices();   <------- rw device count off by 1
      
      As a note, prior to commit cf89af14 ("btrfs: dev-replace: fail
      mount if we don't have replace item with target device"), rw_devices
      was decremented on removing a writable device in
      __btrfs_free_extra_devids only if the BTRFS_DEV_STATE_REPLACE_TGT bit
      was not set for the device. However, this check does not need to be
      reinstated as it is now redundant and incorrect.
      
      In __btrfs_free_extra_devids, we skip removing the device if it is the
      target for replacement. This is done by checking whether device->devid
      == BTRFS_DEV_REPLACE_DEVID. Since BTRFS_DEV_STATE_REPLACE_TGT is set
      only on the device with devid BTRFS_DEV_REPLACE_DEVID, no devices
      should have the BTRFS_DEV_STATE_REPLACE_TGT bit set after the check,
      and so it's redundant to test for that bit.
      
      Additionally, following commit 82372bc8
      
       ("Btrfs: make
      the logic of source device removing more clear"), rw_devices is
      incremented whenever a writeable device is added to the alloc
      list (including the target device in btrfs_dev_replace_finishing), so
      all removals of writable devices from the alloc list should also be
      accompanied by a decrement to rw_devices.
      
      Reported-by: default avatar <syzbot+a70e2ad0879f160b9217@syzkaller.appspotmail.com>
      Fixes: cf89af14
      
       ("btrfs: dev-replace: fail mount if we don't have replace item with target device")
      CC: stable@vger.kernel.org # 5.10+
      Tested-by: default avatar <syzbot+a70e2ad0879f160b9217@syzkaller.appspotmail.com>
      Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      57429c1e
    • Jan Kiszka's avatar
      x86/asm: Ensure asm/proto.h can be included stand-alone · 61f2cbc7
      Jan Kiszka authored
      [ Upstream commit f7b21a0e
      
       ]
      
      Fix:
      
        ../arch/x86/include/asm/proto.h:14:30: warning: ‘struct task_struct’ declared \
          inside parameter list will not be visible outside of this definition or declaration
        long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2);
                                     ^~~~~~~~~~~
      
        .../arch/x86/include/asm/proto.h:40:34: warning: ‘struct task_struct’ declared \
          inside parameter list will not be visible outside of this definition or declaration
         long do_arch_prctl_common(struct task_struct *task, int option,
                                          ^~~~~~~~~~~
      
      if linux/sched.h hasn't be included previously. This fixes a build error
      when this header is used outside of the kernel tree.
      
       [ bp: Massage commit message. ]
      
      Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Link: https://lkml.kernel.org/r/b76b4be3-cf66-f6b2-9a6c-3e7ef54f9845@web.de
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61f2cbc7
    • Cong Wang's avatar
      net_sched: check error pointer in tcf_dump_walker() · 99372c38
      Cong Wang authored
      [ Upstream commit 580e4273
      
       ]
      
      Although we take RTNL on dump path, it is possible to
      skip RTNL on insertion path. So the following race condition
      is possible:
      
      rtnl_lock()		// no rtnl lock
      			mutex_lock(&idrinfo->lock);
      			// insert ERR_PTR(-EBUSY)
      			mutex_unlock(&idrinfo->lock);
      tc_dump_action()
      rtnl_unlock()
      
      So we have to skip those temporary -EBUSY entries on dump path
      too.
      
      Reported-and-tested-by: default avatar <syzbot+b47bc4f247856fb4d9e1@syzkaller.appspotmail.com>
      Fixes: 0fedc63f
      
       ("net_sched: commit action insertions together")
      Cc: Vlad Buslov <vladbu@mellanox.com>
      Cc: Jamal Hadi Salim <jhs@mojatatu.com>
      Cc: Jiri Pirko <jiri@resnulli.us>
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      99372c38
  2. Jul 31, 2021
    • Greg Kroah-Hartman's avatar
      Linux 5.4.137 · 5b1de8e1
      Greg Kroah-Hartman authored
      
      
      Link: https://lore.kernel.org/r/20210729135142.920143237@linuxfoundation.org
      Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Tested-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Tested-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Tested-by: default avatarLinux Kernel Functional Testing <lkft@linaro.org>
      Tested-by: default avatarSudip Mukherjee <sudip.mukherjee@codethink.co.uk>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      v5.4.137
      5b1de8e1
    • Vasily Averin's avatar
      ipv6: ip6_finish_output2: set sk into newly allocated nskb · ebb1b38b
      Vasily Averin authored
      [ Upstream commit 2d85a1b3 ]
      
      skb_set_owner_w() should set sk not to old skb but to new nskb.
      
      Fixes: 5796015f
      
       ("ipv6: allocate enough headroom in ip6_finish_output2()")
      Signed-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
      Link: https://lore.kernel.org/r/70c0744f-89ae-1869-7e3e-4fa292158f4b@virtuozzo.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ebb1b38b
    • Sudeep Holla's avatar
      ARM: dts: versatile: Fix up interrupt controller node names · 6c041239
      Sudeep Holla authored
      [ Upstream commit 82a1c675
      
       ]
      
      Once the new schema interrupt-controller/arm,vic.yaml is added, we get
      the below warnings:
      
              arch/arm/boot/dts/versatile-ab.dt.yaml:
              intc@10140000: $nodename:0: 'intc@10140000' does not match
              '^interrupt-controller(@[0-9a-f,]+)*$'
      
      	arch/arm/boot/dts/versatile-ab.dt.yaml:
      	intc@10140000: 'clear-mask' does not match any of the regexes
      
      Fix the node names for the interrupt controller to conform
      to the standard node name interrupt-controller@.. Also drop invalid
      clear-mask property.
      
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Link: https://lore.kernel.org/r/20210701132118.759454-1-sudeep.holla@arm.com'
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6c041239
    • Christoph Hellwig's avatar
      iomap: remove the length variable in iomap_seek_hole · befa9005
      Christoph Hellwig authored
      [ Upstream commit 49694d14
      
       ]
      
      The length variable is rather pointless given that it can be trivially
      deduced from offset and size.  Also the initial calculation can lead
      to KASAN warnings.
      
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reported-by: default avatarLeizhen (ThunderTown) <thunder.leizhen@huawei.com>
      Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      befa9005
    • Christoph Hellwig's avatar
      iomap: remove the length variable in iomap_seek_data · 83fb41b2
      Christoph Hellwig authored
      [ Upstream commit 3ac1d426
      
       ]
      
      The length variable is rather pointless given that it can be trivially
      deduced from offset and size.  Also the initial calculation can lead
      to KASAN warnings.
      
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reported-by: default avatarLeizhen (ThunderTown) <thunder.leizhen@huawei.com>
      Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      83fb41b2
    • Hyunchul Lee's avatar
      cifs: fix the out of range assignment to bit fields in parse_server_interfaces · 302e1acd
      Hyunchul Lee authored
      [ Upstream commit c9c9c681
      
       ]
      
      Because the out of range assignment to bit fields
      are compiler-dependant, the fields could have wrong
      value.
      
      Signed-off-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      302e1acd
    • Cristian Marussi's avatar
      firmware: arm_scmi: Fix range check for the maximum number of pending messages · 02a470e3
      Cristian Marussi authored
      [ Upstream commit bdb8742d
      
       ]
      
      SCMI message headers carry a sequence number and such field is sized to
      allow for MSG_TOKEN_MAX distinct numbers; moreover zero is not really an
      acceptable maximum number of pending in-flight messages.
      
      Fix accordingly the checks performed on the value exported by transports
      in scmi_desc.max_msg
      
      Link: https://lore.kernel.org/r/20210712141833.6628-3-cristian.marussi@arm.com
      Reported-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
      Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
      [sudeep.holla: updated the patch title and error message]
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      02a470e3
    • Sudeep Holla's avatar
      firmware: arm_scmi: Fix possible scmi_linux_errmap buffer overflow · 289dd584
      Sudeep Holla authored
      [ Upstream commit 7a691f16
      
       ]
      
      The scmi_linux_errmap buffer access index is supposed to depend on the
      array size to prevent element out of bounds access. It uses SCMI_ERR_MAX
      to check bounds but that can mismatch with the array size. It also
      changes the success into -EIO though scmi_linux_errmap is never used in
      case of success, it is expected to work for success case too.
      
      It is slightly confusing code as the negative of the error code
      is used as index to the buffer. Fix it by negating it at the start and
      make it more readable.
      
      Link: https://lore.kernel.org/r/20210707135028.1869642-1-sudeep.holla@arm.com
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Reviewed-by: default avatarCristian Marussi <cristian.marussi@arm.com>
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      289dd584
    • Desmond Cheong Zhi Xi's avatar
      hfs: add lock nesting notation to hfs_find_init · e3acb292
      Desmond Cheong Zhi Xi authored
      [ Upstream commit b3b2177a
      
       ]
      
      Syzbot reports a possible recursive lock in [1].
      
      This happens due to missing lock nesting information.  From the logs, we
      see that a call to hfs_fill_super is made to mount the hfs filesystem.
      While searching for the root inode, the lock on the catalog btree is
      grabbed.  Then, when the parent of the root isn't found, a call to
      __hfs_bnode_create is made to create the parent of the root.  This
      eventually leads to a call to hfs_ext_read_extent which grabs a lock on
      the extents btree.
      
      Since the order of locking is catalog btree -> extents btree, this lock
      hierarchy does not lead to a deadlock.
      
      To tell lockdep that this locking is safe, we add nesting notation to
      distinguish between catalog btrees, extents btrees, and attributes
      btrees (for HFS+).  This has already been done in hfsplus.
      
      Link: https://syzkaller.appspot.com/bug?id=f007ef1d7a31a469e3be7aeb0fde0769b18585db [1]
      Link: https://lkml.kernel.org/r/20210701030756.58760-4-desmondcheongzx@gmail.com
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reported-by: default avatar <syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com>
      Tested-by: default avatar <syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e3acb292
    • Desmond Cheong Zhi Xi's avatar
      hfs: fix high memory mapping in hfs_bnode_read · af117829
      Desmond Cheong Zhi Xi authored
      [ Upstream commit 54a5ead6
      
       ]
      
      Pages that we read in hfs_bnode_read need to be kmapped into kernel
      address space.  However, currently only the 0th page is kmapped.  If the
      given offset + length exceeds this 0th page, then we have an invalid
      memory access.
      
      To fix this, we kmap relevant pages one by one and copy their relevant
      portions of data.
      
      An example of invalid memory access occurring without this fix can be seen
      in the following crash report:
      
        ==================================================================
        BUG: KASAN: use-after-free in memcpy include/linux/fortify-string.h:191 [inline]
        BUG: KASAN: use-after-free in hfs_bnode_read+0xc4/0xe0 fs/hfs/bnode.c:26
        Read of size 2 at addr ffff888125fdcffe by task syz-executor5/4634
      
        CPU: 0 PID: 4634 Comm: syz-executor5 Not tainted 5.13.0-syzkaller #0
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
        Call Trace:
         __dump_stack lib/dump_stack.c:79 [inline]
         dump_stack+0x195/0x1f8 lib/dump_stack.c:120
         print_address_description.constprop.0+0x1d/0x110 mm/kasan/report.c:233
         __kasan_report mm/kasan/report.c:419 [inline]
         kasan_report.cold+0x7b/0xd4 mm/kasan/report.c:436
         check_region_inline mm/kasan/generic.c:180 [inline]
         kasan_check_range+0x154/0x1b0 mm/kasan/generic.c:186
         memcpy+0x24/0x60 mm/kasan/shadow.c:65
         memcpy include/linux/fortify-string.h:191 [inline]
         hfs_bnode_read+0xc4/0xe0 fs/hfs/bnode.c:26
         hfs_bnode_read_u16 fs/hfs/bnode.c:34 [inline]
         hfs_bnode_find+0x880/0xcc0 fs/hfs/bnode.c:365
         hfs_brec_find+0x2d8/0x540 fs/hfs/bfind.c:126
         hfs_brec_read+0x27/0x120 fs/hfs/bfind.c:165
         hfs_cat_find_brec+0x19a/0x3b0 fs/hfs/catalog.c:194
         hfs_fill_super+0xc13/0x1460 fs/hfs/super.c:419
         mount_bdev+0x331/0x3f0 fs/super.c:1368
         hfs_mount+0x35/0x40 fs/hfs/super.c:457
         legacy_get_tree+0x10c/0x220 fs/fs_context.c:592
         vfs_get_tree+0x93/0x300 fs/super.c:1498
         do_new_mount fs/namespace.c:2905 [inline]
         path_mount+0x13f5/0x20e0 fs/namespace.c:3235
         do_mount fs/namespace.c:3248 [inline]
         __do_sys_mount fs/namespace.c:3456 [inline]
         __se_sys_mount fs/namespace.c:3433 [inline]
         __x64_sys_mount+0x2b8/0x340 fs/namespace.c:3433
         do_syscall_64+0x37/0xc0 arch/x86/entry/common.c:47
         entry_SYSCALL_64_after_hwframe+0x44/0xae
        RIP: 0033:0x45e63a
        Code: 48 c7 c2 bc ff ff ff f7 d8 64 89 02 b8 ff ff ff ff eb d2 e8 88 04 00 00 0f 1f 84 00 00 00 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
        RSP: 002b:00007f9404d410d8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
        RAX: ffffffffffffffda RBX: 0000000020000248 RCX: 000000000045e63a
        RDX: 0000000020000000 RSI: 0000000020000100 RDI: 00007f9404d41120
        RBP: 00007f9404d41120 R08: 00000000200002c0 R09: 0000000020000000
        R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
        R13: 0000000000000003 R14: 00000000004ad5d8 R15: 0000000000000000
      
        The buggy address belongs to the page:
        page:00000000dadbcf3e refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x125fdc
        flags: 0x2fffc0000000000(node=0|zone=2|lastcpupid=0x3fff)
        raw: 02fffc0000000000 ffffea000497f748 ffffea000497f6c8 0000000000000000
        raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
        page dumped because: kasan: bad access detected
      
        Memory state around the buggy address:
         ffff888125fdce80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff888125fdcf00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        >ffff888125fdcf80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                                                        ^
         ffff888125fdd000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff888125fdd080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        ==================================================================
      
      Link: https://lkml.kernel.org/r/20210701030756.58760-3-desmondcheongzx@gmail.com
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      af117829
    • Desmond Cheong Zhi Xi's avatar
      hfs: add missing clean-up in hfs_fill_super · 89136a47
      Desmond Cheong Zhi Xi authored
      [ Upstream commit 16ee572e
      
       ]
      
      Patch series "hfs: fix various errors", v2.
      
      This series ultimately aims to address a lockdep warning in
      hfs_find_init reported by Syzbot [1].
      
      The work done for this led to the discovery of another bug, and the
      Syzkaller repro test also reveals an invalid memory access error after
      clearing the lockdep warning.  Hence, this series is broken up into
      three patches:
      
      1. Add a missing call to hfs_find_exit for an error path in
         hfs_fill_super
      
      2. Fix memory mapping in hfs_bnode_read by fixing calls to kmap
      
      3. Add lock nesting notation to tell lockdep that the observed locking
         hierarchy is safe
      
      This patch (of 3):
      
      Before exiting hfs_fill_super, the struct hfs_find_data used in
      hfs_find_init should be passed to hfs_find_exit to be cleaned up, and to
      release the lock held on the btree.
      
      The call to hfs_find_exit is missing from an error path.  We add it back
      in by consolidating calls to hfs_find_exit for error paths.
      
      Link: https://syzkaller.appspot.com/bug?id=f007ef1d7a31a469e3be7aeb0fde0769b18585db [1]
      Link: https://lkml.kernel.org/r/20210701030756.58760-1-desmondcheongzx@gmail.com
      Link: https://lkml.kernel.org/r/20210701030756.58760-2-desmondcheongzx@gmail.com
      Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
      Reviewed-by: default avatarViacheslav Dubeyko <slava@dubeyko.com>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Shuah Khan <skhan@linuxfoundation.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      89136a47
    • Vasily Averin's avatar
      ipv6: allocate enough headroom in ip6_finish_output2() · ded37d03
      Vasily Averin authored
      [ Upstream commit 5796015f
      
       ]
      
      When TEE target mirrors traffic to another interface, sk_buff may
      not have enough headroom to be processed correctly.
      ip_finish_output2() detect this situation for ipv4 and allocates
      new skb with enogh headroom. However ipv6 lacks this logic in
      ip_finish_output2 and it leads to skb_under_panic:
      
       skbuff: skb_under_panic: text:ffffffffc0866ad4 len:96 put:24
       head:ffff97be85e31800 data:ffff97be85e317f8 tail:0x58 end:0xc0 dev:gre0
       ------------[ cut here ]------------
       kernel BUG at net/core/skbuff.c:110!
       invalid opcode: 0000 [#1] SMP PTI
       CPU: 2 PID: 393 Comm: kworker/2:2 Tainted: G           OE     5.13.0 #13
       Hardware name: Virtuozzo KVM, BIOS 1.11.0-2.vz7.4 04/01/2014
       Workqueue: ipv6_addrconf addrconf_dad_work
       RIP: 0010:skb_panic+0x48/0x4a
       Call Trace:
        skb_push.cold.111+0x10/0x10
        ipgre_header+0x24/0xf0 [ip_gre]
        neigh_connected_output+0xae/0xf0
        ip6_finish_output2+0x1a8/0x5a0
        ip6_output+0x5c/0x110
        nf_dup_ipv6+0x158/0x1000 [nf_dup_ipv6]
        tee_tg6+0x2e/0x40 [xt_TEE]
        ip6t_do_table+0x294/0x470 [ip6_tables]
        nf_hook_slow+0x44/0xc0
        nf_hook.constprop.34+0x72/0xe0
        ndisc_send_skb+0x20d/0x2e0
        ndisc_send_ns+0xd1/0x210
        addrconf_dad_work+0x3c8/0x540
        process_one_work+0x1d1/0x370
        worker_thread+0x30/0x390
        kthread+0x116/0x130
        ret_from_fork+0x22/0x30
      
      Signed-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ded37d03
    • Xin Long's avatar
      sctp: move 198 addresses from unusable to private scope · f65b7f37
      Xin Long authored
      [ Upstream commit 1d11fa23
      
       ]
      
      The doc draft-stewart-tsvwg-sctp-ipv4-00 that restricts 198 addresses
      was never published. These addresses as private addresses should be
      allowed to use in SCTP.
      
      As Michael Tuexen suggested, this patch is to move 198 addresses from
      unusable to private scope.
      
      Reported-by: default avatarSérgio <surkamp@gmail.com>
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Acked-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f65b7f37
    • Eric Dumazet's avatar
      net: annotate data race around sk_ll_usec · c8d32973
      Eric Dumazet authored
      [ Upstream commit 0dbffbb5
      
       ]
      
      sk_ll_usec is read locklessly from sk_can_busy_loop()
      while another thread can change its value in sock_setsockopt()
      
      This is correct but needs annotations.
      
      BUG: KCSAN: data-race in __skb_try_recv_datagram / sock_setsockopt
      
      write to 0xffff88814eb5f904 of 4 bytes by task 14011 on cpu 0:
       sock_setsockopt+0x1287/0x2090 net/core/sock.c:1175
       __sys_setsockopt+0x14f/0x200 net/socket.c:2100
       __do_sys_setsockopt net/socket.c:2115 [inline]
       __se_sys_setsockopt net/socket.c:2112 [inline]
       __x64_sys_setsockopt+0x62/0x70 net/socket.c:2112
       do_syscall_64+0x4a/0x90 arch/x86/entry/common.c:47
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      read to 0xffff88814eb5f904 of 4 bytes by task 14001 on cpu 1:
       sk_can_busy_loop include/net/busy_poll.h:41 [inline]
       __skb_try_recv_datagram+0x14f/0x320 net/core/datagram.c:273
       unix_dgram_recvmsg+0x14c/0x870 net/unix/af_unix.c:2101
       unix_seqpacket_recvmsg+0x5a/0x70 net/unix/af_unix.c:2067
       ____sys_recvmsg+0x15d/0x310 include/linux/uio.h:244
       ___sys_recvmsg net/socket.c:2598 [inline]
       do_recvmmsg+0x35c/0x9f0 net/socket.c:2692
       __sys_recvmmsg net/socket.c:2771 [inline]
       __do_sys_recvmmsg net/socket.c:2794 [inline]
       __se_sys_recvmmsg net/socket.c:2787 [inline]
       __x64_sys_recvmmsg+0xcf/0x150 net/socket.c:2787
       do_syscall_64+0x4a/0x90 arch/x86/entry/common.c:47
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      value changed: 0x00000000 -> 0x00000101
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 1 PID: 14001 Comm: syz-executor.3 Not tainted 5.13.0-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c8d32973
    • Yang Yingliang's avatar
      net/802/garp: fix memleak in garp_request_join() · c23b9a56
      Yang Yingliang authored
      [ Upstream commit 42ca63f9
      
       ]
      
      I got kmemleak report when doing fuzz test:
      
      BUG: memory leak
      unreferenced object 0xffff88810c909b80 (size 64):
        comm "syz", pid 957, jiffies 4295220394 (age 399.090s)
        hex dump (first 32 bytes):
          01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 08 00 00 00 01 02 00 04  ................
        backtrace:
          [<00000000ca1f2e2e>] garp_request_join+0x285/0x3d0
          [<00000000bf153351>] vlan_gvrp_request_join+0x15b/0x190
          [<0000000024005e72>] vlan_dev_open+0x706/0x980
          [<00000000dc20c4d4>] __dev_open+0x2bb/0x460
          [<0000000066573004>] __dev_change_flags+0x501/0x650
          [<0000000035b42f83>] rtnl_configure_link+0xee/0x280
          [<00000000a5e69de0>] __rtnl_newlink+0xed5/0x1550
          [<00000000a5258f4a>] rtnl_newlink+0x66/0x90
          [<00000000506568ee>] rtnetlink_rcv_msg+0x439/0xbd0
          [<00000000b7eaeae1>] netlink_rcv_skb+0x14d/0x420
          [<00000000c373ce66>] netlink_unicast+0x550/0x750
          [<00000000ec74ce74>] netlink_sendmsg+0x88b/0xda0
          [<00000000381ff246>] sock_sendmsg+0xc9/0x120
          [<000000008f6a2db3>] ____sys_sendmsg+0x6e8/0x820
          [<000000008d9c1735>] ___sys_sendmsg+0x145/0x1c0
          [<00000000aa39dd8b>] __sys_sendmsg+0xfe/0x1d0
      
      Calling garp_request_leave() after garp_request_join(), the attr->state
      is set to GARP_APPLICANT_VO, garp_attr_destroy() won't be called in last
      transmit event in garp_uninit_applicant(), the attr of applicant will be
      leaked. To fix this leak, iterate and free each attr of applicant before
      rerturning from garp_uninit_applicant().
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c23b9a56
    • Yang Yingliang's avatar
      net/802/mrp: fix memleak in mrp_request_join() · 88c4cae3
      Yang Yingliang authored
      [ Upstream commit 996af621
      
       ]
      
      I got kmemleak report when doing fuzz test:
      
      BUG: memory leak
      unreferenced object 0xffff88810c239500 (size 64):
      comm "syz-executor940", pid 882, jiffies 4294712870 (age 14.631s)
      hex dump (first 32 bytes):
      01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
      00 00 00 00 00 00 00 00 01 00 00 00 01 02 00 04 ................
      backtrace:
      [<00000000a323afa4>] slab_alloc_node mm/slub.c:2972 [inline]
      [<00000000a323afa4>] slab_alloc mm/slub.c:2980 [inline]
      [<00000000a323afa4>] __kmalloc+0x167/0x340 mm/slub.c:4130
      [<000000005034ca11>] kmalloc include/linux/slab.h:595 [inline]
      [<000000005034ca11>] mrp_attr_create net/802/mrp.c:276 [inline]
      [<000000005034ca11>] mrp_request_join+0x265/0x550 net/802/mrp.c:530
      [<00000000fcfd81f3>] vlan_mvrp_request_join+0x145/0x170 net/8021q/vlan_mvrp.c:40
      [<000000009258546e>] vlan_dev_open+0x477/0x890 net/8021q/vlan_dev.c:292
      [<0000000059acd82b>] __dev_open+0x281/0x410 net/core/dev.c:1609
      [<000000004e6dc695>] __dev_change_flags+0x424/0x560 net/core/dev.c:8767
      [<00000000471a09af>] rtnl_configure_link+0xd9/0x210 net/core/rtnetlink.c:3122
      [<0000000037a4672b>] __rtnl_newlink+0xe08/0x13e0 net/core/rtnetlink.c:3448
      [<000000008d5d0fda>] rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3488
      [<000000004882fe39>] rtnetlink_rcv_msg+0x369/0xa10 net/core/rtnetlink.c:5552
      [<00000000907e6c54>] netlink_rcv_skb+0x134/0x3d0 net/netlink/af_netlink.c:2504
      [<00000000e7d7a8c4>] netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
      [<00000000e7d7a8c4>] netlink_unicast+0x4a0/0x6a0 net/netlink/af_netlink.c:1340
      [<00000000e0645d50>] netlink_sendmsg+0x78e/0xc90 net/netlink/af_netlink.c:1929
      [<00000000c24559b7>] sock_sendmsg_nosec net/socket.c:654 [inline]
      [<00000000c24559b7>] sock_sendmsg+0x139/0x170 net/socket.c:674
      [<00000000fc210bc2>] ____sys_sendmsg+0x658/0x7d0 net/socket.c:2350
      [<00000000be4577b5>] ___sys_sendmsg+0xf8/0x170 net/socket.c:2404
      
      Calling mrp_request_leave() after mrp_request_join(), the attr->state
      is set to MRP_APPLICANT_VO, mrp_attr_destroy() won't be called in last
      TX event in mrp_uninit_applicant(), the attr of applicant will be leaked.
      To fix this leak, iterate and free each attr of applicant before rerturning
      from mrp_uninit_applicant().
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      88c4cae3
    • Paul Gortmaker's avatar
      cgroup1: fix leaked context root causing sporadic NULL deref in LTP · eef99860
      Paul Gortmaker authored
      commit 1e7107c5 upstream.
      
      Richard reported sporadic (roughly one in 10 or so) null dereferences and
      other strange behaviour for a set of automated LTP tests.  Things like:
      
         BUG: kernel NULL pointer dereference, address: 0000000000000008
         #PF: supervisor read access in kernel mode
         #PF: error_code(0x0000) - not-present page
         PGD 0 P4D 0
         Oops: 0000 [#1] PREEMPT SMP PTI
         CPU: 0 PID: 1516 Comm: umount Not tainted 5.10.0-yocto-standard #1
         Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014
         RIP: 0010:kernfs_sop_show_path+0x1b/0x60
      
      ...or these others:
      
         RIP: 0010:do_mkdirat+0x6a/0xf0
         RIP: 0010:d_alloc_parallel+0x98/0x510
         RIP: 0010:do_readlinkat+0x86/0x120
      
      There were other less common instances of some kind of a general scribble
      but the common theme was mount and cgroup and a dubious dentry triggering
      the NULL dereference.  I was only able to reproduce it under qemu by
      replicating Richard's setup as closely as possible - I never did get it
      to happen on bare metal, even while keeping everything else the same.
      
      In commit 71d883c3
      
       ("cgroup_do_mount(): massage calling conventions")
      we see this as a part of the overall change:
      
         --------------
                 struct cgroup_subsys *ss;
         -       struct dentry *dentry;
      
         [...]
      
         -       dentry = cgroup_do_mount(&cgroup_fs_type, fc->sb_flags, root,
         -                                CGROUP_SUPER_MAGIC, ns);
      
         [...]
      
         -       if (percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
         -               struct super_block *sb = dentry->d_sb;
         -               dput(dentry);
         +       ret = cgroup_do_mount(fc, CGROUP_SUPER_MAGIC, ns);
         +       if (!ret && percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
         +               struct super_block *sb = fc->root->d_sb;
         +               dput(fc->root);
                         deactivate_locked_super(sb);
                         msleep(10);
                         return restart_syscall();
                 }
         --------------
      
      In changing from the local "*dentry" variable to using fc->root, we now
      export/leave that dentry pointer in the file context after doing the dput()
      in the unlikely "is_dying" case.   With LTP doing a crazy amount of back to
      back mount/unmount [testcases/bin/cgroup_regression_5_1.sh] the unlikely
      becomes slightly likely and then bad things happen.
      
      A fix would be to not leave the stale reference in fc->root as follows:
      
         --------------
                        dput(fc->root);
        +               fc->root = NULL;
                        deactivate_locked_super(sb);
         --------------
      
      ...but then we are just open-coding a duplicate of fc_drop_locked() so we
      simply use that instead.
      
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Zefan Li <lizefan.x@bytedance.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: stable@vger.kernel.org      # v5.1+
      Reported-by: default avatarRichard Purdie <richard.purdie@linuxfoundation.org>
      Fixes: 71d883c3
      
       ("cgroup_do_mount(): massage calling conventions")
      Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eef99860
    • Yang Yingliang's avatar
      workqueue: fix UAF in pwq_unbound_release_workfn() · 7f0365b4
      Yang Yingliang authored
      commit b42b0bdd upstream.
      
      I got a UAF report when doing fuzz test:
      
      [  152.880091][ T8030] ==================================================================
      [  152.881240][ T8030] BUG: KASAN: use-after-free in pwq_unbound_release_workfn+0x50/0x190
      [  152.882442][ T8030] Read of size 4 at addr ffff88810d31bd00 by task kworker/3:2/8030
      [  152.883578][ T8030]
      [  152.883932][ T8030] CPU: 3 PID: 8030 Comm: kworker/3:2 Not tainted 5.13.0+ #249
      [  152.885014][ T8030] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      [  152.886442][ T8030] Workqueue: events pwq_unbound_release_workfn
      [  152.887358][ T8030] Call Trace:
      [  152.887837][ T8030]  dump_stack_lvl+0x75/0x9b
      [  152.888525][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.889371][ T8030]  print_address_description.constprop.10+0x48/0x70
      [  152.890326][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.891163][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.891999][ T8030]  kasan_report.cold.15+0x82/0xdb
      [  152.892740][ T8030]  ? pwq_unbound_release_workfn+0x50/0x190
      [  152.893594][ T8030]  __asan_load4+0x69/0x90
      [  152.894243][ T8030]  pwq_unbound_release_workfn+0x50/0x190
      [  152.895057][ T8030]  process_one_work+0x47b/0x890
      [  152.895778][ T8030]  worker_thread+0x5c/0x790
      [  152.896439][ T8030]  ? process_one_work+0x890/0x890
      [  152.897163][ T8030]  kthread+0x223/0x250
      [  152.897747][ T8030]  ? set_kthread_struct+0xb0/0xb0
      [  152.898471][ T8030]  ret_from_fork+0x1f/0x30
      [  152.899114][ T8030]
      [  152.899446][ T8030] Allocated by task 8884:
      [  152.900084][ T8030]  kasan_save_stack+0x21/0x50
      [  152.900769][ T8030]  __kasan_kmalloc+0x88/0xb0
      [  152.901416][ T8030]  __kmalloc+0x29c/0x460
      [  152.902014][ T8030]  alloc_workqueue+0x111/0x8e0
      [  152.902690][ T8030]  __btrfs_alloc_workqueue+0x11e/0x2a0
      [  152.903459][ T8030]  btrfs_alloc_workqueue+0x6d/0x1d0
      [  152.904198][ T8030]  scrub_workers_get+0x1e8/0x490
      [  152.904929][ T8030]  btrfs_scrub_dev+0x1b9/0x9c0
      [  152.905599][ T8030]  btrfs_ioctl+0x122c/0x4e50
      [  152.906247][ T8030]  __x64_sys_ioctl+0x137/0x190
      [  152.906916][ T8030]  do_syscall_64+0x34/0xb0
      [  152.907535][ T8030]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  152.908365][ T8030]
      [  152.908688][ T8030] Freed by task 8884:
      [  152.909243][ T8030]  kasan_save_stack+0x21/0x50
      [  152.909893][ T8030]  kasan_set_track+0x20/0x30
      [  152.910541][ T8030]  kasan_set_free_info+0x24/0x40
      [  152.911265][ T8030]  __kasan_slab_free+0xf7/0x140
      [  152.911964][ T8030]  kfree+0x9e/0x3d0
      [  152.912501][ T8030]  alloc_workqueue+0x7d7/0x8e0
      [  152.913182][ T8030]  __btrfs_alloc_workqueue+0x11e/0x2a0
      [  152.913949][ T8030]  btrfs_alloc_workqueue+0x6d/0x1d0
      [  152.914703][ T8030]  scrub_workers_get+0x1e8/0x490
      [  152.915402][ T8030]  btrfs_scrub_dev+0x1b9/0x9c0
      [  152.916077][ T8030]  btrfs_ioctl+0x122c/0x4e50
      [  152.916729][ T8030]  __x64_sys_ioctl+0x137/0x190
      [  152.917414][ T8030]  do_syscall_64+0x34/0xb0
      [  152.918034][ T8030]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  152.918872][ T8030]
      [  152.919203][ T8030] The buggy address belongs to the object at ffff88810d31bc00
      [  152.919203][ T8030]  which belongs to the cache kmalloc-512 of size 512
      [  152.921155][ T8030] The buggy address is located 256 bytes inside of
      [  152.921155][ T8030]  512-byte region [ffff88810d31bc00, ffff88810d31be00)
      [  152.922993][ T8030] The buggy address belongs to the page:
      [  152.923800][ T8030] page:ffffea000434c600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10d318
      [  152.925249][ T8030] head:ffffea000434c600 order:2 compound_mapcount:0 compound_pincount:0
      [  152.926399][ T8030] flags: 0x57ff00000010200(slab|head|node=1|zone=2|lastcpupid=0x7ff)
      [  152.927515][ T8030] raw: 057ff00000010200 dead000000000100 dead000000000122 ffff888009c42c80
      [  152.928716][ T8030] raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
      [  152.929890][ T8030] page dumped because: kasan: bad access detected
      [  152.930759][ T8030]
      [  152.931076][ T8030] Memory state around the buggy address:
      [  152.931851][ T8030]  ffff88810d31bc00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.932967][ T8030]  ffff88810d31bc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.934068][ T8030] >ffff88810d31bd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.935189][ T8030]                    ^
      [  152.935763][ T8030]  ffff88810d31bd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [  152.936847][ T8030]  ffff88810d31be00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  152.937940][ T8030] ==================================================================
      
      If apply_wqattrs_prepare() fails in alloc_workqueue(), it will call put_pwq()
      which invoke a work queue to call pwq_unbound_release_workfn() and use the 'wq'.
      The 'wq' allocated in alloc_workqueue() will be freed in error path when
      apply_wqattrs_prepare() fails. So it will lead a UAF.
      
      CPU0                                          CPU1
      alloc_workqueue()
      alloc_and_link_pwqs()
      apply_wqattrs_prepare() fails
      apply_wqattrs_cleanup()
      schedule_work(&pwq->unbound_release_work)
      kfree(wq)
                                                    worker_thread()
                                                    pwq_unbound_release_workfn() <- trigger uaf here
      
      If apply_wqattrs_prepare() fails, the new pwq are not linked, it doesn't
      hold any reference to the 'wq', 'wq' is invalid to access in the worker,
      so add check pwq if linked to fix this.
      
      Fixes: 2d5f0764
      
       ("workqueue: split apply_workqueue_attrs() into 3 stages")
      Cc: stable@vger.kernel.org # v4.2+
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Suggested-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
      Tested-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f0365b4
    • Miklos Szeredi's avatar
      af_unix: fix garbage collect vs MSG_PEEK · 85abe0d4
      Miklos Szeredi authored
      commit cbcf0112
      
       upstream.
      
      unix_gc() assumes that candidate sockets can never gain an external
      reference (i.e.  be installed into an fd) while the unix_gc_lock is
      held.  Except for MSG_PEEK this is guaranteed by modifying inflight
      count under the unix_gc_lock.
      
      MSG_PEEK does not touch any variable protected by unix_gc_lock (file
      count is not), yet it needs to be serialized with garbage collection.
      Do this by locking/unlocking unix_gc_lock:
      
       1) increment file count
      
       2) lock/unlock barrier to make sure incremented file count is visible
          to garbage collection
      
       3) install file into fd
      
      This is a lock barrier (unlike smp_mb()) that ensures that garbage
      collection is run completely before or completely after the barrier.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      85abe0d4
    • Maxim Levitsky's avatar
      KVM: x86: determine if an exception has an error code only when injecting it. · af45f352
      Maxim Levitsky authored
      commit b97f0745
      
       upstream.
      
      A page fault can be queued while vCPU is in real paged mode on AMD, and
      AMD manual asks the user to always intercept it
      (otherwise result is undefined).
      The resulting VM exit, does have an error code.
      
      Signed-off-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Message-Id: <20210225154135.405125-2-mlevitsk@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarZubin Mithra <zsm@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      af45f352
    • Yonghong Song's avatar
      tools: Allow proper CC/CXX/... override with LLVM=1 in Makefile.include · 828cab3c
      Yonghong Song authored
      commit f62700ce
      
       upstream.
      
      selftests/bpf/Makefile includes tools/scripts/Makefile.include.
      With the following command
        make -j60 LLVM=1 LLVM_IAS=1  <=== compile kernel
        make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1 V=1
      some files are still compiled with gcc. This patch
      fixed the case if CC/AR/LD/CXX/STRIP is allowed to be
      overridden, it will be written to clang/llvm-ar/..., instead of
      gcc binaries. The definition of CC_NO_CLANG is also relocated
      to the place after the above CC is defined.
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210413153419.3028165-1-yhs@fb.com
      Cc: Anders Roxell <anders.roxell@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      828cab3c
    • Greg Kroah-Hartman's avatar
      selftest: fix build error in tools/testing/selftests/vm/userfaultfd.c · 525c5513
      Greg Kroah-Hartman authored
      When backporting 0db282ba
      
       ("selftest: use mmap instead of
      posix_memalign to allocate memory") to this stable branch, I forgot a {
      breaking the build.
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      525c5513
  3. Jul 28, 2021