memory-control icon indicating copy to clipboard operation
memory-control copied to clipboard

`mlock`

Open daxpedda opened this issue 4 years ago • 3 comments

For security purposes it would also be interesting to add mlock. I am not versed in the WASM spec and I am not sure if this should be added here or in multi-memory.

The main use-case is to protect sensitive data by preventing it from using swap memory.

daxpedda avatar Feb 08 '22 17:02 daxpedda

This could be added here, could you elaborate a little bit more on your use case? What sorts of applications would you expect to use mlock?

dtig avatar Feb 09 '22 23:02 dtig

For example currently I'm working on implementing OPAQUE to be used on the client through WASM in the browser. This would require holding some secrets that should not leak to swap, for example the user password.

More complicated cases could hold encryption keys and the like when the Web Crypto API is not enough or when used in conjunction with it.

daxpedda avatar Feb 12 '22 16:02 daxpedda

I just saw that it was also mentioned here: https://github.com/WebAssembly/design/issues/1397#issuecomment-926088470.

As far as I understand it was only posted as a reference, my intention is also to re-post it here just for reference too.

Lock

OSes also allow locking virtual pages to physical pages, so that they will not be "evicted" to the page file or relocated to another part of RAM. Obviously, the maximum amount of memory for which this can happen is limited to some portion of the total physical RAM in the system.

Although there's nothing stopping an application from using this feature as a performance optimization ("I know this chunk of memory is important and I never want it swapped out"), it is mainly used for kernel or hardware communication. Because virtual addresses are per-process, and pages can be transient in physical memory, anything that needs to be quickly accessed by multiple processes, the kernel, or hardware collaboratively may need to be locked in physical memory so that it does not need to go through costly kernel operations to ensure consistency.

daxpedda avatar Feb 26 '23 11:02 daxpedda