An error occurred fetching the project authors.
  1. 05 Jun, 2023 1 commit
  2. 31 Jan, 2023 1 commit
  3. 05 Jan, 2023 1 commit
    • Borislav Petkov (AMD)'s avatar
      x86/alternatives: Add alt_instr.flags · 5d1dd961
      Borislav Petkov (AMD) authored
      Add a struct alt_instr.flags field which will contain different flags
      controlling alternatives patching behavior.
      
      The initial idea was to be able to specify it as a separate macro
      parameter but that would mean touching all possible invocations of the
      alternatives macros and thus a lot of churn.
      
      What is more, as PeterZ suggested, being able to say ALT_NOT(feature) is
      very readable and explains exactly what is meant.
      
      So make the feature field a u32 where the patching flags are the upper
      u16 part of the dword quantity while the lower u16 word is the feature.
      
      The highest feature number currently is 0x26a (i.e., word 19) so there
      is plenty of space. If that becomes insufficient, the field can be
      extended to u64 which will then make struct alt_instr of the nice size
      of 16 bytes (14 bytes currently).
      
      There should be no functional changes resulting from this.
      Suggested-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
      Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/Y6RCoJEtxxZWwotd@zn.tnic
      5d1dd961
  4. 15 Dec, 2022 1 commit
  5. 02 Dec, 2022 1 commit
  6. 08 Nov, 2022 1 commit
  7. 01 Nov, 2022 3 commits
  8. 25 Oct, 2022 1 commit
  9. 17 Oct, 2022 4 commits
  10. 27 Sep, 2022 1 commit
    • Nadav Amit's avatar
      x86/alternative: Fix race in try_get_desc() · efd608fa
      Nadav Amit authored
      I encountered some occasional crashes of poke_int3_handler() when
      kprobes are set, while accessing desc->vec.
      
      The text poke mechanism claims to have an RCU-like behavior, but it
      does not appear that there is any quiescent state to ensure that
      nobody holds reference to desc. As a result, the following race
      appears to be possible, which can lead to memory corruption.
      
        CPU0					CPU1
        ----					----
        text_poke_bp_batch()
        -> smp_store_release(&bp_desc, &desc)
      
        [ notice that desc is on
          the stack			]
      
      					poke_int3_handler()
      
      					[ int3 might be kprobe's
      					  so sync events are do not
      					  help ]
      
      					-> try_get_desc(descp=&bp_desc)
      					   desc = __READ_ONCE(bp_desc)
      
      					   if (!desc) [false, success]
        WRITE_ONCE(bp_desc, NULL);
        atomic_dec_and_test(&desc.refs)
      
        [ success, desc space on the stack
          is being reused and might have
          non-zero value. ]
      					arch_atomic_inc_not_zero(&desc->refs)
      
      					[ might succeed since desc points to
      					  stack memory that was freed and might
      					  be reused. ]
      
      Fix this issue with small backportable patch. Instead of trying to
      make RCU-like behavior for bp_desc, just eliminate the unnecessary
      level of indirection of bp_desc, and hold the whole descriptor as a
      global.  Anyhow, there is only a single descriptor at any given
      moment.
      
      Fixes: 1f676247 ("x86/alternatives: Implement a better poke_int3_handler() completion scheme")
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: stable@kernel.org
      Link: https://lkml.kernel.org/r/20220920224743.3089-1-namit@vmware.com
      efd608fa
  11. 15 Sep, 2022 1 commit
  12. 20 Jul, 2022 1 commit
  13. 29 Jun, 2022 1 commit
  14. 27 Jun, 2022 2 commits
    • Peter Zijlstra's avatar
      x86,static_call: Use alternative RET encoding · ee88d363
      Peter Zijlstra authored
      In addition to teaching static_call about the new way to spell 'RET',
      there is an added complication in that static_call() is allowed to
      rewrite text before it is known which particular spelling is required.
      
      In order to deal with this; have a static_call specific fixup in the
      apply_return() 'alternative' patching routine that will rewrite the
      static_call trampoline to match the definite sequence.
      
      This in turn creates the problem of uniquely identifying static call
      trampolines. Currently trampolines are 8 bytes, the first 5 being the
      jmp.d32/ret sequence and the final 3 a byte sequence that spells out
      'SCT'.
      
      This sequence is used in __static_call_validate() to ensure it is
      patching a trampoline and not a random other jmp.d32. That is,
      false-positives shouldn't be plenty, but aren't a big concern.
      
      OTOH the new __static_call_fixup() must not have false-positives, and
      'SCT' decodes to the somewhat weird but semi plausible sequence:
      
        push %rbx
        rex.XB push %r12
      
      Additionally, there are SLS concerns with immediate jumps. Combined it
      seems like a good moment to change the signature to a single 3 byte
      trap instruction that is unique to this usage and will not ever get
      generated by accident.
      
      As such, change the signature to: '0x0f, 0xb9, 0xcc', which decodes
      to:
      
        ud1 %esp, %ecx
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      ee88d363
    • Peter Zijlstra's avatar
      x86: Undo return-thunk damage · 15e67227
      Peter Zijlstra authored
      Introduce X86_FEATURE_RETHUNK for those afflicted with needing this.
      
        [ bp: Do only INT3 padding - simpler. ]
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      15e67227
  15. 23 May, 2022 1 commit
  16. 22 Apr, 2022 1 commit
  17. 15 Mar, 2022 3 commits
  18. 21 Feb, 2022 1 commit
  19. 08 Feb, 2022 1 commit
  20. 09 Dec, 2021 1 commit
  21. 08 Dec, 2021 1 commit
  22. 28 Oct, 2021 4 commits
  23. 03 Jun, 2021 2 commits
  24. 12 May, 2021 1 commit
  25. 02 Apr, 2021 1 commit
    • Peter Zijlstra's avatar
      x86/alternatives: Optimize optimize_nops() · 23c1ad53
      Peter Zijlstra authored
      Currently, optimize_nops() scans to see if the alternative starts with
      NOPs. However, the emit pattern is:
      
        141:	\oldinstr
        142:	.skip (len-(142b-141b)), 0x90
      
      That is, when 'oldinstr' is short, the tail is padded with NOPs. This case
      never gets optimized.
      
      Rewrite optimize_nops() to replace any trailing string of NOPs inside
      the alternative to larger NOPs. Also run it irrespective of patching,
      replacing NOPs in both the original and replaced code.
      
      A direct consequence is that 'padlen' becomes superfluous, so remove it.
      
       [ bp:
         - Adjust commit message
         - remove a stale comment about needing to pad
         - add a comment in optimize_nops()
         - exit early if the NOP verif. loop catches a mismatch - function
           should not not add NOPs in that case
         - fix the "optimized NOPs" offsets output ]
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Link: https://lkml.kernel.org/r/20210326151259.442992235@infradead.org
      23c1ad53
  26. 31 Mar, 2021 1 commit
  27. 15 Mar, 2021 2 commits
    • Peter Zijlstra's avatar
      x86: Remove dynamic NOP selection · a89dfde3
      Peter Zijlstra authored
      This ensures that a NOP is a NOP and not a random other instruction that
      is also a NOP. It allows simplification of dynamic code patching that
      wants to verify existing code before writing new instructions (ftrace,
      jump_label, static_call, etc..).
      
      Differentiating on NOPs is not a feature.
      
      This pessimises 32bit (DONTCARE) and 32bit on 64bit CPUs (CARELESS).
      32bit is not a performance target.
      
      Everything x86_64 since AMD K10 (2007) and Intel IvyBridge (2012) is
      fine with using NOPL (as opposed to prefix NOP). And per FEATURE_NOPL
      being required for x86_64, all x86_64 CPUs can use NOPL. So stop
      caring about NOPs, simplify things and get on with life.
      
      [ The problem seems to be that some uarchs can only decode NOPL on a
      single front-end port while others have severe decode penalties for
      excessive prefixes. All modern uarchs can handle both, except Atom,
      which has prefix penalties. ]
      
      [ Also, much doubt you can actually measure any of this on normal
      workloads. ]
      
      After this, FEATURE_NOPL is unused except for required-features for
      x86_64. FEATURE_K8 is only used for PTI.
      
       [ bp: Kernel build measurements showed ~0.3s slowdown on Sandybridge
         which is hardly a slowdown. Get rid of X86_FEATURE_K7, while at it. ]
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Acked-by: Alexei Starovoitov <alexei.starovoitov@gmail.com> # bpf
      Acked-by: default avatarLinus Torvalds <torvalds@linuxfoundation.org>
      Link: https://lkml.kernel.org/r/20210312115749.065275711@infradead.org
      a89dfde3
    • Borislav Petkov's avatar
      x86/alternative: Use insn_decode() · 63c66cde
      Borislav Petkov authored
      No functional changes, just simplification.
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Link: https://lkml.kernel.org/r/20210304174237.31945-10-bp@alien8.de
      63c66cde