Skip to content

Prevent oversize TLS labels. - #11577

Closed
bernd-edlinger wants to merge 1 commit into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:prevent_oversize_tls_labels
Closed

bernd-edlinger wants to merge 1 commit into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:prevent_oversize_tls_labels

Conversation

@bernd-edlinger

Copy link
Copy Markdown
Member

I see no valid use case in such labels.

[extended tests]

Checklist
  • documentation is added or updated
  • tests are added or updated

@mattcaswell

Copy link
Copy Markdown
Member

I don't think this change is correct. It would actually change the behaviour of the SSL_export_keying_materialI() and SSL_export_keying_material_early() functions in a non-compatible way.
The use of labels longer than 12 is allowed by the RFC8446:

       struct {
           uint16 length = Length;
           opaque label<7..255> = "tls13 " + Label;
           opaque context<0..255> = Context;
       } HkdfLabel;

So, syntactically labels of up 249 bytes in length are fine. The particular text in the RFC that you mention in your comment is only saying that labels defined in that spec are 12 or less. It says nothing about labels defined elsewhere.

There are in fact a number of labels defined in the IANA TLS Exporter Label registry which are longer than 12. See:

https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Ah, okay, that was the problem, so which one is the longest valid
exporter label then?

@mattcaswell

Copy link
Copy Markdown
Member

Ah, okay, that was the problem, so which one is the longest valid
exporter label then?

The longest valid label allowed by the spec is 249 bytes.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Okay, but who uses 249 bytes?

@mattcaswell

Copy link
Copy Markdown
Member

Okay, but who uses 249 bytes?

No one currently. The longest in the IANA registry that I can see is 31. But there is nothing preventing IANA from registering a longer one.

@kaduk

kaduk commented Apr 20, 2020

Copy link
Copy Markdown
Contributor

