Repository navigation
Don't trust the OPENSSL_ia32cap envvar more than the cpuid instruction - #5860
bernd-edlinger wants to merge 3 commits into
Conversation
|
Not that I would endorse following, but if you google for "OPENSSL_ia32cap VPS enforce AES-NI", you'll find people who make use of unmasked value. Not that they do it right, but they seem to appreciate it. One should also recognize that OPENSSL_ia32cap is kind of a troubleshooting thing, i.e. you are supposed to know what you are doing. And taking responsibility for SIGILL is kind of part of knowing what you're doing. Also imagine somebody submits problem report and says "I've assigned this value and get this error". You try to reproduce it and don't get the error. Is it because a bit was masked on reporter's system or yours? I mean if reported has the bit and it was silently masked on your system, you wouldn't know. With unmasked assign you'd get SIGILL and know directly that you can't reproduce the environment. In other words I for one see value in unmasked assign. But sure, I can as well recognize value of masked. So maybe if we choose to do something about it, I'd say that it would be appropriate to recognize more operators. I mean now it recognizes |
|
I just stumbled over this because I looked for getenv which is used in setuid process. |
|
So enabling something that is not supported by the cpuid is probably a nice thing, |
|
I read the article you mentioned, but do you believe the hypervisor will preserve the |
Once again, I'm not endorsing what they do, rather contrary. I'm not even saying that they do the wrong thing right, even here rather contrary :-) What I'm saying is that I see value in unmasked flag assignment nevertheless. Or in other words I argue against suggested modification as it stands now and suggest to consider keeping unmasked assignment, for example by means of recognizing additional operators like As for issetugid. One can probably argue that it would be appropriate to mask value with cpuid in such case, yes. But And whatever outcome would be, OPENSSL_ia32cap.pod would need adjustment. |
I don't follow, what ring0?
You mean non-x86 style when you set SIGILL handler and see if instruction crashes? Rather not. I'd say it would be unnecessary complication (and implicit endorsement of doing wrong thing ;-) |
I mean privileged, like issetguid at least. |
Definitely, but also other OPENSSL_ppccap OPENSSL_armcap and OPENSSL_sparcv9cap |
There was a problem hiding this comment.
unless I am mistaken OPENSSL_ia32cap=0:~1 did not initialize OPENSSL_ia32cap_P[2..3]
and used an uninitialized value in the &= here
There was a problem hiding this comment.
That's why I added the OPENSSL_ia32_cpuid call in ifdef-OPENSSL_OVERRIDE_CPUID above.
There was a problem hiding this comment.
0:~1 did not initialize OPENSSL_ia32cap_P[2..3]
Well, it you set first quadword, then second one is cleared. One of problems is that there are certain relationships between bits in first and second quadwords(*), and instead of tracking them, it's just easier to say that if first quadword is set, second one is simply cleared. Yes, you can sense contradiction, because if there are relationships, then masking bits in first quadword with ~ should track these relationships. Admittedly code is a bit heuristic and user should mostly be aware of what's going on. There are invalid/inappropriate combinations, but tracking them down is daunting task and it's not clear if it's worth the effort... But it might be just me...
(*) For example if you mask xmm, then you shouldn't be using ymm.
|
I'm sorry, but I [for one] am opposed to introduction of another knob. I can accept an argument in favour of conditional masking depending on issetugid (though I don't quite recognize importance yet), but not another knob, sorry. |
|
Sorry, I know if's your baby... But, I think masking certain bits, in the cpuid can not cause anything harmful. |
That's not what I'm hinting at. Me being opposed to additional knob is because I'm opposed to any additional knob, it has nothing to do with the fact that suggested knob affects OPENSSL_ia32cap. Nor am I saying that one can't criticize it, you're welcomed to do so. But I'd be opposed to making it overly complex.
And you can do it as is, just stick with |
405b35a to
96f4640
Compare
There was a problem hiding this comment.
Outcome would be wrong if you clear PMULL and set AES. Because it will never probe for AES. However, instead of treating it as special case, it might be appropriate to simply switch to (mask & CAP) && sigsetjmp() in all cases. Not only will it fix this corner case, it would be more readable. I mean sigsetjmp is effectively part of the probe, so you first decide if you should perform probe, then perform it. As opposite to making half way into probe then deciding if you should proceed to final part of the probe.
There was a problem hiding this comment.
I read the C90 standard very carefully, and it says setjmp must be called only in one of these ways:
An invocation of the setjmp macro shall appear only in one of the
following contexts:
* the entire controlling expression of a selection or iteration statement;
* one operand of a relational or equality operator with the other
operand an integral constant expression, with the resulting expression
being the entire controlling expression of a selection or iteration
statement;
* the operand of a unary ! operator with the resulting expression
being the entire controlling expression of a selection or iteration
statement; or
* the entire expression of an expression statement (possibly cast to void).
so the suggested syntax is non-compliant.
There was a problem hiding this comment.
Would if (mask & (ARMV8_PMULL|ARMV8_AES)) do the right thing?
There was a problem hiding this comment.
This should work:
if (mask & ...)
if (sigsetjmp(....)
There was a problem hiding this comment.
Right, keyword is to flip conditions.
There was a problem hiding this comment.
I'm still opposed to the additional knob. Question is how many would actually use it, especially in suggested form. By this last remark I mean that it would make sense if it would also resolve run-time switches at compile time, and even remove unused code. But otherwise it would really be something for somebody to occasionally test something in non-production environment. But thing is that in such case that somebody can just as well simply temporarily modify the code by adding an assignment followed by return. [I did it at several occasions.] As for making it real in sense that capability override flag would resolve run-time switches and drop unused code. Trade-off here is if savings are worth the trouble of maintaining the #if spaghetti. I mean OpenSSL is not exactly suitable for resource-constrained environments and space savings would be negligible in proportion to the rest.
There was a problem hiding this comment.
For completeness sake I probably should mention that there were suggestions to take run-time switches out of assembly modules and break them into segments so that linker can omit unreferenced code. The question was risen rather in context of code reuse in other projects [more suitable for resource-constrained environments]. I'd say this would be more meaningful goal than to introduce #if spaghetti that would be OpenSSL-specific. However, such goal would have to be supported by multiple projects, there ought to be some synergy...
|
Let me rephrase a little bit. How is suggested modification for x86 essentially different from simply not accepting input without Just in case, once again, it's not like I'm totally opposed to changes in this area, but question still is if it's right moment, and maybe while we at it, then it would be appropriate to go out of the box all the way. Say symbolic names like ~SSE... |
|
First I wanted to be able to meet your request to be able to try out different bits Together with the build_all_generated I do see a use in embedded O/S like I do for instance maintain an Cortex-A8 based eCos environment, Probing the CPU for NEON won't work, because the O/S port does not That's why I thought a compile option would be really what I will need some day. |
|
Looks like we fail to build with --strict-warnings enabed: |
There was a problem hiding this comment.
??? What's wrong with else here?
There was a problem hiding this comment.
if mask = PMULL | AES but runtime check fails the AES check will not be tried.
There was a problem hiding this comment.
previously the else was on the "if (sigsetjmp...)"
but now it is on the "if (mask & PMULL)"
either way I can miss the AES check.
My understanding is that if you don't flip a bit, then NEON instructions will fail. So that if OS doesn't "want" to support NEON, then it just doesn't do anything, bit is off at power-up, instructions will fail, and so probe will work. And of course if it flips the bit, but doesn't do anything at context switch, in which case one can wonder if it's right... Is it actually case? I.e. it flips the bit but doesn't handle context switch? I.e. NEON probe in fact succeeds on Cortex-A8? Though I can understand the desire to avoid the probing even if probe fails.. I don't know much about eCos, are there user vs. kernel lands? If no and code is sufficiently privileged to read that coprocessor register... |
|
Yes, I agree, it that is how you say, then automatic probing will likely do the right thing :) eCos is just a multi-threaded micro-kernel with everything linked statically. |
|
And no guard pages on the tasks! |
55e0ea9 to
376a8e6
Compare
|
ping @dot-asm and @bernd-edlinger to come to an agreement here :) |
|
I believe the only thing missing is to guard use of OPENSSL_ia32cap with the issetuidgid call. There is no point in making this mostly debugging interface fully user-proof. |
|
Thanks, I was considering that as well, but what if the user set OPENSSL_ia32cap |
|
You mean that a setuid app would depend on the caller to set OPENSSL_ia32cap properly otherwise it would not work? I cannot imagine such broken system or said in other way, such broken system deserves its breakage anyway. |
|
But if that is the case, why do we have this kludge at all? |
|
For bug testing, development, performance testing? |
And what I'm saying is that non-NEON option would be all one needs. There is really no point to have OPENSSL_ARMCAP_OVERRIDE. [And again, this is provided that -march=armv6[t2] is deemed unsuitable for the purpose. I mean as it stands now -march=armv6[t2] produces code that is perfectly executable on armv7 processor such as Cortex-A8, but without NEON.] There is one thing I seem to fail to clarify. I merely express my opinion on why I for one consider suggestions suboptimal. If somebody considers suggestion suitable, just approve... |
Well, these are formally "orthogonal" arguments. In sense that if solution is viewed unsafe, then we can't argue "they shouldn't be doing it", because we have to consider ill-minded user, one that would do it on purpose. I want to point out that I haven't actually dismissed(*) the idea of masking capability vectors, I only said that unmasked capability vector assignment does have value/application. At the same time I also said that I can see the value of masking too, just don't recognize significance. In other words in my mind it's "recognized value" on one hand vs. "believe it's just unsafe" on the other. And as long as the latter is formulated like that, I'll be inclined to choose former. And it does mean that if latter formulation was more substantial, I for one would weigh it differently. (*) Biggest objection I have is OPENSS_*CAP_OVERRIDE as additional compile-time knob, and it has nothing to do with masking. |
|
Just in case that is not clear, with the additional compile-time options I have in mind the use case of And what I don't understand, is why these few lines of code that are necessary to handle such |
|
This has nothing to do with set[e]uid handling at all - just supporting that viewpoint. And this mechanism has been used many times to solve issues at runtime for users. |
|
Whew, long thread. This is not a 1.1.1-specific issue, so removing that milestone. |
d99aee6 to
810aa94
Compare
|
Rebased. |
Fixes test failures with illegal values in OPENSSL_ia32cap, i.e.: OPENSSL_ia32cap=0xFFFFFFFFFFFFFFFF:0xFFFFFFFFFFFFFFFF make test Add a configure option -DOPENSSL_IA32CAP_OVERRIDE=x:y Add some documentation for OPENSSL_IA32CAP_OVERRRIDE
Fixes test failures with illegal values in OPENSSL_armcap, i.e.: OPENSSL_armcap=0xFFFFFFFF make test Add a configure option -DOPENSSL_ARMCAP_OVERRIDE=x
Fixes test failures with illegal values in OPENSSL_ppccap, i.e.: OPENSSL_ppccap=0xFFFFFFFF make test Add a configure option -DOPENSSL_PPCCAP_OVERRIDE=x
b8338c4 to
a929ff7
Compare
|
I consider this a security relevant issue. |
|
I think this PR is trying to do multiple things at the same time:
Maybe this PR can be split in 2, so that we can discuss each part on it's own? My understand is, that on some platforms you don't actually want to detect at runtime which instructions are supported by potentially running illegal instructions, because the platform doesn't have proper support for doing that. You want to be able to say at compile time which CPU features you want to support. Not building the assembler that's not supported is not enough, you want to force the use of those that are build without doing the runtime check. |
|
The control by compile flags is just the beginning, in my road map, |
|
I am not sure this is the right approach. I can only repeat that to make it fully security irrelevant I would use ossl_safe_getenv(). There is no point in trying to outsmart the user who would need to already know details about his CPU when he is trying to set the environment variable. |
|
To make it clear I was talking above about this change of the OPENSSL_xxcap semantics as is, not about build-time switching on/off assembler modules/code-paths. I would not be against that one. |
Fixes test failures with illegal values in OPENSSL_ia32cap, i.e.:
OPENSSL_ia32cap=0xFFFFFFFFFFFFFFFF:0xFFFFFFFFFFFFFFFF make test
@dot-asm this one's for you ;)