You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As noted in #106, libssh2 uses memset to zero memory. Compiler are free to (and happily do) optimize those calls away. In order to be sure that the memory is actually zero'd, memset_s/SecureZeroMemory (if available), or perhaps a simple loop with store through a volatile pointer should be used.
I've added _libssh2_explicit_zero() to do just this included in pull request #248. It uses SecureZeroMemory or memset_s followed by the volatile pointer if neither is available.
I should note, existing code needs to be updated to use the new API once the pull request is approved. Edit: scrubbed code for memset using 0, made required changes.
@willco007 Was the existing code in the WinCNG backend updated? I am getting the unsupported warning with WinCNG, even though it did implement this functionality first.
And I am also getting this error while building with classic MinGW:
pem.c: In function '_libssh2_openssh_pem_parse_data':
pem.c:614:25: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
out_buf->data = malloc(decrypted.len);
^~~~~~
pem.c:614:25: warning: incompatible implicit declaration of built-in function 'malloc'
pem.c:614:25: note: include '<stdlib.h>' or provide a declaration of 'malloc'
@mback2k I've updated the call in pem.c to use LIBSSH2_CALLOC() instead of malloc directly which should fix your warning there.
The new zeroing memory is done in common code such has kex.c and pem.c in locations where libssh2 was using memset 0 which is a no-op on some platforms. I did not change the way specific backends work. My suggestion would be to soft deprecate the clear memory build flag and backends always zero sensitive memory, if needed, using the new API _libssh2_explicit_zero(). Hope that helps clarify things a bit.
@willco007 Thanks for your fix and explanation. Unfortunately SecureZeroMemory is not declared in legacy MinGW, so you would either have to check for it being there and disable the feature if not or test if adding a fallback declaration in the header could help, see here.
Activity
mback2k commentedon Aug 14, 2016
The WinCNG backend already provides a method to securely free memory:
https://github.com/libssh2/libssh2/blob/master/src/wincng.c#L311
Maybe such a method could be made available by all crypto backends for general use across libssh2?
changed _libssh2_bzero to _libssh2_explicit_zero libssh2#120
willco007 commentedon Apr 27, 2018
I've added _libssh2_explicit_zero() to do just this included in pull request #248. It uses SecureZeroMemory or memset_s followed by the volatile pointer if neither is available.
willco007 commentedon Apr 27, 2018
I should note, existing code needs to be updated to use the new API once the pull request is approved. Edit: scrubbed code for memset using 0, made required changes.
Cleaned up memory management libssh2#120
ED25519 Key Support #39 (#248)
mback2k commentedon Aug 26, 2018
@willco007 Was the existing code in the WinCNG backend updated? I am getting the unsupported warning with WinCNG, even though it did implement this functionality first.
And I am also getting this error while building with classic MinGW:
Error source: https://libssh2build.uxnr.de/admin/builders/libssh2_wincng_mingw_x86/builds/1715/steps/compile/logs/stdio
willco007 commentedon Aug 27, 2018
@mback2k I've updated the call in pem.c to use LIBSSH2_CALLOC() instead of malloc directly which should fix your warning there.
The new zeroing memory is done in common code such has kex.c and pem.c in locations where libssh2 was using memset 0 which is a no-op on some platforms. I did not change the way specific backends work. My suggestion would be to soft deprecate the clear memory build flag and backends always zero sensitive memory, if needed, using the new API _libssh2_explicit_zero(). Hope that helps clarify things a bit.
mback2k commentedon Aug 31, 2018
@willco007 Thanks for your fix and explanation. Unfortunately SecureZeroMemory is not declared in legacy MinGW, so you would either have to check for it being there and disable the feature if not or test if adding a fallback declaration in the header could help, see here.
willco007 commentedon Aug 31, 2018
I am testing for it in _libssh2_explicit_zero(), using the define HAVE_DECL_SECUREZEROMEMORY; assuming it works correctly.
mback2k commentedon Sep 2, 2018
Thanks for the information, I pushed some commits to fix compatibility with legacy MinGW / Windows XP.
ED25519 Key Support libssh2#39 (libssh2#248)
ED25519 Key Support libssh2#39 (libssh2#248)