Skip to content

Make allocation/free/clean available to providers#8886

Closed
richsalz wants to merge 2 commits intoopenssl:masterfrom
richsalz:core-malloc
Closed

Make allocation/free/clean available to providers#8886
richsalz wants to merge 2 commits intoopenssl:masterfrom
richsalz:core-malloc

Conversation

@richsalz
Copy link
Contributor

@richsalz richsalz commented May 6, 2019

As a side-note, editing crypto/build.info for the FIPS provider, as opposed to providers/fips/build.info, is kind of confusing.

This DOES NOT WORK if an application calls CRYPTO_set_mem_functions I will do so in a separate PR once this is merged.

@paulidale paulidale added the branch: master Applies to master branch label May 9, 2019
@paulidale paulidale added the approval: review pending This pull request needs review by a committer label May 9, 2019
@paulidale
Copy link
Contributor

Ping @openssl/committers ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: maybe remove blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept the blank line, added a comment why.

paulidale
paulidale previously approved these changes May 22, 2019
Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still good.

slontis
slontis previously approved these changes May 22, 2019
@paulidale
Copy link
Contributor

A second review is required.

@richsalz
Copy link
Contributor Author

your colleague @slontis approved. :) maybe he wants to do this as his first official commit?

@t-j-h
Copy link
Member

t-j-h commented May 22, 2019

We are updating the tooling to make sure same-organisation approvals aren't seen as a match to avoid any potential perceived conflict of interest in the review process ...

@richsalz
Copy link
Contributor Author

@t-j-h nice to see that being made policy (since i first started it about akamai). Just for clarification, does that also mean not approving PR's from one's one organization?

@slontis
Copy link
Member

slontis commented May 22, 2019

In future I will not approve if @paulidale has already approved. (This applies to our own PR's also).

@slontis slontis dismissed their stale review May 22, 2019 02:24

An org can only issue one approval.

@richsalz
Copy link
Contributor Author

Rebased; needs reviews.

@paulidale
Copy link
Contributor

paulidale commented May 24, 2019

Needs a rebase and a second review. ignore this, stale page.

@paulidale
Copy link
Contributor

paulidale commented May 24, 2019

Has a decision about the control functions been made about them being offered from providers or not?

@levitte
Copy link
Member

levitte commented May 24, 2019

I will continue to point out that set_params and get_params type functions can be used as controls. It's all in what the receiving end does in response to OSSL_PARAM values...

@slontis
Copy link
Member

slontis commented May 27, 2019

Ping @openssl/committers ?

static OSSL_core_get_param_types_fn *c_get_param_types;
static OSSL_core_get_params_fn *c_get_params;
static OSSL_core_put_error_fn *c_put_error;
static OSSL_core_add_error_vdata_fn *c_add_error_vdata;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the initialization?

Copy link
Member

@slontis slontis May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a seperate PR (#8887).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the C guarantee to initialize to NULL.

@levitte
Copy link
Member

levitte commented May 27, 2019

Regarding dispatch macro names, @richsalz and I have already had a discussion in #8887 and disagree somewhat. At the very least, I think that _GET_ in the middle of them unnecessary.

Also, for naming purposes, I'm thinking that if we do want to have something that is explicitly meant to provide the public OpenSSL API, the dispatch macro names for them should maybe have a different prefix than OSSL_FUNC_CORE... perhaps OSSL_FUNC_OSSL? So, something like this?

#define OSSL_FUNC_OSSL_CRYPTO_MALLOC       nn
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_malloc, (size_t num, const char *file, int line))

@slontis
Copy link
Member

slontis commented May 27, 2019

Maybe @levitte & @mattcaswell should confer on these names so it can move forward.

@levitte
Copy link
Member

levitte commented May 27, 2019

We had a quick chat, and @mattcaswell said something that reminded me to look more closely in core_numbers.h and remind myself.
There's this comment:

/*-
 * Identities
 * ----------
 *
 * All series start with 1, to allow 0 to be an array terminator.
 * For any FUNC identity, we also provide a function signature typedef
 * and a static inline function to extract a function pointer from a
 * OSSL_DISPATCH element in a type safe manner.
 *
 * Names:
 * for any function base name 'foo' (uppercase form 'FOO'), we will have
 * the following:
 * - a macro for the identity with the name OSSL_FUNC_'FOO' or derivates
 *   thereof (to be specified further down)
 * - a function signature typedef with the name OSSL_'foo'_fn
 * - a function pointer extractor function with the name OSSL_'foo'
 */

Following that, and if the intention is to have a 1:1 mapping to the public API, then it should look like this, right?

/* Memory allocation, freeing, clearing. */
#define OSSL_FUNC_CRYPTO_MALLOC       10
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_malloc, (size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_ZALLOC       11
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_zalloc, (size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_MEMDUP       12
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_memdup, (const void *str, size_t siz, const char *file, int line))
#define OSSL_FUNC_CRYPTO_STRDUP       13
OSSL_CORE_MAKE_FUNC(char *,
        CRYPTO_strdup, (const char *str, const char *file, int line))
#define OSSL_FUNC_CRYPTO_STRNDUP      14
OSSL_CORE_MAKE_FUNC(char *,
        CRYPTO_strndup, (const char *str, size_t s, const char *file, int line))
#define OSSL_FUNC_CRYPTO_FREE         15
OSSL_CORE_MAKE_FUNC(void,
        CRYPTO_free, (void *ptr, const char *file, int line))
#define OSSL_FUNC_CRYPTO_CLEAR_FREE   16
OSSL_CORE_MAKE_FUNC(void,
        CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_REALLOC      17
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_realloc, (void *addr, size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 18
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_SECURE_MALLOC 19
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_secure_malloc, (size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 20
OSSL_CORE_MAKE_FUNC(void *,
        CRYPTO_secure_zalloc, (size_t num, const char *file, int line))
#define OSSL_FUNC_CRYPTO_SECURE_FREE   21
OSSL_CORE_MAKE_FUNC(void,
        CRYPTO_secure_free, (void *ptr, const char *file, int line))
#define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 22
OSSL_CORE_MAKE_FUNC(void,
        CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file, int line))
#define OSSL_FUNC_OPENSSL_CLEANSE 23
OSSL_CORE_MAKE_FUNC(void,
        OPENSSL_cleanse, (void *ptr, size_t len))
#define OSSL_FUNC_OPENSSL_HEXSTR2BUF 24
OSSL_CORE_MAKE_FUNC(unsigned char *,
        OPENSSL_hexstr2buf, (const char *str, long *len))

@levitte
Copy link
Member

levitte commented May 27, 2019

(previous comment edited, I had pasted in much more than I intended...)

@richsalz
Copy link
Contributor Author

@levitte regarding #8886 (comment) isn't that what this PR has? But on the other hand, using one person's code comment to justify a policy seems a little weak to me :)

@richsalz
Copy link
Contributor Author

Re #8886 (comment), perhaps the OMC, the committers, and/or the FIPS sponsors should be included in any such discussions as how to name things? Not just two paid fellows.

@richsalz
Copy link
Contributor Author

I fixed the define names thanks for the fix!

Can I suggest that maybe in the future we don't need to line up the values with things like this, lots of other lines between defines? :) Just put name space value

@richsalz
Copy link
Contributor Author

The function and define names were fixed, this is rebased, so now it needs a reconfirm and another review.

@paulidale
Copy link
Contributor

CI failures look relevant.

@paulidale paulidale dismissed their stale review June 12, 2019 01:18

CI broken :(

@paulidale paulidale removed the approval: review pending This pull request needs review by a committer label Jun 12, 2019
@richsalz
Copy link
Contributor Author

richsalz commented Jun 12, 2019

Oops, clobbered some of my fixes. New commit pushed that fixes the CI (and function/macro naming) issues. There is now a new (minor?) issue, however, that is described in db3480e

@richsalz
Copy link
Contributor Author

argh, rebased (that was a hard one) and pushed. ping.

@richsalz
Copy link
Contributor Author

I cannot figure out why some of the CI builds are failing; time-out issues? Any clues?

@paulidale
Copy link
Contributor

The one I looked at is the evp_extra test failing -- I don't think this one isn't timing critical.
Hmmm...

@slontis
Copy link
Member

slontis commented Jun 18, 2019

I also was looking at that same test..
This is probably not helpful...
See if you can reproduce it locally with your changes.. (Maybe it only happens with non debug?)

export LD_LIBRARY_PATH=.
export OPENSSL_MODULES=providers
./test/evp_extra_test

If you know which test it is you can do this

./test/evp_extra_test -test 13 -iter 4

@slontis
Copy link
Member

slontis commented Jun 18, 2019

Hmm maybe one of your function signatures is wrong.. If you call a function with incorrect args it can just crash. I had an incorrect return type causing a crash a while ago.

@richsalz
Copy link
Contributor Author

AARGH. I figured it out. Line 234:

	    OPENSSL_CTX *ctx = OPENSSL_CTX_new();

which calls CRYPTO_zalloc, but the upcall hasn't been created yet!

Pinging @mattcaswell and anyone else who has thoughts about how to fix this issue.

@slontis
Copy link
Member

slontis commented Jun 18, 2019

This is a recent change that moved the CTX_new() to before the resolving takes place..
At least some of the resolve will need to move up before the new(). If there are any failures then maybe the statics should all be set back to NULL.

@richsalz
Copy link
Contributor Author

I can fix the segv, but then there's memory leak that doesn't happen on master. :( see 5a3e30c

@richsalz
Copy link
Contributor Author

Doing all the resolves first is reasonable, they are just looking up and setting static globals.

@richsalz richsalz mentioned this pull request Jun 18, 2019
2 tasks
Also make OPENSSL_hexstr2buf available to providers.
EVP control functions need hexstring conversion, so move any
memory-allocating functions in o_str.c into new file mem_str.c
@richsalz
Copy link
Contributor Author

richsalz commented Jul 3, 2019

This is nearly two months old and got first approval more than a month ago. Since then I've rebased multiple times, worked around errors in master, etc. Right now there's an appveyor build failure which I don't understand: https://ci.appveyor.com/project/openssl/openssl/builds/25709908/job/r85f0x7jbnf6824v#L5017

@richsalz
Copy link
Contributor Author

This builds. It's needed. It's been sitting for weeks/months. Ping.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still happy with these changes.

Copy link
Contributor

@mspncp mspncp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Just two general remarks resp. questions.

{ OSSL_FUNC_CORE_ADD_ERROR_VDATA, (void (*)(void))core_add_error_vdata },
#endif

{ OSSL_FUNC_CRYPTO_MALLOC, (void (*)(void))CRYPTO_malloc },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: why isn't there a macro for declaring these entries to reduce boilerplate code? For example, OSSL_DISPATCH_ENTRY(CRYPTO_MALLOC, CRYPTO_malloc)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind such a macro. PR welcome 😉

@paulidale
Copy link
Contributor

I'll leave the last two comments for @mattcaswell (& perhaps @levitte) to respond to.
In the meantime, I've merged this. Thanks for your patience.

@paulidale paulidale closed this Jul 11, 2019
levitte pushed a commit that referenced this pull request Jul 11, 2019
Also make OPENSSL_hexstr2buf available to providers.
EVP control functions need hexstring conversion, so move any
memory-allocating functions in o_str.c into new file mem_str.c

Reviewed-by: Matthias St. Pierre <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #8886)
@richsalz richsalz deleted the core-malloc branch July 17, 2019 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants