patch-src_secmem_c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. $OpenBSD: patch-src_secmem_c,v 1.3 2016/12/10 07:24:45 ajacoutot Exp $
  2. Patch copied from gnupg/patches/patch-util_secmem_c
  3. --- src/secmem.c.orig Fri Dec 9 15:25:37 2016
  4. +++ src/secmem.c Sat Dec 10 08:20:22 2016
  5. @@ -36,6 +36,9 @@
  6. #include <sys/capability.h>
  7. #endif
  8. #endif
  9. +#include <sys/param.h>
  10. +#include <sys/sysctl.h>
  11. +#include <uvm/uvm_swap_encrypt.h>
  12. #include "g10lib.h"
  13. #include "secmem.h"
  14. @@ -247,8 +250,24 @@ mb_get_new (pooldesc_t *pool, memblock_t *block, size_
  15. static void
  16. print_warn (void)
  17. {
  18. - if (!no_warning)
  19. - log_info (_("Warning: using insecure memory!\n"));
  20. + int mib[3], swapencrypt = 0;
  21. + size_t len;
  22. +
  23. + mib[0] = CTL_VM;
  24. + mib[1] = VM_SWAPENCRYPT;
  25. + mib[2] = SWPENC_ENABLE;
  26. +
  27. + len = sizeof(swapencrypt);
  28. +
  29. + if (sysctl(mib, 3, &swapencrypt, &len, NULL, 0) == -1)
  30. + log_info("WARNING: Can't receive vm.swapencrypt.enable sysctl value\n");
  31. +
  32. + if (!no_warning && !swapencrypt)
  33. + {
  34. + log_info("WARNING: Using insecure memory!\n");
  35. + log_info("Please enable swap encryption via"
  36. + " 'sysctl vm.swapencrypt.enable=1'.\n");
  37. + }
  38. }