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