We seem to have already had to increase this value once, even, in 0fb2815 (though it's not quite the scenario that I was initially remembering).

@mattcaswell

Copy link
Copy Markdown
Member

We seem to have already had to increase this value once, even, in 0fb2815 (though it's not quite the scenario that I was initially remembering).

As a by-product of some other related changes draft 20 increased the effective maximum label length from 246 to 249 (because it shortened the "prefix" used on the label from "TLS 1.3, " (9 characters to "tls13 " (6 characters)). But we didn't notice the impact on the max label length straight away - until the commit you mentioned.

@kroeckx

kroeckx commented Apr 20, 2020 via email

Copy link
Copy Markdown
Member

@kaduk

kaduk commented Apr 20, 2020

Copy link
Copy Markdown
Contributor

Ah, thanks; Kurt found the one I was thinking of (that git log -S didn't).

@richsalz

Copy link
Copy Markdown
Contributor

Not every exported label has to be registered. I could envision some apps using generated exporters that come close to the length. For example, using long German compound words for service names, or punycode of long asian words :)

@bernd-edlinger

Copy link
Copy Markdown
Member Author

I would call TOR illegal use of OpenSSL.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

@mattcaswell

The longest in the IANA registry that I can see is 31. But there is nothing preventing IANA from registering a longer one.

So which is the longest IANA Approved Label then?
I would like to use that in the test case.

@mattcaswell

Copy link
Copy Markdown
Member

So which is the longest IANA Approved Label then?

Longest current one is:

EXPORTER-ETSI-TC-M2M-Connection

@mattcaswell

Copy link
Copy Markdown
Member

I would call TOR illegal use of OpenSSL.

No - I don't think so.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Excuse me, Terrorists use the TOR browser to purchase weapons,
and they did that within 2 KM from my home. They Kill 9 Children

https://de.wikipedia.org/wiki/Anschlag_in_M%C3%BCnchen_2016

So excuse me, when I DO NOT ACCEPT THAT STUPID IDEA.

@romen

romen commented Apr 26, 2020 •

Copy link
Copy Markdown
Member

@bernd-edlinger cutting down the supported length just because currently the longest registered one has a given length is exactly the kind of behavior that led to the big mess in TLS 1.3 to mimic TLS 1.2 just because middleboxes hard-coded stuff and checks that were not mandated by the standard.

We want openssl to be a compliant library and toolkit, and we don't want to be part of the ossification problem or one of those implementations that claim to be compliant with standards but then cut some corners due to their own unilateral interpretation of them.

From my part this PR would have a -1 vote.

The discussion of merits and demerits of TOR (or any other application or library that is a user of OpenSSL) does not belong here, and supporting it or not is a personal matter: as a project we currently are a free libre open source project, and we do not limit the freedom of any of our users to copy, modify, or redistribute our source code (within the boundaries of our license), and we do not prevent anyone from becoming a user of OpenSSL; the OMC would have to vote to change this, if changing it is even possible according to the project bylaws.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Sorry, is there no other SSL library than OpenSSL which supports TOR?
Can't they use WolfSSL, that sounds much more aggressive, IMHO.......

@richsalz

richsalz commented Apr 26, 2020 via email

Copy link
Copy Markdown
Contributor

@paulidale paulidale added the hold: discussion The community needs to establish a consensus how to move forward with the issue or PR label Apr 26, 2020
@paulidale

Copy link
Copy Markdown
Contributor

I've added the hold label based on @romen's comment.

@romen

romen commented Apr 26, 2020

Copy link
Copy Markdown
Member

I've added the hold label based on @romen's comment.

I believe it's up to @bernd-edlinger to write a proposal of what the OTC should decide upon for this PR.
I don't think I can write such a proposal because I am either misunderstanding @bernd-edlinger 's intent or I am biased against my current interpretation of it.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Okay, will do, it may take me some time to think about the right wording.

Meanwhile I just want to quote what I signed in my ICLA:

"You accept and agree to the following terms and conditions for Your present and future
Contributions submitted to the Foundation. In return, the Foundation shall not use Your
Contributions in a way that is contrary to the public benefit."

So what I consider the dark net is contrary to the public benefit ?
Can I withdraw my ICLA in that case ?

@kroeckx

kroeckx commented Apr 27, 2020 via email

Copy link
Copy Markdown
Member

@bernd-edlinger

Copy link
Copy Markdown
Member Author

It's my understanding that the ICLA can not be terminated. But you can stop contributing code. And if you want we can disable the ICLA so that no new contributions are merged.

it is a contract, if one side does not fulfill it, the other side does not fulfill it either.

I am not a lawyer, but I am sure a lawyer will call me on my phone and ask
if he can help me.

@paulidale

Copy link
Copy Markdown
Contributor

It definitely isn't a contract, it lacks "consideration" (which is a really complicated legal term that's the basis of contract law).

Your ICLA granted exactly what @kroeckx wrote: a perpetual irrevocable license to your contributions.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Nice try.
How do you know that I did not add a "consideration" to the text????

@bernd-edlinger bernd-edlinger added hold: need omc decision and removed hold: discussion The community needs to establish a consensus how to move forward with the issue or PR labels Apr 28, 2020
@openssl openssl deleted a comment Apr 28, 2020
@bernd-edlinger

Copy link
Copy Markdown
Member Author

Exactly, and I believe WE (i mean the world) should start to make peace.
Sometimes secrets are necessary, but we lost the balance.
All of the internet traffic is encrypted anyway. But the DNS system
is broken. The root servers do not work any more.
Today governments mistrust their own people.
Even the western world is starting to fall apart.
On the other hand we have only one planet. There is no second chance.
I do not see real difference even with Russia or China.
They all love their children, and they do not want them to be kille by
terrorists, and/or by drugs.

The challenge we have is to understand each other, communicate
without shouting at each other, and understand the feelings
of other people that are not in the same room, but thousands of
kilometres apart. TOR does not help with that, and did I mention
the NSA can break both TOR since they operate part of that
net, see sponsors: DARPA. And they can event break the
anonymity of the bit coin's block chain. I wonder if they
invented the whole idea of the block chain.

@t-j-h

t-j-h commented May 10, 2020

Copy link
Copy Markdown
Member

But it is a management decision: Do we want to support TOR or NOT.
And do our sponsors want to support TOR with their money?

@bernd-edlinger I don't think this is the right way to approach the entire question. Basically we produce software that is open source and available for use. We don't place any restrictions on its use other than those contained in the license. We make no judgement about how the software is used - we don't work to preclude any specific use of the software.

If you wanted to place limitations on who can use software you release for a specific purpose then that would have to be encoded in the license being used and you would have to check each user and any of their users. That certainly isn't practical and very much isn't the open source model.

Thinking in a more practical sense - if you wanted to control who uses you software you simply shouldn't release it as open source. Anyone who is performing what you would consider illegal activities (in however you define those) doesn't have to make much of a leap to ignore any license terms you might add. Exerting greater control over your users is very much a commercial closed source style approach - but even then you aren't able to achieve a perfect solution in terms of complete control (e.g. software piracy).

We aim to be apolitical in our approach and that extends (in my view) to basically accepting that there will be people who we disagree with that will benefit from the efforts we have performed. We accept that as part of the overwhelming greater benefits to those who aren't in that category - and also accept that each one of us has a different view point on whom we would find objectionable.

This is a community effort and not that of a single person and with all communities comes the price of accepting the "community" view in order to participate. If the balance doesn't meet any specific persons needs, they are also free to form a new community or direct their efforts elsewhere.

It is sad to see any member of the community frustrated with how the resulting software is used - but that is simply one of the costs of a broad community and the open source model. I think the balance remains overwhelmingly positive.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

I understand that they can still use the software for whatever they like,
and I have no problem with that, but I do not see why it should be so
easy, a one-line patch they can handle, but still everyone will see that
we do not unconditionally endorse what they do with this software.
It is similar how we decided that Multi-prime RSA should not use
so many primes that it is factorizable with the ECM method.
It is still possible, but it needs a small patch, just configuring
like ./config allow-unsafe-multi-prime is not enough, that was
the OMC decision for a very similar issue. unconditionally

@bernd-edlinger

Copy link
Copy Markdown
Member Author

@InfoHunter do you remember?

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Hmm, I am thinking about how could we reach a consensus instead of a majority
decision taken by a privileged minority (OMC).

The motivation of the original patch was conserve stack space,
that it hurts the TOR browser was an unexpected side effect, but one that
brings good karma IMHO.

Thinking about it I came to this idea:
Obviously TOR developers are able to do a patch and change the limit to what
they need. That is an acceptable outcome to me, but obviously not to others here.
We preserve stack space which is good for embedded applications and
TOR can by-pass this if they want.
Even a majority decision in my sense, by the OMC will not make those happy
who are then overruled by this decision. Needless to say that the opposite decision will
make me leave the openssl project.

Maybe we can get to a consensus if we make it a per config parameters
override-able limit like ./config -DTLS13_MAX_LABEL_LEN=200
so they just have to change their setup to define the limit they need,
and if embedded people think that 12 is better suited for their needs
than the default 31 they can do that as well?

What do you think, could this make way for a consensus?

@romen

romen commented May 14, 2020

Copy link
Copy Markdown
Member

@bernd-edlinger I don't think we should support this behavior, not even as a config option.

Limiting this size, even in constrained devices, is applying an arbitrary non-regulated restriction to the TLS 1.3 standard.

If the embedded developer decided to limit this size to 12 or 31 (or whatever below the limit designed in the standard), and that device ends up becoming a network appliance, it's going to create problems for everyone once a widely adopted label requires to use a longer and valid length.

This kind of "optimizations" are harmful for the ecosystem and must be considered for what they are (in TLS 1.2 and earlier we failed to do so, and the evidence of the cost of it is quite clear in the last year or so of proceedings for the TLS 1.3 design before its release): the creation of products that claim compliance with a standard while being non-compliant by design.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Okay, as I said, you are asking me to leave the project?

@romen

romen commented May 14, 2020

Copy link
Copy Markdown
Member

Okay, as I said, you are asking me to leave the project?

@bernd-edlinger absolutely not!
I value you and your contributions to this and other projects!

I am only trying to explain, to the best of my ability, why I think this change should not be part of OpenSSL, for the technical reasons I mentioned.

I am really sorry this is coming across as personal, and I apologize for not being able to convey my message in a better way.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

@romen do I read your message correct, you are opposed to this PR even if
I change the default to the completely useless 249 ?

@kaduk

kaduk commented May 14, 2020

Copy link
Copy Markdown
Contributor

In all honesty, the fact that you are trying to use the "longest currently assigned value in the IANA registry" as a criterion makes me inclined to go ask IANA to register a lable of the longest length allowed by the protocol. The only real barrier to doing so is the opinion of the designated experts for that registry, and given the existence of RFC 8701 I expect them to be amneable to proposals designed to ensure that the TLS protocol remains as flexible in practice as it is intended to be.
What we put in comments in openssl, just one of many TLS implementations, has absolutely no bearing on what any individual is able to do and make requests of IANA to do.

@t8m

t8m commented May 15, 2020

Copy link
Copy Markdown
Member

On the other hand I can understand the concern about the stack-size occupied with the buffer in embedded application where the actual application using the openssl build is well known and does not require anything more than the regular TLS-1.3 labels. So if the default is changed to 249 and the comment adjusted accordingly, in my opinion it would be acceptable for merge.

@romen

romen commented May 15, 2020

Copy link
Copy Markdown
Member

On the other hand I can understand the concern about the stack-size occupied with the buffer in embedded application where the actual application using the openssl build is well known and does not require anything more than the regular TLS-1.3 labels. So if the default is changed to 249 and the comment adjusted accordingly, in my opinion it would be acceptable for merge.

My personal opinion is that even for devices at the edge, the approach of "today this is the max size we need to satisfy our requirements, let's claim we are TLS compliant even if we introduce constraints explicitly in contrast with the letter of the standard" with the corollary of "let the users and engineers of tomorrow face the potential future compatibility issues" is not justifiable and shouldn't be endorsed by the OpenSSL project by providing a configure option to do so.

I would rather prefer that embedded developers and engineers that want to do this to save costs and optimize things today shifting the cost of the issues to the future were to do so by patching on their own the OpenSSL source code, and completely owning the responsibility for doing so so that the project does not have any blame in fostering this anti-pattern.

In my opinion it's fine to have this as a define that requires minimal intervention (one line change that replaces the value 249 to 32 or whatever) by the adopters, so we are not making their life intentionally more complicate than it needs to be, yet it clearly makes a statement that the project does not endorse such choice and takes no responsibility if the developers prefer to create products that are not compliant with the standards.

As I mentioned in private correspondence with @bernd-edlinger , this is my personal opinion and feedback I am providing now that the proposition for a discussion is being formulated so that who proposes it is well aware in advance of some of the critiques that might be raised.
This is definitely not meant as a "veto" or "aut-aut" on my part (and such a thing is anyway not even a possibility according to our bylaws): if the outcome of our discussion is that the project collectively decides that my current position is not the right one to be adopted, I will accept it.

Also, I am definitely not a TLS expert, I am discussing this mostly as a matter of principle based on my personal impression of what I consider systemic malpractices highlighted during the troubled design process of TLS 1.3, and I admit I may have a distorted perception of what could be the potential consequences to the infrastructure, the end-users, and the project if we were to adopt the decision of limiting the label length based on the longest currently assigned value: I am completely open to the idea that justified pragmatic reasons might take a precedence here, or that I might be completely wrong.
Luckily, many active contributors and committers to the project are indeed TLS experts, and this discussion can lead to the optimal solution for our users and benefit everyone involved.

@romen

romen commented May 15, 2020 •

Copy link
Copy Markdown
Member

@romen do I read your message correct, you are opposed to this PR even if
I change the default to the completely useless 249 ?

@bernd-edlinger I missed this yesterday, sorry.

Yes, I would be opposed to having this as a configure option, for the reasons stated above.

Before this PR a developer that wants to use OpenSSL but decides to be intentionally non-compliant with the letter of the spec, can already apply a patch such as this:

diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c
index e81f3656ee..0122356456 100644
--- a/ssl/tls13_enc.c
+++ b/ssl/tls13_enc.c
@@ -14,7 +14,7 @@
 #include <openssl/kdf.h>
 #include <openssl/core_names.h>
 
-#define TLS13_MAX_LABEL_LEN     249
+#define TLS13_MAX_LABEL_LEN     31
 
 /* Always filled with zeros */
 static const unsigned char default_zeros[EVP_MAX_MD_SIZE];

Plus a similar change to "cheat" on the 90-test_sslapi.t test, that with the value currently set to 249 is also testing interoperability with applications using valid longer values for this field.

Often embedded developers use Yocto or similar systems to customize and tweak software source, compilation options, etc. for the target platforms, so I don't think that adding such a trivial patch to the list of patches applied in one of the layers is going to be an excessive burden for developers of constrained systems.
At the same time, leaving things as they were before this PR, avoids endorsing a practice that explicitly violates the letter of the standard, which allows this field to have a maximum length of 249 bytes, and clearly shifts responsibility for this change from the OpenSSL project to the developer/vendor of the non-compliant product.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Sorry, but an embedded device should know which labels are needed.
It is most likely those have never heard about SSL_export_keying_material.
I could not imagine any use case where SSL_export_keying_material is
used at all. This AP iI is so highly unusual that we completely overlooked
it in the original patch that turned out to break the TOR browser.
And on the other hand, I do not think that they would really be upset it
they just add a config option, to configure a feature exactly as needed.
But I really do not understand, why you do insist so much in not allowing
anybody to configure their openssl to their need.
I must say I begin to dislike the way how this project operates,
with all those majority decisions, you are going to suppress the
minority. You as a representative of the majority in this project
should be ashamed, of how you claim you would respect the
majority decision, and you imply I should of course do the same, while
I am already sure how the decision will be in the end.
When I seek for consensus, you seek for majority rules.
When I try to understand your feelings, you try to ignore mine.

@levitte

levitte commented May 15, 2020

Copy link
Copy Markdown
Member

But I really do not understand, why you do insist so much in not allowing anybody to configure their openssl to their need.

This is an interoperability issue. That makes it bigger than a mere openssl problem. Please don't ignore that aspect.

When I seek for consensus, you seek for majority rules.

I for one love consensus work. However, you have to recognise that it's hard to reach consensus when two opposing views keep on standing their ground.

@romen

romen commented May 15, 2020

Copy link
Copy Markdown
Member

@bernd-edlinger , I'll answer point to point, assuming the various items are directed at my own comments.

Sorry, but an embedded device should know which labels are needed.
It is most likely those have never heard about SSL_export_keying_material.
I could not imagine any use case where SSL_export_keying_material is
used at all. This AP iI is so highly unusual that we completely overlooked
it in the original patch that turned out to break the TOR browser.

I admit my scarce knowledge in this area, I defer to whatever it is that people more expertise than me on the matter have to say about it.
I still believe there is value to raise objections as I did, when an individual has the impression we might be collectively making a mistake making this or that change.
I am perfectly happy to have a discussion about technical matters in such a case, even if it turns out in the end that my objection was based on false premises, misguided or that I was simply wrong.
I can accept it, learn from it, and I can still believe that even if it required people to spend their time arguing over some matters, it was not wasted time and both the project and all the individuals involved in the discussion benefited from it.

And on the other hand, I do not think that they would really be upset it
they just add a config option, to configure a feature exactly as needed.
But I really do not understand, why you do insist so much in not allowing
anybody to configure their openssl to their need.

I stated that personally I would prefer if OpenSSL did not have a configure option that results in a non-compliant implementation of TLS 1.3.
As an open source software anybody has a right to derive their own modified version of OpenSSL applying the patches the prefer to obtain what they want, included a non-compliant TLS 1.3 implementation.

I am not advocating that nobody can alter the source code to do what they want with their modified version of OpenSSL. I am rather expressing my personal opinion that the project should avoid official support for configurations resulting in non-compliance, as I see non-compliance as a bug.

The fact that I express this personal opinion does not mean that I believe the project MUST do what I say because I said so.
I invite the discussion, I am open to let the arguments of others change my mind and show me that I was wrong.

In my limited experience, so far I am under the impression that the Project has welcomed consensus whenever possible, and has public bylaws that clearly state how to resolve situations when a unanimous consensus is not reached in a reasonable time.

I must say I begin to dislike the way how this project operates,
with all those majority decisions, you are going to suppress the
minority.

On this specific matter, as far as I am aware, the Project has not taken yet any vote or decision overruling a minority.
I raised an objection, we have an OTC hold because this matches the criteria for applying it, and we are discussing about either reaching a consensus or formulating a proposal for the OTC or the OMC to vote upon.

I say OTC or OMC because, to me, it seems like we are mixing 2 separate issues in this discussion:

  • technical decision (about which this PR was originally about when it was opened), about limiting the max size of labels;
  • policy decision about changing the project license and guidelines with the goal to prevent specific project or users (the Tor project, or any other project any other contributor dislikes now or in the
    future) from using OpenSSL.

I would rather discuss the second matter in a dedicated issue, because it is tangent to what this PR was originally about, and it is also related to personal feelings and beliefs that are not really helping reaching a decision on the more technical matter.

You as a representative of the majority in this project
should be ashamed, of how you claim you would respect the
majority decision, and you imply I should of course do the same, while
I am already sure how the decision will be in the end.

I am not assuming I am a representative of the majority, and I am not trying to silence you personally, or a minority.
All the opinions I expressed so far have been my own and I did not speak on behalf of the Project or a majority.

I apologize if the way I wrote my previous comments was perceived as if I was implying that you must personally accept the majority decision in virtue of the fact that it aligns with my personal preference.
This is not what I meant, I only wanted to make it clear that I don't feel entitled to be always right and that any decision against my opinion is necessarily a wrong decision.

When/if there will be votes on the technical matter and on the policy matter, I will accept the outcome because I personally trust and value the contributors to the project and I am confident that the processes that are in place to find a solution when unanimous consensus is not achieved will deliver the optimal compromise, even if it is against my initial position.

When I seek for consensus, you seek for majority rules.

I am sorry, I don't think I am acting against looking for consensus.
If we achieve consensus as a result of this discussion I would be very happy about it.
If we don't manage to reach consensus, there are rules that allow anybody to submit a proposal for a vote by either the OMC or the OTC.

This is actually in fairness to whoever proposes a change (in this case, your position), rather than to who wants to keep things as they currently are (in this case, my position): the alternative would be that a PR stagnates forever while a hard-to-reach consensus is pursued, favoring who opposes change.

So, if I indeed wanted to abuse our bylaws to prevent this change to be merged I would be more effective if I actively pushed for reaching unanimous consensus and delaying a majority vote.

When I try to understand your feelings, you try to ignore mine.

If I keep discussing here on GitHub and via personal emails is because I want to understand your reasons and your feelings, I am not trying to ignore yours.

Regarding the technical matter of this PR, it seems to me that your feelings are less involved than for the policy matter. Splitting the two things and treating them separately might help in avoiding to feel like I am actively trying to ignore your feelings.

@mattcaswell

Copy link
Copy Markdown
Member

I have an alternative proposal that I believe satisfies both @bernd-edlinger's objectives and @romen's concerns.

IIUC @bernd-edlinger is concerned about stack space. We can allocate a smaller stack space if OPENSSL_SMALL_FOOTPRINT is defined - but allocate additional heap space to hold longer labels at run time if they are needed (which in most cases they will not be):

diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c
index e81f3656ee..026221b69c 100644
--- a/ssl/tls13_enc.c
+++ b/ssl/tls13_enc.c
@@ -14,7 +14,8 @@
 #include <openssl/kdf.h>
 #include <openssl/core_names.h>
 
-#define TLS13_MAX_LABEL_LEN     249
+#define TLS13_MAX_LABEL_LEN            249
+#define TLS13_MAX_TYPICAL_LABEL_LEN     31
 
 /* Always filled with zeros */
 static const unsigned char default_zeros[EVP_MAX_MD_SIZE];
@@ -42,7 +43,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
     OSSL_PARAM params[5], *p = params;
     int mode = EVP_PKEY_HKDEF_MODE_EXPAND_ONLY;
     const char *mdname = EVP_MD_name(md);
-    int ret;
+    int ret = 0;
     size_t hkdflabellen;
     size_t hashlen;
     /*
@@ -50,9 +51,16 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
      * prefix and label + bytes for the label itself + 1 byte length of hash
      * + bytes for the hash itself
      */
-    unsigned char hkdflabel[sizeof(uint16_t) + sizeof(uint8_t)
-                            + (sizeof(label_prefix) - 1) + TLS13_MAX_LABEL_LEN
-                            + 1 + EVP_MAX_MD_SIZE];
+#define HKDF_LABEL_OVERHEAD (sizeof(uint16_t) + sizeof(uint8_t) \
+                             + (sizeof(label_prefix) - 1) \
+                             + 1 + EVP_MAX_MD_SIZE)
+#ifdef OPENSSL_SMALL_FOOTPRINT
+    unsigned char hkdflabelst[HKDF_LABEL_OVERHEAD + TLS13_MAX_TYPICAL_LABEL_LEN];
+#else
+    unsigned char hkdflabelst[HKDF_LABEL_OVERHEAD + TLS13_MAX_LABEL_LEN];
+#endif
+    unsigned char *hkdflabel = hkdflabelst;
+    size_t hkdflabelsize = sizeof(hkdflabelst);
     WPACKET pkt;
 
     kctx = EVP_KDF_CTX_new(kdf);
@@ -71,13 +79,28 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
              */
             SSLerr(SSL_F_TLS13_HKDF_EXPAND, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
         }
-        EVP_KDF_CTX_free(kctx);
-        return 0;
+        goto err;
+    }
+#ifdef OPENSSL_SMALL_FOOTPRINT
+    if (labellen > TLS13_MAX_TYPICAL_LABEL_LEN) {
+        hkdflabelsize = HKDF_LABEL_OVERHEAD + labellen;
+        hkdflabel = OPENSSL_malloc(hkdflabelsize);
+        if (hkdflabel == NULL) {
+            if (fatal) {
+                SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_HKDF_EXPAND,
+                         ERR_R_MALLOC_FAILURE);
+            } else {
+                SSLerr(SSL_F_TLS13_HKDF_EXPAND, ERR_R_MALLOC_FAILURE);
+            }
+            goto err;
+        }
     }
