25 Mar, 2020

1 commit

  • The new macro set has a consistent namespace and uses C99 initializers
    instead of the grufty C89 ones.

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Borislav Petkov
    Reviewed-by: Greg Kroah-Hartman
    Link: https://lkml.kernel.org/r/20200320131510.700250889@linutronix.de

    Thomas Gleixner
     

11 Dec, 2019

1 commit


31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 3029 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070032.746973796@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

25 Apr, 2019

1 commit

  • The flags field in 'struct shash_desc' never actually does anything.
    The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP.
    However, no shash algorithm ever sleeps, making this flag a no-op.

    With this being the case, inevitably some users who can't sleep wrongly
    pass MAY_SLEEP. These would all need to be fixed if any shash algorithm
    actually started sleeping. For example, the shash_ahash_*() functions,
    which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP
    from the ahash API to the shash API. However, the shash functions are
    called under kmap_atomic(), so actually they're assumed to never sleep.

    Even if it turns out that some users do need preemption points while
    hashing large buffers, we could easily provide a helper function
    crypto_shash_update_large() which divides the data into smaller chunks
    and calls crypto_shash_update() and cond_resched() for each chunk. It's
    not necessary to have a flag in 'struct shash_desc', nor is it necessary
    to make individual shash algorithms aware of this at all.

    Therefore, remove shash_desc::flags, and document that the
    crypto_shash_*() functions can be called from any context.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

09 Jul, 2018

1 commit

  • Many shash algorithms set .cra_flags = CRYPTO_ALG_TYPE_SHASH. But this
    is redundant with the C structure type ('struct shash_alg'), and
    crypto_register_shash() already sets the type flag automatically,
    clearing any type flag that was already there. Apparently the useless
    assignment has just been copy+pasted around.

    So, remove the useless assignment from all the shash algorithms.

    This patch shouldn't change any actual behavior.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

22 Sep, 2017

1 commit


01 Nov, 2016

1 commit

  • Now that lazy FPU is gone, we don't use CR0.TS (except possibly in
    KVM guest mode). Remove irq_ts_save(), irq_ts_restore(), and all of
    their callers.

    Signed-off-by: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Dave Hansen
    Cc: Denys Vlasenko
    Cc: Fenghua Yu
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Oleg Nesterov
    Cc: Paolo Bonzini
    Cc: Peter Zijlstra
    Cc: Quentin Casasnovas
    Cc: Rik van Riel
    Cc: Rusty Russell
    Cc: Thomas Gleixner
    Cc: kvm list
    Link: http://lkml.kernel.org/r/70b9b9e7ba70659bedcb08aba63d0f9214f338f2.1477951965.git.luto@kernel.org
    Signed-off-by: Ingo Molnar

    Andy Lutomirski
     

19 Dec, 2015

1 commit

  • Those are stupid and code should use static_cpu_has_safe() or
    boot_cpu_has() instead. Kill the least used and unused ones.

    The remaining ones need more careful inspection before a conversion can
    happen. On the TODO.

    Signed-off-by: Borislav Petkov
    Link: http://lkml.kernel.org/r/1449481182-27541-4-git-send-email-bp@alien8.de
    Cc: David Sterba
    Cc: Herbert Xu
    Cc: Peter Zijlstra
    Cc: Matt Mackall
    Cc: Chris Mason
    Cc: Josef Bacik
    Signed-off-by: Thomas Gleixner

    Borislav Petkov
     

19 May, 2015

1 commit

  • We already have fpu/types.h, move i387.h to fpu/api.h.

    The file name has become a misnomer anyway: it offers generic FPU APIs,
    but is not limited to i387 functionality.

    Reviewed-by: Borislav Petkov
    Cc: Andy Lutomirski
    Cc: Dave Hansen
    Cc: Fenghua Yu
    Cc: H. Peter Anvin
    Cc: Linus Torvalds
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

24 Nov, 2014

1 commit


22 May, 2014

1 commit


27 Jan, 2012

1 commit

  • Add support for auto-loading of crypto drivers based on cpuid features.
    This enables auto-loading of the VIA and Intel specific drivers
    for AES, hashing and CRCs.

    Requires the earlier infrastructure patch to add x86 modinfo.
    I kept it all in a single patch for now.

    I dropped the printks when the driver cpuid doesn't match (imho
    drivers never should print anything in such a case)

    One drawback is that udev doesn't know if the drivers are used or not,
    so they will be unconditionally loaded at boot up. That's better
    than not loading them at all, like it often happens.

    Cc: Dave Jones
    Cc: Kay Sievers
    Cc: Jen Axboe
    Cc: Herbert Xu
    Cc: Huang Ying
    Signed-off-by: Andi Kleen
    Signed-off-by: Thomas Renninger
    Acked-by: H. Peter Anvin
    Signed-off-by: Greg Kroah-Hartman

    Andi Kleen
     

