Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding OPENSSL_secure_zalloc and BIO_s_secmem #1476

Merged
merged 16 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crypto/bio/bio_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,7 @@ int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership) {
int BIO_set_mem_eof_return(BIO *bio, int eof_value) {
return (int)BIO_ctrl(bio, BIO_C_SET_BUF_MEM_EOF_RETURN, eof_value, NULL);
}

const BIO_METHOD *BIO_s_secmem(void) {
return BIO_s_mem();
}
2 changes: 2 additions & 0 deletions crypto/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ size_t CRYPTO_secure_used(void) { return 0; }

void *OPENSSL_secure_malloc(size_t size) { return OPENSSL_malloc(size); }

void *OPENSSL_secure_zalloc(size_t size) { return OPENSSL_zalloc(size); }
justsmth marked this conversation as resolved.
Show resolved Hide resolved

void OPENSSL_secure_clear_free(void *ptr, size_t len) {
OPENSSL_clear_free(ptr, len);
}
Expand Down
3 changes: 3 additions & 0 deletions include/openssl/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ OPENSSL_EXPORT int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership);
// default is -1 so that additional data can be written once exhausted.
OPENSSL_EXPORT int BIO_set_mem_eof_return(BIO *bio, int eof_value);

// Returns the normal BIO_METHOD |BIO_s_mem|. Deprecated since AWS-LC does not
smittals2 marked this conversation as resolved.
Show resolved Hide resolved
// support secure heaps.
OPENSSL_EXPORT OPENSSL_DEPRECATED const BIO_METHOD *BIO_s_secmem(void);
smittals2 marked this conversation as resolved.
Show resolved Hide resolved

// BIO close flags.
//
Expand Down
10 changes: 9 additions & 1 deletion include/openssl/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,16 @@ OPENSSL_EXPORT int CRYPTO_secure_malloc_initialized(void);
// CRYPTO_secure_used returns zero.
OPENSSL_EXPORT size_t CRYPTO_secure_used(void);

// OPENSSL supports the concept of secure heaps to help protect applications from pointer overruns or underruns that
// could return arbitrary data from the program's dynamic memory area where sensitive information may be stored.
// AWS-LC does not support secure heaps. Therefore, |OPENSSL_secure_malloc| and |OPENSSL_secure_zalloc| are
// implemented as wrappers around their normal counterparts.

// OPENSSL_secure_malloc calls |OPENSSL_malloc|.
OPENSSL_EXPORT void *OPENSSL_secure_malloc(size_t size);
OPENSSL_EXPORT OPENSSL_DEPRECATED void *OPENSSL_secure_malloc(size_t size);

// OPENSSL_secure_zalloc calls |OPENSSL_zalloc|.
OPENSSL_EXPORT OPENSSL_DEPRECATED void *OPENSSL_secure_zalloc(size_t size);
smittals2 marked this conversation as resolved.
Show resolved Hide resolved

// OPENSSL_secure_clear_free calls |OPENSSL_clear_free|.
OPENSSL_EXPORT void OPENSSL_secure_clear_free(void *ptr, size_t len);
smittals2 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading