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 all 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
4 changes: 4 additions & 0 deletions include/openssl/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,11 @@ OPENSSL_EXPORT int BIO_meth_set_puts(BIO_METHOD *method,
// BIO_meth_get_puts returns |puts| function of |method|.
OPENSSL_EXPORT int (*BIO_meth_get_puts(const BIO_METHOD *method)) (BIO *, const char *);

// BIO_s_secmem returns the normal BIO_METHOD |BIO_s_mem|. Deprecated since AWS-LC
// does not support secure heaps.
OPENSSL_EXPORT OPENSSL_DEPRECATED const BIO_METHOD *BIO_s_secmem(void);


// General No-op Functions [Deprecated].

// BIO_set_write_buffer_size returns zero.
Expand Down
11 changes: 11 additions & 0 deletions include/openssl/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ OPENSSL_EXPORT int CRYPTO_set_mem_functions(
void *(*r)(void *, size_t, const char *, int),
void (*f)(void *, const char *, int));

// 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. The initialization functions intentionally return zero to indicate that secure
// heaps aren't supported. We return the regular malloc and zalloc versions when the secure_* counterparts are called,
// which is what OPENSSL does when secure heap is not enabled.
// If there is any interest in utilizing "secure heaps" with AWS-LC, cut us an issue at
// https://github.com/aws/aws-lc/issues/new/choose

// CRYPTO_secure_malloc_init returns zero.
OPENSSL_EXPORT int CRYPTO_secure_malloc_init(size_t size, size_t min_size);

Expand All @@ -250,6 +258,9 @@ OPENSSL_EXPORT size_t CRYPTO_secure_used(void);
// OPENSSL_secure_malloc calls |OPENSSL_malloc|.
OPENSSL_EXPORT void *OPENSSL_secure_malloc(size_t size);

// OPENSSL_secure_zalloc calls |OPENSSL_zalloc|.
OPENSSL_EXPORT void *OPENSSL_secure_zalloc(size_t size);

// 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