27 Mar, 2011

1 commit

  • Add new SHA-1/256 module that never needs any fallback and just calls the
    PadLock hardware instruction supported from VIA Nano processors to implement
    the "update" and "final" function.

    They are respectively named "sha1_alg_nano" and "sha256_alg_nano", and will
    be used on any VIA Nano processor or the later ones. On VIA C7 CPU, the
    "sha1_alg" and "sha256_alg" modules will still be used as before.

    Signed-off-by: Brilly Wu
    Signed-off-by: Kary Jin
    Signed-off-by: Herbert Xu

    Brilly Wu
     

07 Jan, 2011

1 commit


02 Feb, 2010

1 commit

  • As the padlock driver for SHA uses a software fallback to perform
    partial hashing, it must implement custom import/export functions.
    Otherwise hmac which depends on import/export for prehashing will
    not work with padlock-sha.

    Reported-by: Wolfgang Walter
    Signed-off-by: Herbert Xu

    Herbert Xu
     

22 Sep, 2009

1 commit

  • The PadLock hardware requires the output buffer for SHA to be
    128-bit aligned. We currentply place the buffer on the stack,
    and ask gcc to align it to 128 bits. That doesn't work on i386
    because the kernel stack is only aligned to 32 bits. This patch
    changes the code to align the buffer by hand so that the hardware
    doesn't fault on unaligned buffers.

    Reported-by: Séguier Régis
    Tested-by: Séguier Régis
    Signed-off-by: Herbert Xu

    Herbert Xu
     

16 Jul, 2009

1 commit


15 Jul, 2009

1 commit

  • The previous change to allow hashing from states other than the
    initial broke compilation on i386 because the inline assembly
    tried to squeeze a u64 into a 32-bit register. As we've already
    checked for 32-bit overflows we can simply truncate it to u32,
    or unsigned long so that we don't truncate at all on x86-64.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

14 Jul, 2009

1 commit

  • This patch converts the padlock-sha implementation to shash.
    In doing so the existing mechanism of storing the data until
    final is no longer viable as we do not have a way of allocating
    data in crypto_shash_init and then reliably freeing it.

    This is just as well because a better way of handling the problem
    is to hash everything but the last chunk using normal sha code
    and then provide the intermediate result to the padlock device.

    This is good enough because the primary application of padlock-sha
    is IPsec and there the data is laid out in the form of an hmac
    header followed by the rest of the packet. In essence we can
    provide all the data to the padlock as the hmac header only needs
    to be hashed once.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

11 Jul, 2009

1 commit


26 Feb, 2009

1 commit

  • With the mandatory algorithm testing at registration, we have
    now created a deadlock with algorithms requiring fallbacks.
    This can happen if the module containing the algorithm requiring
    fallback is loaded first, without the fallback module being loaded
    first. The system will then try to test the new algorithm, find
    that it needs to load a fallback, and then try to load that.

    As both algorithms share the same module alias, it can attempt
    to load the original algorithm again and block indefinitely.

    As algorithms requiring fallbacks are a special case, we can fix
    this by giving them a different module alias than the rest. Then
    it's just a matter of using the right aliases according to what
    algorithms we're trying to find.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

13 Aug, 2008

