Skip to content
Snippets Groups Projects
  1. Sep 26, 2022
    • Zhihao Cheng's avatar
      quota: Check next/prev free block number after reading from quota file · 6c27d754
      Zhihao Cheng authored
      hulk inclusion
      category: bugfix
      bugzilla: 187046, https://gitee.com/openeuler/kernel/issues/I5QH0X
      CVE: NA
      
      --------------------------------
      
      Following process:
       Init: v2_read_file_info: <3> dqi_free_blk 0 dqi_free_entry 5 dqi_blks 6
      
       Step 1. chown bin f_a -> dquot_acquire -> v2_write_dquot:
        qtree_write_dquot
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            write_blk(info->dqi_blocks) // info->dqi_blocks = 6, failure. The
      	   content in physical block (corresponding to blk 6) is random.
      
       Step 2. chown root f_a -> dquot_transfer -> dqput_all -> dqput ->
               ext4_release_dquot -> v2_release_dquot -> qtree_delete_dquot:
        dquot_release
         remove_tree
          free_dqentry
           put_free_dqblk(6)
            info->dqi_free_blk = blk    // info->dqi_free_blk = 6
      
       Step 3. drop cache (buffer head for block 6 is released)
      
       Step 4. chown bin f_b -> dquot_acquire -> commit_dqblk -> v2_write_dquot:
        qtree_write_dquot
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            dh = (struct qt_disk_dqdbheader *)buf
            blk = info->dqi_free_blk     // 6
            ret = read_blk(info, blk, buf)  // The content of buf is random
            info->dqi_free_blk = le32_to_cpu(dh->dqdh_next_free)  // random blk
      
       Step 5. chown bin f_c -> notify_change -> ext4_setattr -> dquot_transfer:
        dquot = dqget -> acquire_dquot -> ext4_acquire_dquot -> dquot_acquire ->
                commit_dqblk -> v2_write_dquot -> dq_insert_tree:
         do_insert_tree
          find_free_dqentry
           get_free_dqblk
            blk = info->dqi_free_blk    // If blk < 0 and blk is not an error
      				     code, it will be returned as dquot
      
        transfer_to[USRQUOTA] = dquot  // A random negative value
        __dquot_transfer(transfer_to)
         dquot_add_inodes(transfer_to[cnt])
          spin_lock(&dquot->dq_dqb_lock)  // page fault
      
      , which will lead to kernel page fault:
       Quota error (device sda): qtree_write_dquot: Error -8000 occurred
       while creating quota
       BUG: unable to handle page fault for address: ffffffffffffe120
       #PF: supervisor write access in kernel mode
       #PF: error_code(0x0002) - not-present page
       Oops: 0002 [#1] PREEMPT SMP
       CPU: 0 PID: 5974 Comm: chown Not tainted 6.0.0-rc1-00004
       Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
       RIP: 0010:_raw_spin_lock+0x3a/0x90
       Call Trace:
        dquot_add_inodes+0x28/0x270
        __dquot_transfer+0x377/0x840
        dquot_transfer+0xde/0x540
        ext4_setattr+0x405/0x14d0
        notify_change+0x68e/0x9f0
        chown_common+0x300/0x430
        __x64_sys_fchownat+0x29/0x40
      
      In order to avoid accessing invalid quota memory address, this patch adds
      block number checking of next/prev free block read from quota file.
      
      Fetch a reproducer in [Link].
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216372
      
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      6c27d754
    • Hyunwoo Kim's avatar
      efi: capsule-loader: Fix use-after-free in efi_capsule_write · 27dfef31
      Hyunwoo Kim authored
      mainline inclusion
      from mainline-v6.0-rc5
      commit 9cb636b5f6a8cc6d1b50809ec8f8d33ae0c84c95
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5QI0W
      
      
      CVE: CVE-2022-40307
      
      ---------------------------
      
      A race condition may occur if the user calls close() on another thread
      during a write() operation on the device node of the efi capsule.
      
      This is a race condition that occurs between the efi_capsule_write() and
      efi_capsule_flush() functions of efi_capsule_fops, which ultimately
      results in UAF.
      
      So, the page freeing process is modified to be done in
      efi_capsule_release() instead of efi_capsule_flush().
      
      Cc: <stable@vger.kernel.org> # v4.9+
      Signed-off-by: default avatarHyunwoo Kim <imv4bel@gmail.com>
      Link: https://lore.kernel.org/all/20220907102920.GA88602@ubuntu/
      
      
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: default avatarXia Longlong <xialonglong1@huawei.com>
      Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Reviewed-by: Xiu Jianfeng <x...
      27dfef31
    • Lu Wei's avatar
      ipvlan: Fix out-of-bound bugs caused by unset skb->mac_header · 4b633c1e
      Lu Wei authored
      mainline inclusion
      from mainline-v6.0-rc6
      commit 81225b2ea161af48e093f58e8dfee6d705b16af4
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5SYBY
      
      
      CVE: NA
      
      --------------------------------
      
      If an AF_PACKET socket is used to send packets through ipvlan and the
      default xmit function of the AF_PACKET socket is changed from
      dev_queue_xmit() to packet_direct_xmit() via setsockopt() with the option
      name of PACKET_QDISC_BYPASS, the skb->mac_header may not be reset and
      remains as the initial value of 65535, this may trigger slab-out-of-bounds
      bugs as following:
      
      =================================================================
      UG: KASAN: slab-out-of-bounds in ipvlan_xmit_mode_l2+0xdb/0x330 [ipvlan]
      PU: 2 PID: 1768 Comm: raw_send Kdump: loaded Not tainted 6.0.0-rc4+ #6
      ardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33
      all Trace:
      print_address_description.constprop.0+0x1d/0x160
      print_report.cold+0x4f/0x112
      kasan_report+0xa3/0x130
      ipvlan_xmit_mode_l2+0xdb/0x330 [ipvlan]
      ipvlan_start_xmit+0x29/0xa0 [ipvlan]
      __dev_direct_xmit+0x2e2/0x380
      packet_direct_xmit+0x22/0x60
      packet_snd+0x7c9/0xc40
      sock_sendmsg+0x9a/0xa0
      __sys_sendto+0x18a/0x230
      __x64_sys_sendto+0x74/0x90
      do_syscall_64+0x3b/0x90
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      The root cause is:
        1. packet_snd() only reset skb->mac_header when sock->type is SOCK_RAW
           and skb->protocol is not specified as in packet_parse_headers()
      
        2. packet_direct_xmit() doesn't reset skb->mac_header as dev_queue_xmit()
      
      In this case, skb->mac_header is 65535 when ipvlan_xmit_mode_l2() is
      called. So when ipvlan_xmit_mode_l2() gets mac header with eth_hdr() which
      use "skb->head + skb->mac_header", out-of-bound access occurs.
      
      This patch replaces eth_hdr() with skb_eth_hdr() in ipvlan_xmit_mode_l2()
      and reset mac header in multicast to solve this out-of-bound bug.
      
      Fixes: 2ad7bf36 ("ipvlan: Initial check-in of the IPVLAN driver.")
      Signed-off-by: default avatarLu Wei <luwei32@huawei.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarLu Wei <luwei32@huawei.com>
      Reviewed-by: default avatarYue Haibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      4b633c1e
    • Wang Wensheng's avatar
      mm/sharepool: Fix UAF reported by KASAN · 89f5304b
      Wang Wensheng authored
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5PD4P
      
      
      CVE: NA
      
      --------------------------------
      
      [ 2058.802818][  T290] BUG: KASAN: use-after-free in get_process_sp_res+0x70/0x134
      [ 2058.810194][  T290] Read of size 8 at addr ffff00088dc6ab28 by task test_debug_loop/290
      [ 2058.820520][  T290] CPU: 5 PID: 290 Comm: test_debug_loop Tainted: G        W  OE     5.10.0+ #2
      [ 2058.829377][  T290] Hardware name: EVB(EP) (DT)
      [ 2058.833982][  T290] Call trace:
      [ 2058.837217][  T290]  dump_backtrace+0x0/0x30c
      [ 2058.841660][  T290]  show_stack+0x20/0x30
      [ 2058.845758][  T290]  dump_stack+0x120/0x1b0
      [ 2058.850028][  T290]  print_address_description.constprop.0+0x2c/0x1fc
      [ 2058.856555][  T290]  __kasan_report+0xfc/0x160
      [ 2058.861086][  T290]  kasan_report+0x44/0xb0
      [ 2058.865356][  T290]  __asan_load8+0x94/0xd0
      [ 2058.869623][  T290]  get_process_sp_res+0x70/0x134
      [ 2058.874501][  T290]  proc_usage_show+0x1ac/0x304
      [ 2058.879208][  T290]  seq_read_iter+0x254/0x750
      [ 2058.883728][  T290]  proc_reg_read_iter+0x100/0x140
      [ 2058.888689][  T290]  new_sync_read+0x1cc/0x2c0
      [ 2058.893215][  T290]  vfs_read+0x1f4/0x250
      [ 2058.897304][  T290]  ksys_read+0xcc/0x170
      [ 2058.901399][  T290]  __arm64_sys_read+0x4c/0x60
      [ 2058.906016][  T290]  el0_svc_common.constprop.0+0xb4/0x2a0
      [ 2058.911584][  T290]  do_el0_svc+0x8c/0xb0
      [ 2058.915677][  T290]  el0_svc+0x20/0x30
      [ 2058.919503][  T290]  el0_sync_handler+0xb0/0xbc
      [ 2058.924114][  T290]  el0_sync+0x180/0x1c0
      [ 2058.928190][  T290]
      [ 2058.930444][  T290] Allocated by task 2176:
      [ 2058.934714][  T290]  kasan_save_stack+0x28/0x60
      [ 2058.939328][  T290]  __kasan_kmalloc.constprop.0+0xc8/0xf0
      [ 2058.944909][  T290]  kasan_kmalloc+0x10/0x20
      [ 2058.949268][  T290]  kmem_cache_alloc_trace+0x128/0xabc
      [ 2058.954577][  T290]  create_spg_node+0x58/0x214
      [ 2058.959188][  T290]  local_group_add_task+0x30/0x14c
      [ 2058.964231][  T290]  init_local_group+0xd0/0x1a0
      [ 2058.968936][  T290]  sp_init_group_master_locked.part.0+0x19c/0x290
      [ 2058.975298][  T290]  mg_sp_group_add_task+0x73c/0xdb0
      [ 2058.980456][  T290]  dev_sp_add_group+0x124/0x2dc [sharepool_dev]
      [ 2058.986647][  T290]  dev_ioctl+0x21c/0x2ec [sharepool_dev]
      [ 2058.992222][  T290]  __arm64_sys_ioctl+0xd8/0x120
      [ 2058.997010][  T290]  el0_svc_common.constprop.0+0xb4/0x2a0
      [ 2059.002572][  T290]  do_el0_svc+0x8c/0xb0
      [ 2059.006662][  T290]  el0_svc+0x20/0x30
      [ 2059.010489][  T290]  el0_sync_handler+0xb0/0xbc
      [ 2059.015101][  T290]  el0_sync+0x180/0x1c0
      [ 2059.019176][  T290]
      [ 2059.021427][  T290] Freed by task 4125:
      [ 2059.025343][  T290]  kasan_save_stack+0x28/0x60
      [ 2059.029949][  T290]  kasan_set_track+0x28/0x40
      [ 2059.034476][  T290]  kasan_set_free_info+0x24/0x50
      [ 2059.039347][  T290]  __kasan_slab_free+0x104/0x1ac
      [ 2059.044227][  T290]  kasan_slab_free+0x14/0x20
      [ 2059.048744][  T290]  kfree+0x164/0xb94
      [ 2059.052576][  T290]  sp_group_post_exit+0xf0/0x980
      [ 2059.057448][  T290]  mmput.part.0+0xb4/0x220
      [ 2059.061790][  T290]  mmput+0x2c/0x40
      [ 2059.065450][  T290]  exit_mm+0x27c/0x3a0
      [ 2059.069450][  T290]  do_exit+0x2a0/0x790
      [ 2059.073448][  T290]  do_group_exit+0x64/0x100
      [ 2059.077884][  T290]  get_signal+0x1fc/0x9fc
      [ 2059.082144][  T290]  do_signal+0x110/0x2cc
      [ 2059.086320][  T290]  do_notify_resume+0x158/0x2b0
      [ 2059.091108][  T290]  work_pending+0xc/0x6d4
      [ 2059.095358][  T290]
      
      Signed-off-by: default avatarWang Wensheng <wangwensheng4@huawei.com>
      Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      89f5304b
    • David Jeffery's avatar
      blk-mq: avoid extending delays of active hctx from blk_mq_delay_run_hw_queues · 9c7724ae
      David Jeffery authored
      mainline inclusion
      from mainline-v5.18-rc1
      commit 8f5fea65b06de1cc51d4fc23fb4d378d1abd6ed7
      category: bugfix
      bugzilla: 187541, https://gitee.com/openeuler/kernel/issues/I5RUM6
      
      
      CVE: NA
      
      --------------------------------
      
      When blk_mq_delay_run_hw_queues sets an hctx to run in the future, it can
      reset the delay length for an already pending delayed work run_work. This
      creates a scenario where multiple hctx may have their queues set to run,
      but if one runs first and finds nothing to do, it can reset the delay of
      another hctx and stall the other hctx's ability to run requests.
      
      To avoid this I/O stall when an hctx's run_work is already pending,
      leave it untouched to run at its current designated time rather than
      extending its delay. The work will still run which keeps closed the race
      calling blk_mq_delay_run_hw_queues is needed for while also avoiding the
      I/O stall.
      
      Signed-off-by: default avatarDavid Jeffery <djeffery@redhat.com>
      Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
      Link: https://lore.kernel.org/r/20220131203337.GA17666@redhat
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      9c7724ae
    • Ma Wupeng's avatar
      mm: mem_reliable: Start fallback if no suitable zone found · f8f0da00
      Ma Wupeng authored
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SK3S
      
      
      CVE: NA
      
      --------------------------------
      
      For reliable memory allocation bind to nodes which do not hvve any
      reliable zones, its memory allocation will fail and then warn message
      will be produced at the end of __alloc_pages_slowpath().
      
      Though this memory allocation can fallback to movable zone in
      check_after_alloc() if fallback is enabled, something should be done to
      prevent this pointless warn log.
      
      To solve this problem, fallback to movable zone if no suitable zone found.
      
      Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
      Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      f8f0da00
  2. Sep 22, 2022
  3. Sep 20, 2022
  4. Sep 14, 2022
    • Jann Horn's avatar
      mm: Force TLB flush for PFNMAP mappings before unlink_file_vma() · 01f05a1e
      Jann Horn authored
      stable inclusion
      from stable-v4.19.257
      commit c3b1e88f14e7f442e2ddcbec94527eec84ac0ca3
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5PE9S
      CVE: CVE-2022-39188
      
      --------------------------------
      
      commit b67fbebd4cf980aecbcc750e1462128bffe8ae15 upstream.
      
      Some drivers rely on having all VMAs through which a PFN might be
      accessible listed in the rmap for correctness.
      However, on X86, it was possible for a VMA with stale TLB entries
      to not be listed in the rmap.
      
      This was fixed in mainline with
      commit b67fbebd4cf9 ("mmu_gather: Force tlb-flush VM_PFNMAP vmas"),
      but that commit relies on preceding refactoring in
      commit 18ba064e42df3 ("mmu_gather: Let there be one tlb_{start,end}_vma()
      implementation") and commit 1e9fdf21a4339 ("mmu_gather: Remove per arch
      tlb_{start,end}_vma()").
      
      This patch provides equivalent protection without needing that
      refactoring, by forcing a TLB flush between removing PTEs in
      unmap_vmas() and ...
    • Hyunwoo Kim's avatar
      video: fbdev: pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write · 0c93f29f
      Hyunwoo Kim authored
      mainline inclusion
      from mainline-v5.19-rc4
      commit a09d2d00af53b43c6f11e6ab3cb58443c2cac8a7
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5PRMO
      
      
      CVE: CVE-2022-39842
      
      ---------------------
      
      In pxa3xx_gcu_write, a count parameter of type size_t is passed to words of
      type int.  Then, copy_from_user() may cause a heap overflow because it is used
      as the third argument of copy_from_user().
      
      Signed-off-by: default avatarHyunwoo Kim <imv4bel@gmail.com>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarZhao Wenhui <zhaowenhui8@huawei.com>
      Reviewed-by: default avatarChen Hui <judy.chenhui@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      0c93f29f
    • Paolo Bonzini's avatar
      KVM: x86: do not report a vCPU as preempted outside instruction boundaries · adb2f636
      Paolo Bonzini authored
      mainline inclusion
      from mainline-v5.19-rc2
      commit 6cd88243c7e03845a450795e134b488fc2afb736
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5PJ7H
      
      
      CVE: CVE-2022-39189
      
      ----------------------------------------
      
      If a vCPU is outside guest mode and is scheduled out, it might be in the
      process of making a memory access.  A problem occurs if another vCPU uses
      the PV TLB flush feature during the period when the vCPU is scheduled
      out, and a virtual address has already been translated but has not yet
      been accessed, because this is equivalent to using a stale TLB entry.
      
      To avoid this, only report a vCPU as preempted if sure that the guest
      is at an instruction boundary.  A rescheduling request will be delivered
      to the host physical CPU as an external interrupt, so for simplicity
      consider any vmexit *not* instruction boundary except for external
      interrupts.
      
      It would in principle be okay to report the vCPU as preempted also
      if it is sleeping in kvm_vcpu_block(): a TLB flush IPI will incur the
      vmentry/vmexit overhead unnecessarily, and optimistic spinning is
      also unlikely to succeed.  However, leave it for later because right
      now kvm_vcpu_check_block() is doing memory accesses.  Even
      though the TLB flush issue only applies to virtual memory address,
      it's very much preferrable to be conservative.
      
      Reported-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      
      conflict:
      	arch/x86/include/asm/kvm_host.h
      	arch/x86/kvm/svm.c
      	arch/x86/kvm/vmx.c
      	arch/x86/kvm/x86.c
      
      Signed-off-by: default avatarGuo Mengqi <guomengqi3@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
    • Andrew Murray's avatar
      KVM: arm64: Write arch.mdcr_el2 changes since last vcpu_load on VHE · 0ff1abf0
      Andrew Murray authored
      mainline inclusion
      from mainline-v5.6
      commit 4942dc66
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5QR6C
      CVE: NA
      
      -------------
      
      On VHE systems arch.mdcr_el2 is written to mdcr_el2 at vcpu_load time to
      set options for self-hosted debug and the performance monitors
      extension.
      
      Unfortunately the value of arch.mdcr_el2 is not calculated until
      kvm_arm_setup_debug() in the run loop after the vcpu has been loaded.
      This means that the initial brief iterations of the run loop use a zero
      value of mdcr_el2 - until the vcpu is preempted. This also results in a
      delay between changes to vcpu->guest_debug taking effect.
      
      Fix this by writing to mdcr_el2 in kvm_arm_setup_debug() on VHE systems
      when a change to arch.mdcr_el2 has been detected.
      
      Fixes: d5a21bcc ("KVM: arm64: Move common VHE/non-VHE trap config in separate functions")
      Cc: <stable@vger.kernel.org> # 4.17.x-
      Suggested-by: James Mors...
      0ff1abf0
  5. Sep 13, 2022
  6. Sep 07, 2022