Message ID | 20230719142500.13623-1-jo.vanbulck@cs.kuleuven.be (mailing list archive) |
---|---|
Headers | show |
Series | selftests/sgx: Harden test enclave | expand |
On Wed Jul 19, 2023 at 5:24 PM EEST, Jo Van Bulck wrote: > While I understand that the bare-metal Intel SGX selftest enclave is > certainly not intended as a full-featured independent production runtime, > it has been noted on this mailing list before that "people are likely to > copy this code for their own enclaves" and that it provides a "great > starting point if you want to do things from scratch" [1]. Thus, proper and > complete example code is vital for security-sensitive functionality, like the > selftest example enclave. If anyone copied the source code for their own enclave, they would have to publish their source code, given the GPLv2 license. There's a lot of source code in kselftest, which probably has at least some security issues. I'm not sure, at least based on this motivation, why would we care? BR, Jarkko
On 20.07.23 19:25, Jarkko Sakkinen wrote: > There's a lot of source code in kselftest, which probably has at least > some security issues. > > I'm not sure, at least based on this motivation, why would we care? I'd argue that, in general, code examples are often used as templates and may thus inherit any vulnerabilities therein. This may be especially relevant here as your selftest enclave is in my knowledge the only available truly minimal SGX enclave that can be built and extended while only relying on standard tools and no heavy frameworks like the Intel SGX SDK. Thus, as noted before on this mailing list, it may be an attractive start for people who want to build things from scratch. IMHO the example enclave should do a best effort to reasonably follow SGX coding best practices and not have _known_ security vulnerabilities in it. Note that these are not advanced microarchitectural attacks with ugly LFENCE defenses, but plain, architectural memory-safety exploit preventions with minimal sanitization checks, not unlike the existing protections against buffer overflow where best practices are followed for op->type. Apart from that, the added checks only enforce correct behavior in the test framework, only validating that things are sane and as expected. Thus, to some extent, the added checks may even increase resilience of the test framework. Best, Jo
On 7/20/23 12:12, Jo Van Bulck wrote: > On 20.07.23 19:25, Jarkko Sakkinen wrote: >> There's a lot of source code in kselftest, which probably has at least >> some security issues. >> >> I'm not sure, at least based on this motivation, why would we care? > > I'd argue that, in general, code examples are often used as templates > and may thus inherit any vulnerabilities therein. This may be especially > relevant here as your selftest enclave is in my knowledge the only > available truly minimal SGX enclave that can be built and extended while > only relying on standard tools and no heavy frameworks like the Intel > SGX SDK. Thus, as noted before on this mailing list, it may be an > attractive start for people who want to build things from scratch. > > IMHO the example enclave should do a best effort to reasonably follow > SGX coding best practices and not have _known_ security vulnerabilities > in it. On the other hand, if we don't leave glaring, known "security" vulnerabilities in it, even more people will be fooled into trying to use our example code for something that needs actual security. I personally don't know the first thing about writing a secure enclave. I just know it's _really_ hard and I honestly don't expect someone to do it without the help of the SDK.
On 20.07.23 21:56, Dave Hansen wrote: > On the other hand, if we don't leave glaring, known "security" > vulnerabilities in it, even more people will be fooled into trying to > use our example code for something that needs actual security. I see the reasoning, but I'm afraid it's generally hard to stop people from copying good examples as templates for their own projects.. I do believe in the value of clean, minimal open-source example enclave code. In this respect, I personally (and others on the past mailing list as well, it seems) really like the minimal self-contained Linux selftest enclave! I think, with the fixes in this patch series, the Linux selftest enclave can continue to bring value to the community and help in further diversifying the open-source SGX ecosystem. FWIW, I'd not call these "glaring" security holes, but rather subtle oversights that I think most people who would copy the code today may well not be aware of and inherit unknowingly (e.g., reference [2] from my original message did a wide-scale study of the open-source SGX ecosystem as of 2019 and showed exactly these kinds of ABI/API vulnerabilities were widespread and re-occurring in several SGX production projects). > I personally don't know the first thing about writing a secure enclave. > I just know it's _really_ hard and I honestly don't expect someone to do > it without the help of the SDK. Agreed, it _is_ hard indeed. And it has been a moving target over the years, especially with software/compiler defenses for different waves of microarchitectural vulnerabilities (Spectre, LVI, etc.). That being said, I do think that we learned a lot as a community and we have a much better grasp on how to write (reasonably) secure enclave software these days. Sanitizing the ABI and API remains a core enclave software responsibility (whereas microarchitectural attacks can arguably be mostly mitigated through hardware silicon/ucode patches and/or automatic compiler mitigations). I do agree that sane end users should use a shielding runtime to abstract away most of these concerns, where the Intel SGX SDK is just one of many in a growing open-source SGX ecosystem (see for instance earlier references [2,3] for an overview). But there may be good reasons to want to do things from scratch when building your own SGX shielding runtime, e.g., support for custom languages (Rust, Go) or library OSs. I think the Linux selftest enclave helps in further diversifying the open-source SGX ecosystem and can provide an excellent starting point (with the fixes in this patch series). Best, Jo
On Thu Jul 20, 2023 at 7:12 PM UTC, Jo Van Bulck wrote: > On 20.07.23 19:25, Jarkko Sakkinen wrote: > > There's a lot of source code in kselftest, which probably has at least > > some security issues. > > > > I'm not sure, at least based on this motivation, why would we care? > > I'd argue that, in general, code examples are often used as templates > and may thus inherit any vulnerabilities therein. This may be especially > relevant here as your selftest enclave is in my knowledge the only > available truly minimal SGX enclave that can be built and extended while > only relying on standard tools and no heavy frameworks like the Intel > SGX SDK. Thus, as noted before on this mailing list, it may be an > attractive start for people who want to build things from scratch. If you use this code as a template, you have a legal risk in your hands because of GPLv2 licensing. > IMHO the example enclave should do a best effort to reasonably follow > SGX coding best practices and not have _known_ security vulnerabilities > in it. Note that these are not advanced microarchitectural attacks with > ugly LFENCE defenses, but plain, architectural memory-safety exploit > preventions with minimal sanitization checks, not unlike the existing > protections against buffer overflow where best practices are followed > for op->type. I'm not sure what are the "best practices" behavior in the context of a kselftest instance. > Apart from that, the added checks only enforce correct behavior in the > test framework, only validating that things are sane and as expected. > Thus, to some extent, the added checks may even increase resilience of > the test framework. I'm not sure what is "correct" behavior in the context of a kselftest instance. > Best, > Jo This code is not meant for production. I implemented it specifically for kselftest, and that is exactly its scope. BR, Jarkko
On 22.07.23 20:10, Jarkko Sakkinen wrote: > This code is not meant for production. I implemented it specifically for > kselftest, and that is exactly its scope. I see, makes sense. As per Dave's suggestion, I'll see if I can submit a proposed minimal patch to remove any existing sanitization code that is not necessary for kselftest (eg register cleansing) and avoid any misguided impressions of the test enclave being representative. > I'm not sure what is "correct" behavior in the context of a kselftest > instance. True. But at least when defining "correct" as passing the selftests, then I think it makes sense to merge the compiler optimization fixes. As the existing code clearly emits wrong assembly that breaks the selftests when switching optimization levels (which may always also be incorporated by default in future gcc versions or other compilers like clang). Thus, I'll separate this out and submit another patch to ensure correctness with compiler optimizations only. Best, Jo
On Mon Jul 24, 2023 at 10:46 AM UTC, Jo Van Bulck wrote: > On 22.07.23 20:10, Jarkko Sakkinen wrote: > > This code is not meant for production. I implemented it specifically for > > kselftest, and that is exactly its scope. > > I see, makes sense. As per Dave's suggestion, I'll see if I can submit a > proposed minimal patch to remove any existing sanitization code that is > not necessary for kselftest (eg register cleansing) and avoid any > misguided impressions of the test enclave being representative. > > > I'm not sure what is "correct" behavior in the context of a kselftest > > instance. > > True. But at least when defining "correct" as passing the selftests, > then I think it makes sense to merge the compiler optimization fixes. As > the existing code clearly emits wrong assembly that breaks the selftests > when switching optimization levels (which may always also be > incorporated by default in future gcc versions or other compilers like > clang). > > Thus, I'll separate this out and submit another patch to ensure > correctness with compiler optimizations only. > > Best, > Jo It should be relatively easy to relicense the code as most of the commits have Intel copyright. Personally I would not mind because that would give opportunity for code that I wrote to have a wider audience but it needs to be forked with some other license first. BR, Jarkko
On 28.07.23 20:54, Jarkko Sakkinen wrote > It should be relatively easy to relicense the code as most of the > commits have Intel copyright. > > Personally I would not mind because that would give opportunity for > code that I wrote to have a wider audience but it needs to be forked > with some other license first. > I support also the idea of refining the selftest as a run-time, which > could perhaps consist of the following steps: > > 1. Create a repository of the self-compiling selftest with GPLv2. You > could add also AUTHORS file for the initial content by crawling this > data from the git log. > 2. Create a commit with sob's from the required stakeholders, which > changes the license to something more appropriate, and get the > sob's with some process. Thank you Jarkko, appreciated! I plan to start working on the fork from next month onwards. However, I think GPL would be the best license for this project and I'd prefer to stick to it for the time being. Best, Jo
On Mon Aug 7, 2023 at 9:06 AM EEST, Jo Van Bulck wrote: > On 28.07.23 20:54, Jarkko Sakkinen wrote > > It should be relatively easy to relicense the code as most of the > > commits have Intel copyright. > > > > Personally I would not mind because that would give opportunity for > > code that I wrote to have a wider audience but it needs to be forked > > with some other license first. > > > I support also the idea of refining the selftest as a run-time, which > > could perhaps consist of the following steps: > > > > 1. Create a repository of the self-compiling selftest with GPLv2. You > > could add also AUTHORS file for the initial content by crawling this > > data from the git log. > > 2. Create a commit with sob's from the required stakeholders, which > > changes the license to something more appropriate, and get the > > sob's with some process. > > Thank you Jarkko, appreciated! I plan to start working on the fork from > next month onwards. However, I think GPL would be the best license for > this project and I'd prefer to stick to it for the time being. > > Best, > Jo Ask from me permission when you have things moving forward, and I'll very likely give permission to all my post-Intel contributions, which are not that many. PS. You can quite easily get full authors list with some git magic so pretty easy to keep things legal wise in shape. BR, Jarkko