(possible) bug in the use of VirtualLock in secure_allocator #1462

issue xanatos opened this issue on June 14, 2012
  1. xanatos commented at 1:57 PM on June 14, 2012: none

    From http://msdn.microsoft.com/en-us/library/windows/desktop/aa366895(v=vs.85).aspx

    There is no lock count for virtual pages, so multiple calls to the VirtualUnlock function are never required to unlock a region of pages.

    And remembering that a page in Windows is 4kb, and that the keys we use are much much smaller, we get that if you allocate two private keys that get to be in the same memory page and then one of the two is freed, it will probably VirtualUnlock the other key. Woops.

  2. laanwj commented at 2:15 PM on June 14, 2012: member

    Ouch. If this is true, it'd be safer to allocate a locked memory pool once and then distribute from that (and maybe increase the size as needed), instead of trying to lock/unlock on allocation/deallocation every time. That'd likely also improve performance.

    Boost.Pool could probably help here.

  3. Diapolo commented at 5:31 PM on June 14, 2012: none

    /subscribe

  4. laanwj commented at 5:35 PM on June 14, 2012: member

    Please don't do that (/subscribe). Only comment if you have something to add. Mind that everyone on the thread gets email when you post.

  5. Diapolo commented at 5:37 PM on June 14, 2012: none

    Sorry, as this is a Windows thing and I'm interested in further replies but couldn't add anything to it currently I did that. Would be nice to have an subscribe to this issue option. Won't do this again!

  6. xanatos commented at 6:00 PM on June 14, 2012: none

    I'll add that this problem isn't Windows only: http://man7.org/linux/man-pages/man2/mlock.2.html

    Memory locks do not stack, that is, pages which have been locked several times by calls to mlock() or mlockall() will be unlocked by a single call to munlock()

  7. laanwj referenced this in commit c96ca68f9a on Aug 22, 2012
  8. laanwj referenced this in commit e95568b78d on Aug 23, 2012
  9. sipa referenced this in commit af1c6b93b7 on Aug 24, 2012
  10. laanwj closed this on Aug 24, 2012

  11. laanwj commented at 8:00 PM on August 24, 2012: member

    This is solved in pull request #1699

  12. suprnurd referenced this in commit 82a4643135 on Dec 5, 2017
  13. lateminer referenced this in commit 2e21e51f07 on May 6, 2020
  14. lateminer referenced this in commit 976f46d6e1 on May 6, 2020
  15. lateminer referenced this in commit e830b59def on May 6, 2020
  16. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me