diff options
Diffstat (limited to 'meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch')
-rw-r--r-- | meta/recipes-support/libgcrypt/files/CVE-2019-12904_p1.patch | 176 |
1 files changed, 176 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 @@ | |||
1 | From 263ad8ae08f287e32656d4e3e0116479f3d9ad9d Mon Sep 17 00:00:00 2001 | ||
2 | From: Jussi Kivilinna <jussi.kivilinna@iki.fi> | ||
3 | Date: Fri, 31 May 2019 17:27:25 +0300 | ||
4 | Subject: [PATCH] GCM: move look-up table to .data section and unshare between processes | ||
5 | Reply-To: shuagr@microsoft.com | ||
6 | |||
7 | CVE: CVE-2019-12904_p1 | ||
8 | Upstream-Status: Backport | ||
9 | Signed-off-by: Shubham Agrawal<shuagr@microsoft.com> | ||
10 | Upstream-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 | ||
15 | after. | ||
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 | ||
19 | look-up table pages between processes. | ||
20 | -- | ||
21 | GnuPG-bug-id: 4541 | ||
22 | Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi> | ||
23 | --- | ||
24 | cipher/cipher-gcm.c | 129 ++++++++++++++++++++++++++++++++++++++-------------- | ||
25 | 1 file changed, 95 insertions(+), 34 deletions(-) | ||
26 | |||
27 | diff --git a/cipher/cipher-gcm.c b/cipher/cipher-gcm.c | ||
28 | index 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 | -- | ||
175 | 2.7.4 | ||
176 | |||