Comments (2)
The relevant documentation is this:
In addition, sodium_mlock() is called on the region to help avoid it being swapped to disk.
(found here)
I think clarification would be appropriate here, e.g.:
In addition, sodium_mlock() is called on the region to help avoid it being swapped to disk. Note however that sodium_mlock() may fail, in which case sodium_malloc() will return the memory regardless, but it will not be mlocked. If you need to rely on mlocking, consider calling
sodium_mlock()
explicitly, and checking its return value.
I would also suggest documenting this design decision in the source code, to avoid future misunderstandings of this kind.
from libsodium.
These system calls are intentionally not checked here.
We can't guarantee that sodium_malloc()
can lock memory. On some environments, memory locking just doesn't exist. On others, such as WebAssembly, the function is failing right now, but may eventually work (and this will, very likely, also depend on the runtime).
On other systems, the system call may or may not work according to the system configuration and the amount of already locked memory, which is very non-deterministic.
For many application developers, sodium_malloc()
would be seen as something that "randomly fails" and would discourage its use.
The reason is was introduced is to mitigate heartbleed-like attacks. It can also be used as a general bound checking mechanism, and it's widely used that way in the test suite. Locking memory is just a bonus step, but without any guarantees. If the documentation states it otherwise or is confusing, that should be clarified.
For cases where memory locking is absolutely required, there is the sodium_mlock()
function.
from libsodium.
Related Issues (20)
- Compiling test codes successfully ,but the generated executable file does not run. HOT 1
- Linker command failed - android-armv7 script HOT 6
- AES-256 GCM crypto_stream - are there any plans to support it? HOT 3
- is the constant crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX wrong? HOT 4
- Where can I download Libsodium DLLs? HOT 1
- Not all bits of secret key are significant in crypto_box_open HOT 3
- [Some error I got when I am implementing commitment scheme based on lib sodium] HOT 1
- AEGIS-[128,256]X HOT 2
- Cross platform decrypting
- strict-aliasing violation in blkxor pwhash_scryptsalsa208sha256_nosse.c HOT 1
- Test failing during pip install as a dependency of pynacl==1.5.0 on arm64/apple m1 image building HOT 1
- macOS randombytes_buf infinite loop HOT 14
- Chacha/box tests segfault when compiling with LLVM Polly HOT 1
- support for veilid crypto HOT 4
- aarch64 build fails after updating from 1.0.18 to 1.0.19 HOT 2
- android-ndk-r26-rc1 build error for stable HOT 6
- Why soname change from 23 to 26 HOT 1
- [UB] memcpy could be called on null dst pointer in function escrypt_r HOT 2
- Shouldn't crypto_pwdhash_PRIMITIVE be 'argon2id' ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsodium.