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

Fix safestack #12781

Closed
wants to merge 32 commits into from
Closed

Fix safestack #12781

wants to merge 32 commits into from

Conversation

mattcaswell
Copy link
Member

We fix 3 problems with safestack:

  • Including an openssl header file without linking against libcrypto
    can cause compilation failures (even if the app does not otherwise need
    to link against libcrypto). See issue The story of safestack.h and lhash.h #8102
  • Recent changes means that applications in no-deprecated builds will need
    to include additional macro calls in the source code for all stacks that
    they need to use - which is an API break. This changes avoids that
    necessity.
  • It is not possible to write code using stacks that works in both a
    no-deprecated and a normal build of OpenSSL. See issue sk_GENERAL_NAME_num not defined if compiled with no-deprecated #12707.

Fixes #12707
Contains a partial fix for #8102. A similar PR will be needed for hash to
fully fix.

@mattcaswell mattcaswell added the branch: master Merge to master branch label Sep 3, 2020
@mattcaswell
Copy link
Member Author

This is marked as WIP because make update gets confused by the header files that are now generated. Not sure what I need to do to fix that at the moment.

@richsalz
Copy link
Contributor

richsalz commented Sep 3, 2020

Do you need to tweak doc/man3/DEFINE_STACK_OF.pod?

@mattcaswell
Copy link
Member Author

Do you need to tweak doc/man3/DEFINE_STACK_OF.pod?

Yeah, possibly. I'll check.

@rsbeckerca
Copy link
Contributor

I would like to conduct a build test of this on NonStop, when it's available.

@mattcaswell
Copy link
Member Author

I would like to conduct a build test of this on NonStop, when it's available.

Please do!

@richsalz
Copy link
Contributor

richsalz commented Sep 3, 2020

Does this address the 'make update' issue?

diff --git a/util/mknum.pl b/util/mknum.pl
index 871c07055b..f8ae786746 100644
--- a/util/mknum.pl
+++ b/util/mknum.pl
@@ -52,7 +52,9 @@ my %orig_names = ();
 # Invalidate all entries, they get revalidated when we re-check below
 $ordinals->invalidate();
 
