1. 17 3月, 2018 1 次提交
  2. 17 2月, 2018 1 次提交
  3. 06 12月, 2017 1 次提交
  4. 25 7月, 2017 1 次提交
    • S
      x86/microcode/AMD: Free unneeded patch before exit from update_cache() · a99f0342
      Shu Wang 提交于
      verify_and_add_patch() allocates memory for a microcode patch and hands
      it down to be added to the cache of patches. However, if the cache
      already has the latest patch, the newly allocated one needs to be freed
      before returning. Do that.
      
      This issue has been found by kmemleak:
      
        unreferenced object 0xffff88010e780b40 (size 32):
          comm "bash", pid 860, jiffies 4294690939 (age 29.297s)
          backtrace:
             kmemleak_alloc
             kmem_cache_alloc_trace
             load_microcode_amd.isra.0
             request_microcode_amd
             reload_store
             dev_attr_store
             sysfs_kf_write
             kernfs_fop_write
             __vfs_write
             vfs_write
             SyS_write
             do_syscall_64
             return_from_SYSCALL_64
             0xffffffffffffffff
      
        (gdb) list *0xffffffff81050d60
        0xffffffff81050d60 is in load_microcode_amd
                      (arch/x86/kernel/cpu/microcode/amd.c:616).
      
      which is this:
      
      	patch = kzalloc(sizeof(*patch), GFP_KERNEL);
      -->	if (!patch) {
      		pr_err("Patch allocation failure.\n");
      		return -EINVAL;
      	}
      Signed-off-by: NShu Wang <shuwang@redhat.com>
      [ Rewrite commit message. ]
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: chuhu@redhat.com
      Cc: liwang@redhat.com
      Link: http://lkml.kernel.org/r/20170724101228.17326-2-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      a99f0342
  5. 26 6月, 2017 1 次提交
  6. 29 5月, 2017 1 次提交
    • B
      x86/microcode/AMD: Change load_microcode_amd()'s param to bool to fix preemptibility bug · dac6ca24
      Borislav Petkov 提交于
      With CONFIG_DEBUG_PREEMPT enabled, I get:
      
        BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
        caller is debug_smp_processor_id
        CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.12.0-rc2+ #2
        Call Trace:
         dump_stack
         check_preemption_disabled
         debug_smp_processor_id
         save_microcode_in_initrd_amd
         ? microcode_init
         save_microcode_in_initrd
         ...
      
      because, well, it says it above, we're using smp_processor_id() in
      preemptible code.
      
      But passing the CPU number is not really needed. It is only used to
      determine whether we're on the BSP, and, if so, to save the microcode
      patch for early loading.
      
       [ We don't absolutely need to do it on the BSP but we do that
         customarily there. ]
      
      Instead, convert that function parameter to a boolean which denotes
      whether the patch should be saved or not, thereby avoiding the use of
      smp_processor_id() in preemptible code.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/20170528200414.31305-1-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      dac6ca24
  7. 13 5月, 2017 1 次提交
  8. 18 3月, 2017 1 次提交
  9. 30 1月, 2017 1 次提交
    • B
      x86/microcode: Do not access the initrd after it has been freed · 24c25032
      Borislav Petkov 提交于
      When we look for microcode blobs, we first try builtin and if that
      doesn't succeed, we fallback to the initrd supplied to the kernel.
      
      However, at some point doing boot, that initrd gets jettisoned and we
      shouldn't access it anymore. But we do, as the below KASAN report shows.
      That's because find_microcode_in_initrd() doesn't check whether the
      initrd is still valid or not.
      
      So do that.
      
        ==================================================================
        BUG: KASAN: use-after-free in find_cpio_data
        Read of size 1 by task swapper/1/0
        page:ffffea0000db9d40 count:0 mapcount:0 mapping:          (null) index:0x1
        flags: 0x100000000000000()
        raw: 0100000000000000 0000000000000000 0000000000000001 00000000ffffffff
        raw: dead000000000100 dead000000000200 0000000000000000 0000000000000000
        page dumped because: kasan: bad access detected
        CPU: 1 PID: 0 Comm: swapper/1 Tainted: G        W       4.10.0-rc5-debug-00075-g2dbde22 #3
        Hardware name: Dell Inc. XPS 13 9360/0839Y6, BIOS 1.2.3 12/01/2016
        Call Trace:
         dump_stack
         ? _atomic_dec_and_lock
         ? __dump_page
         kasan_report_error
         ? pointer
         ? find_cpio_data
         __asan_report_load1_noabort
         ? find_cpio_data
         find_cpio_data
         ? vsprintf
         ? dump_stack
         ? get_ucode_user
         ? print_usage_bug
         find_microcode_in_initrd
         __load_ucode_intel
         ? collect_cpu_info_early
         ? debug_check_no_locks_freed
         load_ucode_intel_ap
         ? collect_cpu_info
         ? trace_hardirqs_on
         ? flat_send_IPI_mask_allbutself
         load_ucode_ap
         ? get_builtin_firmware
         ? flush_tlb_func
         ? do_raw_spin_trylock
         ? cpumask_weight
         cpu_init
         ? trace_hardirqs_off
         ? play_dead_common
         ? native_play_dead
         ? hlt_play_dead
         ? syscall_init
         ? arch_cpu_idle_dead
         ? do_idle
         start_secondary
         start_cpu
        Memory state around the buggy address:
         ffff880036e74f00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff880036e74f80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        >ffff880036e75000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                           ^
         ffff880036e75080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
         ffff880036e75100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        ==================================================================
      Reported-by: NAndrey Ryabinin <aryabinin@virtuozzo.com>
      Tested-by: NAndrey Ryabinin <aryabinin@virtuozzo.com>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/20170126165833.evjemhbqzaepirxo@pd.tnicSigned-off-by: NIngo Molnar <mingo@kernel.org>
      24c25032
  10. 23 1月, 2017 12 次提交
  11. 19 12月, 2016 3 次提交
  12. 28 10月, 2016 1 次提交
    • B
      x86/microcode/AMD: Fix more fallout from CONFIG_RANDOMIZE_MEMORY=y · 1c27f646
      Borislav Petkov 提交于
      We needed the physical address of the container in order to compute the
      offset within the relocated ramdisk. And we did this by doing __pa() on
      the virtual address.
      
      However, __pa() does checks whether the physical address is within
      PAGE_OFFSET and __START_KERNEL_map - see __phys_addr() - which fail
      if we have CONFIG_RANDOMIZE_MEMORY enabled: we feed a virtual address
      which *doesn't* have the randomization offset into a function which uses
      PAGE_OFFSET which *does* have that offset.
      
      This makes this check fire:
      
      	VIRTUAL_BUG_ON((x > y) || !phys_addr_valid(x));
      			^^^^^^
      
      due to the randomization offset.
      
      The fix is as simple as using __pa_nodebug() because we do that
      randomization offset accounting later in that function ourselves.
      Reported-by: NBob Peterson <rpeterso@redhat.com>
      Tested-by: NBob Peterson <rpeterso@redhat.com>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andreas Gruenbacher <agruenba@redhat.com>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Whitehouse <swhiteho@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-mm <linux-mm@kvack.org>
      Cc: stable@vger.kernel.org # 4.9
      Link: http://lkml.kernel.org/r/20161027123623.j2jri5bandimboff@pd.tnicSigned-off-by: NIngo Molnar <mingo@kernel.org>
      1c27f646
  13. 25 10月, 2016 6 次提交
    • B
      x86/microcode: Bump driver version, update copyrights · 14cfbe55
      Borislav Petkov 提交于
      Let's increment that number finally: it is long overdue.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-13-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      14cfbe55
    • B
      x86/microcode: Rework microcode loading · 06b8534c
      Borislav Petkov 提交于
      Yeah, I know, I know, this is a huuge patch and reviewing it is hard.
      
      Sorry but this is the only way I could think of in which I can rewrite
      the microcode patches loading procedure without breaking (knowingly) the
      driver.
      
      So maybe this patch is easier to review if one looks at the files after
      the patch has been applied instead at the diff. Because then it becomes
      pretty obvious:
      
      * The BSP-loading path - load_ucode_bsp() is working independently from
        the AP path now and it doesn't save any pointers or patches anymore -
        it solely parses the builtin or initrd microcode and applies the patch.
        That's it.
      
      This fixes the CONFIG_RANDOMIZE_MEMORY offset fun more solidly.
      
      * The AP-loading path - load_ucode_ap() then goes and scans
        builtin/initrd *again* for the microcode patches but it caches them this
        time so that we don't have to do that scan on each AP but only once.
      
      This simplifies the code considerably.
      
      Then, when we save the microcode from the initrd/builtin, we go and
      add the relevant patches to our own cache. The AMD side did do that
      and now the Intel side does it too. So no more pointer copying and
      blabla, we save the microcode patches ourselves and are independent from
      initrd/builtin.
      
      This whole conversion gives us other benefits like unifying the
      initrd parsing into a single function: find_microcode_in_initrd() is
      used by both.
      
      The diffstat speaks for itself: 456 insertions(+), 695 deletions(-)
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-12-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      06b8534c
    • B
      x86/microcode/amd: Move private inlines to .c and mark local functions static · 76bd11c2
      Borislav Petkov 提交于
      Make them all static as they're used in a single file now.
      
      No functionality change.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-10-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      76bd11c2
    • B
      x86/microcode/amd: Hand down the CPU family · b3763a67
      Borislav Petkov 提交于
      Will be needed in a following patch.
      
      No functionality change.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-7-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      b3763a67
    • B
      x86/microcode: Export the microcode cache linked list · 058dc498
      Borislav Petkov 提交于
      It will be used by both drivers so move it to core.c.
      
      No functionality change.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-6-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      058dc498
    • B
      x86/microcode: Run the AP-loading routine only on the application processors · 777284b6
      Borislav Petkov 提交于
      cpu_init() is run also on the BSP (in addition to the APs):
      
       x86_64_start_kernel
       |-> x86_64_start_reservations
       |-> start_kernel
       |-> trap_init
       |-> cpu_init
       |-> load_ucode_ap
       ...
      
      but we run the AP (Application Processors) microcode loading routine
      there too even though we have a BSP-specific routine for that:
      load_ucode_bsp().
      
      Which is unnecessary. So let's limit the AP microcode loading routine to
      the APs only.
      
      Remove a useless comment while at it.
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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>
      Link: http://lkml.kernel.org/r/20161025095522.11964-2-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      777284b6
  14. 05 9月, 2016 1 次提交
  15. 18 8月, 2016 1 次提交
  16. 08 6月, 2016 3 次提交
  17. 17 2月, 2016 1 次提交
  18. 09 2月, 2016 3 次提交