Updates for SGX 2.17 reproducible build.

Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
This commit is contained in:
Zhang Lili
2022-06-15 11:49:48 +08:00
parent 0f61c27a40
commit 1deb73848a
119 changed files with 2122 additions and 880 deletions
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2011-2021 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "DEFS.h"
/*
* void* __memcpy_verw(void *dst, const void *src)
*
*/
ENTRY(__memcpy_verw)
RETGUARD_SETUP(__memcpy_verw, r10)
movb (%rsi), %al
sub $8, %rsp
mov %ds, (%rsp)
verw (%rsp)
movb %al, (%rdi)
mfence
lfence
add $8, %rsp
movq %rdi, %rax
RETGUARD_CHECK(__memcpy_verw, r10)
ret
END_STRONG(__memcpy_verw)
/*
* void* __memcpy_8a(void *dst, const void *src)
*
*/
ENTRY(__memcpy_8a)
RETGUARD_SETUP(__memcpy_8a, r10)
movq (%rsi), %rax
movq %rax, (%rdi)
movq %rdi, %rax
RETGUARD_CHECK(__memcpy_8a, r10)
ret
END_STRONG(__memcpy_8a)
+44
View File
@@ -48,6 +48,7 @@ typedef long word; /* "word" used for optimal copy speed */
extern void *_intel_fast_memcpy(void *, void *, size_t);
#endif
/*
* Copy a block of memory, not handling overlap.
*/
@@ -100,6 +101,49 @@ done:
return (dst0);
}
extern void* __memcpy_verw(void *dst0, const void *src0);
extern void* __memcpy_8a(void *dst0, const void *src0);
// use in the enclave when dst is outside the enclave
void* memcpy_verw(void *dst0, const void *src0, size_t len)
{
char* dst = dst0;
const char *src = (const char *)src0;
if(len == 0 || dst == src)
{
return dst0;
}
//abort if overlap exist
if ((dst < src && dst + len > src) ||
(src < dst && src + len > dst))
{
abort();
}
while (len >= 8) {
if((unsigned long long)dst%8 == 0) {
// 8-byte-aligned - don't need <VERW><MFENCE LFENCE> bracketing
__memcpy_8a(dst, src);
src += 8;
dst += 8;
len -= 8;
}
else{
// not 8-byte-aligned - need <VERW><MFENCE LFENCE> bracketing
__memcpy_verw(dst, src);
src++;
dst++;
len--;
}
}
// less than 8 bytes left - need <VERW> <MFENCE LFENCE> bracketing
for (unsigned i = 0; i < len; i++) {
__memcpy_verw(dst, src);
src++;
dst++;
}
return dst0;
}
void *
memcpy(void *dst0, const void *src0, size_t length)
+72
View File
@@ -62,3 +62,75 @@ memmove(void *dst0, const void *src0, size_t length)
#endif
}
extern void* __memcpy_verw(void *dst0, const void *src0);
extern void* __memcpy_8a(void *dst0, const void *src0);
void *
memmove_verw(void *dst, const void *src, size_t count)
{
if(count == 0 || dst == src)
{
return dst;
}
if (dst < src)
{
// if src is above dst, we have to copy front to back
// to avoid overwriting the data we want to copy.
char* dst0 = (char*)dst;
const char *src0 = (const char *)src;
while (count >= 8) {
if((unsigned long long)dst0%8 == 0) {
// 8-byte-aligned - don't need <VERW><MFENCE LFENCE> bracketing
__memcpy_8a(dst0, src0);
src0 += 8;
dst0 += 8;
count -= 8;
}
else{
// not 8-byte-aligned - need <VERW><MFENCE LFENCE> bracketing
__memcpy_verw(dst0, src0);
src0++;
dst0++;
count--;
}
}
// less than 8 bytes left - need <VERW> <MFENCE LFENCE> bracketing
for (unsigned i = 0; i < count; i++) {
__memcpy_verw(dst0, src0);
src0++;
dst0++;
}
}
else
{
// If dst is above src, we have to copy back to front
// to avoid overwriting the data we want to copy.
char* dst0 = (char*)dst + count -1;
const char *src0 = (const char *)src + count -1;
while (count >= 8) {
if((unsigned long long)dst0%8 == 7) {
// 8-byte-aligned - don't need <VERW><MFENCE LFENCE> bracketing
__memcpy_8a(dst0 - 7, src0 - 7);
src0 -= 8;
dst0 -= 8;
count -= 8;
}
else{
// not 8-byte-aligned - need <VERW><MFENCE LFENCE> bracketing
__memcpy_verw(dst0, src0);
src0--;
dst0--;
count--;
}
}
// less than 8 bytes left - need <VERW> <MFENCE LFENCE> bracketing
for (unsigned i = 0; i < count; i++) {
__memcpy_verw(dst0, src0);
src0--;
dst0--;
}
}
return dst;
}
+38 -1
View File
@@ -32,6 +32,8 @@
*/
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#ifdef _TLIBC_USE_INTEL_FAST_STRING_
extern void *_intel_fast_memset(void *, void *, size_t);
@@ -39,6 +41,42 @@ extern void *_intel_fast_memset(void *, void *, size_t);
extern void *__memset(void *dst, int c, size_t n);
#endif
extern void* __memcpy_verw(void *dst0, const void *src0);
extern void* __memcpy_8a(void *dst0, const void *src0);
void *
memset_verw(void *dst, int c, size_t len)
{
char* dst0 = dst;
if (len == 0 || dst == NULL)
{
return dst;
}
unsigned char tt = (unsigned char)c;
uint64_t tmp = 0;
memset((void*)&tmp, c, 8);
while (len >= 8) {
if((unsigned long long)dst0%8 == 0) {
// 8-byte-aligned - don't need <VERW><MFENCE LFENCE> bracketing
__memcpy_8a(dst0, (void*)&tmp);
dst0 += 8;
len -= 8;
}
else{
// not 8-byte-aligned - need <VERW><MFENCE LFENCE> bracketing
__memcpy_verw(dst0, (void *)&tt);
dst0++;
len--;
}
}
// less than 8 bytes left - need <VERW> <MFENCE LFENCE> bracketing
for (unsigned i = 0; i < len; i++) {
__memcpy_verw(dst0, (void *)&tt);
dst0++;
}
return dst;
}
void *
memset(void *dst, int c, size_t n)
{
@@ -48,4 +86,3 @@ memset(void *dst, int c, size_t n)
return __memset(dst, c, n);
#endif /* !_TLIBC_USE_INTEL_FAST_STRING_ */
}
+35
View File
@@ -81,3 +81,38 @@ memset_s(void *s, size_t smax, int c, size_t n)
return err;
}
}
errno_t
memset_verw_s(void *s, size_t smax, int c, size_t n)
{
errno_t err = 0;
if (s == NULL) {
err = EINVAL;
goto out;
}
if (smax > SIZE_MAX) {
err = E2BIG;
goto out;
}
if (n > SIZE_MAX) {
err = E2BIG;
n = smax;
}
if (n > smax) {
err = EOVERFLOW;
n = smax;
}
memset_verw(s, c, n);
out:
if (err == 0)
return 0;
else {
errno = err;
/* XXX call runtime-constraint handler */
return err;
}
}