1. 27 May, 2020 7 commits
    • Roberto Sassu's avatar
      evm: Check also if *tfm is an error pointer in init_desc() · 4c7a2e76
      Roberto Sassu authored
      [ Upstream commit 53de3b08 ]
      
      This patch avoids a kernel panic due to accessing an error pointer set by
      crypto_alloc_shash(). It occurs especially when there are many files that
      require an unsupported algorithm, as it would increase the likelihood of
      the following race condition:
      
      Task A: *tfm = crypto_alloc_shash() <= error pointer
      Task B: if (*tfm == NULL) <= *tfm is not NULL, use it
      Task B: rc = crypto_shash_init(desc) <= panic
      Task A: *tfm = NULL
      
      This patch uses the IS_ERR_OR_NULL macro to determine whether or not a new
      crypto context must be created.
      
      Cc: stable@vger.kernel.org
      Fixes: d46eb369 ("evm: crypto hash replaced by shash")
      Co-developed-by: default avatarKrzysztof Struczynski <krzysztof.struczynski@huawei.com>
      Signed-off-by: default avatarKrzysztof Struczynski <krzysztof.struczynski@huawei.com>
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4c7a2e76
    • Roberto Sassu's avatar
      ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash() · 904de138
      Roberto Sassu authored
      [ Upstream commit 0014cc04 ]
      
      Commit a408e4a8 ("ima: open a new file instance if no read
      permissions") tries to create a new file descriptor to calculate a file
      digest if the file has not been opened with O_RDONLY flag. However, if a
      new file descriptor cannot be obtained, it sets the FMODE_READ flag to
      file->f_flags instead of file->f_mode.
      
      This patch fixes this issue by replacing f_flags with f_mode as it was
      before that commit.
      
      Cc: stable@vger.kernel.org # 4.20.x
      Fixes: a408e4a8 ("ima: open a new file instance if no read permissions")
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      904de138
    • Vincent Chen's avatar
      riscv: set max_pfn to the PFN of the last page · 512f9837
      Vincent Chen authored
      commit c749bb2d upstream.
      
      The current max_pfn equals to zero. In this case, I found it caused users
      cannot get some page information through /proc such as kpagecount in v5.6
      kernel because of new sanity checks. The following message is displayed by
      stress-ng test suite with the command "stress-ng --verbose --physpage 1 -t
      1" on HiFive unleashed board.
      
       # stress-ng --verbose --physpage 1 -t 1
       stress-ng: debug: [109] 4 processors online, 4 processors configured
       stress-ng: info: [109] dispatching hogs: 1 physpage
       stress-ng: debug: [109] cache allocate: reducing cache level from L3 (too high) to L0
       stress-ng: debug: [109] get_cpu_cache: invalid cache_level: 0
       stress-ng: info: [109] cache allocate: using built-in defaults as no suitable cache found
       stress-ng: debug: [109] cache allocate: default cache size: 2048K
       stress-ng: debug: [109] starting stressors
       stress-ng: debug: [109] 1 stressor spawned
       stress-ng: debug: [110] stress-ng-physpage: started [110] (instance 0)
       stress-ng: error: [110] stress-ng-physpage: cannot read page count for address 0x3fd34de000 in /proc/kpagecount, errno=0 (Success)
       stress-ng: error: [110] stress-ng-physpage: cannot read page count for address 0x3fd32db078 in /proc/kpagecount, errno=0 (Success)
       ...
       stress-ng: error: [110] stress-ng-physpage: cannot read page count for address 0x3fd32db078 in /proc/kpagecount, errno=0 (Success)
       stress-ng: debug: [110] stress-ng-physpage: exited [110] (instance 0)
       stress-ng: debug: [109] process [110] terminated
       stress-ng: info: [109] successful run completed in 1.00s
       #
      
      After applying this patch, the kernel can pass the test.
      
       # stress-ng --verbose --physpage 1 -t 1
       stress-ng: debug: [104] 4 processors online, 4 processors configured stress-ng: info: [104] dispatching hogs: 1 physpage
       stress-ng: info: [104] cache allocate: using defaults, can't determine cache details from sysfs
       stress-ng: debug: [104] cache allocate: default cache size: 2048K
       stress-ng: debug: [104] starting stressors
       stress-ng: debug: [104] 1 stressor spawned
       stress-ng: debug: [105] stress-ng-physpage: started [105] (instance 0) stress-ng: debug: [105] stress-ng-physpage: exited [105] (instance 0) stress-ng: debug: [104] process [105] terminated
       stress-ng: info: [104] successful run completed in 1.01s
       #
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarVincent Chen <vincent.chen@sifive.com>
      Reviewed-by: default avatarAnup Patel <anup@brainfault.org>
      Reviewed-by: default avatarYash Shah <yash.shah@sifive.com>
      Tested-by: default avatarYash Shah <yash.shah@sifive.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      [Palmer: back-ported to 4.19]
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      512f9837
    • Miaohe Lin's avatar
      KVM: SVM: Fix potential memory leak in svm_cpu_init() · 00870815
      Miaohe Lin authored
      commit d80b64ff upstream.
      
      When kmalloc memory for sd->sev_vmcbs failed, we forget to free the page
      held by sd->save_area. Also get rid of the var r as '-ENOMEM' is actually
      the only possible outcome here.
      Reviewed-by: default avatarLiran Alon <liran.alon@oracle.com>
      Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00870815
    • Kevin Hao's avatar
      i2c: dev: Fix the race between the release of i2c_dev and cdev · a612c4ec
      Kevin Hao authored
      commit 1413ef63 upstream.
      
      The struct cdev is embedded in the struct i2c_dev. In the current code,
      we would free the i2c_dev struct directly in put_i2c_dev(), but the
      cdev is manged by a kobject, and the release of it is not predictable.
      So it is very possible that the i2c_dev is freed before the cdev is
      entirely released. We can easily get the following call trace with
      CONFIG_DEBUG_KOBJECT_RELEASE and CONFIG_DEBUG_OBJECTS_TIMERS enabled.
        ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x38
        WARNING: CPU: 19 PID: 1 at lib/debugobjects.c:325 debug_print_object+0xb0/0xf0
        Modules linked in:
        CPU: 19 PID: 1 Comm: swapper/0 Tainted: G        W         5.2.20-yocto-standard+ #120
        Hardware name: Marvell OcteonTX CN96XX board (DT)
        pstate: 80c00089 (Nzcv daIf +PAN +UAO)
        pc : debug_print_object+0xb0/0xf0
        lr : debug_print_object+0xb0/0xf0
        sp : ffff00001292f7d0
        x29: ffff00001292f7d0 x28: ffff800b82151788
        x27: 0000000000000001 x26: ffff800b892c0000
        x25: ffff0000124a2558 x24: 0000000000000000
        x23: ffff00001107a1d8 x22: ffff0000116b5088
        x21: ffff800bdc6afca8 x20: ffff000012471ae8
        x19: ffff00001168f2c8 x18: 0000000000000010
        x17: 00000000fd6f304b x16: 00000000ee79de43
        x15: ffff800bc0e80568 x14: 79616c6564203a74
        x13: 6e6968207473696c x12: 5f72656d6974203a
        x11: ffff0000113f0018 x10: 0000000000000000
        x9 : 000000000000001f x8 : 0000000000000000
        x7 : ffff0000101294cc x6 : 0000000000000000
        x5 : 0000000000000000 x4 : 0000000000000001
        x3 : 00000000ffffffff x2 : 0000000000000000
        x1 : 387fc15c8ec0f200 x0 : 0000000000000000
        Call trace:
         debug_print_object+0xb0/0xf0
         __debug_check_no_obj_freed+0x19c/0x228
         debug_check_no_obj_freed+0x1c/0x28
         kfree+0x250/0x440
         put_i2c_dev+0x68/0x78
         i2cdev_detach_adapter+0x60/0xc8
         i2cdev_notifier_call+0x3c/0x70
         notifier_call_chain+0x8c/0xe8
         blocking_notifier_call_chain+0x64/0x88
         device_del+0x74/0x380
         device_unregister+0x54/0x78
         i2c_del_adapter+0x278/0x2d0
         unittest_i2c_bus_remove+0x3c/0x80
         platform_drv_remove+0x30/0x50
         device_release_driver_internal+0xf4/0x1c0
         driver_detach+0x58/0xa0
         bus_remove_driver+0x84/0xd8
         driver_unregister+0x34/0x60
         platform_driver_unregister+0x20/0x30
         of_unittest_overlay+0x8d4/0xbe0
         of_unittest+0xae8/0xb3c
         do_one_initcall+0xac/0x450
         do_initcall_level+0x208/0x224
         kernel_init_freeable+0x2d8/0x36c
         kernel_init+0x18/0x108
         ret_from_fork+0x10/0x1c
        irq event stamp: 3934661
        hardirqs last  enabled at (3934661): [<ffff00001009fa04>] debug_exception_exit+0x4c/0x58
        hardirqs last disabled at (3934660): [<ffff00001009fb14>] debug_exception_enter+0xa4/0xe0
        softirqs last  enabled at (3934654): [<ffff000010081d94>] __do_softirq+0x46c/0x628
        softirqs last disabled at (3934649): [<ffff0000100b4a1c>] irq_exit+0x104/0x118
      
      This is a common issue when using cdev embedded in a struct.
      Fortunately, we already have a mechanism to solve this kind of issue.
      Please see commit 233ed09d ("chardev: add helper function to
      register char devs with a struct device") for more detail.
      
      In this patch, we choose to embed the struct device into the i2c_dev,
      and use the API provided by the commit 233ed09d to make sure that
      the release of i2c_dev and cdev are in sequence.
      Signed-off-by: default avatarKevin Hao <haokexin@gmail.com>
      Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
      Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a612c4ec
    • Arnd Bergmann's avatar
      ubsan: build ubsan.c more conservatively · f5a8138c
      Arnd Bergmann authored
      commit af700eae upstream.
      
      objtool points out several conditions that it does not like, depending
      on the combination with other configuration options and compiler
      variants:
      
      stack protector:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0xbf: call to __stack_chk_fail() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0xbe: call to __stack_chk_fail() with UACCESS enabled
      
      stackleak plugin:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x4a: call to stackleak_track_stack() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x4a: call to stackleak_track_stack() with UACCESS enabled
      
      kasan:
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x25: call to memcpy() with UACCESS enabled
        lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x25: call to memcpy() with UACCESS enabled
      
      The stackleak and kasan options just need to be disabled for this file
      as we do for other files already.  For the stack protector, we already
      attempt to disable it, but this fails on clang because the check is
      mixed with the gcc specific -fno-conserve-stack option.  According to
      Andrey Ryabinin, that option is not even needed, dropping it here fixes
      the stackprotector issue.
      
      Link: http://lkml.kernel.org/r/20190722125139.1335385-1-arnd@arndb.de
      Link: https://lore.kernel.org/lkml/20190617123109.667090-1-arnd@arndb.de/t/
      Link: https://lore.kernel.org/lkml/20190722091050.2188664-1-arnd@arndb.de/t/
      Fixes: d08965a2 ("x86/uaccess, ubsan: Fix UBSAN vs. SMAP")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.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>
      f5a8138c
    • Peter Zijlstra's avatar
      x86/uaccess, ubsan: Fix UBSAN vs. SMAP · ce1cc0d8
      Peter Zijlstra authored
      commit d08965a2 upstream.
      
      UBSAN can insert extra code in random locations; including AC=1
      sections. Typically this code is not safe and needs wrapping.
      
      So far, only __ubsan_handle_type_mismatch* have been observed in AC=1
      sections and therefore only those are annotated.
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      [stable backport: only take the lib/Makefile change to resolve gcc-10
       build issues]
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce1cc0d8
  2. 20 May, 2020 33 commits