+#endif
+
 
     hashlen = EVP_MD_size(md);
 
-    if (!WPACKET_init_static_len(&pkt, hkdflabel, sizeof(hkdflabel), 0)
+    if (!WPACKET_init_static_len(&pkt, hkdflabel, hkdflabelsize, 0)
             || !WPACKET_put_bytes_u16(&pkt, outlen)
             || !WPACKET_start_sub_packet_u8(&pkt)
             || !WPACKET_memcpy(&pkt, label_prefix, sizeof(label_prefix) - 1)
@@ -86,14 +109,13 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
             || !WPACKET_sub_memcpy_u8(&pkt, data, (data == NULL) ? 0 : datalen)
             || !WPACKET_get_total_written(&pkt, &hkdflabellen)
             || !WPACKET_finish(&pkt)) {
-        EVP_KDF_CTX_free(kctx);
         WPACKET_cleanup(&pkt);
         if (fatal)
             SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_HKDF_EXPAND,
                      ERR_R_INTERNAL_ERROR);
         else
             SSLerr(SSL_F_TLS13_HKDF_EXPAND, ERR_R_INTERNAL_ERROR);
-        return 0;
+        goto err;
     }
 
     *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode);
@@ -105,12 +127,10 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
                                              hkdflabel, hkdflabellen);
     *p++ = OSSL_PARAM_construct_end();
 