-foreach my $f (($symhacks_file // (), @ARGV)) {
+foreach my $forig (($symhacks_file // (), @ARGV)) {
+    my $f = $forig;
+    $f = "$f.in" if -f "$f.in";
     print STDERR $f," ","-" x (69 - length($f)),"\n" if $verbose;
     open IN, $f || die "Couldn't open $f: $!\n";
     foreach (parse(<IN>, { filename => $f,

CHANGES.md Outdated Show resolved Hide resolved
@levitte
Copy link
Member

levitte commented Sep 4, 2020

Does this address the 'make update' issue?

Nope. The C parser doesn't understand the perl snippet.
I'm working on a solution where we scan the generated headers rather than their .in template. Nearly there.

@levitte
Copy link
Member

levitte commented Sep 4, 2020

I've pushed a few commits (one squash) that should fix the 'make update' issues

@mattcaswell mattcaswell changed the title WIP: Fix safestack Fix safestack Sep 4, 2020
@mattcaswell
Copy link
Member Author

I've pushed a few commits (one squash) that should fix the 'make update' issues

Awesome! Thanks.

@mattcaswell
Copy link
Member Author

Do you need to tweak doc/man3/DEFINE_STACK_OF.pod?

I re-read it, and I think its still accurate. The original macros still remain, and should still be used for generating custom stacks. Its only for our own stacks that appear in public headers where take a slightly different approach. So from an API perspective, nothing has changed.

@mattcaswell
Copy link
Member Author

I've rebased this and taken it out of WIP now that the make update issues are resolved. Let's see what the CIs make of it.

I've fixed the nit @slontis noted above. I also pushed one fixup on top of @levitte's commits to resolve a minor error there.

Please take a look.

@rsbeckerca
Copy link
Contributor

I'm going to try cloning your branch, adding my port changes, and see what happens.

@@ -1098,7 +1098,6 @@ errors:
$base = $base_in;
$dir = catfile($config{builddir}, $d);
}
my $parent =
Copy link
Member

Choose a reason for hiding this comment

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

Oops... good catch

@rsbeckerca
Copy link
Contributor

The safestack compile issue went away on NonStop, however, the argument list too long problem is back. This was fixed at 1.1.1 but has returned. Is it possible that when this PR is merged that the build changes will return?

make[1]: execvp: ar: Argument list too long
Makefile:9327: recipe for target 'libcrypto.a' failed
make[1]: *** [libcrypto.a] Error 127

@mattcaswell
Copy link
Member Author

The safestack compile issue went away on NonStop, however, the argument list too long problem is back. This was fixed at 1.1.1 but has returned. Is it possible that when this PR is merged that the build changes will return?

I wonder if @levitte can comment on that

@mattcaswell
Copy link
Member Author

Looks like doc-nits is complaining. It doesn't like all the new macros

@rsbeckerca
Copy link
Contributor

The safestack compile issue went away on NonStop, however, the argument list too long problem is back. This was fixed at 1.1.1 but has returned. Is it possible that when this PR is merged that the build changes will return?

I wonder if @levitte can comment on that

I did try a whole bunch of shell tricks to try to put $? into a file, but it's just too large for the platform's environment space to handle. I'm open to trying suggestions.

@mattcaswell
Copy link
Member Author

Looks like doc-nits is complaining. It doesn't like all the new macros

Fixup pushed to ignore them. We document them as sk_TYPE_blah. Possibly we should link all the macros to that one page....but that would be a very long list.

@levitte
Copy link
Member

levitte commented Sep 4, 2020

#12706 should help with the ar problem

@rsbeckerca
Copy link
Contributor

#12706 should help with the ar problem

Yes, we are using that in the 1.1.1 port, I believe. Perhaps we should wait for that to be merged in. @mattcaswell do you think this PR is compatible with your changes?

@mattcaswell
Copy link
Member Author

Yes, we are using that in the 1.1.1 port, I believe. Perhaps we should wait for that to be merged in. @mattcaswell do you think this PR is compatible with your changes?

I don't expect there to be any significant conflict

@rsbeckerca
Copy link
Contributor

I am able to build OpenSSL 3.0.0 on HPE NonStop using this fix and #12706 plus a hack to the Makefile for building libcrypto.so (same issue as with ar - the command line is too large). In any event, this fix looks good to me. I have not been able to run the regression suite yet, but I think that is independent of this fix.

@levitte
Copy link
Member

levitte commented Sep 6, 2020

One of the Travis jobs complains:

crypto/ex_data.c:448:6: error: expression result unused; should this cast be to 'void'? [-Werror,-Wunused-value]
    ((void *)OPENSSL_sk_set(ossl_check_void_sk_type(ad->sk), (idx), ossl_check_void_type(val)));
     ^     ~
1 error generated.

I believe, but am not entirely sure that the quick fix is this:

diff --git a/crypto/ex_data.c b/crypto/ex_data.c
index 80a136164a..f241b53f4e 100644
--- a/crypto/ex_data.c
+++ b/crypto/ex_data.c
@@ -447,7 +447,7 @@ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
             return 0;
         }
     }
-    sk_void_set(ad->sk, idx, val);
+    (void)sk_void_set(ad->sk, idx, val);
     return 1;
 }
 

openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
... and add SKM_DEFINE_STACK_OF_INTERNAL

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
The safestack code generation was generating a little too much. Some of
it could be done with a normal macro.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
'or' has lower priority than '||' in perl, which affects evaluation order.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
'make ordinals' assumed that all headers reside in the source tree,
which is no longer true, now that we generate a number of them.  This
needed some refactoring.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
util/mkerr.pl detects if a header is now a '.in' template, and adjusts
the header file it reads accordingly.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
openssl-machine pushed a commit that referenced this pull request Sep 13, 2020
Some compilers are very picky about unused return values.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #12781)
@richsalz
Copy link
Contributor

Thank you for finishing this off (er, doing it correctly). I had no idea it would be so much work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sk_GENERAL_NAME_num not defined if compiled with no-deprecated
9 participants