"H.J. Lu" <hjl.tools(a)gmail.com> writes:
> Intel Control-flow Enforcement Technology (CET):
>
> https://software.intel.com/en-us/articles/intel-sdm
>
> contains shadow stack (SHSTK) and indirect branch tracking (IBT). When
> CET is enabled, ELF object files must be marked with .note.gnu.property
> section. Also when IBT is enabled, all indirect branch targets must
> start with ENDBR instruction.
>
> This patch adds X86_ENDBR and the CET marker to config.m4.in when CET
> is enabled. It updates PROLOGUE with X86_ENDBR.
I'd like to have a look at what gcc produces. How is it enabled with
gcc? In the docs, I find
-mshstk
The -mshstk option enables shadow stack built-in functions from x86
Control-flow Enforcement Technology (CET).
but when I try compiling a trivial function,
$ cat foo-cet.c
int foo(void) {return 0;}
$ gcc -save-temps -c -mshstk foo-cet.c
I get no endbr instruction and no note in the foo-cet.s. I'm using
gcc-8.3. I do get an
.section .note.GNU-stack,"",@progbits
corresponding to Nettle's ASM_MARK_NOEXEC_STACK
> --- a/config.m4.in
> +++ b/config.m4.in
> @@ -8,6 +8,10 @@ define(<ALIGN_LOG>, <@ASM_ALIGN_LOG@>)dnl
> define(<W64_ABI>, <@W64_ABI@>)dnl
> define(<RODATA>, <@ASM_RODATA@>)dnl
> define(<WORDS_BIGENDIAN>, <@ASM_WORDS_BIGENDIAN@>)dnl
> +define(<X86_ENDBR>,<@X86_ENDBR@>)dnl
> +divert(1)
> +@X86_GNU_PROPERTY@
> +divert
> divert(1)
> @ASM_MARK_NOEXEC_STACK@
> divert
You can put the two properties in the same m4 divert. Also, please
rename the autoconf substitutions with ASM_ prefix, and something more
descriptive than X64_GNU_PROPERTY. E.g., ASM_X86_ENDBR and
ASM_X86_MARK_CET.
> diff --git a/configure.ac b/configure.ac
> index ba3ab7c6..e9ed630c 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -803,6 +803,82 @@ EOF
> ASM_ALIGN_LOG="$nettle_cv_asm_align_log"
> fi
>
> +dnl Define
> +dnl 1. X86_ENDBR for endbr32/endbr64.
> +dnl 2. X86_GNU_PROPERTY to add a .note.gnu.property section to mark
> +dnl Intel CET support if needed.
> +dnl .section ".note.gnu.property", "a"
> +dnl .p2align POINTER-ALIGN
> +dnl .long 1f - 0f
> +dnl .long 4f - 1f
> +dnl .long 5
> +dnl 0:
> +dnl .asciz "GNU"
> +dnl 1:
> +dnl .p2align POINTER-ALIGN
> +dnl .long 0xc0000002
> +dnl .long 3f - 2f
> +dnl 2:
> +dnl .long 3
> +dnl 3:
> +dnl .p2align POINTER-ALIGN
> +dnl 4:
No need to repeat the definition in full in this comment. And as I think
I've said before, I'm a bit surprised that it needs to be this verbose.
> +AC_CACHE_CHECK([if Intel CET is enabled],
> + [nettle_cv_asm_x86_intel_cet],
> + [AC_TRY_COMPILE([
> +#ifndef __CET__
> +#error Intel CET is not enabled
> +#endif
> + ], [],
> + [nettle_cv_asm_x86_intel_cet=yes],
> + [nettle_cv_asm_x86_intel_cet=no])])
> +if test "$nettle_cv_asm_x86_intel_cet" = yes; then
> + case $ABI in
> + 32|standard)
> + X86_ENDBR=endbr32
> + p2align=2
> + ;;
> + 64)
> + X86_ENDBR=endbr64
> + p2align=3
> + ;;
> + x32)
> + X86_ENDBR=endbr64
> + p2align=2
> + ;;
> + esac
> + AC_CACHE_CHECK([if .note.gnu.property section is needed],
> + [nettle_cv_asm_x86_gnu_property],
> + [AC_TRY_COMPILE([
> +#if !defined __ELF__ || !defined __CET__
> +#error GNU property is not needed
> +#endif
> + ], [],
> + [nettle_cv_asm_x86_gnu_property=yes],
> + [nettle_cv_asm_x86_gnu_property=no])])
> +else
> + nettle_cv_asm_x86_gnu_property=no
> +fi
> +if test "$nettle_cv_asm_x86_gnu_property" = yes; then
> + X86_GNU_PROPERTY="
> + .section \".note.gnu.property\", \"a\"
> + .p2align $p2align
> + .long 1f - 0f
> + .long 4f - 1f
> + .long 5
> +0:
> + .asciz \"GNU\"
> +1:
> + .p2align $p2align
> + .long 0xc0000002
> + .long 3f - 2f
> +2:
> + .long 3
> +3:
> + .p2align $p2align
> +4:"
> +fi
Maybe a bit easier to read if you use single quotes for
X86_GNU_PROPERTY='...', don't escape the inner double quotes. That
leaves the expansion of $p2align, maybe it's better to define a separate
substituted variable for pointer alignment? (If there's no easier way to
enforce pointer-alignment).
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
From: Dmitry Baryshkov <dbaryshkov(a)gmail.com>
Move cmac-des3 meta information from testsuite/cmac-test.c to main
Nettle library.
Signed-off-by: Dmitry Baryshkov <dbaryshkov(a)gmail.com>
---
Makefile.in | 2 +-
cmac-des3-meta.c | 52 +++++++++++++++++++++++++++++++++++++++
nettle-meta-macs.c | 1 +
nettle-meta.h | 1 +
testsuite/cmac-test.c | 12 ---------
testsuite/meta-mac-test.c | 1 +
6 files changed, 56 insertions(+), 13 deletions(-)
create mode 100644 cmac-des3-meta.c
diff --git a/Makefile.in b/Makefile.in
index d4fcb81302a2..ddc304285321 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -103,7 +103,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
gcm-camellia128.c gcm-camellia128-meta.c \
gcm-camellia256.c gcm-camellia256-meta.c \
cmac.c cmac64.c cmac-aes128.c cmac-aes256.c cmac-des3.c \
- cmac-aes128-meta.c cmac-aes256-meta.c \
+ cmac-aes128-meta.c cmac-aes256-meta.c cmac-des3-meta.c \
gost28147.c gosthash94.c gosthash94-meta.c \
hmac.c hmac-gosthash94.c hmac-md5.c hmac-ripemd160.c \
hmac-sha1.c hmac-sha224.c hmac-sha256.c hmac-sha384.c \
diff --git a/cmac-des3-meta.c b/cmac-des3-meta.c
new file mode 100644
index 000000000000..7fdee8e680cf
--- /dev/null
+++ b/cmac-des3-meta.c
@@ -0,0 +1,52 @@
+/* cmac-des3-meta.c
+
+ Copyright (C) 2020 Dmitry Baryshkov
+
+ This file is part of GNU Nettle.
+
+ GNU Nettle is free software: you can redistribute it and/or
+ modify it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ or both in parallel, as here.
+
+ GNU Nettle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see http://www.gnu.org/licenses/.
+*/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
+#include "nettle-meta.h"
+
+#include "cmac.h"
+
+const struct nettle_mac nettle_cmac_des3 =
+{
+ "cmac_des3",
+ sizeof(struct cmac_des3_ctx),
+ CMAC64_DIGEST_SIZE,
+ DES3_KEY_SIZE,
+
+ (nettle_set_key_func*) cmac_des3_set_key,
+ (nettle_hash_update_func*) cmac_des3_update,
+ (nettle_hash_digest_func*) cmac_des3_digest
+};
diff --git a/nettle-meta-macs.c b/nettle-meta-macs.c
index cb9ede851573..a658ee39e230 100644
--- a/nettle-meta-macs.c
+++ b/nettle-meta-macs.c
@@ -40,6 +40,7 @@
const struct nettle_mac * const _nettle_macs[] = {
&nettle_cmac_aes128,
&nettle_cmac_aes256,
+ &nettle_cmac_des3,
&nettle_hmac_md5,
&nettle_hmac_ripemd160,
&nettle_hmac_sha1,
diff --git a/nettle-meta.h b/nettle-meta.h
index 5d86615f94cc..7a6af363426b 100644
--- a/nettle-meta.h
+++ b/nettle-meta.h
@@ -276,6 +276,7 @@ nettle_get_macs (void);
extern const struct nettle_mac nettle_cmac_aes128;
extern const struct nettle_mac nettle_cmac_aes256;
+extern const struct nettle_mac nettle_cmac_des3;
/* HMAC variants with key size = digest size */
extern const struct nettle_mac nettle_hmac_md5;
diff --git a/testsuite/cmac-test.c b/testsuite/cmac-test.c
index 1a2cd0e591cf..a71baa086d01 100644
--- a/testsuite/cmac-test.c
+++ b/testsuite/cmac-test.c
@@ -2,18 +2,6 @@
#include "nettle-internal.h"
#include "cmac.h"
-const struct nettle_mac nettle_cmac_des3 =
-{
- "CMAC-3DES",
- sizeof(struct cmac_des3_ctx),
- CMAC64_DIGEST_SIZE,
- DES3_KEY_SIZE,
-
- (nettle_set_key_func*) cmac_des3_set_key,
- (nettle_hash_update_func*) cmac_des3_update,
- (nettle_hash_digest_func*) cmac_des3_digest
-};
-
#define test_cmac_aes128(key, msg, ref) \
test_mac(&nettle_cmac_aes128, key, msg, ref)
diff --git a/testsuite/meta-mac-test.c b/testsuite/meta-mac-test.c
index 32b6f20f07cd..55339441c99f 100644
--- a/testsuite/meta-mac-test.c
+++ b/testsuite/meta-mac-test.c
@@ -4,6 +4,7 @@
const char* macs[] = {
"cmac_aes128",
"cmac_aes256",
+ "cmac_des3",
"hmac_md5",
"hmac_ripemd160",
"hmac_sha1",
--
2.24.1
Hello, please see the following gnutls issue
https://gitlab.com/gnutls/gnutls/issues/941.
Nettle today is working on aarch64, aarch64_be and arm, but broken on armeb.
You can test it using the following way:
1. Enable CONFIG_X86_X32=y in kernel.
2. Install qemu-user with required arch and start qemu-binfmt service.
Run commands:
docker run -it puchuu/test_aarch64-unknown-linux-gnu bash
env-update && source /etc/profile
MAKEOPTS='-j16' FEATURES='test' emerge -v1 dev-libs/nettle
Unfortunately I can't provide complete armeb image, because its build
depends on working nettle. I can provide only armeb results:
FAIL: chacha
FAIL: memxor
FAIL: ccm
FAIL: pss
FAIL: rsa-pss-sign-tr
5 of 98 tests failed
I am launching "./testsuite/chacha-test" directly, result:
Error, length 7, expected:
76b8e0ada0f13d
Got:
ade0a9f13d9076
qemu: uncaught target signal 6 (Aborted) - core dumped
So it looks like armeb is completely broken today.