• mancha security's avatar
    lib: memzero_explicit: use barrier instead of OPTIMIZER_HIDE_VAR · e60e4dc0
    mancha security authored
    commit 0b053c95 upstream.
    
    OPTIMIZER_HIDE_VAR(), as defined when using gcc, is insufficient to
    ensure protection from dead store optimization.
    
    For the random driver and crypto drivers, calls are emitted ...
    
      $ gdb vmlinux
      (gdb) disassemble memzero_explicit
      Dump of assembler code for function memzero_explicit:
        0xffffffff813a18b0 <+0>:	push   %rbp
        0xffffffff813a18b1 <+1>:	mov    %rsi,%rdx
        0xffffffff813a18b4 <+4>:	xor    %esi,%esi
        0xffffffff813a18b6 <+6>:	mov    %rsp,%rbp
        0xffffffff813a18b9 <+9>:	callq  0xffffffff813a7120 <memset>
        0xffffffff813a18be <+14>:	pop    %rbp
        0xffffffff813a18bf <+15>:	retq
      End of assembler dump.
    
      (gdb) disassemble extract_entropy
      [...]
        0xffffffff814a5009 <+313>:	mov    %r12,%rdi
        0xffffffff814a500c <+316>:	mov    $0xa,%esi
        0xffffffff814a5011 <+321>:	callq  0xffffffff813a18b0 <memzero_explicit>
        0xffffffff814a5016 <+326>:	mov    -0x48...
    e60e4dc0