summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch176
-rw-r--r--meta/recipes-support/libgcrypt/files/CVE-2019-12904_p2.patch330
-rw-r--r--meta/recipes-support/libgcrypt/libgcrypt_1.8.4.bb2
3 files changed, 508 insertions, 0 deletions
diff --git a/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch b/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch
new file mode 100644
index 0000000000..cda52119ba
--- /dev/null
+++ b/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch
@@ -0,0 +1,176 @@
1From 263ad8ae08f287e32656d4e3e0116479f3d9ad9d Mon Sep 17 00:00:00 2001
2From: Jussi Kivilinna <jussi.kivilinna@iki.fi>
3Date: Fri, 31 May 2019 17:27:25 +0300
4Subject: [PATCH] GCM: move look-up table to .data section and unshare between processes
5Reply-To: shuagr@microsoft.com
6
7CVE: CVE-2019-12904_p1
8Upstream-Status: Backport
9Signed-off-by: Shubham Agrawal<shuagr@microsoft.com>
10Upstream-commit : https://github.com/gpg/libgcrypt/commit/a4c561aab1014c3630bc88faf6f5246fee16b020
11
12* cipher/cipher-gcm.c (ATTR_ALIGNED_64): New.
13(gcmR): Move to 'gcm_table' structure.
14(gcm_table): New structure for look-up table with counters before and
15after.
16(gcmR): New macro.
17(prefetch_table): Handle input with length not multiple of 256.
18(do_prefetch_tables): Modify pre- and post-table counters to unshare
19look-up table pages between processes.
20--
21GnuPG-bug-id: 4541
22Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
23---
24 cipher/cipher-gcm.c | 129 ++++++++++++++++++++++++++++++++++++++--------------
25 1 file changed, 95 insertions(+), 34 deletions(-)
26
27diff --git a/cipher/cipher-gcm.c b/cipher/cipher-gcm.c
28index 6169d14..97a8015 100644
29--- a/cipher/cipher-gcm.c
30+++ b/cipher/cipher-gcm.c
31@@ -30,6 +30,14 @@
32 #include "./cipher-internal.h"
33
34
35+/* Helper macro to force alignment to 16 or 64 bytes. */
36+#ifdef HAVE_GCC_ATTRIBUTE_ALIGNED
37+# define ATTR_ALIGNED_64 __attribute__ ((aligned (64)))
38+#else
39+# define ATTR_ALIGNED_64
40+#endif
41+
42+
43 #ifdef GCM_USE_INTEL_PCLMUL
44 extern void _gcry_ghash_setup_intel_pclmul (gcry_cipher_hd_t c);
45
46@@ -63,40 +71,93 @@ ghash_armv8_ce_pmull (gcry_cipher_hd_t c, byte *result, const byte *buf,
47
48
49 #ifdef GCM_USE_TABLES
50-static const u16 gcmR[256] = {
51- 0x0000, 0x01c2, 0x0384, 0x0246, 0x0708, 0x06ca, 0x048c, 0x054e,
52- 0x0e10, 0x0fd2, 0x0d94, 0x0c56, 0x0918, 0x08da, 0x0a9c, 0x0b5e,
53- 0x1c20, 0x1de2, 0x1fa4, 0x1e66, 0x1b28, 0x1aea, 0x18ac, 0x196e,
54- 0x1230, 0x13f2, 0x11b4, 0x1076, 0x1538, 0x14fa, 0x16bc, 0x177e,
55- 0x3840, 0x3982, 0x3bc4, 0x3a06, 0x3f48, 0x3e8a, 0x3ccc, 0x3d0e,
56- 0x3650, 0x3792, 0x35d4, 0x3416, 0x3158, 0x309a, 0x32dc, 0x331e,
57- 0x2460, 0x25a2, 0x27e4, 0x2626, 0x2368, 0x22aa, 0x20ec, 0x212e,
58- 0x2a70, 0x2bb2, 0x29f4, 0x2836, 0x2d78, 0x2cba, 0x2efc, 0x2f3e,
59- 0x7080, 0x7142, 0x7304, 0x72c6, 0x7788, 0x764a, 0x740c, 0x75ce,
60- 0x7e90, 0x7f52, 0x7d14, 0x7cd6, 0x7998, 0x785a, 0x7a1c, 0x7bde,
61- 0x6ca0, 0x6d62, 0x6f24, 0x6ee6, 0x6ba8, 0x6a6a, 0x682c, 0x69ee,
62- 0x62b0, 0x6372, 0x6134, 0x60f6, 0x65b8, 0x647a, 0x663c, 0x67fe,
63- 0x48c0, 0x4902, 0x4b44, 0x4a86, 0x4fc8, 0x4e0a, 0x4c4c, 0x4d8e,
64- 0x46d0, 0x4712, 0x4554, 0x4496, 0x41d8, 0x401a, 0x425c, 0x439e,
65- 0x54e0, 0x5522, 0x5764, 0x56a6, 0x53e8, 0x522a, 0x506c, 0x51ae,
66- 0x5af0, 0x5b32, 0x5974, 0x58b6, 0x5df8, 0x5c3a, 0x5e7c, 0x5fbe,
67- 0xe100, 0xe0c2, 0xe284, 0xe346, 0xe608, 0xe7ca, 0xe58c, 0xe44e,
68- 0xef10, 0xeed2, 0xec94, 0xed56, 0xe818, 0xe9da, 0xeb9c, 0xea5e,
69- 0xfd20, 0xfce2, 0xfea4, 0xff66, 0xfa28, 0xfbea, 0xf9ac, 0xf86e,
70- 0xf330, 0xf2f2, 0xf0b4, 0xf176, 0xf438, 0xf5fa, 0xf7bc, 0xf67e,
71- 0xd940, 0xd882, 0xdac4, 0xdb06, 0xde48, 0xdf8a, 0xddcc, 0xdc0e,
72- 0xd750, 0xd692, 0xd4d4, 0xd516, 0xd058, 0xd19a, 0xd3dc, 0xd21e,
73- 0xc560, 0xc4a2, 0xc6e4, 0xc726, 0xc268, 0xc3aa, 0xc1ec, 0xc02e,
74- 0xcb70, 0xcab2, 0xc8f4, 0xc936, 0xcc78, 0xcdba, 0xcffc, 0xce3e,
75- 0x9180, 0x9042, 0x9204, 0x93c6, 0x9688, 0x974a, 0x950c, 0x94ce,
76- 0x9f90, 0x9e52, 0x9c14, 0x9dd6, 0x9898, 0x995a, 0x9b1c, 0x9ade,
77- 0x8da0, 0x8c62, 0x8e24, 0x8fe6, 0x8aa8, 0x8b6a, 0x892c, 0x88ee,
78- 0x83b0, 0x8272, 0x8034, 0x81f6, 0x84b8, 0x857a, 0x873c, 0x86fe,
79- 0xa9c0, 0xa802, 0xaa44, 0xab86, 0xaec8, 0xaf0a, 0xad4c, 0xac8e,
80- 0xa7d0, 0xa612, 0xa454, 0xa596, 0xa0d8, 0xa11a, 0xa35c, 0xa29e,
81- 0xb5e0, 0xb422, 0xb664, 0xb7a6, 0xb2e8, 0xb32a, 0xb16c, 0xb0ae,
82- 0xbbf0, 0xba32, 0xb874, 0xb9b6, 0xbcf8, 0xbd3a, 0xbf7c, 0xbebe,
83-};
84+static struct
85+{
86+ volatile u32 counter_head;
87+ u32 cacheline_align[64 / 4 - 1];
88+ u16 R[256];
89+ volatile u32 counter_tail;
90+} gcm_table ATTR_ALIGNED_64 =
91+ {
92+ 0,
93+ { 0, },
94+ {
95+ 0x0000, 0x01c2, 0x0384, 0x0246, 0x0708, 0x06ca, 0x048c, 0x054e,
96+ 0x0e10, 0x0fd2, 0x0d94, 0x0c56, 0x0918, 0x08da, 0x0a9c, 0x0b5e,
97+ 0x1c20, 0x1de2, 0x1fa4, 0x1e66, 0x1b28, 0x1aea, 0x18ac, 0x196e,
98+ 0x1230, 0x13f2, 0x11b4, 0x1076, 0x1538, 0x14fa, 0x16bc, 0x177e,
99+ 0x3840, 0x3982, 0x3bc4, 0x3a06, 0x3f48, 0x3e8a, 0x3ccc, 0x3d0e,
100+ 0x3650, 0x3792, 0x35d4, 0x3416, 0x3158, 0x309a, 0x32dc, 0x331e,
101+ 0x2460, 0x25a2, 0x27e4, 0x2626, 0x2368, 0x22aa, 0x20ec, 0x212e,
102+ 0x2a70, 0x2bb2, 0x29f4, 0x2836, 0x2d78, 0x2cba, 0x2efc, 0x2f3e,
103+ 0x7080, 0x7142, 0x7304, 0x72c6, 0x7788, 0x764a, 0x740c, 0x75ce,
104+ 0x7e90, 0x7f52, 0x7d14, 0x7cd6, 0x7998, 0x785a, 0x7a1c, 0x7bde,
105+ 0x6ca0, 0x6d62, 0x6f24, 0x6ee6, 0x6ba8, 0x6a6a, 0x682c, 0x69ee,
106+ 0x62b0, 0x6372, 0x6134, 0x60f6, 0x65b8, 0x647a, 0x663c, 0x67fe,
107+ 0x48c0, 0x4902, 0x4b44, 0x4a86, 0x4fc8, 0x4e0a, 0x4c4c, 0x4d8e,
108+ 0x46d0, 0x4712, 0x4554, 0x4496, 0x41d8, 0x401a, 0x425c, 0x439e,
109+ 0x54e0, 0x5522, 0x5764, 0x56a6, 0x53e8, 0x522a, 0x506c, 0x51ae,
110+ 0x5af0, 0x5b32, 0x5974, 0x58b6, 0x5df8, 0x5c3a, 0x5e7c, 0x5fbe,
111+ 0xe100, 0xe0c2, 0xe284, 0xe346, 0xe608, 0xe7ca, 0xe58c, 0xe44e,
112+ 0xef10, 0xeed2, 0xec94, 0xed56, 0xe818, 0xe9da, 0xeb9c, 0xea5e,
113+ 0xfd20, 0xfce2, 0xfea4, 0xff66, 0xfa28, 0xfbea, 0xf9ac, 0xf86e,
114+ 0xf330, 0xf2f2, 0xf0b4, 0xf176, 0xf438, 0xf5fa, 0xf7bc, 0xf67e,
115+ 0xd940, 0xd882, 0xdac4, 0xdb06, 0xde48, 0xdf8a, 0xddcc, 0xdc0e,
116+ 0xd750, 0xd692, 0xd4d4, 0xd516, 0xd058, 0xd19a, 0xd3dc, 0xd21e,
117+ 0xc560, 0xc4a2, 0xc6e4, 0xc726, 0xc268, 0xc3aa, 0xc1ec, 0xc02e,
118+ 0xcb70, 0xcab2, 0xc8f4, 0xc936, 0xcc78, 0xcdba, 0xcffc, 0xce3e,
119+ 0x9180, 0x9042, 0x9204, 0x93c6, 0x9688, 0x974a, 0x950c, 0x94ce,
120+ 0x9f90, 0x9e52, 0x9c14, 0x9dd6, 0x9898, 0x995a, 0x9b1c, 0x9ade,
121+ 0x8da0, 0x8c62, 0x8e24, 0x8fe6, 0x8aa8, 0x8b6a, 0x892c, 0x88ee,
122+ 0x83b0, 0x8272, 0x8034, 0x81f6, 0x84b8, 0x857a, 0x873c, 0x86fe,
123+ 0xa9c0, 0xa802, 0xaa44, 0xab86, 0xaec8, 0xaf0a, 0xad4c, 0xac8e,
124+ 0xa7d0, 0xa612, 0xa454, 0xa596, 0xa0d8, 0xa11a, 0xa35c, 0xa29e,
125+ 0xb5e0, 0xb422, 0xb664, 0xb7a6, 0xb2e8, 0xb32a, 0xb16c, 0xb0ae,
126+ 0xbbf0, 0xba32, 0xb874, 0xb9b6, 0xbcf8, 0xbd3a, 0xbf7c, 0xbebe,
127+ },
128+ 0
129+ };
130+
131+#define gcmR gcm_table.R
132+static inline
133+void prefetch_table(const void *tab, size_t len)
134+{
135+ const volatile byte *vtab = tab;
136+ size_t i;
137+
138+ for (i = 0; len - i >= 8 * 32; i += 8 * 32)
139+ {
140+ (void)vtab[i + 0 * 32];
141+ (void)vtab[i + 1 * 32];
142+ (void)vtab[i + 2 * 32];
143+ (void)vtab[i + 3 * 32];
144+ (void)vtab[i + 4 * 32];
145+ (void)vtab[i + 5 * 32];
146+ (void)vtab[i + 6 * 32];
147+ (void)vtab[i + 7 * 32];
148+ }
149+ for (; i < len; i += 32)
150+ {
151+ (void)vtab[i];
152+ }
153+
154+ (void)vtab[len - 1];
155+}
156+
157+static inline void
158+do_prefetch_tables (const void *gcmM, size_t gcmM_size)
159+{
160+ /* Modify counters to trigger copy-on-write and unsharing if physical pages
161+ * of look-up table are shared between processes. Modifying counters also
162+ * causes checksums for pages to change and hint same-page merging algorithm
163+ * that these pages are frequently changing. */
164+ gcm_table.counter_head++;
165+ gcm_table.counter_tail++;
166+
167+ /* Prefetch look-up tables to cache. */
168+ prefetch_table(gcmM, gcmM_size);
169+ prefetch_table(&gcm_table, sizeof(gcm_table));
170+}
171
172 #ifdef GCM_TABLES_USE_U64
173 static void
174--
1752.7.4
176
diff --git a/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p2.patch b/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p2.patch
new file mode 100644
index 0000000000..0cb503ed65
--- /dev/null
+++ b/meta/recipes-support/libgcrypt/files/CVE-2019-12904_p2.patch
@@ -0,0 +1,330 @@
1From a5c359cc68a4def9bf39f63070837d89711b4e17 Mon Sep 17 00:00:00 2001
2From: Jussi Kivilinna <jussi.kivilinna@iki.fi>
3Date: Fri, 31 May 2019 17:18:09 +0300
4Subject: [PATCH] AES: move look-up tables to .data section and unshare between processes
5Reply-To: shuagr@microsoft.com
6
7CVE: CVE-2019-12904_p2
8Upstream-status: Backport
9Signed-off-by: Shubham Agrawal<shuagr@microsoft.com>
10Upstream-commit: https://github.com/gpg/libgcrypt/commit/daedbbb5541cd8ecda1459d3b843ea4d92788762
11
12* cipher/rijndael-internal.h (ATTR_ALIGNED_64): New.
13* cipher/rijndael-tables.h (encT): Move to 'enc_tables' structure.
14(enc_tables): New structure for encryption table with counters before
15and after.
16(encT): New macro.
17(dec_tables): Add counters before and after encryption table; Move
18from .rodata to .data section.
19(do_encrypt): Change 'encT' to 'enc_tables.T'.
20(do_decrypt): Change '&dec_tables' to 'dec_tables.T'.
21* cipher/cipher-gcm.c (prefetch_table): Make inline; Handle input
22with length not multiple of 256.
23(prefetch_enc, prefetch_dec): Modify pre- and post-table counters
24to unshare look-up table pages between processes.
25--
26
27GnuPG-bug-id: 4541
28Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
29---
30 cipher/rijndael-internal.h | 4 +-
31 cipher/rijndael-tables.h | 155 +++++++++++++++++++++++++--------------------
32 cipher/rijndael.c | 35 ++++++++--
33 3 files changed, 118 insertions(+), 76 deletions(-)
34
35diff --git a/cipher/rijndael-internal.h b/cipher/rijndael-internal.h
36index 160fb8c..a62d4b7 100644
37--- a/cipher/rijndael-internal.h
38+++ b/cipher/rijndael-internal.h
39@@ -29,11 +29,13 @@
40 #define BLOCKSIZE (128/8)
41
42
43-/* Helper macro to force alignment to 16 bytes. */
44+/* Helper macro to force alignment to 16 or 64 bytes. */
45 #ifdef HAVE_GCC_ATTRIBUTE_ALIGNED
46 # define ATTR_ALIGNED_16 __attribute__ ((aligned (16)))
47+# define ATTR_ALIGNED_64 __attribute__ ((aligned (64)))
48 #else
49 # define ATTR_ALIGNED_16
50+# define ATTR_ALIGNED_64
51 #endif
52
53
54diff --git a/cipher/rijndael-tables.h b/cipher/rijndael-tables.h
55index 8359470..b54d959 100644
56--- a/cipher/rijndael-tables.h
57+++ b/cipher/rijndael-tables.h
58@@ -21,80 +21,98 @@
59 /* To keep the actual implementation at a readable size we use this
60 include file to define the tables. */
61
62-static const u32 encT[256] =
63+static struct
64+{
65+ volatile u32 counter_head;
66+ u32 cacheline_align[64 / 4 - 1];
67+ u32 T[256];
68+ volatile u32 counter_tail;
69+} enc_tables ATTR_ALIGNED_64 =
70 {
71- 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6,
72- 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
73- 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
74- 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec,
75- 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa,
76- 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
77- 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45,
78- 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b,
79- 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c,
80- 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
81- 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9,
82- 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
83- 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d,
84- 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f,
85- 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
86- 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea,
87- 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34,
88- 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
89- 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d,
90- 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
91- 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1,
92- 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6,
93- 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972,
94- 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
95- 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed,
96- 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511,
97- 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe,
98- 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b,
99- 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05,
100- 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
101- 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142,
102- 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf,
103- 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3,
104- 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e,
105- 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a,
106- 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
107- 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3,
108- 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b,
109- 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428,
110- 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
111- 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14,
112- 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
113- 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4,
114- 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2,
115- 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
116- 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949,
117- 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf,
118- 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
119- 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c,
120- 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
121- 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e,
122- 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f,
123- 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc,
124- 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
125- 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969,
126- 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27,
127- 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122,
128- 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433,
129- 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9,
130- 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
131- 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a,
132- 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0,
133- 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e,
134- 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c
135+ 0,
136+ { 0, },
137+ {
138+ 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6,
139+ 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
140+ 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
141+ 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec,
142+ 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa,
143+ 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
144+ 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45,
145+ 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b,
146+ 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c,
147+ 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
148+ 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9,
149+ 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
150+ 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d,
151+ 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f,
152+ 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
153+ 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea,
154+ 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34,
155+ 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
156+ 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d,
157+ 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
158+ 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1,
159+ 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6,
160+ 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972,
161+ 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
162+ 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed,
163+ 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511,
164+ 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe,
165+ 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b,
166+ 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05,
167+ 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
168+ 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142,
169+ 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf,
170+ 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3,
171+ 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e,
172+ 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a,
173+ 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
174+ 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3,
175+ 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b,
176+ 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428,
177+ 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
178+ 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14,
179+ 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
180+ 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4,
181+ 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2,
182+ 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
183+ 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949,
184+ 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf,
185+ 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
186+ 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c,
187+ 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
188+ 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e,
189+ 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f,
190+ 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc,
191+ 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
192+ 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969,
193+ 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27,
194+ 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122,
195+ 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433,
196+ 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9,
197+ 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
198+ 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a,
199+ 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0,
200+ 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e,
201+ 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c
202+ },
203+ 0
204 };
205
206-static const struct
207+#define encT enc_tables.T
208+
209+static struct
210 {
211+ volatile u32 counter_head;
212+ u32 cacheline_align[64 / 4 - 1];
213 u32 T[256];
214 byte inv_sbox[256];
215-} dec_tables =
216+ volatile u32 counter_tail;
217+} dec_tables ATTR_ALIGNED_64 =
218 {
219+ 0,
220+ { 0, },
221 {
222 0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a,
223 0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b,
224@@ -194,7 +212,8 @@ static const struct
225 0xc8,0xeb,0xbb,0x3c,0x83,0x53,0x99,0x61,
226 0x17,0x2b,0x04,0x7e,0xba,0x77,0xd6,0x26,
227 0xe1,0x69,0x14,0x63,0x55,0x21,0x0c,0x7d
228- }
229+ },
230+ 0
231 };
232
233 #define decT dec_tables.T
234diff --git a/cipher/rijndael.c b/cipher/rijndael.c
235index 8637195..d0edab2 100644
236--- a/cipher/rijndael.c
237+++ b/cipher/rijndael.c
238@@ -227,11 +227,11 @@ static const char *selftest(void);
239
240
241 /* Prefetching for encryption/decryption tables. */
242-static void prefetch_table(const volatile byte *tab, size_t len)
243+static inline void prefetch_table(const volatile byte *tab, size_t len)
244 {
245 size_t i;
246
247- for (i = 0; i < len; i += 8 * 32)
248+ for (i = 0; len - i >= 8 * 32; i += 8 * 32)
249 {
250 (void)tab[i + 0 * 32];
251 (void)tab[i + 1 * 32];
252@@ -242,17 +242,37 @@ static void prefetch_table(const volatile byte *tab, size_t len)
253 (void)tab[i + 6 * 32];
254 (void)tab[i + 7 * 32];
255 }
256+ for (; i < len; i += 32)
257+ {
258+ (void)tab[i];
259+ }
260
261 (void)tab[len - 1];
262 }
263
264 static void prefetch_enc(void)
265 {
266- prefetch_table((const void *)encT, sizeof(encT));
267+ /* Modify counters to trigger copy-on-write and unsharing if physical pages
268+ * of look-up table are shared between processes. Modifying counters also
269+ * causes checksums for pages to change and hint same-page merging algorithm
270+ * that these pages are frequently changing. */
271+ enc_tables.counter_head++;
272+ enc_tables.counter_tail++;
273+
274+ /* Prefetch look-up tables to cache. */
275+ prefetch_table((const void *)&enc_tables, sizeof(enc_tables));
276 }
277
278 static void prefetch_dec(void)
279 {
280+ /* Modify counters to trigger copy-on-write and unsharing if physical pages
281+ * of look-up table are shared between processes. Modifying counters also
282+ * causes checksums for pages to change and hint same-page merging algorithm
283+ * that these pages are frequently changing. */
284+ dec_tables.counter_head++;
285+ dec_tables.counter_tail++;
286+
287+ /* Prefetch look-up tables to cache. */
288 prefetch_table((const void *)&dec_tables, sizeof(dec_tables));
289 }
290
291@@ -737,7 +757,7 @@ do_encrypt (const RIJNDAEL_context *ctx,
292 #ifdef USE_AMD64_ASM
293 # ifdef HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS
294 return _gcry_aes_amd64_encrypt_block(ctx->keyschenc, bx, ax, ctx->rounds,
295- encT);
296+ enc_tables.T);
297 # else
298 /* Call SystemV ABI function without storing non-volatile XMM registers,
299 * as target function does not use vector instruction sets. */
300@@ -757,7 +777,8 @@ do_encrypt (const RIJNDAEL_context *ctx,
301 return ret;
302 # endif /* HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS */
303 #elif defined(USE_ARM_ASM)
304- return _gcry_aes_arm_encrypt_block(ctx->keyschenc, bx, ax, ctx->rounds, encT);
305+ return _gcry_aes_arm_encrypt_block(ctx->keyschenc, bx, ax, ctx->rounds,
306+ enc_tables.T);
307 #else
308 return do_encrypt_fn (ctx, bx, ax);
309 #endif /* !USE_ARM_ASM && !USE_AMD64_ASM*/
310@@ -1120,7 +1141,7 @@ do_decrypt (const RIJNDAEL_context *ctx, unsigned char *bx,
311 #ifdef USE_AMD64_ASM
312 # ifdef HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS
313 return _gcry_aes_amd64_decrypt_block(ctx->keyschdec, bx, ax, ctx->rounds,
314- &dec_tables);
315+ dec_tables.T);
316 # else
317 /* Call SystemV ABI function without storing non-volatile XMM registers,
318 * as target function does not use vector instruction sets. */
319@@ -1141,7 +1162,7 @@ do_decrypt (const RIJNDAEL_context *ctx, unsigned char *bx,
320 # endif /* HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS */
321 #elif defined(USE_ARM_ASM)
322 return _gcry_aes_arm_decrypt_block(ctx->keyschdec, bx, ax, ctx->rounds,
323- &dec_tables);
324+ dec_tables.T);
325 #else
326 return do_decrypt_fn (ctx, bx, ax);
327 #endif /*!USE_ARM_ASM && !USE_AMD64_ASM*/
328--
3292.7.4
330
diff --git a/meta/recipes-support/libgcrypt/libgcrypt_1.8.4.bb b/meta/recipes-support/libgcrypt/libgcrypt_1.8.4.bb
index fda68a2938..13d037880b 100644
--- a/meta/recipes-support/libgcrypt/libgcrypt_1.8.4.bb
+++ b/meta/recipes-support/libgcrypt/libgcrypt_1.8.4.bb
@@ -21,6 +21,8 @@ SRC_URI = "${GNUPG_MIRROR}/libgcrypt/libgcrypt-${PV}.tar.bz2 \
21 file://0003-tests-bench-slope.c-workaround-ICE-failure-on-mips-w.patch \ 21 file://0003-tests-bench-slope.c-workaround-ICE-failure-on-mips-w.patch \
22 file://0002-libgcrypt-fix-building-error-with-O2-in-sysroot-path.patch \ 22 file://0002-libgcrypt-fix-building-error-with-O2-in-sysroot-path.patch \
23 file://0004-tests-Makefile.am-fix-undefined-reference-to-pthread.patch \ 23 file://0004-tests-Makefile.am-fix-undefined-reference-to-pthread.patch \
24 file://CVE-2019-12904_p1.patch \
25 file://CVE-2019-12904_p2.patch \
24" 26"
25SRC_URI[md5sum] = "fbfdaebbbc6d7e5fbbf6ffdb3e139573" 27SRC_URI[md5sum] = "fbfdaebbbc6d7e5fbbf6ffdb3e139573"
26SRC_URI[sha256sum] = "f638143a0672628fde0cad745e9b14deb85dffb175709cacc1f4fe24b93f2227" 28SRC_URI[sha256sum] = "f638143a0672628fde0cad745e9b14deb85dffb175709cacc1f4fe24b93f2227"