-    ret = EVP_KDF_CTX_set_params(kctx, params) <= 0
-        || EVP_KDF_derive(kctx, out, outlen) <= 0;
-
-    EVP_KDF_CTX_free(kctx);
+    ret = EVP_KDF_CTX_set_params(kctx, params) > 0
+          && EVP_KDF_derive(kctx, out, outlen) > 0;
 
-    if (ret != 0) {
+    if (!ret) {
         if (fatal)
             SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_HKDF_EXPAND,
                      ERR_R_INTERNAL_ERROR);
@@ -118,7 +138,13 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
             SSLerr(SSL_F_TLS13_HKDF_EXPAND, ERR_R_INTERNAL_ERROR);
     }
 
-    return ret == 0;
+ err:
+#ifdef OPENSSL_SMALL_FOOTPRINT
+    if (hkdflabel != hkdflabelst)
+        OPENSSL_free(hkdflabel);
+#endif
+    EVP_KDF_CTX_free(kctx);
+    return ret;
 }
 
 /*

@kroeckx

kroeckx commented May 15, 2020 via email

Copy link
Copy Markdown
Member

@romen

romen commented May 15, 2020

Copy link
Copy Markdown
Member

I have an alternative proposal that I believe satisfies both @bernd-edlinger's objectives and @romen's concerns.

IIUC @bernd-edlinger is concerned about stack space. We can allocate a smaller stack space if OPENSSL_SMALL_FOOTPRINT is defined - but allocate additional heap space to hold longer labels at run time if they are needed (which in most cases they will not be):

Thanks @mattcaswell for trying to bridge the gap!

To me this looks like a reasonable compromise, it guarantees that for constrained devices waste is minimal in the common case, without compromising interoperability!

@bernd-edlinger
bernd-edlinger force-pushed the prevent_oversize_tls_labels branch from 2459a12 to 0ae6773 Compare May 16, 2020 18:29
I see no valid use case in such labels.

[extended tests]
@bernd-edlinger
bernd-edlinger force-pushed the prevent_oversize_tls_labels branch from 0ae6773 to 63ac1b6 Compare May 16, 2020 18:41
@bernd-edlinger

Copy link
Copy Markdown
Member Author

Interesting, I never saw travis fail with a "No space left on device" error:
https://api.travis-ci.org/v3/job/687861706/log.txt

�[0K/home/travis/.travis/job_stages: line 427: mtu.jsonpatch: No space left on device
/home/travis/.travis/job_stages: line 428: daemon.json: No space left on device
mv: cannot stat 'daemon.json': No such file or directory
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
...
�[0K$ git clone --depth=50 --quiet https://github.com/openssl/openssl.git openssl/openssl
fatal: could not create leading directories of 'openssl/openssl': No space left on device

�[31;1mThe command "eval git clone --depth=50 --quiet https://github.com/openssl/openssl.git openssl/openssl " failed. Retrying, 2 of 3.�[0m

fatal: write error: No space left on device
fatal: index-pack failed

�[31;1mThe command "eval git clone --depth=50 --quiet https://github.com/openssl/openssl.git openssl/openssl " failed. Retrying, 3 of 3.�[0m

fatal: write error: No space left on device
fatal: index-pack failed

�[31;1mThe command "eval git clone --depth=50 --quiet https://github.com/openssl/openssl.git openssl/openssl " failed 3 times.�[0m

@paulidale paulidale added hold: discussion The community needs to establish a consensus how to move forward with the issue or PR and removed hold: need omc decision labels Jun 2, 2020
@paulidale

Copy link
Copy Markdown
Contributor

I applied the OTC hold. I'm the only person who can remove it without a vote being held.

I've called an OTC vote for this.

@paulidale

Copy link
Copy Markdown
Contributor

The vote is effectively finished:

  • eight against
  • no abstentions
  • no for
  • three not yet voted

The vote to merge this failed.
Closing the PR.

@paulidale paulidale closed this Jun 3, 2020
levitte pushed a commit to openssl/otc that referenced this pull request Feb 23, 2022
topic: Accept and merge #11577.
comment: #11577 reduces the maximum length of TLS labels.
         It also breaks standards compliance.

Personal notes:
 - My vote is against the current implementation of #11577, which does
   break standard compliance.
   I wouldn't be against an hybrid solution like Matt's at
   openssl/openssl#11577 (comment)
   but I am not capable of saying if the added complexity would be
   balanced by the effective benefits for platforms with limited stack
   resources.
 - My vote here is only on the matter of breaking standards compliance.
   It has nothing to do with the other concerns raised alongside the
   technical discussion in #11577: as I see it, those matters are not
   within the OTC responsibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hold: discussion The community needs to establish a consensus how to move forward with the issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.