After rudimentary analysis, it appears the below functions can
potentially produce output, whilst the provider is in error state.
These functions were detected using this method:
```
CFLAGS='-save-temps' ./Configure enable-fips --debug
make -j10
find . -name '*.i' | xargs git add -f
git grep --cached -p ossl_prov_is_running | grep libfips-lib > ossl_prov_is_running.txt
git grep --cached -p 'return' | grep libfips-lib > return.txt
grep '\.i=' return.txt > func-with_return.txt
grep '\.i=' ossl_prov_is_running.txt > func-with-ossl_prov_is_running.txt
grep --fixed-strings --line-regexp --file=func-with-ossl_prov_is_running.txt return.txt > func-without-ossl_prov_is_running.txt
grep -e newctx -e initctx -e dupctx func-without-ossl_prov_is_running.txt | grep -v ossl_prov_is_running
```
And from there doing manual inspection, as the list was short at that
point.
As in compile with keeping pre-processed source code; and use `git
grep --cached -p` to find these preprocessed files, and scan for calls
to return or opssl_prov_is_running, with function name printed. And
then exclude one from the other, to hopefully get a list of all the
functions that do not check for ossl_prov_is_running.
As number of functions without "func-without-ossl_prov_is_running"
check is large, I do wonder which other functions are "interesting" to
check for. I think I'm not scanning for _update functions
correctly. Any tips on improving above analysis will help with
maintaining such checks going forward.
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25580)
(cherry picked from commit
c262cc0c0444f617387adac3ed4cad9f05f9c526)
{
PROV_AES_HMAC_SHA1_CTX *ctx = provctx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
if (ctx == NULL)
return NULL;
{
PROV_AES_HMAC_SHA256_CTX *ctx = provctx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
return OPENSSL_memdup(ctx, sizeof(*ctx));
}
PROV_AES_CCM_CTX *ctx = provctx;
PROV_AES_CCM_CTX *dupctx = NULL;
+ if (!ossl_prov_is_running())
+ return NULL;
+
if (ctx == NULL)
return NULL;
dupctx = OPENSSL_memdup(provctx, sizeof(*ctx));
PROV_AES_GCM_CTX *ctx = provctx;
PROV_AES_GCM_CTX *dctx = NULL;
+ if (!ossl_prov_is_running())
+ return NULL;
+
if (ctx == NULL)
return NULL;
PROV_AES_WRAP_CTX *ctx = wctx;
PROV_AES_WRAP_CTX *dctx = wctx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
if (ctx == NULL)
return NULL;
dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
static void *aes_xts_newctx(void *provctx, unsigned int mode, uint64_t flags,
size_t kbits, size_t blkbits, size_t ivbits)
{
- PROV_AES_XTS_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
+ PROV_AES_XTS_CTX *ctx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
+ ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx != NULL) {
ossl_cipher_generic_initkey(&ctx->base, kbits, blkbits, ivbits, mode,
flags, ossl_prov_cipher_hw_aes_xts(kbits),
#include <openssl/proverr.h>
#include "crypto/rsa.h"
#include "prov/provider_ctx.h"
+#include "prov/providercommon.h"
#include "prov/implementations.h"
#include "prov/securitycheck.h"
static void *rsakem_newctx(void *provctx)
{
- PROV_RSA_CTX *prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
+ PROV_RSA_CTX *prsactx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
+ prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
if (prsactx == NULL)
return NULL;
prsactx->libctx = PROV_LIBCTX_OF(provctx);
PROV_RSA_CTX *srcctx = (PROV_RSA_CTX *)vprsactx;
PROV_RSA_CTX *dstctx;
+ if (!ossl_prov_is_running())
+ return NULL;
+
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
if (dstctx == NULL)
return NULL;
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
int protect = 0;
+ if (!ossl_prov_is_running())
+ return 0;
+
if (prsactx == NULL || vrsa == NULL)
return 0;
{
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
+ if (!ossl_prov_is_running())
+ return 0;
+
switch (prsactx->op) {
case KEM_OP_RSASVE:
return rsasve_generate(prsactx, out, outlen, secret, secretlen);
{
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
+ if (!ossl_prov_is_running())
+ return 0;
+
switch (prsactx->op) {
case KEM_OP_RSASVE:
return rsasve_recover(prsactx, out, outlen, in, inlen);