1. 10 2月, 2022 29 次提交
  2. 29 1月, 2022 11 次提交
    • Z
      livepatch/core: Fix where module get and put in different macro · 12326136
      Zheng Yejian 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SFHQ
      
      --------------------------------
      
      Refer to following function procedure, 'obj->mod' is got if not define
      CONFIG_LIVEPATCH_FTRACE, but it is put if define
      CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY. If enable state of these two
      macros changed, reference count of 'obj->mod' would be wrong.
      
        klp_register_patch
            klp_init_patch
                klp_init_object
                    klp_find_object_module
                        try_module_get    <-- !CONFIG_LIVEPATCH_FTRACE
                    module_put  <-- CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY
            klp_free_patch_start
                klp_free_objects
                    __klp_free_objects
                        module_put <-- CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY
      
      So we use CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY uniformly.
      
      Fixes: c33e4283 ("livepatch/core: Allow implementation without ftrace")
      Signed-off-by: NZheng Yejian <zhengyejian1@huawei.com>
      Reviewed-by: NXu Kuohai <xukuohai@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      12326136
    • Z
      livepatch/core: Remove redundant klp_free_objects_mod_limited · 70e6a87c
      Zheng Yejian 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SFHQ
      
      --------------------------------
      
      Refer to following function procedure, klp_free_objects_mod_limited
      seems redundant, so remove it:
        klp_register_patch
            klp_init_patch
                klp_init_object             <---
                    klp_find_object_module      \
                        try_module_get           |<-- 1. If something wrong here
                jump_label_register         <----
                klp_free_objects_mod_limited    <-- 2. Check and put 'obj->mod'
                    module_put
            klp_free_patch_start    <-- 3. Check and put 'obj->mod' again
                klp_free_objects
                    __klp_free_objects
                        module_put
      Signed-off-by: NZheng Yejian <zhengyejian1@huawei.com>
      Reviewed-by: NXu Kuohai <xukuohai@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      70e6a87c
    • Z
      livepatch/core: Fix reference count issues · a891dbbe
      Zheng Yejian 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SFHQ
      
      --------------------------------
      
      Fix following reference count issues where get 'obj->mod' once but put
      twice:
        1) klp_register_patch
            klp_init_patch
                klp_init_object
                    klp_find_object_module
                        try_module_get    <-- 1. Get refcount once
                    klp_init_object_loaded    <-- 2. If fail here!!!
                    module_put    <-- 3. Put refcount first time
            klp_free_patch_start
                klp_free_objects
                    __klp_free_objects
                        module_put    <-- 4. 'obj->mod' not null, put twice!!!
      
        2) klp_register_patch
          klp_init_patch
              klp_init_object
                  klp_find_object_module
                      try_module_get    <-- 1. Get refcount once
              kobject_add    <-- 2. If other objs fail here!!!
              klp_free_objects_mod_limited
                  module_put    <-- 3. Put refcount first time
          klp_free_patch_start
              klp_free_objects
                  __klp_free_objects
                      module_put    <-- 4. 'obj->mod' not null, put twice!!!
      
      Fixes: c33e4283 ("livepatch/core: Allow implementation without ftrace")
      Signed-off-by: NZheng Yejian <zhengyejian1@huawei.com>
      Reviewed-by: NXu Kuohai <xukuohai@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      a891dbbe
    • W
      arm64/mpam: realign step entry when traversing rmid_transform · df092ea4
      Wang ShaoBo 提交于
      hulk inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SE03
      CVE: NA
      
      ---------------------------------------------------
      
      This makes step entry aligned with step_size*step_cnt but not step_size,
      and check for alignment before traversing rmid_transform.
      
      When modifying rmid with a value not aligned with step_size*step_cnt,
      for_each_rmid_transform_point_step_from might miss next step point if
      it has been occupied in case step_cnt or step_size not equals to 1,
      which will cause the actual allocated rmid to be inconsistent with the
      expected one.
      
      Fixes: 8a2c07b5 ("arm64/mpam: rmid: refine allocation and release process")
      Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      df092ea4
    • X
      dt-bindings: mpam: refactor device tree node structure · 8cfa786d
      Xingang Wang 提交于
      arm64/mpam: refactor device tree structure to support multiple
      devices
      
      ascend inclusion
      category: feature
      bugzilla:
      https://gitee.com/openeuler/kernel/issues/I49RB2
      CVE: NA
      
      ---------------------------------------------------
      
      To support multiple mpam device nodes, all nodes should be organized
      as child of the same parent nodes. This makes sure that the mpam
      discovery start and complete procedure in the right execution order.
      Add modification in the devicetree documentation to record this.
      Signed-off-by: NXingang Wang <wangxingang5@huawei.com>
      Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      8cfa786d
    • X
      arm64/mpam: refactor device tree structure to support multiple devices · c0ec28ac
      Xingang Wang 提交于
      ascend inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4L735
      CVE: NA
      
      ---------------------------------------------------
      
      The process of MPAM device tree initialization is like this:
      arm_mpam_device_probe() 	// driver probe
        mpam_discovery_start()	// start discover mpam devices
          [...] 			// find and add mpam devices
        mpam_discovery_complete()   	// trigger mpam_enable
      
      When there are multiple mpam device nodes, the driver probe procedure
      will execute more than once. However, the mpam_discovery_start() and
      mpam_discovery_complete() should only run once. Besides, the start
      should run first, and the complete should run after all devices added.
      
      So we reorganize the device tree structure, so that there will be only
      one mpam device parent nodes, and the probe procedure will only run once.
      We add the child node to represent the mpam devices, and traverse and
      add all mpam devices in the middle procedure of driver probe.
      Signed-off-by: NXingang Wang <wangxingang5@huawei.com>
      Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      c0ec28ac
    • X
      arm64/mpam: fix __mpam_device_create() section mismatch error · 6238a402
      Xingang Wang 提交于
      ascend inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4L735
      CVE: NA
      
      ---------------------------------------------------
      
      Fix modpost Section mismatch error in __mpam_device_create() and others.
      These warnings will occur in high version gcc, for example 10.1.0.
      
        [...]
        WARNING: vmlinux.o(.text+0x2ed88): Section mismatch in reference from the
        function __mpam_device_create() to the function .init.text:mpam_device_alloc()
        The function __mpam_device_create() references
        the function __init mpam_device_alloc().
        This is often because __mpam_device_create lacks a __init
        annotation or the annotation of mpam_device_alloc is wrong.
      
        WARNING: vmlinux.o(.text.unlikely+0xa5c): Section mismatch in reference from
        the function mpam_resctrl_init() to the function .init.text:mpam_init_padding()
        The function mpam_resctrl_init() references
        the function __init mpam_init_padding().
        This is often because mpam_resctrl_init lacks a __init
        annotation or the annotation of mpam_init_padding is wrong.
      
        WARNING: vmlinux.o(.text.unlikely+0x5a9c): Section mismatch in reference from
        the function resctrl_group_init() to the function .init.text:resctrl_group_setup_root()
        The function resctrl_group_init() references
        the function __init resctrl_group_setup_root().
        This is often because resctrl_group_init lacks a __init
        annotation or the annotation of resctrl_group_setup_root is wrong.
        [...]
      
      Fixes: 682eefba ("arm64/mpam: remove __init macro to support driver probe")
      Signed-off-by: NXingang Wang <wangxingang5@huawei.com>
      Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      6238a402
    • Y
      block, bfq: don't move oom_bfqq · b2fb86b1
      Yu Kuai 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4SDBD
      
      --------------------------------
      
      Our test report a UAF:
      
      [ 2073.019181] ==================================================================
      [ 2073.019188] BUG: KASAN: use-after-free in __bfq_put_async_bfqq+0xa0/0x168
      [ 2073.019191] Write of size 8 at addr ffff8000ccf64128 by task rmmod/72584
      [ 2073.019192]
      [ 2073.019196] CPU: 0 PID: 72584 Comm: rmmod Kdump: loaded Not tainted 4.19.90-yk #5
      [ 2073.019198] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
      [ 2073.019200] Call trace:
      [ 2073.019203]  dump_backtrace+0x0/0x310
      [ 2073.019206]  show_stack+0x28/0x38
      [ 2073.019210]  dump_stack+0xec/0x15c
      [ 2073.019216]  print_address_description+0x68/0x2d0
      [ 2073.019220]  kasan_report+0x238/0x2f0
      [ 2073.019224]  __asan_store8+0x88/0xb0
      [ 2073.019229]  __bfq_put_async_bfqq+0xa0/0x168
      [ 2073.019233]  bfq_put_async_queues+0xbc/0x208
      [ 2073.019236]  bfq_pd_offline+0x178/0x238
      [ 2073.019240]  blkcg_deactivate_policy+0x1f0/0x420
      [ 2073.019244]  bfq_exit_queue+0x128/0x178
      [ 2073.019249]  blk_mq_exit_sched+0x12c/0x160
      [ 2073.019252]  elevator_exit+0xc8/0xd0
      [ 2073.019256]  blk_exit_queue+0x50/0x88
      [ 2073.019259]  blk_cleanup_queue+0x228/0x3d8
      [ 2073.019267]  null_del_dev+0xfc/0x1e0 [null_blk]
      [ 2073.019274]  null_exit+0x90/0x114 [null_blk]
      [ 2073.019278]  __arm64_sys_delete_module+0x358/0x5a0
      [ 2073.019282]  el0_svc_common+0xc8/0x320
      [ 2073.019287]  el0_svc_handler+0xf8/0x160
      [ 2073.019290]  el0_svc+0x10/0x218
      [ 2073.019291]
      [ 2073.019294] Allocated by task 14163:
      [ 2073.019301]  kasan_kmalloc+0xe0/0x190
      [ 2073.019305]  kmem_cache_alloc_node_trace+0x1cc/0x418
      [ 2073.019308]  bfq_pd_alloc+0x54/0x118
      [ 2073.019313]  blkcg_activate_policy+0x250/0x460
      [ 2073.019317]  bfq_create_group_hierarchy+0x38/0x110
      [ 2073.019321]  bfq_init_queue+0x6d0/0x948
      [ 2073.019325]  blk_mq_init_sched+0x1d8/0x390
      [ 2073.019330]  elevator_switch_mq+0x88/0x170
      [ 2073.019334]  elevator_switch+0x140/0x270
      [ 2073.019338]  elv_iosched_store+0x1a4/0x2a0
      [ 2073.019342]  queue_attr_store+0x90/0xe0
      [ 2073.019348]  sysfs_kf_write+0xa8/0xe8
      [ 2073.019351]  kernfs_fop_write+0x1f8/0x378
      [ 2073.019359]  __vfs_write+0xe0/0x360
      [ 2073.019363]  vfs_write+0xf0/0x270
      [ 2073.019367]  ksys_write+0xdc/0x1b8
      [ 2073.019371]  __arm64_sys_write+0x50/0x60
      [ 2073.019375]  el0_svc_common+0xc8/0x320
      [ 2073.019380]  el0_svc_handler+0xf8/0x160
      [ 2073.019383]  el0_svc+0x10/0x218
      [ 2073.019385]
      [ 2073.019387] Freed by task 72584:
      [ 2073.019391]  __kasan_slab_free+0x120/0x228
      [ 2073.019394]  kasan_slab_free+0x10/0x18
      [ 2073.019397]  kfree+0x94/0x368
      [ 2073.019400]  bfqg_put+0x64/0xb0
      [ 2073.019404]  bfqg_and_blkg_put+0x90/0xb0
      [ 2073.019408]  bfq_put_queue+0x220/0x228
      [ 2073.019413]  __bfq_put_async_bfqq+0x98/0x168
      [ 2073.019416]  bfq_put_async_queues+0xbc/0x208
      [ 2073.019420]  bfq_pd_offline+0x178/0x238
      [ 2073.019424]  blkcg_deactivate_policy+0x1f0/0x420
      [ 2073.019429]  bfq_exit_queue+0x128/0x178
      [ 2073.019433]  blk_mq_exit_sched+0x12c/0x160
      [ 2073.019437]  elevator_exit+0xc8/0xd0
      [ 2073.019440]  blk_exit_queue+0x50/0x88
      [ 2073.019443]  blk_cleanup_queue+0x228/0x3d8
      [ 2073.019451]  null_del_dev+0xfc/0x1e0 [null_blk]
      [ 2073.019459]  null_exit+0x90/0x114 [null_blk]
      [ 2073.019462]  __arm64_sys_delete_module+0x358/0x5a0
      [ 2073.019467]  el0_svc_common+0xc8/0x320
      [ 2073.019471]  el0_svc_handler+0xf8/0x160
      [ 2073.019474]  el0_svc+0x10/0x218
      [ 2073.019475]
      [ 2073.019479] The buggy address belongs to the object at ffff8000ccf63f00
       which belongs to the cache kmalloc-1024 of size 1024
      [ 2073.019484] The buggy address is located 552 bytes inside of
       1024-byte region [ffff8000ccf63f00, ffff8000ccf64300)
      [ 2073.019486] The buggy address belongs to the page:
      [ 2073.019492] page:ffff7e000333d800 count:1 mapcount:0 mapping:ffff8000c0003a00 index:0x0 compound_mapcount: 0
      [ 2073.020123] flags: 0x7ffff0000008100(slab|head)
      [ 2073.020403] raw: 07ffff0000008100 ffff7e0003334c08 ffff7e00001f5a08 ffff8000c0003a00
      [ 2073.020409] raw: 0000000000000000 00000000001c001c 00000001ffffffff 0000000000000000
      [ 2073.020411] page dumped because: kasan: bad access detected
      [ 2073.020412]
      [ 2073.020414] Memory state around the buggy address:
      [ 2073.020420]  ffff8000ccf64000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [ 2073.020424]  ffff8000ccf64080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [ 2073.020428] >ffff8000ccf64100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [ 2073.020430]                                   ^
      [ 2073.020434]  ffff8000ccf64180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [ 2073.020438]  ffff8000ccf64200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      [ 2073.020439] ==================================================================
      
      After add some debug info, we found that the root cause is that the
      oom_bfqq is moved to a non-root bfqg.
      
      Thus fix the problem by don't move oom_bfqq.
      Signed-off-by: NYu Kuai <yukuai3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      b2fb86b1
    • L
      fget: clarify and improve __fget_files() implementation · 730361f0
      Linus Torvalds 提交于
      mainline inclusion
      from mainline-5.16-rc6
      commit e386dfc5
      category: perf
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4S0SZ
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e386dfc56f837da66d00a078e5314bc8382fab83
      
      -------------------------------------------------
      
      Commit 054aa8d4 ("fget: check that the fd still exists after getting
      a ref to it") fixed a race with getting a reference to a file just as it
      was being closed.  It was a fairly minimal patch, and I didn't think
      re-checking the file pointer lookup would be a measurable overhead,
      since it was all right there and cached.
      
      But I was wrong, as pointed out by the kernel test robot.
      
      The 'poll2' case of the will-it-scale.per_thread_ops benchmark regressed
      quite noticeably.  Admittedly it seems to be a very artificial test:
      doing "poll()" system calls on regular files in a very tight loop in
      multiple threads.
      
      That means that basically all the time is spent just looking up file
      descriptors without ever doing anything useful with them (not that doing
      'poll()' on a regular file is useful to begin with).  And as a result it
      shows the extra "re-check fd" cost as a sore thumb.
      
      Happily, the regression is fixable by just writing the code to loook up
      the fd to be better and clearer.  There's still a cost to verify the
      file pointer, but now it's basically in the noise even for that
      benchmark that does nothing else - and the code is more understandable
      and has better comments too.
      
      [ Side note: this patch is also a classic case of one that looks very
        messy with the default greedy Myers diff - it's much more legible with
        either the patience of histogram diff algorithm ]
      
      Link: https://lore.kernel.org/lkml/20211210053743.GA36420@xsang-OptiPlex-9020/
      Link: https://lore.kernel.org/lkml/20211213083154.GA20853@linux.intel.com/Reported-by: Nkernel test robot <oliver.sang@intel.com>
      Tested-by: NCarel Si <beibei.si@intel.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Miklos Szeredi <mszeredi@redhat.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      
      Conflicts:
      	fs/file.c
      Signed-off-by: NBaokun Li <libaokun1@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      730361f0
    • G
      KABI: add reserve space for thread_info struct · e8baff77
      Guan Jing 提交于
      hulk inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4KAP1?from=project-issue
      CVE: NA
      
      -------------------------------
      
      We reserve some fields beforehand for thread_info prone to change.
      Signed-off-by: NGuan Jing <guanjing6@huawei.com>
      Reviewed-by: NChen Hui <judy.chenhui@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      e8baff77
    • W
      kabi: Reserve syscall entries for kabi compatibility · 4d13e400
      Wei Li 提交于
      hulk inclusion
      category: feature
      bugzilla: 186175, https://gitee.com/openeuler/kernel/issues/I4S77Z
      CVE: NA
      
      -------------------------------------------------
      
      Reserve several syscall entries for kabi compatibility.
      For arch arm32,ppc32,riscv64,ppc64,arm64,x86_64 currently.
      Signed-off-by: NWei Li <liwei391@huawei.com>
      Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      4d13e400