1 commit

  • Wolfgang Walter reported this oops on his via C3 using padlock for
    AES-encryption:

    ##################################################################

    BUG: unable to handle kernel NULL pointer dereference at 000001f0
    IP: [] __switch_to+0x30/0x117
    *pde = 00000000
    Oops: 0002 [#1] PREEMPT
    Modules linked in:

    Pid: 2071, comm: sleep Not tainted (2.6.26 #11)
    EIP: 0060:[] EFLAGS: 00010002 CPU: 0
    EIP is at __switch_to+0x30/0x117
    EAX: 00000000 EBX: c0493300 ECX: dc48dd00 EDX: c0493300
    ESI: dc48dd00 EDI: c0493530 EBP: c04cff8c ESP: c04cff7c
    DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0068
    Process sleep (pid: 2071, ti=c04ce000 task=dc48dd00 task.ti=d2fe6000)
    Stack: dc48df30 c0493300 00000000 00000000 d2fe7f44 c03b5b43 c04cffc8 00000046
    c0131856 0000005a dc472d3c c0493300 c0493470 d983ae00 00002696 00000000
    c0239f54 00000000 c04c4000 c04cffd8 c01025fe c04f3740 00049800 c04cffe0
    Call Trace:
    [] ? schedule+0x285/0x2ff
    [] ? pm_qos_requirement+0x3c/0x53
    [] ? acpi_processor_idle+0x0/0x434
    [] ? cpu_idle+0x73/0x7f
    [] ? rest_init+0x61/0x63
    =======================

    Wolfgang also found out that adding kernel_fpu_begin() and kernel_fpu_end()
    around the padlock instructions fix the oops.

    Suresh wrote:

    These padlock instructions though don't use/touch SSE registers, but it behaves
    similar to other SSE instructions. For example, it might cause DNA faults
    when cr0.ts is set. While this is a spurious DNA trap, it might cause
    oops with the recent fpu code changes.

    This is the code sequence that is probably causing this problem:

    a) new app is getting exec'd and it is somewhere in between
    start_thread() and flush_old_exec() in the load_xyz_binary()

    b) At pont "a", task's fpu state (like TS_USEDFPU, used_math() etc) is
    cleared.

    c) Now we get an interrupt/softirq which starts using these encrypt/decrypt
    routines in the network stack. This generates a math fault (as
    cr0.ts is '1') which sets TS_USEDFPU and restores the math that is
    in the task's xstate.

    d) Return to exec code path, which does start_thread() which does
    free_thread_xstate() and sets xstate pointer to NULL while
    the TS_USEDFPU is still set.

    e) At the next context switch from the new exec'd task to another task,
    we have a scenarios where TS_USEDFPU is set but xstate pointer is null.
    This can cause an oops during unlazy_fpu() in __switch_to()

    Now:

    1) This should happen with or with out pre-emption. Viro also encountered
    similar problem with out CONFIG_PREEMPT.

    2) kernel_fpu_begin() and kernel_fpu_end() will fix this problem, because
    kernel_fpu_begin() will manually do a clts() and won't run in to the
    situation of setting TS_USEDFPU in step "c" above.

    3) This was working before the fpu changes, because its a spurious
    math fault which doesn't corrupt any fpu/sse registers and the task's
    math state was always in an allocated state.

    With out the recent lazy fpu allocation changes, while we don't see oops,
    there is a possible race still present in older kernels(for example,
    while kernel is using kernel_fpu_begin() in some optimized clear/copy
    page and an interrupt/softirq happens which uses these padlock
    instructions generating DNA fault).

    This is the failing scenario that existed even before the lazy fpu allocation
    changes:

    0. CPU's TS flag is set

    1. kernel using FPU in some optimized copy routine and while doing
    kernel_fpu_begin() takes an interrupt just before doing clts()

    2. Takes an interrupt and ipsec uses padlock instruction. And we
    take a DNA fault as TS flag is still set.

    3. We handle the DNA fault and set TS_USEDFPU and clear cr0.ts

    4. We complete the padlock routine

    5. Go back to step-1, which resumes clts() in kernel_fpu_begin(), finishes
    the optimized copy routine and does kernel_fpu_end(). At this point,
    we have cr0.ts again set to '1' but the task's TS_USEFPU is stilll
    set and not cleared.

    6. Now kernel resumes its user operation. And at the next context
    switch, kernel sees it has do a FP save as TS_USEDFPU is still set
    and then will do a unlazy_fpu() in __switch_to(). unlazy_fpu()
    will take a DNA fault, as cr0.ts is '1' and now, because we are
    in __switch_to(), math_state_restore() will get confused and will
    restore the next task's FP state and will save it in prev tasks's FP state.
    Remember, in __switch_to() we are already on the stack of the next task
    but take a DNA fault for the prev task.

    This causes the fpu leakage.

    Fix the padlock instruction usage by calling them inside the
    context of new routines irq_ts_save/restore(), which clear/restore cr0.ts
    manually in the interrupt context. This will not generate spurious DNA
    in the context of the interrupt which will fix the oops encountered and
    the possible FPU leakage issue.

    Reported-and-bisected-by: Wolfgang Walter
    Signed-off-by: Suresh Siddha
    Signed-off-by: Herbert Xu

    Suresh Siddha
     

10 Jul, 2008

1 commit


27 Oct, 2007

1 commit


11 Oct, 2007

2 commits

  • There are currently several SHA implementations that all define their own
    initialization vectors and size values. Since this values are idential
    move them to a header file under include/crypto.

    Signed-off-by: Jan Glauber
    Signed-off-by: Herbert Xu

    Jan Glauber
     
  • Loading the crypto algorithm by the alias instead of by module directly
    has the advantage that all possible implementations of this algorithm
    are loaded automatically and the crypto API can choose the best one
    depending on its priority.

    Additionally it ensures that the generic implementation as well as the
    HW driver (if available) is loaded in case the HW driver needs the
    generic version as fallback in corner cases.

    Also remove the probe for sha1 in padlock's init code.

    Quote from Herbert:
    The probe is actually pointless since we can always probe when
    the algorithm is actually used which does not lead to dead-locks
    like this.

    Signed-off-by: Sebastian Siewior
    Signed-off-by: Herbert Xu

    Sebastian Siewior
     

21 Sep, 2006

4 commits