1 |
commit: bc9a85789c4e42d0ea50133da958b1a29e193493 |
2 |
Author: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jun 25 10:24:02 2022 +0000 |
4 |
Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jun 25 10:24:02 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=bc9a8578 |
7 |
|
8 |
Linux patch 4.9.320 |
9 |
|
10 |
Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org> |
11 |
|
12 |
0000_README | 4 + |
13 |
1319_linux-4.9.320.patch | 7856 ++++++++++++++++++++++++++++++++++++++++++++++ |
14 |
2 files changed, 7860 insertions(+) |
15 |
|
16 |
diff --git a/0000_README b/0000_README |
17 |
index d2a5bcdd..1aa08f52 100644 |
18 |
--- a/0000_README |
19 |
+++ b/0000_README |
20 |
@@ -1319,6 +1319,10 @@ Patch: 1318_linux-4.9.319.patch |
21 |
From: http://www.kernel.org |
22 |
Desc: Linux 4.9.319 |
23 |
|
24 |
+Patch: 1319_linux-4.9.320.patch |
25 |
+From: http://www.kernel.org |
26 |
+Desc: Linux 4.9.320 |
27 |
+ |
28 |
Patch: 1500_XATTR_USER_PREFIX.patch |
29 |
From: https://bugs.gentoo.org/show_bug.cgi?id=470644 |
30 |
Desc: Support for namespace user.pax.* on tmpfs. |
31 |
|
32 |
diff --git a/1319_linux-4.9.320.patch b/1319_linux-4.9.320.patch |
33 |
new file mode 100644 |
34 |
index 00000000..75e23994 |
35 |
--- /dev/null |
36 |
+++ b/1319_linux-4.9.320.patch |
37 |
@@ -0,0 +1,7856 @@ |
38 |
+diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt |
39 |
+index 97c0ff0787eaf..92a9a3282c5b6 100644 |
40 |
+--- a/Documentation/kernel-parameters.txt |
41 |
++++ b/Documentation/kernel-parameters.txt |
42 |
+@@ -3577,6 +3577,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted. |
43 |
+ ramdisk_size= [RAM] Sizes of RAM disks in kilobytes |
44 |
+ See Documentation/blockdev/ramdisk.txt. |
45 |
+ |
46 |
++ random.trust_cpu={on,off} |
47 |
++ [KNL] Enable or disable trusting the use of the |
48 |
++ CPU's random number generator (if available) to |
49 |
++ fully seed the kernel's CRNG. Default is controlled |
50 |
++ by CONFIG_RANDOM_TRUST_CPU. |
51 |
++ |
52 |
++ random.trust_bootloader={on,off} |
53 |
++ [KNL] Enable or disable trusting the use of a |
54 |
++ seed passed by the bootloader (if available) to |
55 |
++ fully seed the kernel's CRNG. Default is controlled |
56 |
++ by CONFIG_RANDOM_TRUST_BOOTLOADER. |
57 |
++ |
58 |
+ rcu_nocbs= [KNL] |
59 |
+ The argument is a cpu list, as described above. |
60 |
+ |
61 |
+diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt |
62 |
+index 30ba179392d81..79608693ef0b0 100644 |
63 |
+--- a/Documentation/sysctl/kernel.txt |
64 |
++++ b/Documentation/sysctl/kernel.txt |
65 |
+@@ -777,9 +777,40 @@ The kernel command line parameter printk.devkmsg= overrides this and is |
66 |
+ a one-time setting until next reboot: once set, it cannot be changed by |
67 |
+ this sysctl interface anymore. |
68 |
+ |
69 |
+-============================================================== |
70 |
++pty |
71 |
++=== |
72 |
++ |
73 |
++See Documentation/filesystems/devpts.rst. |
74 |
++ |
75 |
++ |
76 |
++random |
77 |
++====== |
78 |
++ |
79 |
++This is a directory, with the following entries: |
80 |
++ |
81 |
++* ``boot_id``: a UUID generated the first time this is retrieved, and |
82 |
++ unvarying after that; |
83 |
++ |
84 |
++* ``uuid``: a UUID generated every time this is retrieved (this can |
85 |
++ thus be used to generate UUIDs at will); |
86 |
++ |
87 |
++* ``entropy_avail``: the pool's entropy count, in bits; |
88 |
++ |
89 |
++* ``poolsize``: the entropy pool size, in bits; |
90 |
++ |
91 |
++* ``urandom_min_reseed_secs``: obsolete (used to determine the minimum |
92 |
++ number of seconds between urandom pool reseeding). This file is |
93 |
++ writable for compatibility purposes, but writing to it has no effect |
94 |
++ on any RNG behavior; |
95 |
++ |
96 |
++* ``write_wakeup_threshold``: when the entropy count drops below this |
97 |
++ (as a number of bits), processes waiting to write to ``/dev/random`` |
98 |
++ are woken up. This file is writable for compatibility purposes, but |
99 |
++ writing to it has no effect on any RNG behavior. |
100 |
++ |
101 |
+ |
102 |
+-randomize_va_space: |
103 |
++randomize_va_space |
104 |
++================== |
105 |
+ |
106 |
+ This option can be used to select the type of process address |
107 |
+ space randomization that is used in the system, for architectures |
108 |
+diff --git a/MAINTAINERS b/MAINTAINERS |
109 |
+index fcaab221553e0..afafd0fa18a9f 100644 |
110 |
+--- a/MAINTAINERS |
111 |
++++ b/MAINTAINERS |
112 |
+@@ -10068,6 +10068,7 @@ F: drivers/block/brd.c |
113 |
+ |
114 |
+ RANDOM NUMBER DRIVER |
115 |
+ M: "Theodore Ts'o" <tytso@×××.edu> |
116 |
++M: Jason A. Donenfeld <Jason@×××××.com> |
117 |
+ S: Maintained |
118 |
+ F: drivers/char/random.c |
119 |
+ |
120 |
+diff --git a/Makefile b/Makefile |
121 |
+index bf4a7b0fe8e74..04cefc7d5b47f 100644 |
122 |
+--- a/Makefile |
123 |
++++ b/Makefile |
124 |
+@@ -1,6 +1,6 @@ |
125 |
+ VERSION = 4 |
126 |
+ PATCHLEVEL = 9 |
127 |
+-SUBLEVEL = 319 |
128 |
++SUBLEVEL = 320 |
129 |
+ EXTRAVERSION = |
130 |
+ NAME = Roaring Lionus |
131 |
+ |
132 |
+diff --git a/arch/alpha/include/asm/timex.h b/arch/alpha/include/asm/timex.h |
133 |
+index afa0c45e3e987..c3ed97c790868 100644 |
134 |
+--- a/arch/alpha/include/asm/timex.h |
135 |
++++ b/arch/alpha/include/asm/timex.h |
136 |
+@@ -27,5 +27,6 @@ static inline cycles_t get_cycles (void) |
137 |
+ __asm__ __volatile__ ("rpcc %0" : "=r"(ret)); |
138 |
+ return ret; |
139 |
+ } |
140 |
++#define get_cycles get_cycles |
141 |
+ |
142 |
+ #endif |
143 |
+diff --git a/arch/arm/include/asm/timex.h b/arch/arm/include/asm/timex.h |
144 |
+index f6fcc67ef06ef..c06d38f0df8ec 100644 |
145 |
+--- a/arch/arm/include/asm/timex.h |
146 |
++++ b/arch/arm/include/asm/timex.h |
147 |
+@@ -14,5 +14,6 @@ |
148 |
+ |
149 |
+ typedef unsigned long cycles_t; |
150 |
+ #define get_cycles() ({ cycles_t c; read_current_timer(&c) ? 0 : c; }) |
151 |
++#define random_get_entropy() (((unsigned long)get_cycles()) ?: random_get_entropy_fallback()) |
152 |
+ |
153 |
+ #endif |
154 |
+diff --git a/arch/ia64/include/asm/timex.h b/arch/ia64/include/asm/timex.h |
155 |
+index 86c7db8611803..0117fa73ad490 100644 |
156 |
+--- a/arch/ia64/include/asm/timex.h |
157 |
++++ b/arch/ia64/include/asm/timex.h |
158 |
+@@ -38,6 +38,7 @@ get_cycles (void) |
159 |
+ ret = ia64_getreg(_IA64_REG_AR_ITC); |
160 |
+ return ret; |
161 |
+ } |
162 |
++#define get_cycles get_cycles |
163 |
+ |
164 |
+ extern void ia64_cpu_local_tick (void); |
165 |
+ extern unsigned long long ia64_native_sched_clock (void); |
166 |
+diff --git a/arch/m68k/include/asm/timex.h b/arch/m68k/include/asm/timex.h |
167 |
+index efc1f48923573..bbaf67f3a952d 100644 |
168 |
+--- a/arch/m68k/include/asm/timex.h |
169 |
++++ b/arch/m68k/include/asm/timex.h |
170 |
+@@ -34,7 +34,7 @@ static inline unsigned long random_get_entropy(void) |
171 |
+ { |
172 |
+ if (mach_random_get_entropy) |
173 |
+ return mach_random_get_entropy(); |
174 |
+- return 0; |
175 |
++ return random_get_entropy_fallback(); |
176 |
+ } |
177 |
+ #define random_get_entropy random_get_entropy |
178 |
+ |
179 |
+diff --git a/arch/mips/include/asm/timex.h b/arch/mips/include/asm/timex.h |
180 |
+index 8026baf46e729..2e107886f97ac 100644 |
181 |
+--- a/arch/mips/include/asm/timex.h |
182 |
++++ b/arch/mips/include/asm/timex.h |
183 |
+@@ -76,25 +76,24 @@ static inline cycles_t get_cycles(void) |
184 |
+ else |
185 |
+ return 0; /* no usable counter */ |
186 |
+ } |
187 |
++#define get_cycles get_cycles |
188 |
+ |
189 |
+ /* |
190 |
+ * Like get_cycles - but where c0_count is not available we desperately |
191 |
+ * use c0_random in an attempt to get at least a little bit of entropy. |
192 |
+- * |
193 |
+- * R6000 and R6000A neither have a count register nor a random register. |
194 |
+- * That leaves no entropy source in the CPU itself. |
195 |
+ */ |
196 |
+ static inline unsigned long random_get_entropy(void) |
197 |
+ { |
198 |
+- unsigned int prid = read_c0_prid(); |
199 |
+- unsigned int imp = prid & PRID_IMP_MASK; |
200 |
++ unsigned int c0_random; |
201 |
+ |
202 |
+- if (can_use_mips_counter(prid)) |
203 |
++ if (can_use_mips_counter(read_c0_prid())) |
204 |
+ return read_c0_count(); |
205 |
+- else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A)) |
206 |
+- return read_c0_random(); |
207 |
++ |
208 |
++ if (cpu_has_3kex) |
209 |
++ c0_random = (read_c0_random() >> 8) & 0x3f; |
210 |
+ else |
211 |
+- return 0; /* no usable register */ |
212 |
++ c0_random = read_c0_random() & 0x3f; |
213 |
++ return (random_get_entropy_fallback() << 6) | (0x3f - c0_random); |
214 |
+ } |
215 |
+ #define random_get_entropy random_get_entropy |
216 |
+ |
217 |
+diff --git a/arch/nios2/include/asm/timex.h b/arch/nios2/include/asm/timex.h |
218 |
+index 2f2abb28ec2fd..9c9b50599ea30 100644 |
219 |
+--- a/arch/nios2/include/asm/timex.h |
220 |
++++ b/arch/nios2/include/asm/timex.h |
221 |
+@@ -20,5 +20,8 @@ |
222 |
+ typedef unsigned long cycles_t; |
223 |
+ |
224 |
+ extern cycles_t get_cycles(void); |
225 |
++#define get_cycles get_cycles |
226 |
++ |
227 |
++#define random_get_entropy() (((unsigned long)get_cycles()) ?: random_get_entropy_fallback()) |
228 |
+ |
229 |
+ #endif |
230 |
+diff --git a/arch/parisc/include/asm/timex.h b/arch/parisc/include/asm/timex.h |
231 |
+index 2bd51f6d832bb..87aeeee5b700f 100644 |
232 |
+--- a/arch/parisc/include/asm/timex.h |
233 |
++++ b/arch/parisc/include/asm/timex.h |
234 |
+@@ -11,9 +11,10 @@ |
235 |
+ |
236 |
+ typedef unsigned long cycles_t; |
237 |
+ |
238 |
+-static inline cycles_t get_cycles (void) |
239 |
++static inline cycles_t get_cycles(void) |
240 |
+ { |
241 |
+ return mfctl(16); |
242 |
+ } |
243 |
++#define get_cycles get_cycles |
244 |
+ |
245 |
+ #endif |
246 |
+diff --git a/arch/powerpc/include/asm/archrandom.h b/arch/powerpc/include/asm/archrandom.h |
247 |
+index 9ff848e3c4a62..d8da8c0fb928c 100644 |
248 |
+--- a/arch/powerpc/include/asm/archrandom.h |
249 |
++++ b/arch/powerpc/include/asm/archrandom.h |
250 |
+@@ -5,27 +5,28 @@ |
251 |
+ |
252 |
+ #include <asm/machdep.h> |
253 |
+ |
254 |
+-static inline int arch_get_random_long(unsigned long *v) |
255 |
++static inline bool arch_get_random_long(unsigned long *v) |
256 |
+ { |
257 |
+- return 0; |
258 |
++ return false; |
259 |
+ } |
260 |
+ |
261 |
+-static inline int arch_get_random_int(unsigned int *v) |
262 |
++static inline bool arch_get_random_int(unsigned int *v) |
263 |
+ { |
264 |
+- return 0; |
265 |
++ return false; |
266 |
+ } |
267 |
+ |
268 |
+-static inline int arch_get_random_seed_long(unsigned long *v) |
269 |
++static inline bool arch_get_random_seed_long(unsigned long *v) |
270 |
+ { |
271 |
+ if (ppc_md.get_random_seed) |
272 |
+ return ppc_md.get_random_seed(v); |
273 |
+ |
274 |
+- return 0; |
275 |
++ return false; |
276 |
+ } |
277 |
+-static inline int arch_get_random_seed_int(unsigned int *v) |
278 |
++ |
279 |
++static inline bool arch_get_random_seed_int(unsigned int *v) |
280 |
+ { |
281 |
+ unsigned long val; |
282 |
+- int rc; |
283 |
++ bool rc; |
284 |
+ |
285 |
+ rc = arch_get_random_seed_long(&val); |
286 |
+ if (rc) |
287 |
+@@ -33,16 +34,6 @@ static inline int arch_get_random_seed_int(unsigned int *v) |
288 |
+ |
289 |
+ return rc; |
290 |
+ } |
291 |
+- |
292 |
+-static inline int arch_has_random(void) |
293 |
+-{ |
294 |
+- return 0; |
295 |
+-} |
296 |
+- |
297 |
+-static inline int arch_has_random_seed(void) |
298 |
+-{ |
299 |
+- return !!ppc_md.get_random_seed; |
300 |
+-} |
301 |
+ #endif /* CONFIG_ARCH_RANDOM */ |
302 |
+ |
303 |
+ #ifdef CONFIG_PPC_POWERNV |
304 |
+diff --git a/arch/powerpc/include/asm/timex.h b/arch/powerpc/include/asm/timex.h |
305 |
+index 2cf846edb3fcc..28b8a63bc3661 100644 |
306 |
+--- a/arch/powerpc/include/asm/timex.h |
307 |
++++ b/arch/powerpc/include/asm/timex.h |
308 |
+@@ -53,6 +53,7 @@ static inline cycles_t get_cycles(void) |
309 |
+ return ret; |
310 |
+ #endif |
311 |
+ } |
312 |
++#define get_cycles get_cycles |
313 |
+ |
314 |
+ #endif /* __KERNEL__ */ |
315 |
+ #endif /* _ASM_POWERPC_TIMEX_H */ |
316 |
+diff --git a/arch/s390/include/asm/timex.h b/arch/s390/include/asm/timex.h |
317 |
+index f1330245b5840..f9c222cfc65c2 100644 |
318 |
+--- a/arch/s390/include/asm/timex.h |
319 |
++++ b/arch/s390/include/asm/timex.h |
320 |
+@@ -168,6 +168,7 @@ static inline cycles_t get_cycles(void) |
321 |
+ { |
322 |
+ return (cycles_t) get_tod_clock() >> 2; |
323 |
+ } |
324 |
++#define get_cycles get_cycles |
325 |
+ |
326 |
+ int get_phys_clock(unsigned long long *clock); |
327 |
+ void init_cpu_timer(void); |
328 |
+diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c |
329 |
+index 7678f7956409b..1847bc3ff163b 100644 |
330 |
+--- a/arch/s390/mm/pgtable.c |
331 |
++++ b/arch/s390/mm/pgtable.c |
332 |
+@@ -595,7 +595,7 @@ void ptep_zap_key(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
333 |
+ PGSTE_GR_BIT | PGSTE_GC_BIT); |
334 |
+ ptev = pte_val(*ptep); |
335 |
+ if (!(ptev & _PAGE_INVALID) && (ptev & _PAGE_WRITE)) |
336 |
+- page_set_storage_key(ptev & PAGE_MASK, PAGE_DEFAULT_KEY, 1); |
337 |
++ page_set_storage_key(ptev & PAGE_MASK, PAGE_DEFAULT_KEY, 0); |
338 |
+ pgste_set_unlock(ptep, pgste); |
339 |
+ preempt_enable(); |
340 |
+ } |
341 |
+diff --git a/arch/sparc/include/asm/timex_32.h b/arch/sparc/include/asm/timex_32.h |
342 |
+index b6ccdb0d6f7de..b805c511755d6 100644 |
343 |
+--- a/arch/sparc/include/asm/timex_32.h |
344 |
++++ b/arch/sparc/include/asm/timex_32.h |
345 |
+@@ -8,8 +8,6 @@ |
346 |
+ |
347 |
+ #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */ |
348 |
+ |
349 |
+-/* XXX Maybe do something better at some point... -DaveM */ |
350 |
+-typedef unsigned long cycles_t; |
351 |
+-#define get_cycles() (0) |
352 |
++#include <asm-generic/timex.h> |
353 |
+ |
354 |
+ #endif |
355 |
+diff --git a/arch/um/include/asm/timex.h b/arch/um/include/asm/timex.h |
356 |
+index 0f4ada08f7488..62a0fbf79420f 100644 |
357 |
+--- a/arch/um/include/asm/timex.h |
358 |
++++ b/arch/um/include/asm/timex.h |
359 |
+@@ -1,13 +1,8 @@ |
360 |
+ #ifndef __UM_TIMEX_H |
361 |
+ #define __UM_TIMEX_H |
362 |
+ |
363 |
+-typedef unsigned long cycles_t; |
364 |
+- |
365 |
+-static inline cycles_t get_cycles (void) |
366 |
+-{ |
367 |
+- return 0; |
368 |
+-} |
369 |
+- |
370 |
+ #define CLOCK_TICK_RATE (HZ) |
371 |
+ |
372 |
++#include <asm-generic/timex.h> |
373 |
++ |
374 |
+ #endif |
375 |
+diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h |
376 |
+index 3ac991d81e74d..4d3cac3c9b250 100644 |
377 |
+--- a/arch/x86/include/asm/archrandom.h |
378 |
++++ b/arch/x86/include/asm/archrandom.h |
379 |
+@@ -86,10 +86,6 @@ static inline bool rdseed_int(unsigned int *v) |
380 |
+ return ok; |
381 |
+ } |
382 |
+ |
383 |
+-/* Conditional execution based on CPU type */ |
384 |
+-#define arch_has_random() static_cpu_has(X86_FEATURE_RDRAND) |
385 |
+-#define arch_has_random_seed() static_cpu_has(X86_FEATURE_RDSEED) |
386 |
+- |
387 |
+ /* |
388 |
+ * These are the generic interfaces; they must not be declared if the |
389 |
+ * stubs in <linux/random.h> are to be invoked, |
390 |
+@@ -99,22 +95,22 @@ static inline bool rdseed_int(unsigned int *v) |
391 |
+ |
392 |
+ static inline bool arch_get_random_long(unsigned long *v) |
393 |
+ { |
394 |
+- return arch_has_random() ? rdrand_long(v) : false; |
395 |
++ return static_cpu_has(X86_FEATURE_RDRAND) ? rdrand_long(v) : false; |
396 |
+ } |
397 |
+ |
398 |
+ static inline bool arch_get_random_int(unsigned int *v) |
399 |
+ { |
400 |
+- return arch_has_random() ? rdrand_int(v) : false; |
401 |
++ return static_cpu_has(X86_FEATURE_RDRAND) ? rdrand_int(v) : false; |
402 |
+ } |
403 |
+ |
404 |
+ static inline bool arch_get_random_seed_long(unsigned long *v) |
405 |
+ { |
406 |
+- return arch_has_random_seed() ? rdseed_long(v) : false; |
407 |
++ return static_cpu_has(X86_FEATURE_RDSEED) ? rdseed_long(v) : false; |
408 |
+ } |
409 |
+ |
410 |
+ static inline bool arch_get_random_seed_int(unsigned int *v) |
411 |
+ { |
412 |
+- return arch_has_random_seed() ? rdseed_int(v) : false; |
413 |
++ return static_cpu_has(X86_FEATURE_RDSEED) ? rdseed_int(v) : false; |
414 |
+ } |
415 |
+ |
416 |
+ extern void x86_init_rdrand(struct cpuinfo_x86 *c); |
417 |
+diff --git a/arch/x86/include/asm/timex.h b/arch/x86/include/asm/timex.h |
418 |
+index 1375cfc93960e..627802b6204c2 100644 |
419 |
+--- a/arch/x86/include/asm/timex.h |
420 |
++++ b/arch/x86/include/asm/timex.h |
421 |
+@@ -4,6 +4,15 @@ |
422 |
+ #include <asm/processor.h> |
423 |
+ #include <asm/tsc.h> |
424 |
+ |
425 |
++static inline unsigned long random_get_entropy(void) |
426 |
++{ |
427 |
++ if (!IS_ENABLED(CONFIG_X86_TSC) && |
428 |
++ !cpu_feature_enabled(X86_FEATURE_TSC)) |
429 |
++ return random_get_entropy_fallback(); |
430 |
++ return rdtsc(); |
431 |
++} |
432 |
++#define random_get_entropy random_get_entropy |
433 |
++ |
434 |
+ /* Assume we use the PIT time source for the clock tick */ |
435 |
+ #define CLOCK_TICK_RATE PIT_TICK_RATE |
436 |
+ |
437 |
+diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h |
438 |
+index 33b6365c22fed..23235c5ef1a14 100644 |
439 |
+--- a/arch/x86/include/asm/tsc.h |
440 |
++++ b/arch/x86/include/asm/tsc.h |
441 |
+@@ -21,13 +21,12 @@ extern void disable_TSC(void); |
442 |
+ |
443 |
+ static inline cycles_t get_cycles(void) |
444 |
+ { |
445 |
+-#ifndef CONFIG_X86_TSC |
446 |
+- if (!boot_cpu_has(X86_FEATURE_TSC)) |
447 |
++ if (!IS_ENABLED(CONFIG_X86_TSC) && |
448 |
++ !cpu_feature_enabled(X86_FEATURE_TSC)) |
449 |
+ return 0; |
450 |
+-#endif |
451 |
+- |
452 |
+ return rdtsc(); |
453 |
+ } |
454 |
++#define get_cycles get_cycles |
455 |
+ |
456 |
+ extern struct system_counterval_t convert_art_to_tsc(cycle_t art); |
457 |
+ |
458 |
+diff --git a/arch/xtensa/include/asm/timex.h b/arch/xtensa/include/asm/timex.h |
459 |
+index f9b389d4e9739..d866bc847d8dc 100644 |
460 |
+--- a/arch/xtensa/include/asm/timex.h |
461 |
++++ b/arch/xtensa/include/asm/timex.h |
462 |
+@@ -30,10 +30,6 @@ |
463 |
+ |
464 |
+ extern unsigned long ccount_freq; |
465 |
+ |
466 |
+-typedef unsigned long long cycles_t; |
467 |
+- |
468 |
+-#define get_cycles() (0) |
469 |
+- |
470 |
+ void local_timer_setup(unsigned cpu); |
471 |
+ |
472 |
+ /* |
473 |
+@@ -69,4 +65,6 @@ static inline void set_linux_timer (unsigned long ccompare) |
474 |
+ WSR_CCOMPARE(LINUX_TIMER, ccompare); |
475 |
+ } |
476 |
+ |
477 |
++#include <asm-generic/timex.h> |
478 |
++ |
479 |
+ #endif /* _XTENSA_TIMEX_H */ |
480 |
+diff --git a/crypto/chacha20_generic.c b/crypto/chacha20_generic.c |
481 |
+index 1cab83146e33b..56603afbf6bd0 100644 |
482 |
+--- a/crypto/chacha20_generic.c |
483 |
++++ b/crypto/chacha20_generic.c |
484 |
+@@ -23,7 +23,8 @@ static inline u32 le32_to_cpuvp(const void *p) |
485 |
+ static void chacha20_docrypt(u32 *state, u8 *dst, const u8 *src, |
486 |
+ unsigned int bytes) |
487 |
+ { |
488 |
+- u8 stream[CHACHA20_BLOCK_SIZE]; |
489 |
++ /* aligned to potentially speed up crypto_xor() */ |
490 |
++ u8 stream[CHACHA20_BLOCK_SIZE] __aligned(sizeof(long)); |
491 |
+ |
492 |
+ if (dst != src) |
493 |
+ memcpy(dst, src, bytes); |
494 |
+diff --git a/crypto/drbg.c b/crypto/drbg.c |
495 |
+index 4bb5f93c94cdb..1b94a4306dfc4 100644 |
496 |
+--- a/crypto/drbg.c |
497 |
++++ b/crypto/drbg.c |
498 |
+@@ -219,6 +219,57 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags) |
499 |
+ } |
500 |
+ } |
501 |
+ |
502 |
++/* |
503 |
++ * FIPS 140-2 continuous self test for the noise source |
504 |
++ * The test is performed on the noise source input data. Thus, the function |
505 |
++ * implicitly knows the size of the buffer to be equal to the security |
506 |
++ * strength. |
507 |
++ * |
508 |
++ * Note, this function disregards the nonce trailing the entropy data during |
509 |
++ * initial seeding. |
510 |
++ * |
511 |
++ * drbg->drbg_mutex must have been taken. |
512 |
++ * |
513 |
++ * @drbg DRBG handle |
514 |
++ * @entropy buffer of seed data to be checked |
515 |
++ * |
516 |
++ * return: |
517 |
++ * 0 on success |
518 |
++ * -EAGAIN on when the CTRNG is not yet primed |
519 |
++ * < 0 on error |
520 |
++ */ |
521 |
++static int drbg_fips_continuous_test(struct drbg_state *drbg, |
522 |
++ const unsigned char *entropy) |
523 |
++{ |
524 |
++ unsigned short entropylen = drbg_sec_strength(drbg->core->flags); |
525 |
++ int ret = 0; |
526 |
++ |
527 |
++ if (!IS_ENABLED(CONFIG_CRYPTO_FIPS)) |
528 |
++ return 0; |
529 |
++ |
530 |
++ /* skip test if we test the overall system */ |
531 |
++ if (list_empty(&drbg->test_data.list)) |
532 |
++ return 0; |
533 |
++ /* only perform test in FIPS mode */ |
534 |
++ if (!fips_enabled) |
535 |
++ return 0; |
536 |
++ |
537 |
++ if (!drbg->fips_primed) { |
538 |
++ /* Priming of FIPS test */ |
539 |
++ memcpy(drbg->prev, entropy, entropylen); |
540 |
++ drbg->fips_primed = true; |
541 |
++ /* priming: another round is needed */ |
542 |
++ return -EAGAIN; |
543 |
++ } |
544 |
++ ret = memcmp(drbg->prev, entropy, entropylen); |
545 |
++ if (!ret) |
546 |
++ panic("DRBG continuous self test failed\n"); |
547 |
++ memcpy(drbg->prev, entropy, entropylen); |
548 |
++ |
549 |
++ /* the test shall pass when the two values are not equal */ |
550 |
++ return 0; |
551 |
++} |
552 |
++ |
553 |
+ /* |
554 |
+ * Convert an integer into a byte representation of this integer. |
555 |
+ * The byte representation is big-endian |
556 |
+@@ -986,55 +1037,79 @@ static const struct drbg_state_ops drbg_hash_ops = { |
557 |
+ ******************************************************************/ |
558 |
+ |
559 |
+ static inline int __drbg_seed(struct drbg_state *drbg, struct list_head *seed, |
560 |
+- int reseed) |
561 |
++ int reseed, enum drbg_seed_state new_seed_state) |
562 |
+ { |
563 |
+ int ret = drbg->d_ops->update(drbg, seed, reseed); |
564 |
+ |
565 |
+ if (ret) |
566 |
+ return ret; |
567 |
+ |
568 |
+- drbg->seeded = true; |
569 |
++ drbg->seeded = new_seed_state; |
570 |
+ /* 10.1.1.2 / 10.1.1.3 step 5 */ |
571 |
+ drbg->reseed_ctr = 1; |
572 |
+ |
573 |
++ switch (drbg->seeded) { |
574 |
++ case DRBG_SEED_STATE_UNSEEDED: |
575 |
++ /* Impossible, but handle it to silence compiler warnings. */ |
576 |
++ case DRBG_SEED_STATE_PARTIAL: |
577 |
++ /* |
578 |
++ * Require frequent reseeds until the seed source is |
579 |
++ * fully initialized. |
580 |
++ */ |
581 |
++ drbg->reseed_threshold = 50; |
582 |
++ break; |
583 |
++ |
584 |
++ case DRBG_SEED_STATE_FULL: |
585 |
++ /* |
586 |
++ * Seed source has become fully initialized, frequent |
587 |
++ * reseeds no longer required. |
588 |
++ */ |
589 |
++ drbg->reseed_threshold = drbg_max_requests(drbg); |
590 |
++ break; |
591 |
++ } |
592 |
++ |
593 |
+ return ret; |
594 |
+ } |
595 |
+ |
596 |
+-static void drbg_async_seed(struct work_struct *work) |
597 |
++static inline int drbg_get_random_bytes(struct drbg_state *drbg, |
598 |
++ unsigned char *entropy, |
599 |
++ unsigned int entropylen) |
600 |
++{ |
601 |
++ int ret; |
602 |
++ |
603 |
++ do { |
604 |
++ get_random_bytes(entropy, entropylen); |
605 |
++ ret = drbg_fips_continuous_test(drbg, entropy); |
606 |
++ if (ret && ret != -EAGAIN) |
607 |
++ return ret; |
608 |
++ } while (ret); |
609 |
++ |
610 |
++ return 0; |
611 |
++} |
612 |
++ |
613 |
++static int drbg_seed_from_random(struct drbg_state *drbg) |
614 |
+ { |
615 |
+ struct drbg_string data; |
616 |
+ LIST_HEAD(seedlist); |
617 |
+- struct drbg_state *drbg = container_of(work, struct drbg_state, |
618 |
+- seed_work); |
619 |
+ unsigned int entropylen = drbg_sec_strength(drbg->core->flags); |
620 |
+ unsigned char entropy[32]; |
621 |
++ int ret; |
622 |
+ |
623 |
+ BUG_ON(!entropylen); |
624 |
+ BUG_ON(entropylen > sizeof(entropy)); |
625 |
+- get_random_bytes(entropy, entropylen); |
626 |
+ |
627 |
+ drbg_string_fill(&data, entropy, entropylen); |
628 |
+ list_add_tail(&data.list, &seedlist); |
629 |
+ |
630 |
+- mutex_lock(&drbg->drbg_mutex); |
631 |
+- |
632 |
+- /* If nonblocking pool is initialized, deactivate Jitter RNG */ |
633 |
+- crypto_free_rng(drbg->jent); |
634 |
+- drbg->jent = NULL; |
635 |
+- |
636 |
+- /* Set seeded to false so that if __drbg_seed fails the |
637 |
+- * next generate call will trigger a reseed. |
638 |
+- */ |
639 |
+- drbg->seeded = false; |
640 |
+- |
641 |
+- __drbg_seed(drbg, &seedlist, true); |
642 |
+- |
643 |
+- if (drbg->seeded) |
644 |
+- drbg->reseed_threshold = drbg_max_requests(drbg); |
645 |
++ ret = drbg_get_random_bytes(drbg, entropy, entropylen); |
646 |
++ if (ret) |
647 |
++ goto out; |
648 |
+ |
649 |
+- mutex_unlock(&drbg->drbg_mutex); |
650 |
++ ret = __drbg_seed(drbg, &seedlist, true, DRBG_SEED_STATE_FULL); |
651 |
+ |
652 |
++out: |
653 |
+ memzero_explicit(entropy, entropylen); |
654 |
++ return ret; |
655 |
+ } |
656 |
+ |
657 |
+ /* |
658 |
+@@ -1056,6 +1131,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, |
659 |
+ unsigned int entropylen = drbg_sec_strength(drbg->core->flags); |
660 |
+ struct drbg_string data1; |
661 |
+ LIST_HEAD(seedlist); |
662 |
++ enum drbg_seed_state new_seed_state = DRBG_SEED_STATE_FULL; |
663 |
+ |
664 |
+ /* 9.1 / 9.2 / 9.3.1 step 3 */ |
665 |
+ if (pers && pers->len > (drbg_max_addtl(drbg))) { |
666 |
+@@ -1083,7 +1159,12 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, |
667 |
+ BUG_ON((entropylen * 2) > sizeof(entropy)); |
668 |
+ |
669 |
+ /* Get seed from in-kernel /dev/urandom */ |
670 |
+- get_random_bytes(entropy, entropylen); |
671 |
++ if (!rng_is_initialized()) |
672 |
++ new_seed_state = DRBG_SEED_STATE_PARTIAL; |
673 |
++ |
674 |
++ ret = drbg_get_random_bytes(drbg, entropy, entropylen); |
675 |
++ if (ret) |
676 |
++ goto out; |
677 |
+ |
678 |
+ if (!drbg->jent) { |
679 |
+ drbg_string_fill(&data1, entropy, entropylen); |
680 |
+@@ -1096,7 +1177,23 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, |
681 |
+ entropylen); |
682 |
+ if (ret) { |
683 |
+ pr_devel("DRBG: jent failed with %d\n", ret); |
684 |
+- return ret; |
685 |
++ |
686 |
++ /* |
687 |
++ * Do not treat the transient failure of the |
688 |
++ * Jitter RNG as an error that needs to be |
689 |
++ * reported. The combined number of the |
690 |
++ * maximum reseed threshold times the maximum |
691 |
++ * number of Jitter RNG transient errors is |
692 |
++ * less than the reseed threshold required by |
693 |
++ * SP800-90A allowing us to treat the |
694 |
++ * transient errors as such. |
695 |
++ * |
696 |
++ * However, we mandate that at least the first |
697 |
++ * seeding operation must succeed with the |
698 |
++ * Jitter RNG. |
699 |
++ */ |
700 |
++ if (!reseed || ret != -EAGAIN) |
701 |
++ goto out; |
702 |
+ } |
703 |
+ |
704 |
+ drbg_string_fill(&data1, entropy, entropylen * 2); |
705 |
+@@ -1121,8 +1218,9 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, |
706 |
+ memset(drbg->C, 0, drbg_statelen(drbg)); |
707 |
+ } |
708 |
+ |
709 |
+- ret = __drbg_seed(drbg, &seedlist, reseed); |
710 |
++ ret = __drbg_seed(drbg, &seedlist, reseed, new_seed_state); |
711 |
+ |
712 |
++out: |
713 |
+ memzero_explicit(entropy, entropylen * 2); |
714 |
+ |
715 |
+ return ret; |
716 |
+@@ -1144,6 +1242,11 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) |
717 |
+ drbg->reseed_ctr = 0; |
718 |
+ drbg->d_ops = NULL; |
719 |
+ drbg->core = NULL; |
720 |
++ if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) { |
721 |
++ kzfree(drbg->prev); |
722 |
++ drbg->prev = NULL; |
723 |
++ drbg->fips_primed = false; |
724 |
++ } |
725 |
+ } |
726 |
+ |
727 |
+ /* |
728 |
+@@ -1213,6 +1316,14 @@ static inline int drbg_alloc_state(struct drbg_state *drbg) |
729 |
+ drbg->scratchpad = PTR_ALIGN(drbg->scratchpadbuf, ret + 1); |
730 |
+ } |
731 |
+ |
732 |
++ if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) { |
733 |
++ drbg->prev = kzalloc(drbg_sec_strength(drbg->core->flags), |
734 |
++ GFP_KERNEL); |
735 |
++ if (!drbg->prev) |
736 |
++ goto fini; |
737 |
++ drbg->fips_primed = false; |
738 |
++ } |
739 |
++ |
740 |
+ return 0; |
741 |
+ |
742 |
+ fini: |
743 |
+@@ -1285,19 +1396,25 @@ static int drbg_generate(struct drbg_state *drbg, |
744 |
+ * here. The spec is a bit convoluted here, we make it simpler. |
745 |
+ */ |
746 |
+ if (drbg->reseed_threshold < drbg->reseed_ctr) |
747 |
+- drbg->seeded = false; |
748 |
++ drbg->seeded = DRBG_SEED_STATE_UNSEEDED; |
749 |
+ |
750 |
+- if (drbg->pr || !drbg->seeded) { |
751 |
++ if (drbg->pr || drbg->seeded == DRBG_SEED_STATE_UNSEEDED) { |
752 |
+ pr_devel("DRBG: reseeding before generation (prediction " |
753 |
+ "resistance: %s, state %s)\n", |
754 |
+ drbg->pr ? "true" : "false", |
755 |
+- drbg->seeded ? "seeded" : "unseeded"); |
756 |
++ (drbg->seeded == DRBG_SEED_STATE_FULL ? |
757 |
++ "seeded" : "unseeded")); |
758 |
+ /* 9.3.1 steps 7.1 through 7.3 */ |
759 |
+ len = drbg_seed(drbg, addtl, true); |
760 |
+ if (len) |
761 |
+ goto err; |
762 |
+ /* 9.3.1 step 7.4 */ |
763 |
+ addtl = NULL; |
764 |
++ } else if (rng_is_initialized() && |
765 |
++ drbg->seeded == DRBG_SEED_STATE_PARTIAL) { |
766 |
++ len = drbg_seed_from_random(drbg); |
767 |
++ if (len) |
768 |
++ goto err; |
769 |
+ } |
770 |
+ |
771 |
+ if (addtl && 0 < addtl->len) |
772 |
+@@ -1390,51 +1507,15 @@ static int drbg_generate_long(struct drbg_state *drbg, |
773 |
+ return 0; |
774 |
+ } |
775 |
+ |
776 |
+-static void drbg_schedule_async_seed(struct random_ready_callback *rdy) |
777 |
+-{ |
778 |
+- struct drbg_state *drbg = container_of(rdy, struct drbg_state, |
779 |
+- random_ready); |
780 |
+- |
781 |
+- schedule_work(&drbg->seed_work); |
782 |
+-} |
783 |
+- |
784 |
+ static int drbg_prepare_hrng(struct drbg_state *drbg) |
785 |
+ { |
786 |
+- int err; |
787 |
+- |
788 |
+ /* We do not need an HRNG in test mode. */ |
789 |
+ if (list_empty(&drbg->test_data.list)) |
790 |
+ return 0; |
791 |
+ |
792 |
+- INIT_WORK(&drbg->seed_work, drbg_async_seed); |
793 |
+- |
794 |
+- drbg->random_ready.owner = THIS_MODULE; |
795 |
+- drbg->random_ready.func = drbg_schedule_async_seed; |
796 |
+- |
797 |
+- err = add_random_ready_callback(&drbg->random_ready); |
798 |
+- |
799 |
+- switch (err) { |
800 |
+- case 0: |
801 |
+- break; |
802 |
+- |
803 |
+- case -EALREADY: |
804 |
+- err = 0; |
805 |
+- /* fall through */ |
806 |
+- |
807 |
+- default: |
808 |
+- drbg->random_ready.func = NULL; |
809 |
+- return err; |
810 |
+- } |
811 |
+- |
812 |
+ drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); |
813 |
+ |
814 |
+- /* |
815 |
+- * Require frequent reseeds until the seed source is fully |
816 |
+- * initialized. |
817 |
+- */ |
818 |
+- drbg->reseed_threshold = 50; |
819 |
+- |
820 |
+- return err; |
821 |
++ return 0; |
822 |
+ } |
823 |
+ |
824 |
+ /* |
825 |
+@@ -1477,7 +1558,7 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers, |
826 |
+ if (!drbg->core) { |
827 |
+ drbg->core = &drbg_cores[coreref]; |
828 |
+ drbg->pr = pr; |
829 |
+- drbg->seeded = false; |
830 |
++ drbg->seeded = DRBG_SEED_STATE_UNSEEDED; |
831 |
+ drbg->reseed_threshold = drbg_max_requests(drbg); |
832 |
+ |
833 |
+ ret = drbg_alloc_state(drbg); |
834 |
+@@ -1528,12 +1609,9 @@ free_everything: |
835 |
+ */ |
836 |
+ static int drbg_uninstantiate(struct drbg_state *drbg) |
837 |
+ { |
838 |
+- if (drbg->random_ready.func) { |
839 |
+- del_random_ready_callback(&drbg->random_ready); |
840 |
+- cancel_work_sync(&drbg->seed_work); |
841 |
++ if (!IS_ERR_OR_NULL(drbg->jent)) |
842 |
+ crypto_free_rng(drbg->jent); |
843 |
+- drbg->jent = NULL; |
844 |
+- } |
845 |
++ drbg->jent = NULL; |
846 |
+ |
847 |
+ if (drbg->d_ops) |
848 |
+ drbg->d_ops->crypto_fini(drbg); |
849 |
+diff --git a/crypto/md4.c b/crypto/md4.c |
850 |
+index 3515af425cc91..810fefb0a007a 100644 |
851 |
+--- a/crypto/md4.c |
852 |
++++ b/crypto/md4.c |
853 |
+@@ -64,23 +64,6 @@ static inline u32 H(u32 x, u32 y, u32 z) |
854 |
+ #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s)) |
855 |
+ #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s)) |
856 |
+ |
857 |
+-/* XXX: this stuff can be optimized */ |
858 |
+-static inline void le32_to_cpu_array(u32 *buf, unsigned int words) |
859 |
+-{ |
860 |
+- while (words--) { |
861 |
+- __le32_to_cpus(buf); |
862 |
+- buf++; |
863 |
+- } |
864 |
+-} |
865 |
+- |
866 |
+-static inline void cpu_to_le32_array(u32 *buf, unsigned int words) |
867 |
+-{ |
868 |
+- while (words--) { |
869 |
+- __cpu_to_le32s(buf); |
870 |
+- buf++; |
871 |
+- } |
872 |
+-} |
873 |
+- |
874 |
+ static void md4_transform(u32 *hash, u32 const *in) |
875 |
+ { |
876 |
+ u32 a, b, c, d; |
877 |
+diff --git a/crypto/md5.c b/crypto/md5.c |
878 |
+index 2355a7c25c458..419f2379b406b 100644 |
879 |
+--- a/crypto/md5.c |
880 |
++++ b/crypto/md5.c |
881 |
+@@ -30,23 +30,6 @@ const u8 md5_zero_message_hash[MD5_DIGEST_SIZE] = { |
882 |
+ }; |
883 |
+ EXPORT_SYMBOL_GPL(md5_zero_message_hash); |
884 |
+ |
885 |
+-/* XXX: this stuff can be optimized */ |
886 |
+-static inline void le32_to_cpu_array(u32 *buf, unsigned int words) |
887 |
+-{ |
888 |
+- while (words--) { |
889 |
+- __le32_to_cpus(buf); |
890 |
+- buf++; |
891 |
+- } |
892 |
+-} |
893 |
+- |
894 |
+-static inline void cpu_to_le32_array(u32 *buf, unsigned int words) |
895 |
+-{ |
896 |
+- while (words--) { |
897 |
+- __cpu_to_le32s(buf); |
898 |
+- buf++; |
899 |
+- } |
900 |
+-} |
901 |
+- |
902 |
+ static inline void md5_transform_helper(struct md5_state *ctx) |
903 |
+ { |
904 |
+ le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32)); |
905 |
+diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c |
906 |
+index 35db918a1de56..42f0a592b5ab0 100644 |
907 |
+--- a/drivers/ata/libata-core.c |
908 |
++++ b/drivers/ata/libata-core.c |
909 |
+@@ -6051,7 +6051,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, |
910 |
+ const struct ata_port_info * const * ppi, |
911 |
+ int n_ports) |
912 |
+ { |
913 |
+- const struct ata_port_info *pi; |
914 |
++ const struct ata_port_info *pi = &ata_dummy_port_info; |
915 |
+ struct ata_host *host; |
916 |
+ int i, j; |
917 |
+ |
918 |
+@@ -6059,7 +6059,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, |
919 |
+ if (!host) |
920 |
+ return NULL; |
921 |
+ |
922 |
+- for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { |
923 |
++ for (i = 0, j = 0; i < host->n_ports; i++) { |
924 |
+ struct ata_port *ap = host->ports[i]; |
925 |
+ |
926 |
+ if (ppi[j]) |
927 |
+diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig |
928 |
+index f4ae000eb2855..1d3813d4f5c81 100644 |
929 |
+--- a/drivers/char/Kconfig |
930 |
++++ b/drivers/char/Kconfig |
931 |
+@@ -593,5 +593,41 @@ config TILE_SROM |
932 |
+ |
933 |
+ source "drivers/char/xillybus/Kconfig" |
934 |
+ |
935 |
+-endmenu |
936 |
++config RANDOM_TRUST_CPU |
937 |
++ bool "Initialize RNG using CPU RNG instructions" |
938 |
++ default y |
939 |
++ depends on ARCH_RANDOM |
940 |
++ help |
941 |
++ Initialize the RNG using random numbers supplied by the CPU's |
942 |
++ RNG instructions (e.g. RDRAND), if supported and available. These |
943 |
++ random numbers are never used directly, but are rather hashed into |
944 |
++ the main input pool, and this happens regardless of whether or not |
945 |
++ this option is enabled. Instead, this option controls whether the |
946 |
++ they are credited and hence can initialize the RNG. Additionally, |
947 |
++ other sources of randomness are always used, regardless of this |
948 |
++ setting. Enabling this implies trusting that the CPU can supply high |
949 |
++ quality and non-backdoored random numbers. |
950 |
++ |
951 |
++ Say Y here unless you have reason to mistrust your CPU or believe |
952 |
++ its RNG facilities may be faulty. This may also be configured at |
953 |
++ boot time with "random.trust_cpu=on/off". |
954 |
++ |
955 |
++config RANDOM_TRUST_BOOTLOADER |
956 |
++ bool "Initialize RNG using bootloader-supplied seed" |
957 |
++ default y |
958 |
++ help |
959 |
++ Initialize the RNG using a seed supplied by the bootloader or boot |
960 |
++ environment (e.g. EFI or a bootloader-generated device tree). This |
961 |
++ seed is not used directly, but is rather hashed into the main input |
962 |
++ pool, and this happens regardless of whether or not this option is |
963 |
++ enabled. Instead, this option controls whether the seed is credited |
964 |
++ and hence can initialize the RNG. Additionally, other sources of |
965 |
++ randomness are always used, regardless of this setting. Enabling |
966 |
++ this implies trusting that the bootloader can supply high quality and |
967 |
++ non-backdoored seeds. |
968 |
++ |
969 |
++ Say Y here unless you have reason to mistrust your bootloader or |
970 |
++ believe its RNG facilities may be faulty. This may also be configured |
971 |
++ at boot time with "random.trust_bootloader=on/off". |
972 |
+ |
973 |
++endmenu |
974 |
+diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c |
975 |
+index 5e79b4bfe27a9..f1121a162ef02 100644 |
976 |
+--- a/drivers/char/hw_random/core.c |
977 |
++++ b/drivers/char/hw_random/core.c |
978 |
+@@ -1,38 +1,18 @@ |
979 |
+ /* |
980 |
+- Added support for the AMD Geode LX RNG |
981 |
+- (c) Copyright 2004-2005 Advanced Micro Devices, Inc. |
982 |
+- |
983 |
+- derived from |
984 |
+- |
985 |
+- Hardware driver for the Intel/AMD/VIA Random Number Generators (RNG) |
986 |
+- (c) Copyright 2003 Red Hat Inc <jgarzik@××××××.com> |
987 |
+- |
988 |
+- derived from |
989 |
+- |
990 |
+- Hardware driver for the AMD 768 Random Number Generator (RNG) |
991 |
+- (c) Copyright 2001 Red Hat Inc <alan@××××××.com> |
992 |
+- |
993 |
+- derived from |
994 |
+- |
995 |
+- Hardware driver for Intel i810 Random Number Generator (RNG) |
996 |
+- Copyright 2000,2001 Jeff Garzik <jgarzik@×××××.com> |
997 |
+- Copyright 2000,2001 Philipp Rumpf <prumpf@××××××××××××.com> |
998 |
+- |
999 |
+- Added generic RNG API |
1000 |
+- Copyright 2006 Michael Buesch <m@××××.ch> |
1001 |
+- Copyright 2005 (c) MontaVista Software, Inc. |
1002 |
+- |
1003 |
+- Please read Documentation/hw_random.txt for details on use. |
1004 |
+- |
1005 |
+- ---------------------------------------------------------- |
1006 |
+- This software may be used and distributed according to the terms |
1007 |
+- of the GNU General Public License, incorporated herein by reference. |
1008 |
+- |
1009 |
++ * hw_random/core.c: HWRNG core API |
1010 |
++ * |
1011 |
++ * Copyright 2006 Michael Buesch <m@××××.ch> |
1012 |
++ * Copyright 2005 (c) MontaVista Software, Inc. |
1013 |
++ * |
1014 |
++ * Please read Documentation/hw_random.txt for details on use. |
1015 |
++ * |
1016 |
++ * This software may be used and distributed according to the terms |
1017 |
++ * of the GNU General Public License, incorporated herein by reference. |
1018 |
+ */ |
1019 |
+ |
1020 |
+- |
1021 |
+ #include <linux/device.h> |
1022 |
+ #include <linux/hw_random.h> |
1023 |
++#include <linux/random.h> |
1024 |
+ #include <linux/module.h> |
1025 |
+ #include <linux/kernel.h> |
1026 |
+ #include <linux/fs.h> |
1027 |
+@@ -45,14 +25,13 @@ |
1028 |
+ #include <linux/err.h> |
1029 |
+ #include <asm/uaccess.h> |
1030 |
+ |
1031 |
+- |
1032 |
+ #define RNG_MODULE_NAME "hw_random" |
1033 |
+-#define PFX RNG_MODULE_NAME ": " |
1034 |
+-#define RNG_MISCDEV_MINOR 183 /* official */ |
1035 |
+- |
1036 |
+ |
1037 |
+ static struct hwrng *current_rng; |
1038 |
++/* the current rng has been explicitly chosen by user via sysfs */ |
1039 |
++static int cur_rng_set_by_user; |
1040 |
+ static struct task_struct *hwrng_fill; |
1041 |
++/* list of registered rngs, sorted decending by quality */ |
1042 |
+ static LIST_HEAD(rng_list); |
1043 |
+ /* Protects rng_list and current_rng */ |
1044 |
+ static DEFINE_MUTEX(rng_mutex); |
1045 |
+@@ -296,7 +275,6 @@ out_put: |
1046 |
+ goto out; |
1047 |
+ } |
1048 |
+ |
1049 |
+- |
1050 |
+ static const struct file_operations rng_chrdev_ops = { |
1051 |
+ .owner = THIS_MODULE, |
1052 |
+ .open = rng_dev_open, |
1053 |
+@@ -307,14 +285,13 @@ static const struct file_operations rng_chrdev_ops = { |
1054 |
+ static const struct attribute_group *rng_dev_groups[]; |
1055 |
+ |
1056 |
+ static struct miscdevice rng_miscdev = { |
1057 |
+- .minor = RNG_MISCDEV_MINOR, |
1058 |
++ .minor = HWRNG_MINOR, |
1059 |
+ .name = RNG_MODULE_NAME, |
1060 |
+ .nodename = "hwrng", |
1061 |
+ .fops = &rng_chrdev_ops, |
1062 |
+ .groups = rng_dev_groups, |
1063 |
+ }; |
1064 |
+ |
1065 |
+- |
1066 |
+ static ssize_t hwrng_attr_current_store(struct device *dev, |
1067 |
+ struct device_attribute *attr, |
1068 |
+ const char *buf, size_t len) |
1069 |
+@@ -329,6 +306,7 @@ static ssize_t hwrng_attr_current_store(struct device *dev, |
1070 |
+ list_for_each_entry(rng, &rng_list, list) { |
1071 |
+ if (sysfs_streq(rng->name, buf)) { |
1072 |
+ err = 0; |
1073 |
++ cur_rng_set_by_user = 1; |
1074 |
+ if (rng != current_rng) |
1075 |
+ err = set_current_rng(rng); |
1076 |
+ break; |
1077 |
+@@ -377,16 +355,27 @@ static ssize_t hwrng_attr_available_show(struct device *dev, |
1078 |
+ return strlen(buf); |
1079 |
+ } |
1080 |
+ |
1081 |
++static ssize_t hwrng_attr_selected_show(struct device *dev, |
1082 |
++ struct device_attribute *attr, |
1083 |
++ char *buf) |
1084 |
++{ |
1085 |
++ return snprintf(buf, PAGE_SIZE, "%d\n", cur_rng_set_by_user); |
1086 |
++} |
1087 |
++ |
1088 |
+ static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR, |
1089 |
+ hwrng_attr_current_show, |
1090 |
+ hwrng_attr_current_store); |
1091 |
+ static DEVICE_ATTR(rng_available, S_IRUGO, |
1092 |
+ hwrng_attr_available_show, |
1093 |
+ NULL); |
1094 |
++static DEVICE_ATTR(rng_selected, S_IRUGO, |
1095 |
++ hwrng_attr_selected_show, |
1096 |
++ NULL); |
1097 |
+ |
1098 |
+ static struct attribute *rng_dev_attrs[] = { |
1099 |
+ &dev_attr_rng_current.attr, |
1100 |
+ &dev_attr_rng_available.attr, |
1101 |
++ &dev_attr_rng_selected.attr, |
1102 |
+ NULL |
1103 |
+ }; |
1104 |
+ |
1105 |
+@@ -443,9 +432,9 @@ int hwrng_register(struct hwrng *rng) |
1106 |
+ { |
1107 |
+ int err = -EINVAL; |
1108 |
+ struct hwrng *old_rng, *tmp; |
1109 |
++ struct list_head *rng_list_ptr; |
1110 |
+ |
1111 |
+- if (rng->name == NULL || |
1112 |
+- (rng->data_read == NULL && rng->read == NULL)) |
1113 |
++ if (!rng->name || (!rng->data_read && !rng->read)) |
1114 |
+ goto out; |
1115 |
+ |
1116 |
+ mutex_lock(&rng_mutex); |
1117 |
+@@ -459,14 +448,27 @@ int hwrng_register(struct hwrng *rng) |
1118 |
+ init_completion(&rng->cleanup_done); |
1119 |
+ complete(&rng->cleanup_done); |
1120 |
+ |
1121 |
++ /* rng_list is sorted by decreasing quality */ |
1122 |
++ list_for_each(rng_list_ptr, &rng_list) { |
1123 |
++ tmp = list_entry(rng_list_ptr, struct hwrng, list); |
1124 |
++ if (tmp->quality < rng->quality) |
1125 |
++ break; |
1126 |
++ } |
1127 |
++ list_add_tail(&rng->list, rng_list_ptr); |
1128 |
++ |
1129 |
+ old_rng = current_rng; |
1130 |
+ err = 0; |
1131 |
+- if (!old_rng) { |
1132 |
++ if (!old_rng || |
1133 |
++ (!cur_rng_set_by_user && rng->quality > old_rng->quality)) { |
1134 |
++ /* |
1135 |
++ * Set new rng as current as the new rng source |
1136 |
++ * provides better entropy quality and was not |
1137 |
++ * chosen by userspace. |
1138 |
++ */ |
1139 |
+ err = set_current_rng(rng); |
1140 |
+ if (err) |
1141 |
+ goto out_unlock; |
1142 |
+ } |
1143 |
+- list_add_tail(&rng->list, &rng_list); |
1144 |
+ |
1145 |
+ if (old_rng && !rng->init) { |
1146 |
+ /* |
1147 |
+@@ -493,12 +495,13 @@ void hwrng_unregister(struct hwrng *rng) |
1148 |
+ list_del(&rng->list); |
1149 |
+ if (current_rng == rng) { |
1150 |
+ drop_current_rng(); |
1151 |
++ cur_rng_set_by_user = 0; |
1152 |
++ /* rng_list is sorted by quality, use the best (=first) one */ |
1153 |
+ if (!list_empty(&rng_list)) { |
1154 |
+- struct hwrng *tail; |
1155 |
+- |
1156 |
+- tail = list_entry(rng_list.prev, struct hwrng, list); |
1157 |
++ struct hwrng *new_rng; |
1158 |
+ |
1159 |
+- set_current_rng(tail); |
1160 |
++ new_rng = list_entry(rng_list.next, struct hwrng, list); |
1161 |
++ set_current_rng(new_rng); |
1162 |
+ } |
1163 |
+ } |
1164 |
+ |
1165 |
+diff --git a/drivers/char/random.c b/drivers/char/random.c |
1166 |
+index 70ee86e034fcd..8e701ea78b0da 100644 |
1167 |
+--- a/drivers/char/random.c |
1168 |
++++ b/drivers/char/random.c |
1169 |
+@@ -1,239 +1,29 @@ |
1170 |
++// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
1171 |
+ /* |
1172 |
+- * random.c -- A strong random number generator |
1173 |
+- * |
1174 |
++ * Copyright (C) 2017-2022 Jason A. Donenfeld <Jason@×××××.com>. All Rights Reserved. |
1175 |
+ * Copyright Matt Mackall <mpm@×××××××.com>, 2003, 2004, 2005 |
1176 |
+- * |
1177 |
+- * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All |
1178 |
+- * rights reserved. |
1179 |
+- * |
1180 |
+- * Redistribution and use in source and binary forms, with or without |
1181 |
+- * modification, are permitted provided that the following conditions |
1182 |
+- * are met: |
1183 |
+- * 1. Redistributions of source code must retain the above copyright |
1184 |
+- * notice, and the entire permission notice in its entirety, |
1185 |
+- * including the disclaimer of warranties. |
1186 |
+- * 2. Redistributions in binary form must reproduce the above copyright |
1187 |
+- * notice, this list of conditions and the following disclaimer in the |
1188 |
+- * documentation and/or other materials provided with the distribution. |
1189 |
+- * 3. The name of the author may not be used to endorse or promote |
1190 |
+- * products derived from this software without specific prior |
1191 |
+- * written permission. |
1192 |
+- * |
1193 |
+- * ALTERNATIVELY, this product may be distributed under the terms of |
1194 |
+- * the GNU General Public License, in which case the provisions of the GPL are |
1195 |
+- * required INSTEAD OF the above restrictions. (This clause is |
1196 |
+- * necessary due to a potential bad interaction between the GPL and |
1197 |
+- * the restrictions contained in a BSD-style copyright.) |
1198 |
+- * |
1199 |
+- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
1200 |
+- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
1201 |
+- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF |
1202 |
+- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
1203 |
+- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
1204 |
+- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
1205 |
+- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
1206 |
+- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
1207 |
+- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
1208 |
+- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
1209 |
+- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH |
1210 |
+- * DAMAGE. |
1211 |
++ * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All rights reserved. |
1212 |
++ * |
1213 |
++ * This driver produces cryptographically secure pseudorandom data. It is divided |
1214 |
++ * into roughly six sections, each with a section header: |
1215 |
++ * |
1216 |
++ * - Initialization and readiness waiting. |
1217 |
++ * - Fast key erasure RNG, the "crng". |
1218 |
++ * - Entropy accumulation and extraction routines. |
1219 |
++ * - Entropy collection routines. |
1220 |
++ * - Userspace reader/writer interfaces. |
1221 |
++ * - Sysctl interface. |
1222 |
++ * |
1223 |
++ * The high level overview is that there is one input pool, into which |
1224 |
++ * various pieces of data are hashed. Prior to initialization, some of that |
1225 |
++ * data is then "credited" as having a certain number of bits of entropy. |
1226 |
++ * When enough bits of entropy are available, the hash is finalized and |
1227 |
++ * handed as a key to a stream cipher that expands it indefinitely for |
1228 |
++ * various consumers. This key is periodically refreshed as the various |
1229 |
++ * entropy collectors, described below, add data to the input pool. |
1230 |
+ */ |
1231 |
+ |
1232 |
+-/* |
1233 |
+- * (now, with legal B.S. out of the way.....) |
1234 |
+- * |
1235 |
+- * This routine gathers environmental noise from device drivers, etc., |
1236 |
+- * and returns good random numbers, suitable for cryptographic use. |
1237 |
+- * Besides the obvious cryptographic uses, these numbers are also good |
1238 |
+- * for seeding TCP sequence numbers, and other places where it is |
1239 |
+- * desirable to have numbers which are not only random, but hard to |
1240 |
+- * predict by an attacker. |
1241 |
+- * |
1242 |
+- * Theory of operation |
1243 |
+- * =================== |
1244 |
+- * |
1245 |
+- * Computers are very predictable devices. Hence it is extremely hard |
1246 |
+- * to produce truly random numbers on a computer --- as opposed to |
1247 |
+- * pseudo-random numbers, which can easily generated by using a |
1248 |
+- * algorithm. Unfortunately, it is very easy for attackers to guess |
1249 |
+- * the sequence of pseudo-random number generators, and for some |
1250 |
+- * applications this is not acceptable. So instead, we must try to |
1251 |
+- * gather "environmental noise" from the computer's environment, which |
1252 |
+- * must be hard for outside attackers to observe, and use that to |
1253 |
+- * generate random numbers. In a Unix environment, this is best done |
1254 |
+- * from inside the kernel. |
1255 |
+- * |
1256 |
+- * Sources of randomness from the environment include inter-keyboard |
1257 |
+- * timings, inter-interrupt timings from some interrupts, and other |
1258 |
+- * events which are both (a) non-deterministic and (b) hard for an |
1259 |
+- * outside observer to measure. Randomness from these sources are |
1260 |
+- * added to an "entropy pool", which is mixed using a CRC-like function. |
1261 |
+- * This is not cryptographically strong, but it is adequate assuming |
1262 |
+- * the randomness is not chosen maliciously, and it is fast enough that |
1263 |
+- * the overhead of doing it on every interrupt is very reasonable. |
1264 |
+- * As random bytes are mixed into the entropy pool, the routines keep |
1265 |
+- * an *estimate* of how many bits of randomness have been stored into |
1266 |
+- * the random number generator's internal state. |
1267 |
+- * |
1268 |
+- * When random bytes are desired, they are obtained by taking the SHA |
1269 |
+- * hash of the contents of the "entropy pool". The SHA hash avoids |
1270 |
+- * exposing the internal state of the entropy pool. It is believed to |
1271 |
+- * be computationally infeasible to derive any useful information |
1272 |
+- * about the input of SHA from its output. Even if it is possible to |
1273 |
+- * analyze SHA in some clever way, as long as the amount of data |
1274 |
+- * returned from the generator is less than the inherent entropy in |
1275 |
+- * the pool, the output data is totally unpredictable. For this |
1276 |
+- * reason, the routine decreases its internal estimate of how many |
1277 |
+- * bits of "true randomness" are contained in the entropy pool as it |
1278 |
+- * outputs random numbers. |
1279 |
+- * |
1280 |
+- * If this estimate goes to zero, the routine can still generate |
1281 |
+- * random numbers; however, an attacker may (at least in theory) be |
1282 |
+- * able to infer the future output of the generator from prior |
1283 |
+- * outputs. This requires successful cryptanalysis of SHA, which is |
1284 |
+- * not believed to be feasible, but there is a remote possibility. |
1285 |
+- * Nonetheless, these numbers should be useful for the vast majority |
1286 |
+- * of purposes. |
1287 |
+- * |
1288 |
+- * Exported interfaces ---- output |
1289 |
+- * =============================== |
1290 |
+- * |
1291 |
+- * There are three exported interfaces; the first is one designed to |
1292 |
+- * be used from within the kernel: |
1293 |
+- * |
1294 |
+- * void get_random_bytes(void *buf, int nbytes); |
1295 |
+- * |
1296 |
+- * This interface will return the requested number of random bytes, |
1297 |
+- * and place it in the requested buffer. |
1298 |
+- * |
1299 |
+- * The two other interfaces are two character devices /dev/random and |
1300 |
+- * /dev/urandom. /dev/random is suitable for use when very high |
1301 |
+- * quality randomness is desired (for example, for key generation or |
1302 |
+- * one-time pads), as it will only return a maximum of the number of |
1303 |
+- * bits of randomness (as estimated by the random number generator) |
1304 |
+- * contained in the entropy pool. |
1305 |
+- * |
1306 |
+- * The /dev/urandom device does not have this limit, and will return |
1307 |
+- * as many bytes as are requested. As more and more random bytes are |
1308 |
+- * requested without giving time for the entropy pool to recharge, |
1309 |
+- * this will result in random numbers that are merely cryptographically |
1310 |
+- * strong. For many applications, however, this is acceptable. |
1311 |
+- * |
1312 |
+- * Exported interfaces ---- input |
1313 |
+- * ============================== |
1314 |
+- * |
1315 |
+- * The current exported interfaces for gathering environmental noise |
1316 |
+- * from the devices are: |
1317 |
+- * |
1318 |
+- * void add_device_randomness(const void *buf, unsigned int size); |
1319 |
+- * void add_input_randomness(unsigned int type, unsigned int code, |
1320 |
+- * unsigned int value); |
1321 |
+- * void add_interrupt_randomness(int irq, int irq_flags); |
1322 |
+- * void add_disk_randomness(struct gendisk *disk); |
1323 |
+- * |
1324 |
+- * add_device_randomness() is for adding data to the random pool that |
1325 |
+- * is likely to differ between two devices (or possibly even per boot). |
1326 |
+- * This would be things like MAC addresses or serial numbers, or the |
1327 |
+- * read-out of the RTC. This does *not* add any actual entropy to the |
1328 |
+- * pool, but it initializes the pool to different values for devices |
1329 |
+- * that might otherwise be identical and have very little entropy |
1330 |
+- * available to them (particularly common in the embedded world). |
1331 |
+- * |
1332 |
+- * add_input_randomness() uses the input layer interrupt timing, as well as |
1333 |
+- * the event type information from the hardware. |
1334 |
+- * |
1335 |
+- * add_interrupt_randomness() uses the interrupt timing as random |
1336 |
+- * inputs to the entropy pool. Using the cycle counters and the irq source |
1337 |
+- * as inputs, it feeds the randomness roughly once a second. |
1338 |
+- * |
1339 |
+- * add_disk_randomness() uses what amounts to the seek time of block |
1340 |
+- * layer request events, on a per-disk_devt basis, as input to the |
1341 |
+- * entropy pool. Note that high-speed solid state drives with very low |
1342 |
+- * seek times do not make for good sources of entropy, as their seek |
1343 |
+- * times are usually fairly consistent. |
1344 |
+- * |
1345 |
+- * All of these routines try to estimate how many bits of randomness a |
1346 |
+- * particular randomness source. They do this by keeping track of the |
1347 |
+- * first and second order deltas of the event timings. |
1348 |
+- * |
1349 |
+- * Ensuring unpredictability at system startup |
1350 |
+- * ============================================ |
1351 |
+- * |
1352 |
+- * When any operating system starts up, it will go through a sequence |
1353 |
+- * of actions that are fairly predictable by an adversary, especially |
1354 |
+- * if the start-up does not involve interaction with a human operator. |
1355 |
+- * This reduces the actual number of bits of unpredictability in the |
1356 |
+- * entropy pool below the value in entropy_count. In order to |
1357 |
+- * counteract this effect, it helps to carry information in the |
1358 |
+- * entropy pool across shut-downs and start-ups. To do this, put the |
1359 |
+- * following lines an appropriate script which is run during the boot |
1360 |
+- * sequence: |
1361 |
+- * |
1362 |
+- * echo "Initializing random number generator..." |
1363 |
+- * random_seed=/var/run/random-seed |
1364 |
+- * # Carry a random seed from start-up to start-up |
1365 |
+- * # Load and then save the whole entropy pool |
1366 |
+- * if [ -f $random_seed ]; then |
1367 |
+- * cat $random_seed >/dev/urandom |
1368 |
+- * else |
1369 |
+- * touch $random_seed |
1370 |
+- * fi |
1371 |
+- * chmod 600 $random_seed |
1372 |
+- * dd if=/dev/urandom of=$random_seed count=1 bs=512 |
1373 |
+- * |
1374 |
+- * and the following lines in an appropriate script which is run as |
1375 |
+- * the system is shutdown: |
1376 |
+- * |
1377 |
+- * # Carry a random seed from shut-down to start-up |
1378 |
+- * # Save the whole entropy pool |
1379 |
+- * echo "Saving random seed..." |
1380 |
+- * random_seed=/var/run/random-seed |
1381 |
+- * touch $random_seed |
1382 |
+- * chmod 600 $random_seed |
1383 |
+- * dd if=/dev/urandom of=$random_seed count=1 bs=512 |
1384 |
+- * |
1385 |
+- * For example, on most modern systems using the System V init |
1386 |
+- * scripts, such code fragments would be found in |
1387 |
+- * /etc/rc.d/init.d/random. On older Linux systems, the correct script |
1388 |
+- * location might be in /etc/rcb.d/rc.local or /etc/rc.d/rc.0. |
1389 |
+- * |
1390 |
+- * Effectively, these commands cause the contents of the entropy pool |
1391 |
+- * to be saved at shut-down time and reloaded into the entropy pool at |
1392 |
+- * start-up. (The 'dd' in the addition to the bootup script is to |
1393 |
+- * make sure that /etc/random-seed is different for every start-up, |
1394 |
+- * even if the system crashes without executing rc.0.) Even with |
1395 |
+- * complete knowledge of the start-up activities, predicting the state |
1396 |
+- * of the entropy pool requires knowledge of the previous history of |
1397 |
+- * the system. |
1398 |
+- * |
1399 |
+- * Configuring the /dev/random driver under Linux |
1400 |
+- * ============================================== |
1401 |
+- * |
1402 |
+- * The /dev/random driver under Linux uses minor numbers 8 and 9 of |
1403 |
+- * the /dev/mem major number (#1). So if your system does not have |
1404 |
+- * /dev/random and /dev/urandom created already, they can be created |
1405 |
+- * by using the commands: |
1406 |
+- * |
1407 |
+- * mknod /dev/random c 1 8 |
1408 |
+- * mknod /dev/urandom c 1 9 |
1409 |
+- * |
1410 |
+- * Acknowledgements: |
1411 |
+- * ================= |
1412 |
+- * |
1413 |
+- * Ideas for constructing this random number generator were derived |
1414 |
+- * from Pretty Good Privacy's random number generator, and from private |
1415 |
+- * discussions with Phil Karn. Colin Plumb provided a faster random |
1416 |
+- * number generator, which speed up the mixing function of the entropy |
1417 |
+- * pool, taken from PGPfone. Dale Worley has also contributed many |
1418 |
+- * useful ideas and suggestions to improve this driver. |
1419 |
+- * |
1420 |
+- * Any flaws in the design are solely my responsibility, and should |
1421 |
+- * not be attributed to the Phil, Colin, or any of authors of PGP. |
1422 |
+- * |
1423 |
+- * Further background information on this topic may be obtained from |
1424 |
+- * RFC 1750, "Randomness Recommendations for Security", by Donald |
1425 |
+- * Eastlake, Steve Crocker, and Jeff Schiller. |
1426 |
+- */ |
1427 |
++#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1428 |
+ |
1429 |
+ #include <linux/utsname.h> |
1430 |
+ #include <linux/module.h> |
1431 |
+@@ -253,8 +43,6 @@ |
1432 |
+ #include <linux/spinlock.h> |
1433 |
+ #include <linux/kthread.h> |
1434 |
+ #include <linux/percpu.h> |
1435 |
+-#include <linux/cryptohash.h> |
1436 |
+-#include <linux/fips.h> |
1437 |
+ #include <linux/ptrace.h> |
1438 |
+ #include <linux/kmemcheck.h> |
1439 |
+ #include <linux/workqueue.h> |
1440 |
+@@ -263,1480 +51,1067 @@ |
1441 |
+ #include <linux/syscalls.h> |
1442 |
+ #include <linux/completion.h> |
1443 |
+ #include <linux/uuid.h> |
1444 |
++#include <linux/siphash.h> |
1445 |
++#include <linux/uio.h> |
1446 |
+ #include <crypto/chacha20.h> |
1447 |
+- |
1448 |
++#include <crypto/blake2s.h> |
1449 |
+ #include <asm/processor.h> |
1450 |
+ #include <asm/uaccess.h> |
1451 |
+ #include <asm/irq.h> |
1452 |
+ #include <asm/irq_regs.h> |
1453 |
+ #include <asm/io.h> |
1454 |
+ |
1455 |
+-#define CREATE_TRACE_POINTS |
1456 |
+-#include <trace/events/random.h> |
1457 |
+- |
1458 |
+-/* #define ADD_INTERRUPT_BENCH */ |
1459 |
++/********************************************************************* |
1460 |
++ * |
1461 |
++ * Initialization and readiness waiting. |
1462 |
++ * |
1463 |
++ * Much of the RNG infrastructure is devoted to various dependencies |
1464 |
++ * being able to wait until the RNG has collected enough entropy and |
1465 |
++ * is ready for safe consumption. |
1466 |
++ * |
1467 |
++ *********************************************************************/ |
1468 |
+ |
1469 |
+ /* |
1470 |
+- * Configuration information |
1471 |
++ * crng_init is protected by base_crng->lock, and only increases |
1472 |
++ * its value (from empty->early->ready). |
1473 |
+ */ |
1474 |
+-#define INPUT_POOL_SHIFT 12 |
1475 |
+-#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5)) |
1476 |
+-#define OUTPUT_POOL_SHIFT 10 |
1477 |
+-#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5)) |
1478 |
+-#define SEC_XFER_SIZE 512 |
1479 |
+-#define EXTRACT_SIZE 10 |
1480 |
+- |
1481 |
+-#define DEBUG_RANDOM_BOOT 0 |
1482 |
++static enum { |
1483 |
++ CRNG_EMPTY = 0, /* Little to no entropy collected */ |
1484 |
++ CRNG_EARLY = 1, /* At least POOL_EARLY_BITS collected */ |
1485 |
++ CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */ |
1486 |
++} crng_init __read_mostly = CRNG_EMPTY; |
1487 |
++#define crng_ready() (likely(crng_init >= CRNG_READY)) |
1488 |
++/* Various types of waiters for crng_init->CRNG_READY transition. */ |
1489 |
++static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait); |
1490 |
++static struct fasync_struct *fasync; |
1491 |
++static DEFINE_SPINLOCK(random_ready_chain_lock); |
1492 |
++static RAW_NOTIFIER_HEAD(random_ready_chain); |
1493 |
+ |
1494 |
+-#define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long)) |
1495 |
++/* Control how we warn userspace. */ |
1496 |
++static struct ratelimit_state urandom_warning = |
1497 |
++ RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3); |
1498 |
++static int ratelimit_disable __read_mostly = |
1499 |
++ IS_ENABLED(CONFIG_WARN_ALL_UNSEEDED_RANDOM); |
1500 |
++module_param_named(ratelimit_disable, ratelimit_disable, int, 0644); |
1501 |
++MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression"); |
1502 |
+ |
1503 |
+ /* |
1504 |
+- * To allow fractional bits to be tracked, the entropy_count field is |
1505 |
+- * denominated in units of 1/8th bits. |
1506 |
++ * Returns whether or not the input pool has been seeded and thus guaranteed |
1507 |
++ * to supply cryptographically secure random numbers. This applies to: the |
1508 |
++ * /dev/urandom device, the get_random_bytes function, and the get_random_{u32, |
1509 |
++ * ,u64,int,long} family of functions. |
1510 |
+ * |
1511 |
+- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in |
1512 |
+- * credit_entropy_bits() needs to be 64 bits wide. |
1513 |
++ * Returns: true if the input pool has been seeded. |
1514 |
++ * false if the input pool has not been seeded. |
1515 |
+ */ |
1516 |
+-#define ENTROPY_SHIFT 3 |
1517 |
+-#define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT) |
1518 |
++bool rng_is_initialized(void) |
1519 |
++{ |
1520 |
++ return crng_ready(); |
1521 |
++} |
1522 |
++EXPORT_SYMBOL(rng_is_initialized); |
1523 |
+ |
1524 |
+-/* |
1525 |
+- * The minimum number of bits of entropy before we wake up a read on |
1526 |
+- * /dev/random. Should be enough to do a significant reseed. |
1527 |
+- */ |
1528 |
+-static int random_read_wakeup_bits = 64; |
1529 |
++/* Used by wait_for_random_bytes(), and considered an entropy collector, below. */ |
1530 |
++static void try_to_generate_entropy(void); |
1531 |
+ |
1532 |
+ /* |
1533 |
+- * If the entropy count falls under this number of bits, then we |
1534 |
+- * should wake up processes which are selecting or polling on write |
1535 |
+- * access to /dev/random. |
1536 |
++ * Wait for the input pool to be seeded and thus guaranteed to supply |
1537 |
++ * cryptographically secure random numbers. This applies to: the /dev/urandom |
1538 |
++ * device, the get_random_bytes function, and the get_random_{u32,u64,int,long} |
1539 |
++ * family of functions. Using any of these functions without first calling |
1540 |
++ * this function forfeits the guarantee of security. |
1541 |
++ * |
1542 |
++ * Returns: 0 if the input pool has been seeded. |
1543 |
++ * -ERESTARTSYS if the function was interrupted by a signal. |
1544 |
+ */ |
1545 |
+-static int random_write_wakeup_bits = 28 * OUTPUT_POOL_WORDS; |
1546 |
++int wait_for_random_bytes(void) |
1547 |
++{ |
1548 |
++ while (!crng_ready()) { |
1549 |
++ int ret; |
1550 |
+ |
1551 |
+-/* |
1552 |
+- * The minimum number of seconds between urandom pool reseeding. We |
1553 |
+- * do this to limit the amount of entropy that can be drained from the |
1554 |
+- * input pool even if there are heavy demands on /dev/urandom. |
1555 |
+- */ |
1556 |
+-static int random_min_urandom_seed = 60; |
1557 |
++ try_to_generate_entropy(); |
1558 |
++ ret = wait_event_interruptible_timeout(crng_init_wait, crng_ready(), HZ); |
1559 |
++ if (ret) |
1560 |
++ return ret > 0 ? 0 : ret; |
1561 |
++ } |
1562 |
++ return 0; |
1563 |
++} |
1564 |
++EXPORT_SYMBOL(wait_for_random_bytes); |
1565 |
+ |
1566 |
+ /* |
1567 |
+- * Originally, we used a primitive polynomial of degree .poolwords |
1568 |
+- * over GF(2). The taps for various sizes are defined below. They |
1569 |
+- * were chosen to be evenly spaced except for the last tap, which is 1 |
1570 |
+- * to get the twisting happening as fast as possible. |
1571 |
+- * |
1572 |
+- * For the purposes of better mixing, we use the CRC-32 polynomial as |
1573 |
+- * well to make a (modified) twisted Generalized Feedback Shift |
1574 |
+- * Register. (See M. Matsumoto & Y. Kurita, 1992. Twisted GFSR |
1575 |
+- * generators. ACM Transactions on Modeling and Computer Simulation |
1576 |
+- * 2(3):179-194. Also see M. Matsumoto & Y. Kurita, 1994. Twisted |
1577 |
+- * GFSR generators II. ACM Transactions on Modeling and Computer |
1578 |
+- * Simulation 4:254-266) |
1579 |
+- * |
1580 |
+- * Thanks to Colin Plumb for suggesting this. |
1581 |
+- * |
1582 |
+- * The mixing operation is much less sensitive than the output hash, |
1583 |
+- * where we use SHA-1. All that we want of mixing operation is that |
1584 |
+- * it be a good non-cryptographic hash; i.e. it not produce collisions |
1585 |
+- * when fed "random" data of the sort we expect to see. As long as |
1586 |
+- * the pool state differs for different inputs, we have preserved the |
1587 |
+- * input entropy and done a good job. The fact that an intelligent |
1588 |
+- * attacker can construct inputs that will produce controlled |
1589 |
+- * alterations to the pool's state is not important because we don't |
1590 |
+- * consider such inputs to contribute any randomness. The only |
1591 |
+- * property we need with respect to them is that the attacker can't |
1592 |
+- * increase his/her knowledge of the pool's state. Since all |
1593 |
+- * additions are reversible (knowing the final state and the input, |
1594 |
+- * you can reconstruct the initial state), if an attacker has any |
1595 |
+- * uncertainty about the initial state, he/she can only shuffle that |
1596 |
+- * uncertainty about, but never cause any collisions (which would |
1597 |
+- * decrease the uncertainty). |
1598 |
++ * Add a callback function that will be invoked when the input |
1599 |
++ * pool is initialised. |
1600 |
+ * |
1601 |
+- * Our mixing functions were analyzed by Lacharme, Roeck, Strubel, and |
1602 |
+- * Videau in their paper, "The Linux Pseudorandom Number Generator |
1603 |
+- * Revisited" (see: http://eprint.iacr.org/2012/251.pdf). In their |
1604 |
+- * paper, they point out that we are not using a true Twisted GFSR, |
1605 |
+- * since Matsumoto & Kurita used a trinomial feedback polynomial (that |
1606 |
+- * is, with only three taps, instead of the six that we are using). |
1607 |
+- * As a result, the resulting polynomial is neither primitive nor |
1608 |
+- * irreducible, and hence does not have a maximal period over |
1609 |
+- * GF(2**32). They suggest a slight change to the generator |
1610 |
+- * polynomial which improves the resulting TGFSR polynomial to be |
1611 |
+- * irreducible, which we have made here. |
1612 |
++ * returns: 0 if callback is successfully added |
1613 |
++ * -EALREADY if pool is already initialised (callback not called) |
1614 |
+ */ |
1615 |
+-static struct poolinfo { |
1616 |
+- int poolbitshift, poolwords, poolbytes, poolbits, poolfracbits; |
1617 |
+-#define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5) |
1618 |
+- int tap1, tap2, tap3, tap4, tap5; |
1619 |
+-} poolinfo_table[] = { |
1620 |
+- /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */ |
1621 |
+- /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */ |
1622 |
+- { S(128), 104, 76, 51, 25, 1 }, |
1623 |
+- /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */ |
1624 |
+- /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */ |
1625 |
+- { S(32), 26, 19, 14, 7, 1 }, |
1626 |
+-#if 0 |
1627 |
+- /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */ |
1628 |
+- { S(2048), 1638, 1231, 819, 411, 1 }, |
1629 |
+- |
1630 |
+- /* x^1024 + x^817 + x^615 + x^412 + x^204 + x + 1 -- 290 */ |
1631 |
+- { S(1024), 817, 615, 412, 204, 1 }, |
1632 |
+- |
1633 |
+- /* x^1024 + x^819 + x^616 + x^410 + x^207 + x^2 + 1 -- 115 */ |
1634 |
+- { S(1024), 819, 616, 410, 207, 2 }, |
1635 |
+- |
1636 |
+- /* x^512 + x^411 + x^308 + x^208 + x^104 + x + 1 -- 225 */ |
1637 |
+- { S(512), 411, 308, 208, 104, 1 }, |
1638 |
+- |
1639 |
+- /* x^512 + x^409 + x^307 + x^206 + x^102 + x^2 + 1 -- 95 */ |
1640 |
+- { S(512), 409, 307, 206, 102, 2 }, |
1641 |
+- /* x^512 + x^409 + x^309 + x^205 + x^103 + x^2 + 1 -- 95 */ |
1642 |
+- { S(512), 409, 309, 205, 103, 2 }, |
1643 |
+- |
1644 |
+- /* x^256 + x^205 + x^155 + x^101 + x^52 + x + 1 -- 125 */ |
1645 |
+- { S(256), 205, 155, 101, 52, 1 }, |
1646 |
+- |
1647 |
+- /* x^128 + x^103 + x^78 + x^51 + x^27 + x^2 + 1 -- 70 */ |
1648 |
+- { S(128), 103, 78, 51, 27, 2 }, |
1649 |
+- |
1650 |
+- /* x^64 + x^52 + x^39 + x^26 + x^14 + x + 1 -- 15 */ |
1651 |
+- { S(64), 52, 39, 26, 14, 1 }, |
1652 |
+-#endif |
1653 |
+-}; |
1654 |
++int __cold register_random_ready_notifier(struct notifier_block *nb) |
1655 |
++{ |
1656 |
++ unsigned long flags; |
1657 |
++ int ret = -EALREADY; |
1658 |
++ |
1659 |
++ if (crng_ready()) |
1660 |
++ return ret; |
1661 |
++ |
1662 |
++ spin_lock_irqsave(&random_ready_chain_lock, flags); |
1663 |
++ if (!crng_ready()) |
1664 |
++ ret = raw_notifier_chain_register(&random_ready_chain, nb); |
1665 |
++ spin_unlock_irqrestore(&random_ready_chain_lock, flags); |
1666 |
++ return ret; |
1667 |
++} |
1668 |
+ |
1669 |
+ /* |
1670 |
+- * Static global variables |
1671 |
++ * Delete a previously registered readiness callback function. |
1672 |
+ */ |
1673 |
+-static DECLARE_WAIT_QUEUE_HEAD(random_read_wait); |
1674 |
+-static DECLARE_WAIT_QUEUE_HEAD(random_write_wait); |
1675 |
+-static DECLARE_WAIT_QUEUE_HEAD(urandom_init_wait); |
1676 |
+-static struct fasync_struct *fasync; |
1677 |
+- |
1678 |
+-static DEFINE_SPINLOCK(random_ready_list_lock); |
1679 |
+-static LIST_HEAD(random_ready_list); |
1680 |
++int __cold unregister_random_ready_notifier(struct notifier_block *nb) |
1681 |
++{ |
1682 |
++ unsigned long flags; |
1683 |
++ int ret; |
1684 |
+ |
1685 |
+-struct crng_state { |
1686 |
+- __u32 state[16]; |
1687 |
+- unsigned long init_time; |
1688 |
+- spinlock_t lock; |
1689 |
+-}; |
1690 |
++ spin_lock_irqsave(&random_ready_chain_lock, flags); |
1691 |
++ ret = raw_notifier_chain_unregister(&random_ready_chain, nb); |
1692 |
++ spin_unlock_irqrestore(&random_ready_chain_lock, flags); |
1693 |
++ return ret; |
1694 |
++} |
1695 |
+ |
1696 |
+-struct crng_state primary_crng = { |
1697 |
+- .lock = __SPIN_LOCK_UNLOCKED(primary_crng.lock), |
1698 |
+-}; |
1699 |
++static void __cold process_random_ready_list(void) |
1700 |
++{ |
1701 |
++ unsigned long flags; |
1702 |
+ |
1703 |
+-/* |
1704 |
+- * crng_init = 0 --> Uninitialized |
1705 |
+- * 1 --> Initialized |
1706 |
+- * 2 --> Initialized from input_pool |
1707 |
+- * |
1708 |
+- * crng_init is protected by primary_crng->lock, and only increases |
1709 |
+- * its value (from 0->1->2). |
1710 |
+- */ |
1711 |
+-static int crng_init = 0; |
1712 |
+-#define crng_ready() (likely(crng_init > 1)) |
1713 |
+-static int crng_init_cnt = 0; |
1714 |
+-static unsigned long crng_global_init_time = 0; |
1715 |
+-#define CRNG_INIT_CNT_THRESH (2*CHACHA20_KEY_SIZE) |
1716 |
+-static void _extract_crng(struct crng_state *crng, |
1717 |
+- __u8 out[CHACHA20_BLOCK_SIZE]); |
1718 |
+-static void _crng_backtrack_protect(struct crng_state *crng, |
1719 |
+- __u8 tmp[CHACHA20_BLOCK_SIZE], int used); |
1720 |
+-static void process_random_ready_list(void); |
1721 |
+- |
1722 |
+-static struct ratelimit_state unseeded_warning = |
1723 |
+- RATELIMIT_STATE_INIT("warn_unseeded_randomness", HZ, 3); |
1724 |
+-static struct ratelimit_state urandom_warning = |
1725 |
+- RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3); |
1726 |
++ spin_lock_irqsave(&random_ready_chain_lock, flags); |
1727 |
++ raw_notifier_call_chain(&random_ready_chain, 0, NULL); |
1728 |
++ spin_unlock_irqrestore(&random_ready_chain_lock, flags); |
1729 |
++} |
1730 |
+ |
1731 |
+-static int ratelimit_disable __read_mostly; |
1732 |
++#define warn_unseeded_randomness() \ |
1733 |
++ if (IS_ENABLED(CONFIG_WARN_ALL_UNSEEDED_RANDOM) && !crng_ready()) \ |
1734 |
++ pr_notice("%s called from %pS with crng_init=%d\n", \ |
1735 |
++ __func__, (void *)_RET_IP_, crng_init) |
1736 |
+ |
1737 |
+-module_param_named(ratelimit_disable, ratelimit_disable, int, 0644); |
1738 |
+-MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression"); |
1739 |
+ |
1740 |
+-/********************************************************************** |
1741 |
++/********************************************************************* |
1742 |
+ * |
1743 |
+- * OS independent entropy store. Here are the functions which handle |
1744 |
+- * storing entropy in an entropy pool. |
1745 |
++ * Fast key erasure RNG, the "crng". |
1746 |
+ * |
1747 |
+- **********************************************************************/ |
1748 |
++ * These functions expand entropy from the entropy extractor into |
1749 |
++ * long streams for external consumption using the "fast key erasure" |
1750 |
++ * RNG described at <https://blog.cr.yp.to/20170723-random.html>. |
1751 |
++ * |
1752 |
++ * There are a few exported interfaces for use by other drivers: |
1753 |
++ * |
1754 |
++ * void get_random_bytes(void *buf, size_t len) |
1755 |
++ * u32 get_random_u32() |
1756 |
++ * u64 get_random_u64() |
1757 |
++ * unsigned int get_random_int() |
1758 |
++ * unsigned long get_random_long() |
1759 |
++ * |
1760 |
++ * These interfaces will return the requested number of random bytes |
1761 |
++ * into the given buffer or as a return value. This is equivalent to |
1762 |
++ * a read from /dev/urandom. The u32, u64, int, and long family of |
1763 |
++ * functions may be higher performance for one-off random integers, |
1764 |
++ * because they do a bit of buffering and do not invoke reseeding |
1765 |
++ * until the buffer is emptied. |
1766 |
++ * |
1767 |
++ *********************************************************************/ |
1768 |
+ |
1769 |
+-struct entropy_store; |
1770 |
+-struct entropy_store { |
1771 |
+- /* read-only data: */ |
1772 |
+- const struct poolinfo *poolinfo; |
1773 |
+- __u32 *pool; |
1774 |
+- const char *name; |
1775 |
+- struct entropy_store *pull; |
1776 |
+- struct work_struct push_work; |
1777 |
+- |
1778 |
+- /* read-write data: */ |
1779 |
+- unsigned long last_pulled; |
1780 |
+- spinlock_t lock; |
1781 |
+- unsigned short add_ptr; |
1782 |
+- unsigned short input_rotate; |
1783 |
+- int entropy_count; |
1784 |
+- int entropy_total; |
1785 |
+- unsigned int initialized:1; |
1786 |
+- unsigned int limit:1; |
1787 |
+- unsigned int last_data_init:1; |
1788 |
+- __u8 last_data[EXTRACT_SIZE]; |
1789 |
++enum { |
1790 |
++ CRNG_RESEED_START_INTERVAL = HZ, |
1791 |
++ CRNG_RESEED_INTERVAL = 60 * HZ |
1792 |
+ }; |
1793 |
+ |
1794 |
+-static ssize_t extract_entropy(struct entropy_store *r, void *buf, |
1795 |
+- size_t nbytes, int min, int rsvd); |
1796 |
+-static ssize_t _extract_entropy(struct entropy_store *r, void *buf, |
1797 |
+- size_t nbytes, int fips); |
1798 |
+- |
1799 |
+-static void crng_reseed(struct crng_state *crng, struct entropy_store *r); |
1800 |
+-static void push_to_pool(struct work_struct *work); |
1801 |
+-static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy; |
1802 |
+-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy; |
1803 |
+- |
1804 |
+-static struct entropy_store input_pool = { |
1805 |
+- .poolinfo = &poolinfo_table[0], |
1806 |
+- .name = "input", |
1807 |
+- .limit = 1, |
1808 |
+- .lock = __SPIN_LOCK_UNLOCKED(input_pool.lock), |
1809 |
+- .pool = input_pool_data |
1810 |
++static struct { |
1811 |
++ u8 key[CHACHA20_KEY_SIZE] __aligned(__alignof__(long)); |
1812 |
++ unsigned long birth; |
1813 |
++ unsigned long generation; |
1814 |
++ spinlock_t lock; |
1815 |
++} base_crng = { |
1816 |
++ .lock = __SPIN_LOCK_UNLOCKED(base_crng.lock) |
1817 |
+ }; |
1818 |
+ |
1819 |
+-static struct entropy_store blocking_pool = { |
1820 |
+- .poolinfo = &poolinfo_table[1], |
1821 |
+- .name = "blocking", |
1822 |
+- .limit = 1, |
1823 |
+- .pull = &input_pool, |
1824 |
+- .lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock), |
1825 |
+- .pool = blocking_pool_data, |
1826 |
+- .push_work = __WORK_INITIALIZER(blocking_pool.push_work, |
1827 |
+- push_to_pool), |
1828 |
++struct crng { |
1829 |
++ u8 key[CHACHA20_KEY_SIZE]; |
1830 |
++ unsigned long generation; |
1831 |
+ }; |
1832 |
+ |
1833 |
+-static __u32 const twist_table[8] = { |
1834 |
+- 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158, |
1835 |
+- 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; |
1836 |
+- |
1837 |
+-/* |
1838 |
+- * This function adds bytes into the entropy "pool". It does not |
1839 |
+- * update the entropy estimate. The caller should call |
1840 |
+- * credit_entropy_bits if this is appropriate. |
1841 |
+- * |
1842 |
+- * The pool is stirred with a primitive polynomial of the appropriate |
1843 |
+- * degree, and then twisted. We twist by three bits at a time because |
1844 |
+- * it's cheap to do so and helps slightly in the expected case where |
1845 |
+- * the entropy is concentrated in the low-order bits. |
1846 |
+- */ |
1847 |
+-static void _mix_pool_bytes(struct entropy_store *r, const void *in, |
1848 |
+- int nbytes) |
1849 |
+-{ |
1850 |
+- unsigned long i, tap1, tap2, tap3, tap4, tap5; |
1851 |
+- int input_rotate; |
1852 |
+- int wordmask = r->poolinfo->poolwords - 1; |
1853 |
+- const char *bytes = in; |
1854 |
+- __u32 w; |
1855 |
+- |
1856 |
+- tap1 = r->poolinfo->tap1; |
1857 |
+- tap2 = r->poolinfo->tap2; |
1858 |
+- tap3 = r->poolinfo->tap3; |
1859 |
+- tap4 = r->poolinfo->tap4; |
1860 |
+- tap5 = r->poolinfo->tap5; |
1861 |
+- |
1862 |
+- input_rotate = r->input_rotate; |
1863 |
+- i = r->add_ptr; |
1864 |
+- |
1865 |
+- /* mix one byte at a time to simplify size handling and churn faster */ |
1866 |
+- while (nbytes--) { |
1867 |
+- w = rol32(*bytes++, input_rotate); |
1868 |
+- i = (i - 1) & wordmask; |
1869 |
+- |
1870 |
+- /* XOR in the various taps */ |
1871 |
+- w ^= r->pool[i]; |
1872 |
+- w ^= r->pool[(i + tap1) & wordmask]; |
1873 |
+- w ^= r->pool[(i + tap2) & wordmask]; |
1874 |
+- w ^= r->pool[(i + tap3) & wordmask]; |
1875 |
+- w ^= r->pool[(i + tap4) & wordmask]; |
1876 |
+- w ^= r->pool[(i + tap5) & wordmask]; |
1877 |
+- |
1878 |
+- /* Mix the result back in with a twist */ |
1879 |
+- r->pool[i] = (w >> 3) ^ twist_table[w & 7]; |
1880 |
+- |
1881 |
+- /* |
1882 |
+- * Normally, we add 7 bits of rotation to the pool. |
1883 |
+- * At the beginning of the pool, add an extra 7 bits |
1884 |
+- * rotation, so that successive passes spread the |
1885 |
+- * input bits across the pool evenly. |
1886 |
+- */ |
1887 |
+- input_rotate = (input_rotate + (i ? 7 : 14)) & 31; |
1888 |
+- } |
1889 |
+- |
1890 |
+- r->input_rotate = input_rotate; |
1891 |
+- r->add_ptr = i; |
1892 |
+-} |
1893 |
++static DEFINE_PER_CPU(struct crng, crngs) = { |
1894 |
++ .generation = ULONG_MAX |
1895 |
++}; |
1896 |
+ |
1897 |
+-static void __mix_pool_bytes(struct entropy_store *r, const void *in, |
1898 |
+- int nbytes) |
1899 |
+-{ |
1900 |
+- trace_mix_pool_bytes_nolock(r->name, nbytes, _RET_IP_); |
1901 |
+- _mix_pool_bytes(r, in, nbytes); |
1902 |
+-} |
1903 |
++/* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */ |
1904 |
++static void extract_entropy(void *buf, size_t len); |
1905 |
+ |
1906 |
+-static void mix_pool_bytes(struct entropy_store *r, const void *in, |
1907 |
+- int nbytes) |
1908 |
++/* This extracts a new crng key from the input pool. */ |
1909 |
++static void crng_reseed(void) |
1910 |
+ { |
1911 |
+ unsigned long flags; |
1912 |
++ unsigned long next_gen; |
1913 |
++ u8 key[CHACHA20_KEY_SIZE]; |
1914 |
+ |
1915 |
+- trace_mix_pool_bytes(r->name, nbytes, _RET_IP_); |
1916 |
+- spin_lock_irqsave(&r->lock, flags); |
1917 |
+- _mix_pool_bytes(r, in, nbytes); |
1918 |
+- spin_unlock_irqrestore(&r->lock, flags); |
1919 |
+-} |
1920 |
++ extract_entropy(key, sizeof(key)); |
1921 |
+ |
1922 |
+-struct fast_pool { |
1923 |
+- __u32 pool[4]; |
1924 |
+- unsigned long last; |
1925 |
+- unsigned short reg_idx; |
1926 |
+- unsigned char count; |
1927 |
+-}; |
1928 |
++ /* |
1929 |
++ * We copy the new key into the base_crng, overwriting the old one, |
1930 |
++ * and update the generation counter. We avoid hitting ULONG_MAX, |
1931 |
++ * because the per-cpu crngs are initialized to ULONG_MAX, so this |
1932 |
++ * forces new CPUs that come online to always initialize. |
1933 |
++ */ |
1934 |
++ spin_lock_irqsave(&base_crng.lock, flags); |
1935 |
++ memcpy(base_crng.key, key, sizeof(base_crng.key)); |
1936 |
++ next_gen = base_crng.generation + 1; |
1937 |
++ if (next_gen == ULONG_MAX) |
1938 |
++ ++next_gen; |
1939 |
++ WRITE_ONCE(base_crng.generation, next_gen); |
1940 |
++ WRITE_ONCE(base_crng.birth, jiffies); |
1941 |
++ if (!crng_ready()) |
1942 |
++ crng_init = CRNG_READY; |
1943 |
++ spin_unlock_irqrestore(&base_crng.lock, flags); |
1944 |
++ memzero_explicit(key, sizeof(key)); |
1945 |
++} |
1946 |
+ |
1947 |
+ /* |
1948 |
+- * This is a fast mixing routine used by the interrupt randomness |
1949 |
+- * collector. It's hardcoded for an 128 bit pool and assumes that any |
1950 |
+- * locks that might be needed are taken by the caller. |
1951 |
++ * This generates a ChaCha block using the provided key, and then |
1952 |
++ * immediately overwites that key with half the block. It returns |
1953 |
++ * the resultant ChaCha state to the user, along with the second |
1954 |
++ * half of the block containing 32 bytes of random data that may |
1955 |
++ * be used; random_data_len may not be greater than 32. |
1956 |
++ * |
1957 |
++ * The returned ChaCha state contains within it a copy of the old |
1958 |
++ * key value, at index 4, so the state should always be zeroed out |
1959 |
++ * immediately after using in order to maintain forward secrecy. |
1960 |
++ * If the state cannot be erased in a timely manner, then it is |
1961 |
++ * safer to set the random_data parameter to &chacha_state[4] so |
1962 |
++ * that this function overwrites it before returning. |
1963 |
+ */ |
1964 |
+-static void fast_mix(struct fast_pool *f) |
1965 |
++static void crng_fast_key_erasure(u8 key[CHACHA20_KEY_SIZE], |
1966 |
++ u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], |
1967 |
++ u8 *random_data, size_t random_data_len) |
1968 |
+ { |
1969 |
+- __u32 a = f->pool[0], b = f->pool[1]; |
1970 |
+- __u32 c = f->pool[2], d = f->pool[3]; |
1971 |
++ u8 first_block[CHACHA20_BLOCK_SIZE]; |
1972 |
+ |
1973 |
+- a += b; c += d; |
1974 |
+- b = rol32(b, 6); d = rol32(d, 27); |
1975 |
+- d ^= a; b ^= c; |
1976 |
++ BUG_ON(random_data_len > 32); |
1977 |
+ |
1978 |
+- a += b; c += d; |
1979 |
+- b = rol32(b, 16); d = rol32(d, 14); |
1980 |
+- d ^= a; b ^= c; |
1981 |
++ chacha_init_consts(chacha_state); |
1982 |
++ memcpy(&chacha_state[4], key, CHACHA20_KEY_SIZE); |
1983 |
++ memset(&chacha_state[12], 0, sizeof(u32) * 4); |
1984 |
++ chacha20_block(chacha_state, first_block); |
1985 |
+ |
1986 |
+- a += b; c += d; |
1987 |
+- b = rol32(b, 6); d = rol32(d, 27); |
1988 |
+- d ^= a; b ^= c; |
1989 |
+- |
1990 |
+- a += b; c += d; |
1991 |
+- b = rol32(b, 16); d = rol32(d, 14); |
1992 |
+- d ^= a; b ^= c; |
1993 |
+- |
1994 |
+- f->pool[0] = a; f->pool[1] = b; |
1995 |
+- f->pool[2] = c; f->pool[3] = d; |
1996 |
+- f->count++; |
1997 |
++ memcpy(key, first_block, CHACHA20_KEY_SIZE); |
1998 |
++ memcpy(random_data, first_block + CHACHA20_KEY_SIZE, random_data_len); |
1999 |
++ memzero_explicit(first_block, sizeof(first_block)); |
2000 |
+ } |
2001 |
+ |
2002 |
+-static void process_random_ready_list(void) |
2003 |
++/* |
2004 |
++ * Return whether the crng seed is considered to be sufficiently old |
2005 |
++ * that a reseeding is needed. This happens if the last reseeding |
2006 |
++ * was CRNG_RESEED_INTERVAL ago, or during early boot, at an interval |
2007 |
++ * proportional to the uptime. |
2008 |
++ */ |
2009 |
++static bool crng_has_old_seed(void) |
2010 |
+ { |
2011 |
+- unsigned long flags; |
2012 |
+- struct random_ready_callback *rdy, *tmp; |
2013 |
+- |
2014 |
+- spin_lock_irqsave(&random_ready_list_lock, flags); |
2015 |
+- list_for_each_entry_safe(rdy, tmp, &random_ready_list, list) { |
2016 |
+- struct module *owner = rdy->owner; |
2017 |
+- |
2018 |
+- list_del_init(&rdy->list); |
2019 |
+- rdy->func(rdy); |
2020 |
+- module_put(owner); |
2021 |
++ static bool early_boot = true; |
2022 |
++ unsigned long interval = CRNG_RESEED_INTERVAL; |
2023 |
++ |
2024 |
++ if (unlikely(READ_ONCE(early_boot))) { |
2025 |
++ time64_t uptime = ktime_get_seconds(); |
2026 |
++ if (uptime >= CRNG_RESEED_INTERVAL / HZ * 2) |
2027 |
++ WRITE_ONCE(early_boot, false); |
2028 |
++ else |
2029 |
++ interval = max_t(unsigned int, CRNG_RESEED_START_INTERVAL, |
2030 |
++ (unsigned int)uptime / 2 * HZ); |
2031 |
+ } |
2032 |
+- spin_unlock_irqrestore(&random_ready_list_lock, flags); |
2033 |
++ return time_is_before_jiffies(READ_ONCE(base_crng.birth) + interval); |
2034 |
+ } |
2035 |
+ |
2036 |
+ /* |
2037 |
+- * Credit (or debit) the entropy store with n bits of entropy. |
2038 |
+- * Use credit_entropy_bits_safe() if the value comes from userspace |
2039 |
+- * or otherwise should be checked for extreme values. |
2040 |
++ * This function returns a ChaCha state that you may use for generating |
2041 |
++ * random data. It also returns up to 32 bytes on its own of random data |
2042 |
++ * that may be used; random_data_len may not be greater than 32. |
2043 |
+ */ |
2044 |
+-static void credit_entropy_bits(struct entropy_store *r, int nbits) |
2045 |
++static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)], |
2046 |
++ u8 *random_data, size_t random_data_len) |
2047 |
+ { |
2048 |
+- int entropy_count, orig; |
2049 |
+- const int pool_size = r->poolinfo->poolfracbits; |
2050 |
+- int nfrac = nbits << ENTROPY_SHIFT; |
2051 |
++ unsigned long flags; |
2052 |
++ struct crng *crng; |
2053 |
+ |
2054 |
+- if (!nbits) |
2055 |
+- return; |
2056 |
++ BUG_ON(random_data_len > 32); |
2057 |
+ |
2058 |
+-retry: |
2059 |
+- entropy_count = orig = ACCESS_ONCE(r->entropy_count); |
2060 |
+- if (nfrac < 0) { |
2061 |
+- /* Debit */ |
2062 |
+- entropy_count += nfrac; |
2063 |
+- } else { |
2064 |
+- /* |
2065 |
+- * Credit: we have to account for the possibility of |
2066 |
+- * overwriting already present entropy. Even in the |
2067 |
+- * ideal case of pure Shannon entropy, new contributions |
2068 |
+- * approach the full value asymptotically: |
2069 |
+- * |
2070 |
+- * entropy <- entropy + (pool_size - entropy) * |
2071 |
+- * (1 - exp(-add_entropy/pool_size)) |
2072 |
+- * |
2073 |
+- * For add_entropy <= pool_size/2 then |
2074 |
+- * (1 - exp(-add_entropy/pool_size)) >= |
2075 |
+- * (add_entropy/pool_size)*0.7869... |
2076 |
+- * so we can approximate the exponential with |
2077 |
+- * 3/4*add_entropy/pool_size and still be on the |
2078 |
+- * safe side by adding at most pool_size/2 at a time. |
2079 |
+- * |
2080 |
+- * The use of pool_size-2 in the while statement is to |
2081 |
+- * prevent rounding artifacts from making the loop |
2082 |
+- * arbitrarily long; this limits the loop to log2(pool_size)*2 |
2083 |
+- * turns no matter how large nbits is. |
2084 |
+- */ |
2085 |
+- int pnfrac = nfrac; |
2086 |
+- const int s = r->poolinfo->poolbitshift + ENTROPY_SHIFT + 2; |
2087 |
+- /* The +2 corresponds to the /4 in the denominator */ |
2088 |
+- |
2089 |
+- do { |
2090 |
+- unsigned int anfrac = min(pnfrac, pool_size/2); |
2091 |
+- unsigned int add = |
2092 |
+- ((pool_size - entropy_count)*anfrac*3) >> s; |
2093 |
+- |
2094 |
+- entropy_count += add; |
2095 |
+- pnfrac -= anfrac; |
2096 |
+- } while (unlikely(entropy_count < pool_size-2 && pnfrac)); |
2097 |
+- } |
2098 |
+- |
2099 |
+- if (unlikely(entropy_count < 0)) { |
2100 |
+- pr_warn("random: negative entropy/overflow: pool %s count %d\n", |
2101 |
+- r->name, entropy_count); |
2102 |
+- WARN_ON(1); |
2103 |
+- entropy_count = 0; |
2104 |
+- } else if (entropy_count > pool_size) |
2105 |
+- entropy_count = pool_size; |
2106 |
+- if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) |
2107 |
+- goto retry; |
2108 |
+- |
2109 |
+- r->entropy_total += nbits; |
2110 |
+- if (!r->initialized && r->entropy_total > 128) { |
2111 |
+- r->initialized = 1; |
2112 |
+- r->entropy_total = 0; |
2113 |
++ /* |
2114 |
++ * For the fast path, we check whether we're ready, unlocked first, and |
2115 |
++ * then re-check once locked later. In the case where we're really not |
2116 |
++ * ready, we do fast key erasure with the base_crng directly, extracting |
2117 |
++ * when crng_init is CRNG_EMPTY. |
2118 |
++ */ |
2119 |
++ if (!crng_ready()) { |
2120 |
++ bool ready; |
2121 |
++ |
2122 |
++ spin_lock_irqsave(&base_crng.lock, flags); |
2123 |
++ ready = crng_ready(); |
2124 |
++ if (!ready) { |
2125 |
++ if (crng_init == CRNG_EMPTY) |
2126 |
++ extract_entropy(base_crng.key, sizeof(base_crng.key)); |
2127 |
++ crng_fast_key_erasure(base_crng.key, chacha_state, |
2128 |
++ random_data, random_data_len); |
2129 |
++ } |
2130 |
++ spin_unlock_irqrestore(&base_crng.lock, flags); |
2131 |
++ if (!ready) |
2132 |
++ return; |
2133 |
+ } |
2134 |
+ |
2135 |
+- trace_credit_entropy_bits(r->name, nbits, |
2136 |
+- entropy_count >> ENTROPY_SHIFT, |
2137 |
+- r->entropy_total, _RET_IP_); |
2138 |
+- |
2139 |
+- if (r == &input_pool) { |
2140 |
+- int entropy_bits = entropy_count >> ENTROPY_SHIFT; |
2141 |
++ /* |
2142 |
++ * If the base_crng is old enough, we reseed, which in turn bumps the |
2143 |
++ * generation counter that we check below. |
2144 |
++ */ |
2145 |
++ if (unlikely(crng_has_old_seed())) |
2146 |
++ crng_reseed(); |
2147 |
+ |
2148 |
+- if (crng_init < 2 && entropy_bits >= 128) { |
2149 |
+- crng_reseed(&primary_crng, r); |
2150 |
+- entropy_bits = r->entropy_count >> ENTROPY_SHIFT; |
2151 |
+- } |
2152 |
++ local_irq_save(flags); |
2153 |
++ crng = raw_cpu_ptr(&crngs); |
2154 |
+ |
2155 |
+- /* should we wake readers? */ |
2156 |
+- if (entropy_bits >= random_read_wakeup_bits) { |
2157 |
+- wake_up_interruptible(&random_read_wait); |
2158 |
+- kill_fasync(&fasync, SIGIO, POLL_IN); |
2159 |
+- } |
2160 |
+- /* If the input pool is getting full, send some |
2161 |
+- * entropy to the blocking pool until it is 75% full. |
2162 |
+- */ |
2163 |
+- if (entropy_bits > random_write_wakeup_bits && |
2164 |
+- r->initialized && |
2165 |
+- r->entropy_total >= 2*random_read_wakeup_bits) { |
2166 |
+- struct entropy_store *other = &blocking_pool; |
2167 |
+- |
2168 |
+- if (other->entropy_count <= |
2169 |
+- 3 * other->poolinfo->poolfracbits / 4) { |
2170 |
+- schedule_work(&other->push_work); |
2171 |
+- r->entropy_total = 0; |
2172 |
+- } |
2173 |
+- } |
2174 |
++ /* |
2175 |
++ * If our per-cpu crng is older than the base_crng, then it means |
2176 |
++ * somebody reseeded the base_crng. In that case, we do fast key |
2177 |
++ * erasure on the base_crng, and use its output as the new key |
2178 |
++ * for our per-cpu crng. This brings us up to date with base_crng. |
2179 |
++ */ |
2180 |
++ if (unlikely(crng->generation != READ_ONCE(base_crng.generation))) { |
2181 |
++ spin_lock(&base_crng.lock); |
2182 |
++ crng_fast_key_erasure(base_crng.key, chacha_state, |
2183 |
++ crng->key, sizeof(crng->key)); |
2184 |
++ crng->generation = base_crng.generation; |
2185 |
++ spin_unlock(&base_crng.lock); |
2186 |
+ } |
2187 |
++ |
2188 |
++ /* |
2189 |
++ * Finally, when we've made it this far, our per-cpu crng has an up |
2190 |
++ * to date key, and we can do fast key erasure with it to produce |
2191 |
++ * some random data and a ChaCha state for the caller. All other |
2192 |
++ * branches of this function are "unlikely", so most of the time we |
2193 |
++ * should wind up here immediately. |
2194 |
++ */ |
2195 |
++ crng_fast_key_erasure(crng->key, chacha_state, random_data, random_data_len); |
2196 |
++ local_irq_restore(flags); |
2197 |
+ } |
2198 |
+ |
2199 |
+-static int credit_entropy_bits_safe(struct entropy_store *r, int nbits) |
2200 |
++static void _get_random_bytes(void *buf, size_t len) |
2201 |
+ { |
2202 |
+- const int nbits_max = r->poolinfo->poolwords * 32; |
2203 |
++ u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)]; |
2204 |
++ u8 tmp[CHACHA20_BLOCK_SIZE]; |
2205 |
++ size_t first_block_len; |
2206 |
+ |
2207 |
+- if (nbits < 0) |
2208 |
+- return -EINVAL; |
2209 |
+- |
2210 |
+- /* Cap the value to avoid overflows */ |
2211 |
+- nbits = min(nbits, nbits_max); |
2212 |
++ if (!len) |
2213 |
++ return; |
2214 |
+ |
2215 |
+- credit_entropy_bits(r, nbits); |
2216 |
+- return 0; |
2217 |
+-} |
2218 |
++ first_block_len = min_t(size_t, 32, len); |
2219 |
++ crng_make_state(chacha_state, buf, first_block_len); |
2220 |
++ len -= first_block_len; |
2221 |
++ buf += first_block_len; |
2222 |
+ |
2223 |
+-/********************************************************************* |
2224 |
+- * |
2225 |
+- * CRNG using CHACHA20 |
2226 |
+- * |
2227 |
+- *********************************************************************/ |
2228 |
++ while (len) { |
2229 |
++ if (len < CHACHA20_BLOCK_SIZE) { |
2230 |
++ chacha20_block(chacha_state, tmp); |
2231 |
++ memcpy(buf, tmp, len); |
2232 |
++ memzero_explicit(tmp, sizeof(tmp)); |
2233 |
++ break; |
2234 |
++ } |
2235 |
+ |
2236 |
+-#define CRNG_RESEED_INTERVAL (300*HZ) |
2237 |
++ chacha20_block(chacha_state, buf); |
2238 |
++ if (unlikely(chacha_state[12] == 0)) |
2239 |
++ ++chacha_state[13]; |
2240 |
++ len -= CHACHA20_BLOCK_SIZE; |
2241 |
++ buf += CHACHA20_BLOCK_SIZE; |
2242 |
++ } |
2243 |
+ |
2244 |
+-static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait); |
2245 |
++ memzero_explicit(chacha_state, sizeof(chacha_state)); |
2246 |
++} |
2247 |
+ |
2248 |
+-#ifdef CONFIG_NUMA |
2249 |
+ /* |
2250 |
+- * Hack to deal with crazy userspace progams when they are all trying |
2251 |
+- * to access /dev/urandom in parallel. The programs are almost |
2252 |
+- * certainly doing something terribly wrong, but we'll work around |
2253 |
+- * their brain damage. |
2254 |
++ * This function is the exported kernel interface. It returns some |
2255 |
++ * number of good random numbers, suitable for key generation, seeding |
2256 |
++ * TCP sequence numbers, etc. It does not rely on the hardware random |
2257 |
++ * number generator. For random bytes direct from the hardware RNG |
2258 |
++ * (when available), use get_random_bytes_arch(). In order to ensure |
2259 |
++ * that the randomness provided by this function is okay, the function |
2260 |
++ * wait_for_random_bytes() should be called and return 0 at least once |
2261 |
++ * at any point prior. |
2262 |
+ */ |
2263 |
+-static struct crng_state **crng_node_pool __read_mostly; |
2264 |
+-#endif |
2265 |
+- |
2266 |
+-static void crng_initialize(struct crng_state *crng) |
2267 |
++void get_random_bytes(void *buf, size_t len) |
2268 |
+ { |
2269 |
+- int i; |
2270 |
+- unsigned long rv; |
2271 |
+- |
2272 |
+- memcpy(&crng->state[0], "expand 32-byte k", 16); |
2273 |
+- if (crng == &primary_crng) |
2274 |
+- _extract_entropy(&input_pool, &crng->state[4], |
2275 |
+- sizeof(__u32) * 12, 0); |
2276 |
+- else |
2277 |
+- get_random_bytes(&crng->state[4], sizeof(__u32) * 12); |
2278 |
+- for (i = 4; i < 16; i++) { |
2279 |
+- if (!arch_get_random_seed_long(&rv) && |
2280 |
+- !arch_get_random_long(&rv)) |
2281 |
+- rv = random_get_entropy(); |
2282 |
+- crng->state[i] ^= rv; |
2283 |
+- } |
2284 |
+- crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1; |
2285 |
++ warn_unseeded_randomness(); |
2286 |
++ _get_random_bytes(buf, len); |
2287 |
+ } |
2288 |
++EXPORT_SYMBOL(get_random_bytes); |
2289 |
+ |
2290 |
+-static int crng_fast_load(const char *cp, size_t len) |
2291 |
++static ssize_t get_random_bytes_user(struct iov_iter *iter) |
2292 |
+ { |
2293 |
+- unsigned long flags; |
2294 |
+- char *p; |
2295 |
++ u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)]; |
2296 |
++ u8 block[CHACHA20_BLOCK_SIZE]; |
2297 |
++ size_t ret = 0, copied; |
2298 |
+ |
2299 |
+- if (!spin_trylock_irqsave(&primary_crng.lock, flags)) |
2300 |
++ if (unlikely(!iov_iter_count(iter))) |
2301 |
+ return 0; |
2302 |
+- if (crng_init != 0) { |
2303 |
+- spin_unlock_irqrestore(&primary_crng.lock, flags); |
2304 |
+- return 0; |
2305 |
+- } |
2306 |
+- p = (unsigned char *) &primary_crng.state[4]; |
2307 |
+- while (len > 0 && crng_init_cnt < CRNG_INIT_CNT_THRESH) { |
2308 |
+- p[crng_init_cnt % CHACHA20_KEY_SIZE] ^= *cp; |
2309 |
+- cp++; crng_init_cnt++; len--; |
2310 |
+- } |
2311 |
+- if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { |
2312 |
+- crng_init = 1; |
2313 |
+- wake_up_interruptible(&crng_init_wait); |
2314 |
+- pr_notice("random: fast init done\n"); |
2315 |
+- } |
2316 |
+- spin_unlock_irqrestore(&primary_crng.lock, flags); |
2317 |
+- return 1; |
2318 |
+-} |
2319 |
+ |
2320 |
+-#ifdef CONFIG_NUMA |
2321 |
+-static void do_numa_crng_init(struct work_struct *work) |
2322 |
+-{ |
2323 |
+- int i; |
2324 |
+- struct crng_state *crng; |
2325 |
+- struct crng_state **pool; |
2326 |
+- |
2327 |
+- pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL); |
2328 |
+- for_each_online_node(i) { |
2329 |
+- crng = kmalloc_node(sizeof(struct crng_state), |
2330 |
+- GFP_KERNEL | __GFP_NOFAIL, i); |
2331 |
+- spin_lock_init(&crng->lock); |
2332 |
+- crng_initialize(crng); |
2333 |
+- pool[i] = crng; |
2334 |
+- } |
2335 |
+- /* pairs with READ_ONCE() in select_crng() */ |
2336 |
+- if (cmpxchg_release(&crng_node_pool, NULL, pool) != NULL) { |
2337 |
+- for_each_node(i) |
2338 |
+- kfree(pool[i]); |
2339 |
+- kfree(pool); |
2340 |
++ /* |
2341 |
++ * Immediately overwrite the ChaCha key at index 4 with random |
2342 |
++ * bytes, in case userspace causes copy_to_user() below to sleep |
2343 |
++ * forever, so that we still retain forward secrecy in that case. |
2344 |
++ */ |
2345 |
++ crng_make_state(chacha_state, (u8 *)&chacha_state[4], CHACHA20_KEY_SIZE); |
2346 |
++ /* |
2347 |
++ * However, if we're doing a read of len <= 32, we don't need to |
2348 |
++ * use chacha_state after, so we can simply return those bytes to |
2349 |
++ * the user directly. |
2350 |
++ */ |
2351 |
++ if (iov_iter_count(iter) <= CHACHA20_KEY_SIZE) { |
2352 |
++ ret = copy_to_iter(&chacha_state[4], CHACHA20_KEY_SIZE, iter); |
2353 |
++ goto out_zero_chacha; |
2354 |
+ } |
2355 |
+-} |
2356 |
+- |
2357 |
+-static DECLARE_WORK(numa_crng_init_work, do_numa_crng_init); |
2358 |
+- |
2359 |
+-static void numa_crng_init(void) |
2360 |
+-{ |
2361 |
+- schedule_work(&numa_crng_init_work); |
2362 |
+-} |
2363 |
+ |
2364 |
+-static struct crng_state *select_crng(void) |
2365 |
+-{ |
2366 |
+- struct crng_state **pool; |
2367 |
+- int nid = numa_node_id(); |
2368 |
+- |
2369 |
+- /* pairs with cmpxchg_release() in do_numa_crng_init() */ |
2370 |
+- pool = READ_ONCE(crng_node_pool); |
2371 |
+- if (pool && pool[nid]) |
2372 |
+- return pool[nid]; |
2373 |
++ for (;;) { |
2374 |
++ chacha20_block(chacha_state, block); |
2375 |
++ if (unlikely(chacha_state[12] == 0)) |
2376 |
++ ++chacha_state[13]; |
2377 |
+ |
2378 |
+- return &primary_crng; |
2379 |
+-} |
2380 |
+-#else |
2381 |
+-static void numa_crng_init(void) {} |
2382 |
+- |
2383 |
+-static struct crng_state *select_crng(void) |
2384 |
+-{ |
2385 |
+- return &primary_crng; |
2386 |
+-} |
2387 |
+-#endif |
2388 |
++ copied = copy_to_iter(block, sizeof(block), iter); |
2389 |
++ ret += copied; |
2390 |
++ if (!iov_iter_count(iter) || copied != sizeof(block)) |
2391 |
++ break; |
2392 |
+ |
2393 |
+-static void crng_reseed(struct crng_state *crng, struct entropy_store *r) |
2394 |
+-{ |
2395 |
+- unsigned long flags; |
2396 |
+- int i, num; |
2397 |
+- union { |
2398 |
+- __u8 block[CHACHA20_BLOCK_SIZE]; |
2399 |
+- __u32 key[8]; |
2400 |
+- } buf; |
2401 |
+- |
2402 |
+- if (r) { |
2403 |
+- num = extract_entropy(r, &buf, 32, 16, 0); |
2404 |
+- if (num == 0) |
2405 |
+- return; |
2406 |
+- } else { |
2407 |
+- _extract_crng(&primary_crng, buf.block); |
2408 |
+- _crng_backtrack_protect(&primary_crng, buf.block, |
2409 |
+- CHACHA20_KEY_SIZE); |
2410 |
+- } |
2411 |
+- spin_lock_irqsave(&crng->lock, flags); |
2412 |
+- for (i = 0; i < 8; i++) { |
2413 |
+- unsigned long rv; |
2414 |
+- if (!arch_get_random_seed_long(&rv) && |
2415 |
+- !arch_get_random_long(&rv)) |
2416 |
+- rv = random_get_entropy(); |
2417 |
+- crng->state[i+4] ^= buf.key[i] ^ rv; |
2418 |
+- } |
2419 |
+- memzero_explicit(&buf, sizeof(buf)); |
2420 |
+- WRITE_ONCE(crng->init_time, jiffies); |
2421 |
+- if (crng == &primary_crng && crng_init < 2) { |
2422 |
+- numa_crng_init(); |
2423 |
+- crng_init = 2; |
2424 |
+- process_random_ready_list(); |
2425 |
+- wake_up_interruptible(&crng_init_wait); |
2426 |
+- pr_notice("random: crng init done\n"); |
2427 |
+- if (unseeded_warning.missed) { |
2428 |
+- pr_notice("random: %d get_random_xx warning(s) missed " |
2429 |
+- "due to ratelimiting\n", |
2430 |
+- unseeded_warning.missed); |
2431 |
+- unseeded_warning.missed = 0; |
2432 |
+- } |
2433 |
+- if (urandom_warning.missed) { |
2434 |
+- pr_notice("random: %d urandom warning(s) missed " |
2435 |
+- "due to ratelimiting\n", |
2436 |
+- urandom_warning.missed); |
2437 |
+- urandom_warning.missed = 0; |
2438 |
++ BUILD_BUG_ON(PAGE_SIZE % sizeof(block) != 0); |
2439 |
++ if (ret % PAGE_SIZE == 0) { |
2440 |
++ if (signal_pending(current)) |
2441 |
++ break; |
2442 |
++ cond_resched(); |
2443 |
+ } |
2444 |
+ } |
2445 |
+- spin_unlock_irqrestore(&crng->lock, flags); |
2446 |
+-} |
2447 |
+ |
2448 |
+-static inline void maybe_reseed_primary_crng(void) |
2449 |
+-{ |
2450 |
+- if (crng_init > 2 && |
2451 |
+- time_after(jiffies, primary_crng.init_time + CRNG_RESEED_INTERVAL)) |
2452 |
+- crng_reseed(&primary_crng, &input_pool); |
2453 |
++ memzero_explicit(block, sizeof(block)); |
2454 |
++out_zero_chacha: |
2455 |
++ memzero_explicit(chacha_state, sizeof(chacha_state)); |
2456 |
++ return ret ? ret : -EFAULT; |
2457 |
+ } |
2458 |
+ |
2459 |
+-static inline void crng_wait_ready(void) |
2460 |
+-{ |
2461 |
+- wait_event_interruptible(crng_init_wait, crng_ready()); |
2462 |
+-} |
2463 |
+- |
2464 |
+-static void _extract_crng(struct crng_state *crng, |
2465 |
+- __u8 out[CHACHA20_BLOCK_SIZE]) |
2466 |
+-{ |
2467 |
+- unsigned long v, flags, init_time; |
2468 |
+- |
2469 |
+- if (crng_ready()) { |
2470 |
+- init_time = READ_ONCE(crng->init_time); |
2471 |
+- if (time_after(READ_ONCE(crng_global_init_time), init_time) || |
2472 |
+- time_after(jiffies, init_time + CRNG_RESEED_INTERVAL)) |
2473 |
+- crng_reseed(crng, crng == &primary_crng ? |
2474 |
+- &input_pool : NULL); |
2475 |
+- } |
2476 |
+- spin_lock_irqsave(&crng->lock, flags); |
2477 |
+- if (arch_get_random_long(&v)) |
2478 |
+- crng->state[14] ^= v; |
2479 |
+- chacha20_block(&crng->state[0], out); |
2480 |
+- if (crng->state[12] == 0) |
2481 |
+- crng->state[13]++; |
2482 |
+- spin_unlock_irqrestore(&crng->lock, flags); |
2483 |
+-} |
2484 |
+- |
2485 |
+-static void extract_crng(__u8 out[CHACHA20_BLOCK_SIZE]) |
2486 |
+-{ |
2487 |
+- _extract_crng(select_crng(), out); |
2488 |
+-} |
2489 |
++/* |
2490 |
++ * Batched entropy returns random integers. The quality of the random |
2491 |
++ * number is good as /dev/urandom. In order to ensure that the randomness |
2492 |
++ * provided by this function is okay, the function wait_for_random_bytes() |
2493 |
++ * should be called and return 0 at least once at any point prior. |
2494 |
++ */ |
2495 |
+ |
2496 |
++#define DEFINE_BATCHED_ENTROPY(type) \ |
2497 |
++struct batch_ ##type { \ |
2498 |
++ /* \ |
2499 |
++ * We make this 1.5x a ChaCha block, so that we get the \ |
2500 |
++ * remaining 32 bytes from fast key erasure, plus one full \ |
2501 |
++ * block from the detached ChaCha state. We can increase \ |
2502 |
++ * the size of this later if needed so long as we keep the \ |
2503 |
++ * formula of (integer_blocks + 0.5) * CHACHA20_BLOCK_SIZE. \ |
2504 |
++ */ \ |
2505 |
++ type entropy[CHACHA20_BLOCK_SIZE * 3 / (2 * sizeof(type))]; \ |
2506 |
++ unsigned long generation; \ |
2507 |
++ unsigned int position; \ |
2508 |
++}; \ |
2509 |
++ \ |
2510 |
++static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = { \ |
2511 |
++ .position = UINT_MAX \ |
2512 |
++}; \ |
2513 |
++ \ |
2514 |
++type get_random_ ##type(void) \ |
2515 |
++{ \ |
2516 |
++ type ret; \ |
2517 |
++ unsigned long flags; \ |
2518 |
++ struct batch_ ##type *batch; \ |
2519 |
++ unsigned long next_gen; \ |
2520 |
++ \ |
2521 |
++ warn_unseeded_randomness(); \ |
2522 |
++ \ |
2523 |
++ if (!crng_ready()) { \ |
2524 |
++ _get_random_bytes(&ret, sizeof(ret)); \ |
2525 |
++ return ret; \ |
2526 |
++ } \ |
2527 |
++ \ |
2528 |
++ local_irq_save(flags); \ |
2529 |
++ batch = raw_cpu_ptr(&batched_entropy_##type); \ |
2530 |
++ \ |
2531 |
++ next_gen = READ_ONCE(base_crng.generation); \ |
2532 |
++ if (batch->position >= ARRAY_SIZE(batch->entropy) || \ |
2533 |
++ next_gen != batch->generation) { \ |
2534 |
++ _get_random_bytes(batch->entropy, sizeof(batch->entropy)); \ |
2535 |
++ batch->position = 0; \ |
2536 |
++ batch->generation = next_gen; \ |
2537 |
++ } \ |
2538 |
++ \ |
2539 |
++ ret = batch->entropy[batch->position]; \ |
2540 |
++ batch->entropy[batch->position] = 0; \ |
2541 |
++ ++batch->position; \ |
2542 |
++ local_irq_restore(flags); \ |
2543 |
++ return ret; \ |
2544 |
++} \ |
2545 |
++EXPORT_SYMBOL(get_random_ ##type); |
2546 |
++ |
2547 |
++DEFINE_BATCHED_ENTROPY(u64) |
2548 |
++DEFINE_BATCHED_ENTROPY(u32) |
2549 |
++ |
2550 |
++#ifdef CONFIG_SMP |
2551 |
+ /* |
2552 |
+- * Use the leftover bytes from the CRNG block output (if there is |
2553 |
+- * enough) to mutate the CRNG key to provide backtracking protection. |
2554 |
++ * This function is called when the CPU is coming up, with entry |
2555 |
++ * CPUHP_RANDOM_PREPARE, which comes before CPUHP_WORKQUEUE_PREP. |
2556 |
+ */ |
2557 |
+-static void _crng_backtrack_protect(struct crng_state *crng, |
2558 |
+- __u8 tmp[CHACHA20_BLOCK_SIZE], int used) |
2559 |
++int __cold random_prepare_cpu(unsigned int cpu) |
2560 |
+ { |
2561 |
+- unsigned long flags; |
2562 |
+- __u32 *s, *d; |
2563 |
+- int i; |
2564 |
+- |
2565 |
+- used = round_up(used, sizeof(__u32)); |
2566 |
+- if (used + CHACHA20_KEY_SIZE > CHACHA20_BLOCK_SIZE) { |
2567 |
+- extract_crng(tmp); |
2568 |
+- used = 0; |
2569 |
+- } |
2570 |
+- spin_lock_irqsave(&crng->lock, flags); |
2571 |
+- s = (__u32 *) &tmp[used]; |
2572 |
+- d = &crng->state[4]; |
2573 |
+- for (i=0; i < 8; i++) |
2574 |
+- *d++ ^= *s++; |
2575 |
+- spin_unlock_irqrestore(&crng->lock, flags); |
2576 |
++ /* |
2577 |
++ * When the cpu comes back online, immediately invalidate both |
2578 |
++ * the per-cpu crng and all batches, so that we serve fresh |
2579 |
++ * randomness. |
2580 |
++ */ |
2581 |
++ per_cpu_ptr(&crngs, cpu)->generation = ULONG_MAX; |
2582 |
++ per_cpu_ptr(&batched_entropy_u32, cpu)->position = UINT_MAX; |
2583 |
++ per_cpu_ptr(&batched_entropy_u64, cpu)->position = UINT_MAX; |
2584 |
++ return 0; |
2585 |
+ } |
2586 |
++#endif |
2587 |
+ |
2588 |
+-static void crng_backtrack_protect(__u8 tmp[CHACHA20_BLOCK_SIZE], int used) |
2589 |
++/* |
2590 |
++ * This function will use the architecture-specific hardware random |
2591 |
++ * number generator if it is available. It is not recommended for |
2592 |
++ * use. Use get_random_bytes() instead. It returns the number of |
2593 |
++ * bytes filled in. |
2594 |
++ */ |
2595 |
++size_t __must_check get_random_bytes_arch(void *buf, size_t len) |
2596 |
+ { |
2597 |
+- _crng_backtrack_protect(select_crng(), tmp, used); |
2598 |
+-} |
2599 |
++ size_t left = len; |
2600 |
++ u8 *p = buf; |
2601 |
+ |
2602 |
+-static ssize_t extract_crng_user(void __user *buf, size_t nbytes) |
2603 |
+-{ |
2604 |
+- ssize_t ret = 0, i = CHACHA20_BLOCK_SIZE; |
2605 |
+- __u8 tmp[CHACHA20_BLOCK_SIZE]; |
2606 |
+- int large_request = (nbytes > 256); |
2607 |
+- |
2608 |
+- while (nbytes) { |
2609 |
+- if (large_request && need_resched()) { |
2610 |
+- if (signal_pending(current)) { |
2611 |
+- if (ret == 0) |
2612 |
+- ret = -ERESTARTSYS; |
2613 |
+- break; |
2614 |
+- } |
2615 |
+- schedule(); |
2616 |
+- } |
2617 |
++ while (left) { |
2618 |
++ unsigned long v; |
2619 |
++ size_t block_len = min_t(size_t, left, sizeof(unsigned long)); |
2620 |
+ |
2621 |
+- extract_crng(tmp); |
2622 |
+- i = min_t(int, nbytes, CHACHA20_BLOCK_SIZE); |
2623 |
+- if (copy_to_user(buf, tmp, i)) { |
2624 |
+- ret = -EFAULT; |
2625 |
++ if (!arch_get_random_long(&v)) |
2626 |
+ break; |
2627 |
+- } |
2628 |
+ |
2629 |
+- nbytes -= i; |
2630 |
+- buf += i; |
2631 |
+- ret += i; |
2632 |
++ memcpy(p, &v, block_len); |
2633 |
++ p += block_len; |
2634 |
++ left -= block_len; |
2635 |
+ } |
2636 |
+- crng_backtrack_protect(tmp, i); |
2637 |
+- |
2638 |
+- /* Wipe data just written to memory */ |
2639 |
+- memzero_explicit(tmp, sizeof(tmp)); |
2640 |
+ |
2641 |
+- return ret; |
2642 |
++ return len - left; |
2643 |
+ } |
2644 |
++EXPORT_SYMBOL(get_random_bytes_arch); |
2645 |
+ |
2646 |
+ |
2647 |
+-/********************************************************************* |
2648 |
++/********************************************************************** |
2649 |
+ * |
2650 |
+- * Entropy input management |
2651 |
++ * Entropy accumulation and extraction routines. |
2652 |
+ * |
2653 |
+- *********************************************************************/ |
2654 |
++ * Callers may add entropy via: |
2655 |
++ * |
2656 |
++ * static void mix_pool_bytes(const void *buf, size_t len) |
2657 |
++ * |
2658 |
++ * After which, if added entropy should be credited: |
2659 |
++ * |
2660 |
++ * static void credit_init_bits(size_t bits) |
2661 |
++ * |
2662 |
++ * Finally, extract entropy via: |
2663 |
++ * |
2664 |
++ * static void extract_entropy(void *buf, size_t len) |
2665 |
++ * |
2666 |
++ **********************************************************************/ |
2667 |
+ |
2668 |
+-/* There is one of these per entropy source */ |
2669 |
+-struct timer_rand_state { |
2670 |
+- cycles_t last_time; |
2671 |
+- long last_delta, last_delta2; |
2672 |
+- unsigned dont_count_entropy:1; |
2673 |
++enum { |
2674 |
++ POOL_BITS = BLAKE2S_HASH_SIZE * 8, |
2675 |
++ POOL_READY_BITS = POOL_BITS, /* When crng_init->CRNG_READY */ |
2676 |
++ POOL_EARLY_BITS = POOL_READY_BITS / 2 /* When crng_init->CRNG_EARLY */ |
2677 |
++}; |
2678 |
++ |
2679 |
++static struct { |
2680 |
++ struct blake2s_state hash; |
2681 |
++ spinlock_t lock; |
2682 |
++ unsigned int init_bits; |
2683 |
++} input_pool = { |
2684 |
++ .hash.h = { BLAKE2S_IV0 ^ (0x01010000 | BLAKE2S_HASH_SIZE), |
2685 |
++ BLAKE2S_IV1, BLAKE2S_IV2, BLAKE2S_IV3, BLAKE2S_IV4, |
2686 |
++ BLAKE2S_IV5, BLAKE2S_IV6, BLAKE2S_IV7 }, |
2687 |
++ .hash.outlen = BLAKE2S_HASH_SIZE, |
2688 |
++ .lock = __SPIN_LOCK_UNLOCKED(input_pool.lock), |
2689 |
+ }; |
2690 |
+ |
2691 |
+-#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, }; |
2692 |
++static void _mix_pool_bytes(const void *buf, size_t len) |
2693 |
++{ |
2694 |
++ blake2s_update(&input_pool.hash, buf, len); |
2695 |
++} |
2696 |
+ |
2697 |
+ /* |
2698 |
+- * Add device- or boot-specific data to the input pool to help |
2699 |
+- * initialize it. |
2700 |
+- * |
2701 |
+- * None of this adds any entropy; it is meant to avoid the problem of |
2702 |
+- * the entropy pool having similar initial state across largely |
2703 |
+- * identical devices. |
2704 |
++ * This function adds bytes into the input pool. It does not |
2705 |
++ * update the initialization bit counter; the caller should call |
2706 |
++ * credit_init_bits if this is appropriate. |
2707 |
+ */ |
2708 |
+-void add_device_randomness(const void *buf, unsigned int size) |
2709 |
++static void mix_pool_bytes(const void *buf, size_t len) |
2710 |
+ { |
2711 |
+- unsigned long time = random_get_entropy() ^ jiffies; |
2712 |
+ unsigned long flags; |
2713 |
+ |
2714 |
+- trace_add_device_randomness(size, _RET_IP_); |
2715 |
+ spin_lock_irqsave(&input_pool.lock, flags); |
2716 |
+- _mix_pool_bytes(&input_pool, buf, size); |
2717 |
+- _mix_pool_bytes(&input_pool, &time, sizeof(time)); |
2718 |
++ _mix_pool_bytes(buf, len); |
2719 |
+ spin_unlock_irqrestore(&input_pool.lock, flags); |
2720 |
+ } |
2721 |
+-EXPORT_SYMBOL(add_device_randomness); |
2722 |
+- |
2723 |
+-static struct timer_rand_state input_timer_state = INIT_TIMER_RAND_STATE; |
2724 |
+ |
2725 |
+ /* |
2726 |
+- * This function adds entropy to the entropy "pool" by using timing |
2727 |
+- * delays. It uses the timer_rand_state structure to make an estimate |
2728 |
+- * of how many bits of entropy this call has added to the pool. |
2729 |
+- * |
2730 |
+- * The number "num" is also added to the pool - it should somehow describe |
2731 |
+- * the type of event which just happened. This is currently 0-255 for |
2732 |
+- * keyboard scan codes, and 256 upwards for interrupts. |
2733 |
+- * |
2734 |
++ * This is an HKDF-like construction for using the hashed collected entropy |
2735 |
++ * as a PRF key, that's then expanded block-by-block. |
2736 |
+ */ |
2737 |
+-static void add_timer_randomness(struct timer_rand_state *state, unsigned num) |
2738 |
++static void extract_entropy(void *buf, size_t len) |
2739 |
+ { |
2740 |
+- struct entropy_store *r; |
2741 |
++ unsigned long flags; |
2742 |
++ u8 seed[BLAKE2S_HASH_SIZE], next_key[BLAKE2S_HASH_SIZE]; |
2743 |
+ struct { |
2744 |
+- long jiffies; |
2745 |
+- unsigned cycles; |
2746 |
+- unsigned num; |
2747 |
+- } sample; |
2748 |
+- long delta, delta2, delta3; |
2749 |
+- |
2750 |
+- preempt_disable(); |
2751 |
+- |
2752 |
+- sample.jiffies = jiffies; |
2753 |
+- sample.cycles = random_get_entropy(); |
2754 |
+- sample.num = num; |
2755 |
+- r = &input_pool; |
2756 |
+- mix_pool_bytes(r, &sample, sizeof(sample)); |
2757 |
+- |
2758 |
+- /* |
2759 |
+- * Calculate number of bits of randomness we probably added. |
2760 |
+- * We take into account the first, second and third-order deltas |
2761 |
+- * in order to make our estimate. |
2762 |
+- */ |
2763 |
+- |
2764 |
+- if (!state->dont_count_entropy) { |
2765 |
+- delta = sample.jiffies - state->last_time; |
2766 |
+- state->last_time = sample.jiffies; |
2767 |
+- |
2768 |
+- delta2 = delta - state->last_delta; |
2769 |
+- state->last_delta = delta; |
2770 |
+- |
2771 |
+- delta3 = delta2 - state->last_delta2; |
2772 |
+- state->last_delta2 = delta2; |
2773 |
+- |
2774 |
+- if (delta < 0) |
2775 |
+- delta = -delta; |
2776 |
+- if (delta2 < 0) |
2777 |
+- delta2 = -delta2; |
2778 |
+- if (delta3 < 0) |
2779 |
+- delta3 = -delta3; |
2780 |
+- if (delta > delta2) |
2781 |
+- delta = delta2; |
2782 |
+- if (delta > delta3) |
2783 |
+- delta = delta3; |
2784 |
+- |
2785 |
+- /* |
2786 |
+- * delta is now minimum absolute delta. |
2787 |
+- * Round down by 1 bit on general principles, |
2788 |
+- * and limit entropy entimate to 12 bits. |
2789 |
+- */ |
2790 |
+- credit_entropy_bits(r, min_t(int, fls(delta>>1), 11)); |
2791 |
++ unsigned long rdseed[32 / sizeof(long)]; |
2792 |
++ size_t counter; |
2793 |
++ } block; |
2794 |
++ size_t i; |
2795 |
++ |
2796 |
++ for (i = 0; i < ARRAY_SIZE(block.rdseed); ++i) { |
2797 |
++ if (!arch_get_random_seed_long(&block.rdseed[i]) && |
2798 |
++ !arch_get_random_long(&block.rdseed[i])) |
2799 |
++ block.rdseed[i] = random_get_entropy(); |
2800 |
+ } |
2801 |
+- preempt_enable(); |
2802 |
+-} |
2803 |
+- |
2804 |
+-void add_input_randomness(unsigned int type, unsigned int code, |
2805 |
+- unsigned int value) |
2806 |
+-{ |
2807 |
+- static unsigned char last_value; |
2808 |
+ |
2809 |
+- /* ignore autorepeat and the like */ |
2810 |
+- if (value == last_value) |
2811 |
+- return; |
2812 |
+- |
2813 |
+- last_value = value; |
2814 |
+- add_timer_randomness(&input_timer_state, |
2815 |
+- (type << 4) ^ code ^ (code >> 4) ^ value); |
2816 |
+- trace_add_input_randomness(ENTROPY_BITS(&input_pool)); |
2817 |
+-} |
2818 |
+-EXPORT_SYMBOL_GPL(add_input_randomness); |
2819 |
++ spin_lock_irqsave(&input_pool.lock, flags); |
2820 |
+ |
2821 |
+-static DEFINE_PER_CPU(struct fast_pool, irq_randomness); |
2822 |
++ /* seed = HASHPRF(last_key, entropy_input) */ |
2823 |
++ blake2s_final(&input_pool.hash, seed); |
2824 |
+ |
2825 |
+-#ifdef ADD_INTERRUPT_BENCH |
2826 |
+-static unsigned long avg_cycles, avg_deviation; |
2827 |
++ /* next_key = HASHPRF(seed, RDSEED || 0) */ |
2828 |
++ block.counter = 0; |
2829 |
++ blake2s(next_key, (u8 *)&block, seed, sizeof(next_key), sizeof(block), sizeof(seed)); |
2830 |
++ blake2s_init_key(&input_pool.hash, BLAKE2S_HASH_SIZE, next_key, sizeof(next_key)); |
2831 |
+ |
2832 |
+-#define AVG_SHIFT 8 /* Exponential average factor k=1/256 */ |
2833 |
+-#define FIXED_1_2 (1 << (AVG_SHIFT-1)) |
2834 |
++ spin_unlock_irqrestore(&input_pool.lock, flags); |
2835 |
++ memzero_explicit(next_key, sizeof(next_key)); |
2836 |
++ |
2837 |
++ while (len) { |
2838 |
++ i = min_t(size_t, len, BLAKE2S_HASH_SIZE); |
2839 |
++ /* output = HASHPRF(seed, RDSEED || ++counter) */ |
2840 |
++ ++block.counter; |
2841 |
++ blake2s(buf, (u8 *)&block, seed, i, sizeof(block), sizeof(seed)); |
2842 |
++ len -= i; |
2843 |
++ buf += i; |
2844 |
++ } |
2845 |
+ |
2846 |
+-static void add_interrupt_bench(cycles_t start) |
2847 |
+-{ |
2848 |
+- long delta = random_get_entropy() - start; |
2849 |
+- |
2850 |
+- /* Use a weighted moving average */ |
2851 |
+- delta = delta - ((avg_cycles + FIXED_1_2) >> AVG_SHIFT); |
2852 |
+- avg_cycles += delta; |
2853 |
+- /* And average deviation */ |
2854 |
+- delta = abs(delta) - ((avg_deviation + FIXED_1_2) >> AVG_SHIFT); |
2855 |
+- avg_deviation += delta; |
2856 |
++ memzero_explicit(seed, sizeof(seed)); |
2857 |
++ memzero_explicit(&block, sizeof(block)); |
2858 |
+ } |
2859 |
+-#else |
2860 |
+-#define add_interrupt_bench(x) |
2861 |
+-#endif |
2862 |
+ |
2863 |
+-static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs) |
2864 |
+-{ |
2865 |
+- __u32 *ptr = (__u32 *) regs; |
2866 |
+- unsigned int idx; |
2867 |
+- |
2868 |
+- if (regs == NULL) |
2869 |
+- return 0; |
2870 |
+- idx = READ_ONCE(f->reg_idx); |
2871 |
+- if (idx >= sizeof(struct pt_regs) / sizeof(__u32)) |
2872 |
+- idx = 0; |
2873 |
+- ptr += idx++; |
2874 |
+- WRITE_ONCE(f->reg_idx, idx); |
2875 |
+- return *ptr; |
2876 |
+-} |
2877 |
++#define credit_init_bits(bits) if (!crng_ready()) _credit_init_bits(bits) |
2878 |
+ |
2879 |
+-void add_interrupt_randomness(int irq, int irq_flags) |
2880 |
++static void __cold _credit_init_bits(size_t bits) |
2881 |
+ { |
2882 |
+- struct entropy_store *r; |
2883 |
+- struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness); |
2884 |
+- struct pt_regs *regs = get_irq_regs(); |
2885 |
+- unsigned long now = jiffies; |
2886 |
+- cycles_t cycles = random_get_entropy(); |
2887 |
+- __u32 c_high, j_high; |
2888 |
+- __u64 ip; |
2889 |
+- unsigned long seed; |
2890 |
+- int credit = 0; |
2891 |
+- |
2892 |
+- if (cycles == 0) |
2893 |
+- cycles = get_reg(fast_pool, regs); |
2894 |
+- c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0; |
2895 |
+- j_high = (sizeof(now) > 4) ? now >> 32 : 0; |
2896 |
+- fast_pool->pool[0] ^= cycles ^ j_high ^ irq; |
2897 |
+- fast_pool->pool[1] ^= now ^ c_high; |
2898 |
+- ip = regs ? instruction_pointer(regs) : _RET_IP_; |
2899 |
+- fast_pool->pool[2] ^= ip; |
2900 |
+- fast_pool->pool[3] ^= (sizeof(ip) > 4) ? ip >> 32 : |
2901 |
+- get_reg(fast_pool, regs); |
2902 |
+- |
2903 |
+- fast_mix(fast_pool); |
2904 |
+- add_interrupt_bench(cycles); |
2905 |
+- |
2906 |
+- if (unlikely(crng_init == 0)) { |
2907 |
+- if ((fast_pool->count >= 64) && |
2908 |
+- crng_fast_load((char *) fast_pool->pool, |
2909 |
+- sizeof(fast_pool->pool))) { |
2910 |
+- fast_pool->count = 0; |
2911 |
+- fast_pool->last = now; |
2912 |
+- } |
2913 |
+- return; |
2914 |
+- } |
2915 |
++ unsigned int new, orig, add; |
2916 |
++ unsigned long flags; |
2917 |
+ |
2918 |
+- if ((fast_pool->count < 64) && |
2919 |
+- !time_after(now, fast_pool->last + HZ)) |
2920 |
++ if (!bits) |
2921 |
+ return; |
2922 |
+ |
2923 |
+- r = &input_pool; |
2924 |
+- if (!spin_trylock(&r->lock)) |
2925 |
+- return; |
2926 |
++ add = min_t(size_t, bits, POOL_BITS); |
2927 |
+ |
2928 |
+- fast_pool->last = now; |
2929 |
+- __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool)); |
2930 |
++ do { |
2931 |
++ orig = READ_ONCE(input_pool.init_bits); |
2932 |
++ new = min_t(unsigned int, POOL_BITS, orig + add); |
2933 |
++ } while (cmpxchg(&input_pool.init_bits, orig, new) != orig); |
2934 |
+ |
2935 |
+- /* |
2936 |
+- * If we have architectural seed generator, produce a seed and |
2937 |
+- * add it to the pool. For the sake of paranoia don't let the |
2938 |
+- * architectural seed generator dominate the input from the |
2939 |
+- * interrupt noise. |
2940 |
+- */ |
2941 |
+- if (arch_get_random_seed_long(&seed)) { |
2942 |
+- __mix_pool_bytes(r, &seed, sizeof(seed)); |
2943 |
+- credit = 1; |
2944 |
++ if (orig < POOL_READY_BITS && new >= POOL_READY_BITS) { |
2945 |
++ crng_reseed(); /* Sets crng_init to CRNG_READY under base_crng.lock. */ |
2946 |
++ process_random_ready_list(); |
2947 |
++ wake_up_interruptible(&crng_init_wait); |
2948 |
++ kill_fasync(&fasync, SIGIO, POLL_IN); |
2949 |
++ pr_notice("crng init done\n"); |
2950 |
++ if (urandom_warning.missed) |
2951 |
++ pr_notice("%d urandom warning(s) missed due to ratelimiting\n", |
2952 |
++ urandom_warning.missed); |
2953 |
++ } else if (orig < POOL_EARLY_BITS && new >= POOL_EARLY_BITS) { |
2954 |
++ spin_lock_irqsave(&base_crng.lock, flags); |
2955 |
++ /* Check if crng_init is CRNG_EMPTY, to avoid race with crng_reseed(). */ |
2956 |
++ if (crng_init == CRNG_EMPTY) { |
2957 |
++ extract_entropy(base_crng.key, sizeof(base_crng.key)); |
2958 |
++ crng_init = CRNG_EARLY; |
2959 |
++ } |
2960 |
++ spin_unlock_irqrestore(&base_crng.lock, flags); |
2961 |
+ } |
2962 |
+- spin_unlock(&r->lock); |
2963 |
+- |
2964 |
+- fast_pool->count = 0; |
2965 |
+- |
2966 |
+- /* award one bit for the contents of the fast pool */ |
2967 |
+- credit_entropy_bits(r, credit + 1); |
2968 |
+ } |
2969 |
+-EXPORT_SYMBOL_GPL(add_interrupt_randomness); |
2970 |
+ |
2971 |
+-#ifdef CONFIG_BLOCK |
2972 |
+-void add_disk_randomness(struct gendisk *disk) |
2973 |
+-{ |
2974 |
+- if (!disk || !disk->random) |
2975 |
+- return; |
2976 |
+- /* first major is 1, so we get >= 0x200 here */ |
2977 |
+- add_timer_randomness(disk->random, 0x100 + disk_devt(disk)); |
2978 |
+- trace_add_disk_randomness(disk_devt(disk), ENTROPY_BITS(&input_pool)); |
2979 |
+-} |
2980 |
+-EXPORT_SYMBOL_GPL(add_disk_randomness); |
2981 |
+-#endif |
2982 |
+ |
2983 |
+-/********************************************************************* |
2984 |
++/********************************************************************** |
2985 |
+ * |
2986 |
+- * Entropy extraction routines |
2987 |
++ * Entropy collection routines. |
2988 |
+ * |
2989 |
+- *********************************************************************/ |
2990 |
+- |
2991 |
+-/* |
2992 |
+- * This utility inline function is responsible for transferring entropy |
2993 |
+- * from the primary pool to the secondary extraction pool. We make |
2994 |
+- * sure we pull enough for a 'catastrophic reseed'. |
2995 |
+- */ |
2996 |
+-static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes); |
2997 |
+-static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes) |
2998 |
+-{ |
2999 |
+- if (!r->pull || |
3000 |
+- r->entropy_count >= (nbytes << (ENTROPY_SHIFT + 3)) || |
3001 |
+- r->entropy_count > r->poolinfo->poolfracbits) |
3002 |
+- return; |
3003 |
+- |
3004 |
+- if (r->limit == 0 && random_min_urandom_seed) { |
3005 |
+- unsigned long now = jiffies; |
3006 |
+- |
3007 |
+- if (time_before(now, |
3008 |
+- r->last_pulled + random_min_urandom_seed * HZ)) |
3009 |
+- return; |
3010 |
+- r->last_pulled = now; |
3011 |
+- } |
3012 |
+- |
3013 |
+- _xfer_secondary_pool(r, nbytes); |
3014 |
+-} |
3015 |
+- |
3016 |
+-static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes) |
3017 |
+-{ |
3018 |
+- __u32 tmp[OUTPUT_POOL_WORDS]; |
3019 |
+- |
3020 |
+- /* For /dev/random's pool, always leave two wakeups' worth */ |
3021 |
+- int rsvd_bytes = r->limit ? 0 : random_read_wakeup_bits / 4; |
3022 |
+- int bytes = nbytes; |
3023 |
+- |
3024 |
+- /* pull at least as much as a wakeup */ |
3025 |
+- bytes = max_t(int, bytes, random_read_wakeup_bits / 8); |
3026 |
+- /* but never more than the buffer size */ |
3027 |
+- bytes = min_t(int, bytes, sizeof(tmp)); |
3028 |
+- |
3029 |
+- trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8, |
3030 |
+- ENTROPY_BITS(r), ENTROPY_BITS(r->pull)); |
3031 |
+- bytes = extract_entropy(r->pull, tmp, bytes, |
3032 |
+- random_read_wakeup_bits / 8, rsvd_bytes); |
3033 |
+- mix_pool_bytes(r, tmp, bytes); |
3034 |
+- credit_entropy_bits(r, bytes*8); |
3035 |
+-} |
3036 |
++ * The following exported functions are used for pushing entropy into |
3037 |
++ * the above entropy accumulation routines: |
3038 |
++ * |
3039 |
++ * void add_device_randomness(const void *buf, size_t len); |
3040 |
++ * void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy); |
3041 |
++ * void add_bootloader_randomness(const void *buf, size_t len); |
3042 |
++ * void add_interrupt_randomness(int irq); |
3043 |
++ * void add_input_randomness(unsigned int type, unsigned int code, unsigned int value); |
3044 |
++ * void add_disk_randomness(struct gendisk *disk); |
3045 |
++ * |
3046 |
++ * add_device_randomness() adds data to the input pool that |
3047 |
++ * is likely to differ between two devices (or possibly even per boot). |
3048 |
++ * This would be things like MAC addresses or serial numbers, or the |
3049 |
++ * read-out of the RTC. This does *not* credit any actual entropy to |
3050 |
++ * the pool, but it initializes the pool to different values for devices |
3051 |
++ * that might otherwise be identical and have very little entropy |
3052 |
++ * available to them (particularly common in the embedded world). |
3053 |
++ * |
3054 |
++ * add_hwgenerator_randomness() is for true hardware RNGs, and will credit |
3055 |
++ * entropy as specified by the caller. If the entropy pool is full it will |
3056 |
++ * block until more entropy is needed. |
3057 |
++ * |
3058 |
++ * add_bootloader_randomness() is called by bootloader drivers, such as EFI |
3059 |
++ * and device tree, and credits its input depending on whether or not the |
3060 |
++ * configuration option CONFIG_RANDOM_TRUST_BOOTLOADER is set. |
3061 |
++ * |
3062 |
++ * add_interrupt_randomness() uses the interrupt timing as random |
3063 |
++ * inputs to the entropy pool. Using the cycle counters and the irq source |
3064 |
++ * as inputs, it feeds the input pool roughly once a second or after 64 |
3065 |
++ * interrupts, crediting 1 bit of entropy for whichever comes first. |
3066 |
++ * |
3067 |
++ * add_input_randomness() uses the input layer interrupt timing, as well |
3068 |
++ * as the event type information from the hardware. |
3069 |
++ * |
3070 |
++ * add_disk_randomness() uses what amounts to the seek time of block |
3071 |
++ * layer request events, on a per-disk_devt basis, as input to the |
3072 |
++ * entropy pool. Note that high-speed solid state drives with very low |
3073 |
++ * seek times do not make for good sources of entropy, as their seek |
3074 |
++ * times are usually fairly consistent. |
3075 |
++ * |
3076 |
++ * The last two routines try to estimate how many bits of entropy |
3077 |
++ * to credit. They do this by keeping track of the first and second |
3078 |
++ * order deltas of the event timings. |
3079 |
++ * |
3080 |
++ **********************************************************************/ |
3081 |
+ |
3082 |
+-/* |
3083 |
+- * Used as a workqueue function so that when the input pool is getting |
3084 |
+- * full, we can "spill over" some entropy to the output pools. That |
3085 |
+- * way the output pools can store some of the excess entropy instead |
3086 |
+- * of letting it go to waste. |
3087 |
+- */ |
3088 |
+-static void push_to_pool(struct work_struct *work) |
3089 |
++static bool trust_cpu __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); |
3090 |
++static bool trust_bootloader __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER); |
3091 |
++static int __init parse_trust_cpu(char *arg) |
3092 |
+ { |
3093 |
+- struct entropy_store *r = container_of(work, struct entropy_store, |
3094 |
+- push_work); |
3095 |
+- BUG_ON(!r); |
3096 |
+- _xfer_secondary_pool(r, random_read_wakeup_bits/8); |
3097 |
+- trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT, |
3098 |
+- r->pull->entropy_count >> ENTROPY_SHIFT); |
3099 |
++ return kstrtobool(arg, &trust_cpu); |
3100 |
+ } |
3101 |
+- |
3102 |
+-/* |
3103 |
+- * This function decides how many bytes to actually take from the |
3104 |
+- * given pool, and also debits the entropy count accordingly. |
3105 |
+- */ |
3106 |
+-static size_t account(struct entropy_store *r, size_t nbytes, int min, |
3107 |
+- int reserved) |
3108 |
++static int __init parse_trust_bootloader(char *arg) |
3109 |
+ { |
3110 |
+- int entropy_count, orig; |
3111 |
+- size_t ibytes, nfrac; |
3112 |
+- |
3113 |
+- BUG_ON(r->entropy_count > r->poolinfo->poolfracbits); |
3114 |
+- |
3115 |
+- /* Can we pull enough? */ |
3116 |
+-retry: |
3117 |
+- entropy_count = orig = ACCESS_ONCE(r->entropy_count); |
3118 |
+- ibytes = nbytes; |
3119 |
+- /* If limited, never pull more than available */ |
3120 |
+- if (r->limit) { |
3121 |
+- int have_bytes = entropy_count >> (ENTROPY_SHIFT + 3); |
3122 |
+- |
3123 |
+- if ((have_bytes -= reserved) < 0) |
3124 |
+- have_bytes = 0; |
3125 |
+- ibytes = min_t(size_t, ibytes, have_bytes); |
3126 |
+- } |
3127 |
+- if (ibytes < min) |
3128 |
+- ibytes = 0; |
3129 |
+- |
3130 |
+- if (unlikely(entropy_count < 0)) { |
3131 |
+- pr_warn("random: negative entropy count: pool %s count %d\n", |
3132 |
+- r->name, entropy_count); |
3133 |
+- WARN_ON(1); |
3134 |
+- entropy_count = 0; |
3135 |
+- } |
3136 |
+- nfrac = ibytes << (ENTROPY_SHIFT + 3); |
3137 |
+- if ((size_t) entropy_count > nfrac) |
3138 |
+- entropy_count -= nfrac; |
3139 |
+- else |
3140 |
+- entropy_count = 0; |
3141 |
+- |
3142 |
+- if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) |
3143 |
+- goto retry; |
3144 |
+- |
3145 |
+- trace_debit_entropy(r->name, 8 * ibytes); |
3146 |
+- if (ibytes && |
3147 |
+- (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_bits) { |
3148 |
+- wake_up_interruptible(&random_write_wait); |
3149 |
+- kill_fasync(&fasync, SIGIO, POLL_OUT); |
3150 |
+- } |
3151 |
+- |
3152 |
+- return ibytes; |
3153 |
++ return kstrtobool(arg, &trust_bootloader); |
3154 |
+ } |
3155 |
++early_param("random.trust_cpu", parse_trust_cpu); |
3156 |
++early_param("random.trust_bootloader", parse_trust_bootloader); |
3157 |
+ |
3158 |
+ /* |
3159 |
+- * This function does the actual extraction for extract_entropy and |
3160 |
+- * extract_entropy_user. |
3161 |
+- * |
3162 |
+- * Note: we assume that .poolwords is a multiple of 16 words. |
3163 |
++ * The first collection of entropy occurs at system boot while interrupts |
3164 |
++ * are still turned off. Here we push in latent entropy, RDSEED, a timestamp, |
3165 |
++ * utsname(), and the command line. Depending on the above configuration knob, |
3166 |
++ * RDSEED may be considered sufficient for initialization. Note that much |
3167 |
++ * earlier setup may already have pushed entropy into the input pool by the |
3168 |
++ * time we get here. |
3169 |
+ */ |
3170 |
+-static void extract_buf(struct entropy_store *r, __u8 *out) |
3171 |
++int __init random_init(const char *command_line) |
3172 |
+ { |
3173 |
+- int i; |
3174 |
+- union { |
3175 |
+- __u32 w[5]; |
3176 |
+- unsigned long l[LONGS(20)]; |
3177 |
+- } hash; |
3178 |
+- __u32 workspace[SHA_WORKSPACE_WORDS]; |
3179 |
+- unsigned long flags; |
3180 |
+- |
3181 |
+- /* |
3182 |
+- * If we have an architectural hardware random number |
3183 |
+- * generator, use it for SHA's initial vector |
3184 |
+- */ |
3185 |
+- sha_init(hash.w); |
3186 |
+- for (i = 0; i < LONGS(20); i++) { |
3187 |
+- unsigned long v; |
3188 |
+- if (!arch_get_random_long(&v)) |
3189 |
+- break; |
3190 |
+- hash.l[i] = v; |
3191 |
+- } |
3192 |
+- |
3193 |
+- /* Generate a hash across the pool, 16 words (512 bits) at a time */ |
3194 |
+- spin_lock_irqsave(&r->lock, flags); |
3195 |
+- for (i = 0; i < r->poolinfo->poolwords; i += 16) |
3196 |
+- sha_transform(hash.w, (__u8 *)(r->pool + i), workspace); |
3197 |
+- |
3198 |
+- /* |
3199 |
+- * We mix the hash back into the pool to prevent backtracking |
3200 |
+- * attacks (where the attacker knows the state of the pool |
3201 |
+- * plus the current outputs, and attempts to find previous |
3202 |
+- * ouputs), unless the hash function can be inverted. By |
3203 |
+- * mixing at least a SHA1 worth of hash data back, we make |
3204 |
+- * brute-forcing the feedback as hard as brute-forcing the |
3205 |
+- * hash. |
3206 |
+- */ |
3207 |
+- __mix_pool_bytes(r, hash.w, sizeof(hash.w)); |
3208 |
+- spin_unlock_irqrestore(&r->lock, flags); |
3209 |
+- |
3210 |
+- memzero_explicit(workspace, sizeof(workspace)); |
3211 |
+- |
3212 |
+- /* |
3213 |
+- * In case the hash function has some recognizable output |
3214 |
+- * pattern, we fold it in half. Thus, we always feed back |
3215 |
+- * twice as much data as we output. |
3216 |
+- */ |
3217 |
+- hash.w[0] ^= hash.w[3]; |
3218 |
+- hash.w[1] ^= hash.w[4]; |
3219 |
+- hash.w[2] ^= rol32(hash.w[2], 16); |
3220 |
+- |
3221 |
+- memcpy(out, &hash, EXTRACT_SIZE); |
3222 |
+- memzero_explicit(&hash, sizeof(hash)); |
3223 |
+-} |
3224 |
+- |
3225 |
+-static ssize_t _extract_entropy(struct entropy_store *r, void *buf, |
3226 |
+- size_t nbytes, int fips) |
3227 |
+-{ |
3228 |
+- ssize_t ret = 0, i; |
3229 |
+- __u8 tmp[EXTRACT_SIZE]; |
3230 |
+- unsigned long flags; |
3231 |
++ ktime_t now = ktime_get_real(); |
3232 |
++ unsigned int i, arch_bits; |
3233 |
++ unsigned long entropy; |
3234 |
+ |
3235 |
+- while (nbytes) { |
3236 |
+- extract_buf(r, tmp); |
3237 |
++#if defined(LATENT_ENTROPY_PLUGIN) |
3238 |
++ static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy; |
3239 |
++ _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); |
3240 |
++#endif |
3241 |
+ |
3242 |
+- if (fips) { |
3243 |
+- spin_lock_irqsave(&r->lock, flags); |
3244 |
+- if (!memcmp(tmp, r->last_data, EXTRACT_SIZE)) |
3245 |
+- panic("Hardware RNG duplicated output!\n"); |
3246 |
+- memcpy(r->last_data, tmp, EXTRACT_SIZE); |
3247 |
+- spin_unlock_irqrestore(&r->lock, flags); |
3248 |
++ for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8; |
3249 |
++ i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) { |
3250 |
++ if (!arch_get_random_seed_long_early(&entropy) && |
3251 |
++ !arch_get_random_long_early(&entropy)) { |
3252 |
++ entropy = random_get_entropy(); |
3253 |
++ arch_bits -= sizeof(entropy) * 8; |
3254 |
+ } |
3255 |
+- i = min_t(int, nbytes, EXTRACT_SIZE); |
3256 |
+- memcpy(buf, tmp, i); |
3257 |
+- nbytes -= i; |
3258 |
+- buf += i; |
3259 |
+- ret += i; |
3260 |
++ _mix_pool_bytes(&entropy, sizeof(entropy)); |
3261 |
+ } |
3262 |
++ _mix_pool_bytes(&now, sizeof(now)); |
3263 |
++ _mix_pool_bytes(utsname(), sizeof(*(utsname()))); |
3264 |
++ _mix_pool_bytes(command_line, strlen(command_line)); |
3265 |
++ add_latent_entropy(); |
3266 |
+ |
3267 |
+- /* Wipe data just returned from memory */ |
3268 |
+- memzero_explicit(tmp, sizeof(tmp)); |
3269 |
++ if (crng_ready()) |
3270 |
++ crng_reseed(); |
3271 |
++ else if (trust_cpu) |
3272 |
++ _credit_init_bits(arch_bits); |
3273 |
+ |
3274 |
+- return ret; |
3275 |
++ return 0; |
3276 |
+ } |
3277 |
+ |
3278 |
+ /* |
3279 |
+- * This function extracts randomness from the "entropy pool", and |
3280 |
+- * returns it in a buffer. |
3281 |
++ * Add device- or boot-specific data to the input pool to help |
3282 |
++ * initialize it. |
3283 |
+ * |
3284 |
+- * The min parameter specifies the minimum amount we can pull before |
3285 |
+- * failing to avoid races that defeat catastrophic reseeding while the |
3286 |
+- * reserved parameter indicates how much entropy we must leave in the |
3287 |
+- * pool after each pull to avoid starving other readers. |
3288 |
++ * None of this adds any entropy; it is meant to avoid the problem of |
3289 |
++ * the entropy pool having similar initial state across largely |
3290 |
++ * identical devices. |
3291 |
+ */ |
3292 |
+-static ssize_t extract_entropy(struct entropy_store *r, void *buf, |
3293 |
+- size_t nbytes, int min, int reserved) |
3294 |
++void add_device_randomness(const void *buf, size_t len) |
3295 |
+ { |
3296 |
+- __u8 tmp[EXTRACT_SIZE]; |
3297 |
++ unsigned long entropy = random_get_entropy(); |
3298 |
+ unsigned long flags; |
3299 |
+ |
3300 |
+- /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */ |
3301 |
+- if (fips_enabled) { |
3302 |
+- spin_lock_irqsave(&r->lock, flags); |
3303 |
+- if (!r->last_data_init) { |
3304 |
+- r->last_data_init = 1; |
3305 |
+- spin_unlock_irqrestore(&r->lock, flags); |
3306 |
+- trace_extract_entropy(r->name, EXTRACT_SIZE, |
3307 |
+- ENTROPY_BITS(r), _RET_IP_); |
3308 |
+- xfer_secondary_pool(r, EXTRACT_SIZE); |
3309 |
+- extract_buf(r, tmp); |
3310 |
+- spin_lock_irqsave(&r->lock, flags); |
3311 |
+- memcpy(r->last_data, tmp, EXTRACT_SIZE); |
3312 |
+- } |
3313 |
+- spin_unlock_irqrestore(&r->lock, flags); |
3314 |
+- } |
3315 |
+- |
3316 |
+- trace_extract_entropy(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_); |
3317 |
+- xfer_secondary_pool(r, nbytes); |
3318 |
+- nbytes = account(r, nbytes, min, reserved); |
3319 |
+- |
3320 |
+- return _extract_entropy(r, buf, nbytes, fips_enabled); |
3321 |
++ spin_lock_irqsave(&input_pool.lock, flags); |
3322 |
++ _mix_pool_bytes(&entropy, sizeof(entropy)); |
3323 |
++ _mix_pool_bytes(buf, len); |
3324 |
++ spin_unlock_irqrestore(&input_pool.lock, flags); |
3325 |
+ } |
3326 |
++EXPORT_SYMBOL(add_device_randomness); |
3327 |
+ |
3328 |
+ /* |
3329 |
+- * This function extracts randomness from the "entropy pool", and |
3330 |
+- * returns it in a userspace buffer. |
3331 |
++ * Interface for in-kernel drivers of true hardware RNGs. |
3332 |
++ * Those devices may produce endless random bits and will be throttled |
3333 |
++ * when our pool is full. |
3334 |
+ */ |
3335 |
+-static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, |
3336 |
+- size_t nbytes) |
3337 |
++void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy) |
3338 |
+ { |
3339 |
+- ssize_t ret = 0, i; |
3340 |
+- __u8 tmp[EXTRACT_SIZE]; |
3341 |
+- int large_request = (nbytes > 256); |
3342 |
+- |
3343 |
+- trace_extract_entropy_user(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_); |
3344 |
+- xfer_secondary_pool(r, nbytes); |
3345 |
+- nbytes = account(r, nbytes, 0, 0); |
3346 |
+- |
3347 |
+- while (nbytes) { |
3348 |
+- if (large_request && need_resched()) { |
3349 |
+- if (signal_pending(current)) { |
3350 |
+- if (ret == 0) |
3351 |
+- ret = -ERESTARTSYS; |
3352 |
+- break; |
3353 |
+- } |
3354 |
+- schedule(); |
3355 |
+- } |
3356 |
+- |
3357 |
+- extract_buf(r, tmp); |
3358 |
+- i = min_t(int, nbytes, EXTRACT_SIZE); |
3359 |
+- if (copy_to_user(buf, tmp, i)) { |
3360 |
+- ret = -EFAULT; |
3361 |
+- break; |
3362 |
+- } |
3363 |
++ mix_pool_bytes(buf, len); |
3364 |
++ credit_init_bits(entropy); |
3365 |
+ |
3366 |
+- nbytes -= i; |
3367 |
+- buf += i; |
3368 |
+- ret += i; |
3369 |
+- } |
3370 |
+- |
3371 |
+- /* Wipe data just returned from memory */ |
3372 |
+- memzero_explicit(tmp, sizeof(tmp)); |
3373 |
+- |
3374 |
+- return ret; |
3375 |
++ /* |
3376 |
++ * Throttle writing to once every CRNG_RESEED_INTERVAL, unless |
3377 |
++ * we're not yet initialized. |
3378 |
++ */ |
3379 |
++ if (!kthread_should_stop() && crng_ready()) |
3380 |
++ schedule_timeout_interruptible(CRNG_RESEED_INTERVAL); |
3381 |
+ } |
3382 |
++EXPORT_SYMBOL_GPL(add_hwgenerator_randomness); |
3383 |
+ |
3384 |
+ /* |
3385 |
+- * This function is the exported kernel interface. It returns some |
3386 |
+- * number of good random numbers, suitable for key generation, seeding |
3387 |
+- * TCP sequence numbers, etc. It does not rely on the hardware random |
3388 |
+- * number generator. For random bytes direct from the hardware RNG |
3389 |
+- * (when available), use get_random_bytes_arch(). |
3390 |
++ * Handle random seed passed by bootloader, and credit it if |
3391 |
++ * CONFIG_RANDOM_TRUST_BOOTLOADER is set. |
3392 |
+ */ |
3393 |
+-void get_random_bytes(void *buf, int nbytes) |
3394 |
++void __init add_bootloader_randomness(const void *buf, size_t len) |
3395 |
+ { |
3396 |
+- __u8 tmp[CHACHA20_BLOCK_SIZE]; |
3397 |
++ mix_pool_bytes(buf, len); |
3398 |
++ if (trust_bootloader) |
3399 |
++ credit_init_bits(len * 8); |
3400 |
++} |
3401 |
+ |
3402 |
+-#if DEBUG_RANDOM_BOOT > 0 |
3403 |
+- if (!crng_ready()) |
3404 |
+- printk(KERN_NOTICE "random: %pF get_random_bytes called " |
3405 |
+- "with crng_init = %d\n", (void *) _RET_IP_, crng_init); |
3406 |
+-#endif |
3407 |
+- trace_get_random_bytes(nbytes, _RET_IP_); |
3408 |
++struct fast_pool { |
3409 |
++ struct work_struct mix; |
3410 |
++ unsigned long pool[4]; |
3411 |
++ unsigned long last; |
3412 |
++ unsigned int count; |
3413 |
++}; |
3414 |
+ |
3415 |
+- while (nbytes >= CHACHA20_BLOCK_SIZE) { |
3416 |
+- extract_crng(buf); |
3417 |
+- buf += CHACHA20_BLOCK_SIZE; |
3418 |
+- nbytes -= CHACHA20_BLOCK_SIZE; |
3419 |
+- } |
3420 |
++static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = { |
3421 |
++#ifdef CONFIG_64BIT |
3422 |
++#define FASTMIX_PERM SIPHASH_PERMUTATION |
3423 |
++ .pool = { SIPHASH_CONST_0, SIPHASH_CONST_1, SIPHASH_CONST_2, SIPHASH_CONST_3 } |
3424 |
++#else |
3425 |
++#define FASTMIX_PERM HSIPHASH_PERMUTATION |
3426 |
++ .pool = { HSIPHASH_CONST_0, HSIPHASH_CONST_1, HSIPHASH_CONST_2, HSIPHASH_CONST_3 } |
3427 |
++#endif |
3428 |
++}; |
3429 |
+ |
3430 |
+- if (nbytes > 0) { |
3431 |
+- extract_crng(tmp); |
3432 |
+- memcpy(buf, tmp, nbytes); |
3433 |
+- crng_backtrack_protect(tmp, nbytes); |
3434 |
+- } else |
3435 |
+- crng_backtrack_protect(tmp, CHACHA20_BLOCK_SIZE); |
3436 |
+- memzero_explicit(tmp, sizeof(tmp)); |
3437 |
++/* |
3438 |
++ * This is [Half]SipHash-1-x, starting from an empty key. Because |
3439 |
++ * the key is fixed, it assumes that its inputs are non-malicious, |
3440 |
++ * and therefore this has no security on its own. s represents the |
3441 |
++ * four-word SipHash state, while v represents a two-word input. |
3442 |
++ */ |
3443 |
++static void fast_mix(unsigned long s[4], unsigned long v1, unsigned long v2) |
3444 |
++{ |
3445 |
++ s[3] ^= v1; |
3446 |
++ FASTMIX_PERM(s[0], s[1], s[2], s[3]); |
3447 |
++ s[0] ^= v1; |
3448 |
++ s[3] ^= v2; |
3449 |
++ FASTMIX_PERM(s[0], s[1], s[2], s[3]); |
3450 |
++ s[0] ^= v2; |
3451 |
+ } |
3452 |
+-EXPORT_SYMBOL(get_random_bytes); |
3453 |
+ |
3454 |
++#ifdef CONFIG_SMP |
3455 |
+ /* |
3456 |
+- * Add a callback function that will be invoked when the nonblocking |
3457 |
+- * pool is initialised. |
3458 |
+- * |
3459 |
+- * returns: 0 if callback is successfully added |
3460 |
+- * -EALREADY if pool is already initialised (callback not called) |
3461 |
+- * -ENOENT if module for callback is not alive |
3462 |
++ * This function is called when the CPU has just come online, with |
3463 |
++ * entry CPUHP_AP_RANDOM_ONLINE, just after CPUHP_AP_WORKQUEUE_ONLINE. |
3464 |
+ */ |
3465 |
+-int add_random_ready_callback(struct random_ready_callback *rdy) |
3466 |
++int __cold random_online_cpu(unsigned int cpu) |
3467 |
+ { |
3468 |
+- struct module *owner; |
3469 |
+- unsigned long flags; |
3470 |
+- int err = -EALREADY; |
3471 |
++ /* |
3472 |
++ * During CPU shutdown and before CPU onlining, add_interrupt_ |
3473 |
++ * randomness() may schedule mix_interrupt_randomness(), and |
3474 |
++ * set the MIX_INFLIGHT flag. However, because the worker can |
3475 |
++ * be scheduled on a different CPU during this period, that |
3476 |
++ * flag will never be cleared. For that reason, we zero out |
3477 |
++ * the flag here, which runs just after workqueues are onlined |
3478 |
++ * for the CPU again. This also has the effect of setting the |
3479 |
++ * irq randomness count to zero so that new accumulated irqs |
3480 |
++ * are fresh. |
3481 |
++ */ |
3482 |
++ per_cpu_ptr(&irq_randomness, cpu)->count = 0; |
3483 |
++ return 0; |
3484 |
++} |
3485 |
++#endif |
3486 |
+ |
3487 |
+- if (crng_ready()) |
3488 |
+- return err; |
3489 |
++static void mix_interrupt_randomness(struct work_struct *work) |
3490 |
++{ |
3491 |
++ struct fast_pool *fast_pool = container_of(work, struct fast_pool, mix); |
3492 |
++ /* |
3493 |
++ * The size of the copied stack pool is explicitly 2 longs so that we |
3494 |
++ * only ever ingest half of the siphash output each time, retaining |
3495 |
++ * the other half as the next "key" that carries over. The entropy is |
3496 |
++ * supposed to be sufficiently dispersed between bits so on average |
3497 |
++ * we don't wind up "losing" some. |
3498 |
++ */ |
3499 |
++ unsigned long pool[2]; |
3500 |
++ unsigned int count; |
3501 |
+ |
3502 |
+- owner = rdy->owner; |
3503 |
+- if (!try_module_get(owner)) |
3504 |
+- return -ENOENT; |
3505 |
++ /* Check to see if we're running on the wrong CPU due to hotplug. */ |
3506 |
++ local_irq_disable(); |
3507 |
++ if (fast_pool != this_cpu_ptr(&irq_randomness)) { |
3508 |
++ local_irq_enable(); |
3509 |
++ return; |
3510 |
++ } |
3511 |
+ |
3512 |
+- spin_lock_irqsave(&random_ready_list_lock, flags); |
3513 |
+- if (crng_ready()) |
3514 |
+- goto out; |
3515 |
++ /* |
3516 |
++ * Copy the pool to the stack so that the mixer always has a |
3517 |
++ * consistent view, before we reenable irqs again. |
3518 |
++ */ |
3519 |
++ memcpy(pool, fast_pool->pool, sizeof(pool)); |
3520 |
++ count = fast_pool->count; |
3521 |
++ fast_pool->count = 0; |
3522 |
++ fast_pool->last = jiffies; |
3523 |
++ local_irq_enable(); |
3524 |
++ |
3525 |
++ mix_pool_bytes(pool, sizeof(pool)); |
3526 |
++ credit_init_bits(max(1u, (count & U16_MAX) / 64)); |
3527 |
+ |
3528 |
+- owner = NULL; |
3529 |
++ memzero_explicit(pool, sizeof(pool)); |
3530 |
++} |
3531 |
++ |
3532 |
++void add_interrupt_randomness(int irq) |
3533 |
++{ |
3534 |
++ enum { MIX_INFLIGHT = 1U << 31 }; |
3535 |
++ unsigned long entropy = random_get_entropy(); |
3536 |
++ struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness); |
3537 |
++ struct pt_regs *regs = get_irq_regs(); |
3538 |
++ unsigned int new_count; |
3539 |
+ |
3540 |
+- list_add(&rdy->list, &random_ready_list); |
3541 |
+- err = 0; |
3542 |
++ fast_mix(fast_pool->pool, entropy, |
3543 |
++ (regs ? instruction_pointer(regs) : _RET_IP_) ^ swab(irq)); |
3544 |
++ new_count = ++fast_pool->count; |
3545 |
+ |
3546 |
+-out: |
3547 |
+- spin_unlock_irqrestore(&random_ready_list_lock, flags); |
3548 |
++ if (new_count & MIX_INFLIGHT) |
3549 |
++ return; |
3550 |
+ |
3551 |
+- module_put(owner); |
3552 |
++ if (new_count < 64 && !time_is_before_jiffies(fast_pool->last + HZ)) |
3553 |
++ return; |
3554 |
+ |
3555 |
+- return err; |
3556 |
++ if (unlikely(!fast_pool->mix.func)) |
3557 |
++ INIT_WORK(&fast_pool->mix, mix_interrupt_randomness); |
3558 |
++ fast_pool->count |= MIX_INFLIGHT; |
3559 |
++ queue_work_on(raw_smp_processor_id(), system_highpri_wq, &fast_pool->mix); |
3560 |
+ } |
3561 |
+-EXPORT_SYMBOL(add_random_ready_callback); |
3562 |
++EXPORT_SYMBOL_GPL(add_interrupt_randomness); |
3563 |
++ |
3564 |
++/* There is one of these per entropy source */ |
3565 |
++struct timer_rand_state { |
3566 |
++ unsigned long last_time; |
3567 |
++ long last_delta, last_delta2; |
3568 |
++}; |
3569 |
+ |
3570 |
+ /* |
3571 |
+- * Delete a previously registered readiness callback function. |
3572 |
++ * This function adds entropy to the entropy "pool" by using timing |
3573 |
++ * delays. It uses the timer_rand_state structure to make an estimate |
3574 |
++ * of how many bits of entropy this call has added to the pool. The |
3575 |
++ * value "num" is also added to the pool; it should somehow describe |
3576 |
++ * the type of event that just happened. |
3577 |
+ */ |
3578 |
+-void del_random_ready_callback(struct random_ready_callback *rdy) |
3579 |
++static void add_timer_randomness(struct timer_rand_state *state, unsigned int num) |
3580 |
+ { |
3581 |
+- unsigned long flags; |
3582 |
+- struct module *owner = NULL; |
3583 |
++ unsigned long entropy = random_get_entropy(), now = jiffies, flags; |
3584 |
++ long delta, delta2, delta3; |
3585 |
++ unsigned int bits; |
3586 |
+ |
3587 |
+- spin_lock_irqsave(&random_ready_list_lock, flags); |
3588 |
+- if (!list_empty(&rdy->list)) { |
3589 |
+- list_del_init(&rdy->list); |
3590 |
+- owner = rdy->owner; |
3591 |
++ /* |
3592 |
++ * If we're in a hard IRQ, add_interrupt_randomness() will be called |
3593 |
++ * sometime after, so mix into the fast pool. |
3594 |
++ */ |
3595 |
++ if (in_irq()) { |
3596 |
++ fast_mix(this_cpu_ptr(&irq_randomness)->pool, entropy, num); |
3597 |
++ } else { |
3598 |
++ spin_lock_irqsave(&input_pool.lock, flags); |
3599 |
++ _mix_pool_bytes(&entropy, sizeof(entropy)); |
3600 |
++ _mix_pool_bytes(&num, sizeof(num)); |
3601 |
++ spin_unlock_irqrestore(&input_pool.lock, flags); |
3602 |
+ } |
3603 |
+- spin_unlock_irqrestore(&random_ready_list_lock, flags); |
3604 |
+- |
3605 |
+- module_put(owner); |
3606 |
+-} |
3607 |
+-EXPORT_SYMBOL(del_random_ready_callback); |
3608 |
+ |
3609 |
+-/* |
3610 |
+- * This function will use the architecture-specific hardware random |
3611 |
+- * number generator if it is available. The arch-specific hw RNG will |
3612 |
+- * almost certainly be faster than what we can do in software, but it |
3613 |
+- * is impossible to verify that it is implemented securely (as |
3614 |
+- * opposed, to, say, the AES encryption of a sequence number using a |
3615 |
+- * key known by the NSA). So it's useful if we need the speed, but |
3616 |
+- * only if we're willing to trust the hardware manufacturer not to |
3617 |
+- * have put in a back door. |
3618 |
+- */ |
3619 |
+-void get_random_bytes_arch(void *buf, int nbytes) |
3620 |
+-{ |
3621 |
+- char *p = buf; |
3622 |
++ if (crng_ready()) |
3623 |
++ return; |
3624 |
+ |
3625 |
+- trace_get_random_bytes_arch(nbytes, _RET_IP_); |
3626 |
+- while (nbytes) { |
3627 |
+- unsigned long v; |
3628 |
+- int chunk = min(nbytes, (int)sizeof(unsigned long)); |
3629 |
++ /* |
3630 |
++ * Calculate number of bits of randomness we probably added. |
3631 |
++ * We take into account the first, second and third-order deltas |
3632 |
++ * in order to make our estimate. |
3633 |
++ */ |
3634 |
++ delta = now - READ_ONCE(state->last_time); |
3635 |
++ WRITE_ONCE(state->last_time, now); |
3636 |
++ |
3637 |
++ delta2 = delta - READ_ONCE(state->last_delta); |
3638 |
++ WRITE_ONCE(state->last_delta, delta); |
3639 |
++ |
3640 |
++ delta3 = delta2 - READ_ONCE(state->last_delta2); |
3641 |
++ WRITE_ONCE(state->last_delta2, delta2); |
3642 |
++ |
3643 |
++ if (delta < 0) |
3644 |
++ delta = -delta; |
3645 |
++ if (delta2 < 0) |
3646 |
++ delta2 = -delta2; |
3647 |
++ if (delta3 < 0) |
3648 |
++ delta3 = -delta3; |
3649 |
++ if (delta > delta2) |
3650 |
++ delta = delta2; |
3651 |
++ if (delta > delta3) |
3652 |
++ delta = delta3; |
3653 |
+ |
3654 |
+- if (!arch_get_random_long(&v)) |
3655 |
+- break; |
3656 |
+- |
3657 |
+- memcpy(p, &v, chunk); |
3658 |
+- p += chunk; |
3659 |
+- nbytes -= chunk; |
3660 |
+- } |
3661 |
++ /* |
3662 |
++ * delta is now minimum absolute delta. Round down by 1 bit |
3663 |
++ * on general principles, and limit entropy estimate to 11 bits. |
3664 |
++ */ |
3665 |
++ bits = min(fls(delta >> 1), 11); |
3666 |
+ |
3667 |
+- if (nbytes) |
3668 |
+- get_random_bytes(p, nbytes); |
3669 |
++ /* |
3670 |
++ * As mentioned above, if we're in a hard IRQ, add_interrupt_randomness() |
3671 |
++ * will run after this, which uses a different crediting scheme of 1 bit |
3672 |
++ * per every 64 interrupts. In order to let that function do accounting |
3673 |
++ * close to the one in this function, we credit a full 64/64 bit per bit, |
3674 |
++ * and then subtract one to account for the extra one added. |
3675 |
++ */ |
3676 |
++ if (in_irq()) |
3677 |
++ this_cpu_ptr(&irq_randomness)->count += max(1u, bits * 64) - 1; |
3678 |
++ else |
3679 |
++ _credit_init_bits(bits); |
3680 |
+ } |
3681 |
+-EXPORT_SYMBOL(get_random_bytes_arch); |
3682 |
+- |
3683 |
+ |
3684 |
+-/* |
3685 |
+- * init_std_data - initialize pool with system data |
3686 |
+- * |
3687 |
+- * @r: pool to initialize |
3688 |
+- * |
3689 |
+- * This function clears the pool's entropy count and mixes some system |
3690 |
+- * data into the pool to prepare it for use. The pool is not cleared |
3691 |
+- * as that can only decrease the entropy in the pool. |
3692 |
+- */ |
3693 |
+-static void init_std_data(struct entropy_store *r) |
3694 |
++void add_input_randomness(unsigned int type, unsigned int code, unsigned int value) |
3695 |
+ { |
3696 |
+- int i; |
3697 |
+- ktime_t now = ktime_get_real(); |
3698 |
+- unsigned long rv; |
3699 |
+- |
3700 |
+- r->last_pulled = jiffies; |
3701 |
+- mix_pool_bytes(r, &now, sizeof(now)); |
3702 |
+- for (i = r->poolinfo->poolbytes; i > 0; i -= sizeof(rv)) { |
3703 |
+- if (!arch_get_random_seed_long(&rv) && |
3704 |
+- !arch_get_random_long(&rv)) |
3705 |
+- rv = random_get_entropy(); |
3706 |
+- mix_pool_bytes(r, &rv, sizeof(rv)); |
3707 |
+- } |
3708 |
+- mix_pool_bytes(r, utsname(), sizeof(*(utsname()))); |
3709 |
++ static unsigned char last_value; |
3710 |
++ static struct timer_rand_state input_timer_state = { INITIAL_JIFFIES }; |
3711 |
++ |
3712 |
++ /* Ignore autorepeat and the like. */ |
3713 |
++ if (value == last_value) |
3714 |
++ return; |
3715 |
++ |
3716 |
++ last_value = value; |
3717 |
++ add_timer_randomness(&input_timer_state, |
3718 |
++ (type << 4) ^ code ^ (code >> 4) ^ value); |
3719 |
+ } |
3720 |
++EXPORT_SYMBOL_GPL(add_input_randomness); |
3721 |
+ |
3722 |
+-/* |
3723 |
+- * Note that setup_arch() may call add_device_randomness() |
3724 |
+- * long before we get here. This allows seeding of the pools |
3725 |
+- * with some platform dependent data very early in the boot |
3726 |
+- * process. But it limits our options here. We must use |
3727 |
+- * statically allocated structures that already have all |
3728 |
+- * initializations complete at compile time. We should also |
3729 |
+- * take care not to overwrite the precious per platform data |
3730 |
+- * we were given. |
3731 |
+- */ |
3732 |
+-static int rand_initialize(void) |
3733 |
++#ifdef CONFIG_BLOCK |
3734 |
++void add_disk_randomness(struct gendisk *disk) |
3735 |
+ { |
3736 |
+- init_std_data(&input_pool); |
3737 |
+- init_std_data(&blocking_pool); |
3738 |
+- crng_initialize(&primary_crng); |
3739 |
+- crng_global_init_time = jiffies; |
3740 |
+- if (ratelimit_disable) { |
3741 |
+- urandom_warning.interval = 0; |
3742 |
+- unseeded_warning.interval = 0; |
3743 |
+- } |
3744 |
+- return 0; |
3745 |
++ if (!disk || !disk->random) |
3746 |
++ return; |
3747 |
++ /* First major is 1, so we get >= 0x200 here. */ |
3748 |
++ add_timer_randomness(disk->random, 0x100 + disk_devt(disk)); |
3749 |
+ } |
3750 |
+-early_initcall(rand_initialize); |
3751 |
++EXPORT_SYMBOL_GPL(add_disk_randomness); |
3752 |
+ |
3753 |
+-#ifdef CONFIG_BLOCK |
3754 |
+-void rand_initialize_disk(struct gendisk *disk) |
3755 |
++void __cold rand_initialize_disk(struct gendisk *disk) |
3756 |
+ { |
3757 |
+ struct timer_rand_state *state; |
3758 |
+ |
3759 |
+@@ -1752,134 +1127,189 @@ void rand_initialize_disk(struct gendisk *disk) |
3760 |
+ } |
3761 |
+ #endif |
3762 |
+ |
3763 |
+-static ssize_t |
3764 |
+-_random_read(int nonblock, char __user *buf, size_t nbytes) |
3765 |
++/* |
3766 |
++ * Each time the timer fires, we expect that we got an unpredictable |
3767 |
++ * jump in the cycle counter. Even if the timer is running on another |
3768 |
++ * CPU, the timer activity will be touching the stack of the CPU that is |
3769 |
++ * generating entropy.. |
3770 |
++ * |
3771 |
++ * Note that we don't re-arm the timer in the timer itself - we are |
3772 |
++ * happy to be scheduled away, since that just makes the load more |
3773 |
++ * complex, but we do not want the timer to keep ticking unless the |
3774 |
++ * entropy loop is running. |
3775 |
++ * |
3776 |
++ * So the re-arming always happens in the entropy loop itself. |
3777 |
++ */ |
3778 |
++static void __cold entropy_timer(unsigned long data) |
3779 |
++{ |
3780 |
++ credit_init_bits(1); |
3781 |
++} |
3782 |
++ |
3783 |
++/* |
3784 |
++ * If we have an actual cycle counter, see if we can |
3785 |
++ * generate enough entropy with timing noise |
3786 |
++ */ |
3787 |
++static void __cold try_to_generate_entropy(void) |
3788 |
+ { |
3789 |
+- ssize_t n; |
3790 |
++ struct { |
3791 |
++ unsigned long entropy; |
3792 |
++ struct timer_list timer; |
3793 |
++ } stack; |
3794 |
+ |
3795 |
+- if (nbytes == 0) |
3796 |
+- return 0; |
3797 |
++ stack.entropy = random_get_entropy(); |
3798 |
+ |
3799 |
+- nbytes = min_t(size_t, nbytes, SEC_XFER_SIZE); |
3800 |
+- while (1) { |
3801 |
+- n = extract_entropy_user(&blocking_pool, buf, nbytes); |
3802 |
+- if (n < 0) |
3803 |
+- return n; |
3804 |
+- trace_random_read(n*8, (nbytes-n)*8, |
3805 |
+- ENTROPY_BITS(&blocking_pool), |
3806 |
+- ENTROPY_BITS(&input_pool)); |
3807 |
+- if (n > 0) |
3808 |
+- return n; |
3809 |
+- |
3810 |
+- /* Pool is (near) empty. Maybe wait and retry. */ |
3811 |
+- if (nonblock) |
3812 |
+- return -EAGAIN; |
3813 |
++ /* Slow counter - or none. Don't even bother */ |
3814 |
++ if (stack.entropy == random_get_entropy()) |
3815 |
++ return; |
3816 |
+ |
3817 |
+- wait_event_interruptible(random_read_wait, |
3818 |
+- ENTROPY_BITS(&input_pool) >= |
3819 |
+- random_read_wakeup_bits); |
3820 |
+- if (signal_pending(current)) |
3821 |
+- return -ERESTARTSYS; |
3822 |
++ __setup_timer_on_stack(&stack.timer, entropy_timer, 0, 0); |
3823 |
++ while (!crng_ready() && !signal_pending(current)) { |
3824 |
++ if (!timer_pending(&stack.timer)) |
3825 |
++ mod_timer(&stack.timer, jiffies + 1); |
3826 |
++ mix_pool_bytes(&stack.entropy, sizeof(stack.entropy)); |
3827 |
++ schedule(); |
3828 |
++ stack.entropy = random_get_entropy(); |
3829 |
+ } |
3830 |
+-} |
3831 |
+ |
3832 |
+-static ssize_t |
3833 |
+-random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
3834 |
+-{ |
3835 |
+- return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes); |
3836 |
++ del_timer_sync(&stack.timer); |
3837 |
++ destroy_timer_on_stack(&stack.timer); |
3838 |
++ mix_pool_bytes(&stack.entropy, sizeof(stack.entropy)); |
3839 |
+ } |
3840 |
+ |
3841 |
+-static ssize_t |
3842 |
+-urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
3843 |
++ |
3844 |
++/********************************************************************** |
3845 |
++ * |
3846 |
++ * Userspace reader/writer interfaces. |
3847 |
++ * |
3848 |
++ * getrandom(2) is the primary modern interface into the RNG and should |
3849 |
++ * be used in preference to anything else. |
3850 |
++ * |
3851 |
++ * Reading from /dev/random has the same functionality as calling |
3852 |
++ * getrandom(2) with flags=0. In earlier versions, however, it had |
3853 |
++ * vastly different semantics and should therefore be avoided, to |
3854 |
++ * prevent backwards compatibility issues. |
3855 |
++ * |
3856 |
++ * Reading from /dev/urandom has the same functionality as calling |
3857 |
++ * getrandom(2) with flags=GRND_INSECURE. Because it does not block |
3858 |
++ * waiting for the RNG to be ready, it should not be used. |
3859 |
++ * |
3860 |
++ * Writing to either /dev/random or /dev/urandom adds entropy to |
3861 |
++ * the input pool but does not credit it. |
3862 |
++ * |
3863 |
++ * Polling on /dev/random indicates when the RNG is initialized, on |
3864 |
++ * the read side, and when it wants new entropy, on the write side. |
3865 |
++ * |
3866 |
++ * Both /dev/random and /dev/urandom have the same set of ioctls for |
3867 |
++ * adding entropy, getting the entropy count, zeroing the count, and |
3868 |
++ * reseeding the crng. |
3869 |
++ * |
3870 |
++ **********************************************************************/ |
3871 |
++ |
3872 |
++SYSCALL_DEFINE3(getrandom, char __user *, ubuf, size_t, len, unsigned int, flags) |
3873 |
+ { |
3874 |
+- unsigned long flags; |
3875 |
+- static int maxwarn = 10; |
3876 |
++ struct iov_iter iter; |
3877 |
++ struct iovec iov; |
3878 |
+ int ret; |
3879 |
+ |
3880 |
+- if (!crng_ready() && maxwarn > 0) { |
3881 |
+- maxwarn--; |
3882 |
+- if (__ratelimit(&urandom_warning)) |
3883 |
+- printk(KERN_NOTICE "random: %s: uninitialized " |
3884 |
+- "urandom read (%zd bytes read)\n", |
3885 |
+- current->comm, nbytes); |
3886 |
+- spin_lock_irqsave(&primary_crng.lock, flags); |
3887 |
+- crng_init_cnt = 0; |
3888 |
+- spin_unlock_irqrestore(&primary_crng.lock, flags); |
3889 |
++ if (flags & ~(GRND_NONBLOCK | GRND_RANDOM | GRND_INSECURE)) |
3890 |
++ return -EINVAL; |
3891 |
++ |
3892 |
++ /* |
3893 |
++ * Requesting insecure and blocking randomness at the same time makes |
3894 |
++ * no sense. |
3895 |
++ */ |
3896 |
++ if ((flags & (GRND_INSECURE | GRND_RANDOM)) == (GRND_INSECURE | GRND_RANDOM)) |
3897 |
++ return -EINVAL; |
3898 |
++ |
3899 |
++ if (!crng_ready() && !(flags & GRND_INSECURE)) { |
3900 |
++ if (flags & GRND_NONBLOCK) |
3901 |
++ return -EAGAIN; |
3902 |
++ ret = wait_for_random_bytes(); |
3903 |
++ if (unlikely(ret)) |
3904 |
++ return ret; |
3905 |
+ } |
3906 |
+- nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); |
3907 |
+- ret = extract_crng_user(buf, nbytes); |
3908 |
+- trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); |
3909 |
+- return ret; |
3910 |
++ |
3911 |
++ ret = import_single_range(READ, ubuf, len, &iov, &iter); |
3912 |
++ if (unlikely(ret)) |
3913 |
++ return ret; |
3914 |
++ return get_random_bytes_user(&iter); |
3915 |
+ } |
3916 |
+ |
3917 |
+-static unsigned int |
3918 |
+-random_poll(struct file *file, poll_table * wait) |
3919 |
++static unsigned int random_poll(struct file *file, poll_table *wait) |
3920 |
+ { |
3921 |
+- unsigned int mask; |
3922 |
+- |
3923 |
+- poll_wait(file, &random_read_wait, wait); |
3924 |
+- poll_wait(file, &random_write_wait, wait); |
3925 |
+- mask = 0; |
3926 |
+- if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits) |
3927 |
+- mask |= POLLIN | POLLRDNORM; |
3928 |
+- if (ENTROPY_BITS(&input_pool) < random_write_wakeup_bits) |
3929 |
+- mask |= POLLOUT | POLLWRNORM; |
3930 |
+- return mask; |
3931 |
++ poll_wait(file, &crng_init_wait, wait); |
3932 |
++ return crng_ready() ? POLLIN | POLLRDNORM : POLLOUT | POLLWRNORM; |
3933 |
+ } |
3934 |
+ |
3935 |
+-static int |
3936 |
+-write_pool(struct entropy_store *r, const char __user *buffer, size_t count) |
3937 |
++static ssize_t write_pool_user(struct iov_iter *iter) |
3938 |
+ { |
3939 |
+- size_t bytes; |
3940 |
+- __u32 t, buf[16]; |
3941 |
+- const char __user *p = buffer; |
3942 |
++ u8 block[BLAKE2S_BLOCK_SIZE]; |
3943 |
++ ssize_t ret = 0; |
3944 |
++ size_t copied; |
3945 |
+ |
3946 |
+- while (count > 0) { |
3947 |
+- int b, i = 0; |
3948 |
++ if (unlikely(!iov_iter_count(iter))) |
3949 |
++ return 0; |
3950 |
+ |
3951 |
+- bytes = min(count, sizeof(buf)); |
3952 |
+- if (copy_from_user(&buf, p, bytes)) |
3953 |
+- return -EFAULT; |
3954 |
++ for (;;) { |
3955 |
++ copied = copy_from_iter(block, sizeof(block), iter); |
3956 |
++ ret += copied; |
3957 |
++ mix_pool_bytes(block, copied); |
3958 |
++ if (!iov_iter_count(iter) || copied != sizeof(block)) |
3959 |
++ break; |
3960 |
+ |
3961 |
+- for (b = bytes ; b > 0 ; b -= sizeof(__u32), i++) { |
3962 |
+- if (!arch_get_random_int(&t)) |
3963 |
++ BUILD_BUG_ON(PAGE_SIZE % sizeof(block) != 0); |
3964 |
++ if (ret % PAGE_SIZE == 0) { |
3965 |
++ if (signal_pending(current)) |
3966 |
+ break; |
3967 |
+- buf[i] ^= t; |
3968 |
++ cond_resched(); |
3969 |
+ } |
3970 |
++ } |
3971 |
+ |
3972 |
+- count -= bytes; |
3973 |
+- p += bytes; |
3974 |
++ memzero_explicit(block, sizeof(block)); |
3975 |
++ return ret ? ret : -EFAULT; |
3976 |
++} |
3977 |
++ |
3978 |
++static ssize_t random_write_iter(struct kiocb *kiocb, struct iov_iter *iter) |
3979 |
++{ |
3980 |
++ return write_pool_user(iter); |
3981 |
++} |
3982 |
+ |
3983 |
+- mix_pool_bytes(r, buf, bytes); |
3984 |
+- cond_resched(); |
3985 |
++static ssize_t urandom_read_iter(struct kiocb *kiocb, struct iov_iter *iter) |
3986 |
++{ |
3987 |
++ static int maxwarn = 10; |
3988 |
++ |
3989 |
++ if (!crng_ready()) { |
3990 |
++ if (!ratelimit_disable && maxwarn <= 0) |
3991 |
++ ++urandom_warning.missed; |
3992 |
++ else if (ratelimit_disable || __ratelimit(&urandom_warning)) { |
3993 |
++ --maxwarn; |
3994 |
++ pr_notice("%s: uninitialized urandom read (%zu bytes read)\n", |
3995 |
++ current->comm, iov_iter_count(iter)); |
3996 |
++ } |
3997 |
+ } |
3998 |
+ |
3999 |
+- return 0; |
4000 |
++ return get_random_bytes_user(iter); |
4001 |
+ } |
4002 |
+ |
4003 |
+-static ssize_t random_write(struct file *file, const char __user *buffer, |
4004 |
+- size_t count, loff_t *ppos) |
4005 |
++static ssize_t random_read_iter(struct kiocb *kiocb, struct iov_iter *iter) |
4006 |
+ { |
4007 |
+- size_t ret; |
4008 |
++ int ret; |
4009 |
+ |
4010 |
+- ret = write_pool(&input_pool, buffer, count); |
4011 |
+- if (ret) |
4012 |
++ ret = wait_for_random_bytes(); |
4013 |
++ if (ret != 0) |
4014 |
+ return ret; |
4015 |
+- |
4016 |
+- return (ssize_t)count; |
4017 |
++ return get_random_bytes_user(iter); |
4018 |
+ } |
4019 |
+ |
4020 |
+ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
4021 |
+ { |
4022 |
+- int size, ent_count; |
4023 |
+ int __user *p = (int __user *)arg; |
4024 |
+- int retval; |
4025 |
++ int ent_count; |
4026 |
+ |
4027 |
+ switch (cmd) { |
4028 |
+ case RNDGETENTCNT: |
4029 |
+- /* inherently racy, no point locking */ |
4030 |
+- ent_count = ENTROPY_BITS(&input_pool); |
4031 |
+- if (put_user(ent_count, p)) |
4032 |
++ /* Inherently racy, no point locking. */ |
4033 |
++ if (put_user(input_pool.init_bits, p)) |
4034 |
+ return -EFAULT; |
4035 |
+ return 0; |
4036 |
+ case RNDADDTOENTCNT: |
4037 |
+@@ -1887,39 +1317,48 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
4038 |
+ return -EPERM; |
4039 |
+ if (get_user(ent_count, p)) |
4040 |
+ return -EFAULT; |
4041 |
+- return credit_entropy_bits_safe(&input_pool, ent_count); |
4042 |
+- case RNDADDENTROPY: |
4043 |
++ if (ent_count < 0) |
4044 |
++ return -EINVAL; |
4045 |
++ credit_init_bits(ent_count); |
4046 |
++ return 0; |
4047 |
++ case RNDADDENTROPY: { |
4048 |
++ struct iov_iter iter; |
4049 |
++ struct iovec iov; |
4050 |
++ ssize_t ret; |
4051 |
++ int len; |
4052 |
++ |
4053 |
+ if (!capable(CAP_SYS_ADMIN)) |
4054 |
+ return -EPERM; |
4055 |
+ if (get_user(ent_count, p++)) |
4056 |
+ return -EFAULT; |
4057 |
+ if (ent_count < 0) |
4058 |
+ return -EINVAL; |
4059 |
+- if (get_user(size, p++)) |
4060 |
++ if (get_user(len, p++)) |
4061 |
+ return -EFAULT; |
4062 |
+- retval = write_pool(&input_pool, (const char __user *)p, |
4063 |
+- size); |
4064 |
+- if (retval < 0) |
4065 |
+- return retval; |
4066 |
+- return credit_entropy_bits_safe(&input_pool, ent_count); |
4067 |
++ ret = import_single_range(WRITE, p, len, &iov, &iter); |
4068 |
++ if (unlikely(ret)) |
4069 |
++ return ret; |
4070 |
++ ret = write_pool_user(&iter); |
4071 |
++ if (unlikely(ret < 0)) |
4072 |
++ return ret; |
4073 |
++ /* Since we're crediting, enforce that it was all written into the pool. */ |
4074 |
++ if (unlikely(ret != len)) |
4075 |
++ return -EFAULT; |
4076 |
++ credit_init_bits(ent_count); |
4077 |
++ return 0; |
4078 |
++ } |
4079 |
+ case RNDZAPENTCNT: |
4080 |
+ case RNDCLEARPOOL: |
4081 |
+- /* |
4082 |
+- * Clear the entropy pool counters. We no longer clear |
4083 |
+- * the entropy pool, as that's silly. |
4084 |
+- */ |
4085 |
++ /* No longer has any effect. */ |
4086 |
+ if (!capable(CAP_SYS_ADMIN)) |
4087 |
+ return -EPERM; |
4088 |
+- input_pool.entropy_count = 0; |
4089 |
+- blocking_pool.entropy_count = 0; |
4090 |
+ return 0; |
4091 |
+ case RNDRESEEDCRNG: |
4092 |
+ if (!capable(CAP_SYS_ADMIN)) |
4093 |
+ return -EPERM; |
4094 |
+- if (crng_init < 2) |
4095 |
++ if (!crng_ready()) |
4096 |
+ return -ENODATA; |
4097 |
+- crng_reseed(&primary_crng, &input_pool); |
4098 |
+- WRITE_ONCE(crng_global_init_time, jiffies - 1); |
4099 |
++ crng_reseed(); |
4100 |
+ return 0; |
4101 |
+ default: |
4102 |
+ return -EINVAL; |
4103 |
+@@ -1932,47 +1371,54 @@ static int random_fasync(int fd, struct file *filp, int on) |
4104 |
+ } |
4105 |
+ |
4106 |
+ const struct file_operations random_fops = { |
4107 |
+- .read = random_read, |
4108 |
+- .write = random_write, |
4109 |
+- .poll = random_poll, |
4110 |
++ .read_iter = random_read_iter, |
4111 |
++ .write_iter = random_write_iter, |
4112 |
++ .poll = random_poll, |
4113 |
+ .unlocked_ioctl = random_ioctl, |
4114 |
+ .fasync = random_fasync, |
4115 |
+ .llseek = noop_llseek, |
4116 |
++ .splice_read = generic_file_splice_read, |
4117 |
++ .splice_write = iter_file_splice_write, |
4118 |
+ }; |
4119 |
+ |
4120 |
+ const struct file_operations urandom_fops = { |
4121 |
+- .read = urandom_read, |
4122 |
+- .write = random_write, |
4123 |
++ .read_iter = urandom_read_iter, |
4124 |
++ .write_iter = random_write_iter, |
4125 |
+ .unlocked_ioctl = random_ioctl, |
4126 |
+ .fasync = random_fasync, |
4127 |
+ .llseek = noop_llseek, |
4128 |
++ .splice_read = generic_file_splice_read, |
4129 |
++ .splice_write = iter_file_splice_write, |
4130 |
+ }; |
4131 |
+ |
4132 |
+-SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, |
4133 |
+- unsigned int, flags) |
4134 |
+-{ |
4135 |
+- if (flags & ~(GRND_NONBLOCK|GRND_RANDOM)) |
4136 |
+- return -EINVAL; |
4137 |
+- |
4138 |
+- if (count > INT_MAX) |
4139 |
+- count = INT_MAX; |
4140 |
+- |
4141 |
+- if (flags & GRND_RANDOM) |
4142 |
+- return _random_read(flags & GRND_NONBLOCK, buf, count); |
4143 |
+- |
4144 |
+- if (!crng_ready()) { |
4145 |
+- if (flags & GRND_NONBLOCK) |
4146 |
+- return -EAGAIN; |
4147 |
+- crng_wait_ready(); |
4148 |
+- if (signal_pending(current)) |
4149 |
+- return -ERESTARTSYS; |
4150 |
+- } |
4151 |
+- return urandom_read(NULL, buf, count, NULL); |
4152 |
+-} |
4153 |
+ |
4154 |
+ /******************************************************************** |
4155 |
+ * |
4156 |
+- * Sysctl interface |
4157 |
++ * Sysctl interface. |
4158 |
++ * |
4159 |
++ * These are partly unused legacy knobs with dummy values to not break |
4160 |
++ * userspace and partly still useful things. They are usually accessible |
4161 |
++ * in /proc/sys/kernel/random/ and are as follows: |
4162 |
++ * |
4163 |
++ * - boot_id - a UUID representing the current boot. |
4164 |
++ * |
4165 |
++ * - uuid - a random UUID, different each time the file is read. |
4166 |
++ * |
4167 |
++ * - poolsize - the number of bits of entropy that the input pool can |
4168 |
++ * hold, tied to the POOL_BITS constant. |
4169 |
++ * |
4170 |
++ * - entropy_avail - the number of bits of entropy currently in the |
4171 |
++ * input pool. Always <= poolsize. |
4172 |
++ * |
4173 |
++ * - write_wakeup_threshold - the amount of entropy in the input pool |
4174 |
++ * below which write polls to /dev/random will unblock, requesting |
4175 |
++ * more entropy, tied to the POOL_READY_BITS constant. It is writable |
4176 |
++ * to avoid breaking old userspaces, but writing to it does not |
4177 |
++ * change any behavior of the RNG. |
4178 |
++ * |
4179 |
++ * - urandom_min_reseed_secs - fixed to the value CRNG_RESEED_INTERVAL. |
4180 |
++ * It is writable to avoid breaking old userspaces, but writing |
4181 |
++ * to it does not change any behavior of the RNG. |
4182 |
+ * |
4183 |
+ ********************************************************************/ |
4184 |
+ |
4185 |
+@@ -1980,25 +1426,28 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, |
4186 |
+ |
4187 |
+ #include <linux/sysctl.h> |
4188 |
+ |
4189 |
+-static int min_read_thresh = 8, min_write_thresh; |
4190 |
+-static int max_read_thresh = OUTPUT_POOL_WORDS * 32; |
4191 |
+-static int max_write_thresh = INPUT_POOL_WORDS * 32; |
4192 |
+-static char sysctl_bootid[16]; |
4193 |
++static int sysctl_random_min_urandom_seed = CRNG_RESEED_INTERVAL / HZ; |
4194 |
++static int sysctl_random_write_wakeup_bits = POOL_READY_BITS; |
4195 |
++static int sysctl_poolsize = POOL_BITS; |
4196 |
++static u8 sysctl_bootid[UUID_SIZE]; |
4197 |
+ |
4198 |
+ /* |
4199 |
+ * This function is used to return both the bootid UUID, and random |
4200 |
+- * UUID. The difference is in whether table->data is NULL; if it is, |
4201 |
++ * UUID. The difference is in whether table->data is NULL; if it is, |
4202 |
+ * then a new UUID is generated and returned to the user. |
4203 |
+- * |
4204 |
+- * If the user accesses this via the proc interface, the UUID will be |
4205 |
+- * returned as an ASCII string in the standard UUID format; if via the |
4206 |
+- * sysctl system call, as 16 bytes of binary data. |
4207 |
+ */ |
4208 |
+-static int proc_do_uuid(struct ctl_table *table, int write, |
4209 |
+- void __user *buffer, size_t *lenp, loff_t *ppos) |
4210 |
++static int proc_do_uuid(struct ctl_table *table, int write, void __user *buf, |
4211 |
++ size_t *lenp, loff_t *ppos) |
4212 |
+ { |
4213 |
+- struct ctl_table fake_table; |
4214 |
+- unsigned char buf[64], tmp_uuid[16], *uuid; |
4215 |
++ u8 tmp_uuid[UUID_SIZE], *uuid; |
4216 |
++ char uuid_string[UUID_STRING_LEN + 1]; |
4217 |
++ struct ctl_table fake_table = { |
4218 |
++ .data = uuid_string, |
4219 |
++ .maxlen = UUID_STRING_LEN |
4220 |
++ }; |
4221 |
++ |
4222 |
++ if (write) |
4223 |
++ return -EPERM; |
4224 |
+ |
4225 |
+ uuid = table->data; |
4226 |
+ if (!uuid) { |
4227 |
+@@ -2013,32 +1462,17 @@ static int proc_do_uuid(struct ctl_table *table, int write, |
4228 |
+ spin_unlock(&bootid_spinlock); |
4229 |
+ } |
4230 |
+ |
4231 |
+- sprintf(buf, "%pU", uuid); |
4232 |
+- |
4233 |
+- fake_table.data = buf; |
4234 |
+- fake_table.maxlen = sizeof(buf); |
4235 |
+- |
4236 |
+- return proc_dostring(&fake_table, write, buffer, lenp, ppos); |
4237 |
++ snprintf(uuid_string, sizeof(uuid_string), "%pU", uuid); |
4238 |
++ return proc_dostring(&fake_table, 0, buf, lenp, ppos); |
4239 |
+ } |
4240 |
+ |
4241 |
+-/* |
4242 |
+- * Return entropy available scaled to integral bits |
4243 |
+- */ |
4244 |
+-static int proc_do_entropy(struct ctl_table *table, int write, |
4245 |
+- void __user *buffer, size_t *lenp, loff_t *ppos) |
4246 |
++/* The same as proc_dointvec, but writes don't change anything. */ |
4247 |
++static int proc_do_rointvec(struct ctl_table *table, int write, void __user *buf, |
4248 |
++ size_t *lenp, loff_t *ppos) |
4249 |
+ { |
4250 |
+- struct ctl_table fake_table; |
4251 |
+- int entropy_count; |
4252 |
+- |
4253 |
+- entropy_count = *(int *)table->data >> ENTROPY_SHIFT; |
4254 |
+- |
4255 |
+- fake_table.data = &entropy_count; |
4256 |
+- fake_table.maxlen = sizeof(entropy_count); |
4257 |
+- |
4258 |
+- return proc_dointvec(&fake_table, write, buffer, lenp, ppos); |
4259 |
++ return write ? 0 : proc_dointvec(table, 0, buf, lenp, ppos); |
4260 |
+ } |
4261 |
+ |
4262 |
+-static int sysctl_poolsize = INPUT_POOL_WORDS * 32; |
4263 |
+ extern struct ctl_table random_table[]; |
4264 |
+ struct ctl_table random_table[] = { |
4265 |
+ { |
4266 |
+@@ -2050,177 +1484,36 @@ struct ctl_table random_table[] = { |
4267 |
+ }, |
4268 |
+ { |
4269 |
+ .procname = "entropy_avail", |
4270 |
++ .data = &input_pool.init_bits, |
4271 |
+ .maxlen = sizeof(int), |
4272 |
+ .mode = 0444, |
4273 |
+- .proc_handler = proc_do_entropy, |
4274 |
+- .data = &input_pool.entropy_count, |
4275 |
+- }, |
4276 |
+- { |
4277 |
+- .procname = "read_wakeup_threshold", |
4278 |
+- .data = &random_read_wakeup_bits, |
4279 |
+- .maxlen = sizeof(int), |
4280 |
+- .mode = 0644, |
4281 |
+- .proc_handler = proc_dointvec_minmax, |
4282 |
+- .extra1 = &min_read_thresh, |
4283 |
+- .extra2 = &max_read_thresh, |
4284 |
++ .proc_handler = proc_dointvec, |
4285 |
+ }, |
4286 |
+ { |
4287 |
+ .procname = "write_wakeup_threshold", |
4288 |
+- .data = &random_write_wakeup_bits, |
4289 |
++ .data = &sysctl_random_write_wakeup_bits, |
4290 |
+ .maxlen = sizeof(int), |
4291 |
+ .mode = 0644, |
4292 |
+- .proc_handler = proc_dointvec_minmax, |
4293 |
+- .extra1 = &min_write_thresh, |
4294 |
+- .extra2 = &max_write_thresh, |
4295 |
++ .proc_handler = proc_do_rointvec, |
4296 |
+ }, |
4297 |
+ { |
4298 |
+ .procname = "urandom_min_reseed_secs", |
4299 |
+- .data = &random_min_urandom_seed, |
4300 |
++ .data = &sysctl_random_min_urandom_seed, |
4301 |
+ .maxlen = sizeof(int), |
4302 |
+ .mode = 0644, |
4303 |
+- .proc_handler = proc_dointvec, |
4304 |
++ .proc_handler = proc_do_rointvec, |
4305 |
+ }, |
4306 |
+ { |
4307 |
+ .procname = "boot_id", |
4308 |
+ .data = &sysctl_bootid, |
4309 |
+- .maxlen = 16, |
4310 |
+ .mode = 0444, |
4311 |
+ .proc_handler = proc_do_uuid, |
4312 |
+ }, |
4313 |
+ { |
4314 |
+ .procname = "uuid", |
4315 |
+- .maxlen = 16, |
4316 |
+ .mode = 0444, |
4317 |
+ .proc_handler = proc_do_uuid, |
4318 |
+ }, |
4319 |
+-#ifdef ADD_INTERRUPT_BENCH |
4320 |
+- { |
4321 |
+- .procname = "add_interrupt_avg_cycles", |
4322 |
+- .data = &avg_cycles, |
4323 |
+- .maxlen = sizeof(avg_cycles), |
4324 |
+- .mode = 0444, |
4325 |
+- .proc_handler = proc_doulongvec_minmax, |
4326 |
+- }, |
4327 |
+- { |
4328 |
+- .procname = "add_interrupt_avg_deviation", |
4329 |
+- .data = &avg_deviation, |
4330 |
+- .maxlen = sizeof(avg_deviation), |
4331 |
+- .mode = 0444, |
4332 |
+- .proc_handler = proc_doulongvec_minmax, |
4333 |
+- }, |
4334 |
+-#endif |
4335 |
+ { } |
4336 |
+ }; |
4337 |
+-#endif /* CONFIG_SYSCTL */ |
4338 |
+- |
4339 |
+-struct batched_entropy { |
4340 |
+- union { |
4341 |
+- unsigned long entropy_long[CHACHA20_BLOCK_SIZE / sizeof(unsigned long)]; |
4342 |
+- unsigned int entropy_int[CHACHA20_BLOCK_SIZE / sizeof(unsigned int)]; |
4343 |
+- }; |
4344 |
+- unsigned int position; |
4345 |
+-}; |
4346 |
+- |
4347 |
+-/* |
4348 |
+- * Get a random word for internal kernel use only. The quality of the random |
4349 |
+- * number is good as /dev/urandom, but there is no backtrack protection, with |
4350 |
+- * the goal of being quite fast and not depleting entropy. |
4351 |
+- */ |
4352 |
+-static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_long); |
4353 |
+-unsigned long get_random_long(void) |
4354 |
+-{ |
4355 |
+- unsigned long ret; |
4356 |
+- struct batched_entropy *batch; |
4357 |
+- |
4358 |
+- batch = &get_cpu_var(batched_entropy_long); |
4359 |
+- if (batch->position % ARRAY_SIZE(batch->entropy_long) == 0) { |
4360 |
+- extract_crng((u8 *)batch->entropy_long); |
4361 |
+- batch->position = 0; |
4362 |
+- } |
4363 |
+- ret = batch->entropy_long[batch->position++]; |
4364 |
+- put_cpu_var(batched_entropy_long); |
4365 |
+- return ret; |
4366 |
+-} |
4367 |
+-EXPORT_SYMBOL(get_random_long); |
4368 |
+- |
4369 |
+-#if BITS_PER_LONG == 32 |
4370 |
+-unsigned int get_random_int(void) |
4371 |
+-{ |
4372 |
+- return get_random_long(); |
4373 |
+-} |
4374 |
+-#else |
4375 |
+-static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_int); |
4376 |
+-unsigned int get_random_int(void) |
4377 |
+-{ |
4378 |
+- unsigned int ret; |
4379 |
+- struct batched_entropy *batch; |
4380 |
+- |
4381 |
+- batch = &get_cpu_var(batched_entropy_int); |
4382 |
+- if (batch->position % ARRAY_SIZE(batch->entropy_int) == 0) { |
4383 |
+- extract_crng((u8 *)batch->entropy_int); |
4384 |
+- batch->position = 0; |
4385 |
+- } |
4386 |
+- ret = batch->entropy_int[batch->position++]; |
4387 |
+- put_cpu_var(batched_entropy_int); |
4388 |
+- return ret; |
4389 |
+-} |
4390 |
+-#endif |
4391 |
+-EXPORT_SYMBOL(get_random_int); |
4392 |
+- |
4393 |
+-/** |
4394 |
+- * randomize_page - Generate a random, page aligned address |
4395 |
+- * @start: The smallest acceptable address the caller will take. |
4396 |
+- * @range: The size of the area, starting at @start, within which the |
4397 |
+- * random address must fall. |
4398 |
+- * |
4399 |
+- * If @start + @range would overflow, @range is capped. |
4400 |
+- * |
4401 |
+- * NOTE: Historical use of randomize_range, which this replaces, presumed that |
4402 |
+- * @start was already page aligned. We now align it regardless. |
4403 |
+- * |
4404 |
+- * Return: A page aligned address within [start, start + range). On error, |
4405 |
+- * @start is returned. |
4406 |
+- */ |
4407 |
+-unsigned long |
4408 |
+-randomize_page(unsigned long start, unsigned long range) |
4409 |
+-{ |
4410 |
+- if (!PAGE_ALIGNED(start)) { |
4411 |
+- range -= PAGE_ALIGN(start) - start; |
4412 |
+- start = PAGE_ALIGN(start); |
4413 |
+- } |
4414 |
+- |
4415 |
+- if (start > ULONG_MAX - range) |
4416 |
+- range = ULONG_MAX - start; |
4417 |
+- |
4418 |
+- range >>= PAGE_SHIFT; |
4419 |
+- |
4420 |
+- if (range == 0) |
4421 |
+- return start; |
4422 |
+- |
4423 |
+- return start + (get_random_long() % range << PAGE_SHIFT); |
4424 |
+-} |
4425 |
+- |
4426 |
+-/* Interface for in-kernel drivers of true hardware RNGs. |
4427 |
+- * Those devices may produce endless random bits and will be throttled |
4428 |
+- * when our pool is full. |
4429 |
+- */ |
4430 |
+-void add_hwgenerator_randomness(const char *buffer, size_t count, |
4431 |
+- size_t entropy) |
4432 |
+-{ |
4433 |
+- struct entropy_store *poolp = &input_pool; |
4434 |
+- |
4435 |
+- if (unlikely(crng_init == 0)) { |
4436 |
+- crng_fast_load(buffer, count); |
4437 |
+- return; |
4438 |
+- } |
4439 |
+- |
4440 |
+- /* Suspend writing if we're above the trickle threshold. |
4441 |
+- * We'll be woken up again once below random_write_wakeup_thresh, |
4442 |
+- * or when the calling thread is about to terminate. |
4443 |
+- */ |
4444 |
+- wait_event_interruptible(random_write_wait, kthread_should_stop() || |
4445 |
+- ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); |
4446 |
+- mix_pool_bytes(poolp, buffer, count); |
4447 |
+- credit_entropy_bits(poolp, entropy); |
4448 |
+-} |
4449 |
+-EXPORT_SYMBOL_GPL(add_hwgenerator_randomness); |
4450 |
++#endif /* CONFIG_SYSCTL */ |
4451 |
+diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c |
4452 |
+index 9a0d0d0ad6d0f..3248aa7a35b36 100644 |
4453 |
+--- a/drivers/hv/vmbus_drv.c |
4454 |
++++ b/drivers/hv/vmbus_drv.c |
4455 |
+@@ -828,7 +828,7 @@ static void vmbus_isr(void) |
4456 |
+ tasklet_schedule(hv_context.msg_dpc[cpu]); |
4457 |
+ } |
4458 |
+ |
4459 |
+- add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0); |
4460 |
++ add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR); |
4461 |
+ } |
4462 |
+ |
4463 |
+ |
4464 |
+diff --git a/drivers/irqchip/irq-gic-realview.c b/drivers/irqchip/irq-gic-realview.c |
4465 |
+index 54c296401525c..61024882c6854 100644 |
4466 |
+--- a/drivers/irqchip/irq-gic-realview.c |
4467 |
++++ b/drivers/irqchip/irq-gic-realview.c |
4468 |
+@@ -56,6 +56,7 @@ realview_gic_of_init(struct device_node *node, struct device_node *parent) |
4469 |
+ |
4470 |
+ /* The PB11MPCore GIC needs to be configured in the syscon */ |
4471 |
+ map = syscon_node_to_regmap(np); |
4472 |
++ of_node_put(np); |
4473 |
+ if (!IS_ERR(map)) { |
4474 |
+ /* new irq mode with no DCC */ |
4475 |
+ regmap_write(map, REALVIEW_SYS_LOCK_OFFSET, |
4476 |
+diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c |
4477 |
+index 2ab6060031a43..9ae24ffb9b09c 100644 |
4478 |
+--- a/drivers/irqchip/irq-gic-v3.c |
4479 |
++++ b/drivers/irqchip/irq-gic-v3.c |
4480 |
+@@ -982,7 +982,7 @@ static int get_cpu_number(struct device_node *dn) |
4481 |
+ { |
4482 |
+ const __be32 *cell; |
4483 |
+ u64 hwid; |
4484 |
+- int i; |
4485 |
++ int cpu; |
4486 |
+ |
4487 |
+ cell = of_get_property(dn, "reg", NULL); |
4488 |
+ if (!cell) |
4489 |
+@@ -996,9 +996,9 @@ static int get_cpu_number(struct device_node *dn) |
4490 |
+ if (hwid & ~MPIDR_HWID_BITMASK) |
4491 |
+ return -1; |
4492 |
+ |
4493 |
+- for (i = 0; i < num_possible_cpus(); i++) |
4494 |
+- if (cpu_logical_map(i) == hwid) |
4495 |
+- return i; |
4496 |
++ for_each_possible_cpu(cpu) |
4497 |
++ if (cpu_logical_map(cpu) == hwid) |
4498 |
++ return cpu; |
4499 |
+ |
4500 |
+ return -1; |
4501 |
+ } |
4502 |
+diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c |
4503 |
+index 8c9a444d61d3c..65bc573d6ab44 100644 |
4504 |
+--- a/drivers/misc/atmel-ssc.c |
4505 |
++++ b/drivers/misc/atmel-ssc.c |
4506 |
+@@ -190,9 +190,9 @@ static int ssc_probe(struct platform_device *pdev) |
4507 |
+ clk_disable_unprepare(ssc->clk); |
4508 |
+ |
4509 |
+ ssc->irq = platform_get_irq(pdev, 0); |
4510 |
+- if (!ssc->irq) { |
4511 |
++ if (ssc->irq < 0) { |
4512 |
+ dev_dbg(&pdev->dev, "could not get irq\n"); |
4513 |
+- return -ENXIO; |
4514 |
++ return ssc->irq; |
4515 |
+ } |
4516 |
+ |
4517 |
+ mutex_lock(&user_lock); |
4518 |
+diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
4519 |
+index 84d6679572210..61a9b60ab0225 100644 |
4520 |
+--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
4521 |
++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
4522 |
+@@ -527,6 +527,17 @@ static inline void mtk_rx_get_desc(struct mtk_rx_dma *rxd, |
4523 |
+ rxd->rxd4 = READ_ONCE(dma_rxd->rxd4); |
4524 |
+ } |
4525 |
+ |
4526 |
++static void *mtk_max_lro_buf_alloc(gfp_t gfp_mask) |
4527 |
++{ |
4528 |
++ unsigned int size = mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH); |
4529 |
++ unsigned long data; |
4530 |
++ |
4531 |
++ data = __get_free_pages(gfp_mask | __GFP_COMP | __GFP_NOWARN, |
4532 |
++ get_order(size)); |
4533 |
++ |
4534 |
++ return (void *)data; |
4535 |
++} |
4536 |
++ |
4537 |
+ /* the qdma core needs scratch memory to be setup */ |
4538 |
+ static int mtk_init_fq_dma(struct mtk_eth *eth) |
4539 |
+ { |
4540 |
+@@ -928,7 +939,10 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, |
4541 |
+ goto release_desc; |
4542 |
+ |
4543 |
+ /* alloc new buffer */ |
4544 |
+- new_data = napi_alloc_frag(ring->frag_size); |
4545 |
++ if (ring->frag_size <= PAGE_SIZE) |
4546 |
++ new_data = napi_alloc_frag(ring->frag_size); |
4547 |
++ else |
4548 |
++ new_data = mtk_max_lro_buf_alloc(GFP_ATOMIC); |
4549 |
+ if (unlikely(!new_data)) { |
4550 |
+ netdev->stats.rx_dropped++; |
4551 |
+ goto release_desc; |
4552 |
+@@ -1231,7 +1245,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag) |
4553 |
+ return -ENOMEM; |
4554 |
+ |
4555 |
+ for (i = 0; i < rx_dma_size; i++) { |
4556 |
+- ring->data[i] = netdev_alloc_frag(ring->frag_size); |
4557 |
++ if (ring->frag_size <= PAGE_SIZE) |
4558 |
++ ring->data[i] = netdev_alloc_frag(ring->frag_size); |
4559 |
++ else |
4560 |
++ ring->data[i] = mtk_max_lro_buf_alloc(GFP_KERNEL); |
4561 |
+ if (!ring->data[i]) |
4562 |
+ return -ENOMEM; |
4563 |
+ } |
4564 |
+diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c |
4565 |
+index 585a0f20835b1..3263e2a2bdfd3 100644 |
4566 |
+--- a/drivers/nfc/nfcmrvl/usb.c |
4567 |
++++ b/drivers/nfc/nfcmrvl/usb.c |
4568 |
+@@ -401,13 +401,25 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data) |
4569 |
+ int err; |
4570 |
+ |
4571 |
+ while ((urb = usb_get_from_anchor(&drv_data->deferred))) { |
4572 |
++ usb_anchor_urb(urb, &drv_data->tx_anchor); |
4573 |
++ |
4574 |
+ err = usb_submit_urb(urb, GFP_ATOMIC); |
4575 |
+- if (err) |
4576 |
++ if (err) { |
4577 |
++ kfree(urb->setup_packet); |
4578 |
++ usb_unanchor_urb(urb); |
4579 |
++ usb_free_urb(urb); |
4580 |
+ break; |
4581 |
++ } |
4582 |
+ |
4583 |
+ drv_data->tx_in_flight++; |
4584 |
++ usb_free_urb(urb); |
4585 |
++ } |
4586 |
++ |
4587 |
++ /* Cleanup the rest deferred urbs. */ |
4588 |
++ while ((urb = usb_get_from_anchor(&drv_data->deferred))) { |
4589 |
++ kfree(urb->setup_packet); |
4590 |
++ usb_free_urb(urb); |
4591 |
+ } |
4592 |
+- usb_scuttle_anchored_urbs(&drv_data->deferred); |
4593 |
+ } |
4594 |
+ |
4595 |
+ static int nfcmrvl_resume(struct usb_interface *intf) |
4596 |
+diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c |
4597 |
+index 6a239c9bbf59b..e797fa92c90dd 100644 |
4598 |
+--- a/drivers/of/fdt.c |
4599 |
++++ b/drivers/of/fdt.c |
4600 |
+@@ -27,6 +27,7 @@ |
4601 |
+ #include <linux/debugfs.h> |
4602 |
+ #include <linux/serial_core.h> |
4603 |
+ #include <linux/sysfs.h> |
4604 |
++#include <linux/random.h> |
4605 |
+ |
4606 |
+ #include <asm/setup.h> /* for COMMAND_LINE_SIZE */ |
4607 |
+ #include <asm/page.h> |
4608 |
+@@ -1068,6 +1069,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, |
4609 |
+ { |
4610 |
+ int l; |
4611 |
+ const char *p; |
4612 |
++ const void *rng_seed; |
4613 |
+ |
4614 |
+ pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); |
4615 |
+ |
4616 |
+@@ -1102,6 +1104,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, |
4617 |
+ |
4618 |
+ pr_debug("Command line is: %s\n", (char*)data); |
4619 |
+ |
4620 |
++ rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); |
4621 |
++ if (rng_seed && l > 0) { |
4622 |
++ add_bootloader_randomness(rng_seed, l); |
4623 |
++ |
4624 |
++ /* try to clear seed so it won't be found. */ |
4625 |
++ fdt_nop_property(initial_boot_params, node, "rng-seed"); |
4626 |
++ } |
4627 |
++ |
4628 |
+ /* break now */ |
4629 |
+ return 1; |
4630 |
+ } |
4631 |
+@@ -1203,8 +1213,6 @@ bool __init early_init_dt_verify(void *params) |
4632 |
+ |
4633 |
+ /* Setup flat device-tree pointer */ |
4634 |
+ initial_boot_params = params; |
4635 |
+- of_fdt_crc32 = crc32_be(~0, initial_boot_params, |
4636 |
+- fdt_totalsize(initial_boot_params)); |
4637 |
+ return true; |
4638 |
+ } |
4639 |
+ |
4640 |
+@@ -1230,6 +1238,8 @@ bool __init early_init_dt_scan(void *params) |
4641 |
+ return false; |
4642 |
+ |
4643 |
+ early_init_dt_scan_nodes(); |
4644 |
++ of_fdt_crc32 = crc32_be(~0, initial_boot_params, |
4645 |
++ fdt_totalsize(initial_boot_params)); |
4646 |
+ return true; |
4647 |
+ } |
4648 |
+ |
4649 |
+diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c |
4650 |
+index 30b5f65b29d15..7f230d0b2fd62 100644 |
4651 |
+--- a/drivers/scsi/lpfc/lpfc_nportdisc.c |
4652 |
++++ b/drivers/scsi/lpfc/lpfc_nportdisc.c |
4653 |
+@@ -633,7 +633,8 @@ lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
4654 |
+ else |
4655 |
+ lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
4656 |
+ if (ndlp->nlp_DID == Fabric_DID) { |
4657 |
+- if (vport->port_state <= LPFC_FDISC) |
4658 |
++ if (vport->port_state <= LPFC_FDISC || |
4659 |
++ vport->fc_flag & FC_PT2PT) |
4660 |
+ goto out; |
4661 |
+ lpfc_linkdown_port(vport); |
4662 |
+ spin_lock_irq(shost->host_lock); |
4663 |
+diff --git a/drivers/scsi/vmw_pvscsi.h b/drivers/scsi/vmw_pvscsi.h |
4664 |
+index d41292ef85f2f..98ad17cb6643d 100644 |
4665 |
+--- a/drivers/scsi/vmw_pvscsi.h |
4666 |
++++ b/drivers/scsi/vmw_pvscsi.h |
4667 |
+@@ -333,8 +333,8 @@ struct PVSCSIRingReqDesc { |
4668 |
+ u8 tag; |
4669 |
+ u8 bus; |
4670 |
+ u8 target; |
4671 |
+- u8 vcpuHint; |
4672 |
+- u8 unused[59]; |
4673 |
++ u16 vcpuHint; |
4674 |
++ u8 unused[58]; |
4675 |
+ } __packed; |
4676 |
+ |
4677 |
+ /* |
4678 |
+diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c |
4679 |
+index 36470ee065967..6010c047f4f86 100644 |
4680 |
+--- a/drivers/staging/comedi/drivers/vmk80xx.c |
4681 |
++++ b/drivers/staging/comedi/drivers/vmk80xx.c |
4682 |
+@@ -694,7 +694,7 @@ static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev) |
4683 |
+ if (!devpriv->usb_rx_buf) |
4684 |
+ return -ENOMEM; |
4685 |
+ |
4686 |
+- size = max(usb_endpoint_maxp(devpriv->ep_rx), MIN_BUF_SIZE); |
4687 |
++ size = max(usb_endpoint_maxp(devpriv->ep_tx), MIN_BUF_SIZE); |
4688 |
+ devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL); |
4689 |
+ if (!devpriv->usb_tx_buf) |
4690 |
+ return -ENOMEM; |
4691 |
+diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c |
4692 |
+index 2d83f1dfb4d69..d3f17b23ac61f 100644 |
4693 |
+--- a/drivers/tty/serial/8250/8250_port.c |
4694 |
++++ b/drivers/tty/serial/8250/8250_port.c |
4695 |
+@@ -1473,6 +1473,8 @@ static inline void __stop_tx(struct uart_8250_port *p) |
4696 |
+ |
4697 |
+ if (em485) { |
4698 |
+ unsigned char lsr = serial_in(p, UART_LSR); |
4699 |
++ p->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
4700 |
++ |
4701 |
+ /* |
4702 |
+ * To provide required timeing and allow FIFO transfer, |
4703 |
+ * __stop_tx_rs485() must be called only when both FIFO and |
4704 |
+diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c |
4705 |
+index 7107931617953..498a44ae2b925 100644 |
4706 |
+--- a/drivers/usb/gadget/udc/lpc32xx_udc.c |
4707 |
++++ b/drivers/usb/gadget/udc/lpc32xx_udc.c |
4708 |
+@@ -3034,6 +3034,7 @@ static int lpc32xx_udc_probe(struct platform_device *pdev) |
4709 |
+ } |
4710 |
+ |
4711 |
+ udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); |
4712 |
++ of_node_put(isp1301_node); |
4713 |
+ if (!udc->isp1301_i2c_client) { |
4714 |
+ retval = -EPROBE_DEFER; |
4715 |
+ goto phy_fail; |
4716 |
+diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c |
4717 |
+index e98532feb0cce..8e49eb68896ac 100644 |
4718 |
+--- a/drivers/usb/serial/io_ti.c |
4719 |
++++ b/drivers/usb/serial/io_ti.c |
4720 |
+@@ -172,6 +172,7 @@ static const struct usb_device_id edgeport_2port_id_table[] = { |
4721 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, |
4722 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, |
4723 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, |
4724 |
++ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) }, |
4725 |
+ { } |
4726 |
+ }; |
4727 |
+ |
4728 |
+@@ -210,6 +211,7 @@ static const struct usb_device_id id_table_combined[] = { |
4729 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, |
4730 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, |
4731 |
+ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, |
4732 |
++ { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) }, |
4733 |
+ { } |
4734 |
+ }; |
4735 |
+ |
4736 |
+diff --git a/drivers/usb/serial/io_usbvend.h b/drivers/usb/serial/io_usbvend.h |
4737 |
+index 6f6a856bc37cd..a470262dcf48b 100644 |
4738 |
+--- a/drivers/usb/serial/io_usbvend.h |
4739 |
++++ b/drivers/usb/serial/io_usbvend.h |
4740 |
+@@ -215,6 +215,7 @@ |
4741 |
+ // |
4742 |
+ // Definitions for other product IDs |
4743 |
+ #define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device |
4744 |
++#define ION_DEVICE_ID_E5805A 0x1A01 // OEM device (rebranded Edgeport/4) |
4745 |
+ |
4746 |
+ |
4747 |
+ #define GENERATION_ID_FROM_USB_PRODUCT_ID(ProductId) \ |
4748 |
+diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c |
4749 |
+index 5b198d881a40a..8add5a762f219 100644 |
4750 |
+--- a/drivers/usb/serial/option.c |
4751 |
++++ b/drivers/usb/serial/option.c |
4752 |
+@@ -430,6 +430,8 @@ static void option_instat_callback(struct urb *urb); |
4753 |
+ #define CINTERION_PRODUCT_CLS8 0x00b0 |
4754 |
+ #define CINTERION_PRODUCT_MV31_MBIM 0x00b3 |
4755 |
+ #define CINTERION_PRODUCT_MV31_RMNET 0x00b7 |
4756 |
++#define CINTERION_PRODUCT_MV31_2_MBIM 0x00b8 |
4757 |
++#define CINTERION_PRODUCT_MV31_2_RMNET 0x00b9 |
4758 |
+ #define CINTERION_PRODUCT_MV32_WA 0x00f1 |
4759 |
+ #define CINTERION_PRODUCT_MV32_WB 0x00f2 |
4760 |
+ |
4761 |
+@@ -1953,6 +1955,10 @@ static const struct usb_device_id option_ids[] = { |
4762 |
+ .driver_info = RSVD(3)}, |
4763 |
+ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_RMNET, 0xff), |
4764 |
+ .driver_info = RSVD(0)}, |
4765 |
++ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_2_MBIM, 0xff), |
4766 |
++ .driver_info = RSVD(3)}, |
4767 |
++ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_2_RMNET, 0xff), |
4768 |
++ .driver_info = RSVD(0)}, |
4769 |
+ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV32_WA, 0xff), |
4770 |
+ .driver_info = RSVD(3)}, |
4771 |
+ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV32_WB, 0xff), |
4772 |
+diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c |
4773 |
+index 50840984fbfac..f62da3b7c27b4 100644 |
4774 |
+--- a/drivers/virtio/virtio_mmio.c |
4775 |
++++ b/drivers/virtio/virtio_mmio.c |
4776 |
+@@ -630,6 +630,7 @@ static int vm_cmdline_set(const char *device, |
4777 |
+ if (!vm_cmdline_parent_registered) { |
4778 |
+ err = device_register(&vm_cmdline_parent); |
4779 |
+ if (err) { |
4780 |
++ put_device(&vm_cmdline_parent); |
4781 |
+ pr_err("Failed to register parent device!\n"); |
4782 |
+ return err; |
4783 |
+ } |
4784 |
+diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c |
4785 |
+index 425bc1a2b8c14..77a97195ef355 100644 |
4786 |
+--- a/fs/9p/vfs_inode_dotl.c |
4787 |
++++ b/fs/9p/vfs_inode_dotl.c |
4788 |
+@@ -656,14 +656,10 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode, |
4789 |
+ if (stat->st_result_mask & P9_STATS_NLINK) |
4790 |
+ set_nlink(inode, stat->st_nlink); |
4791 |
+ if (stat->st_result_mask & P9_STATS_MODE) { |
4792 |
+- inode->i_mode = stat->st_mode; |
4793 |
+- if ((S_ISBLK(inode->i_mode)) || |
4794 |
+- (S_ISCHR(inode->i_mode))) |
4795 |
+- init_special_inode(inode, inode->i_mode, |
4796 |
+- inode->i_rdev); |
4797 |
++ mode = stat->st_mode & S_IALLUGO; |
4798 |
++ mode |= inode->i_mode & ~S_IALLUGO; |
4799 |
++ inode->i_mode = mode; |
4800 |
+ } |
4801 |
+- if (stat->st_result_mask & P9_STATS_RDEV) |
4802 |
+- inode->i_rdev = new_decode_dev(stat->st_rdev); |
4803 |
+ if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) && |
4804 |
+ stat->st_result_mask & P9_STATS_SIZE) |
4805 |
+ v9fs_i_size_write(inode, stat->st_size); |
4806 |
+diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c |
4807 |
+index 2a7fb2cf19b81..f39b656012339 100644 |
4808 |
+--- a/fs/ext4/mballoc.c |
4809 |
++++ b/fs/ext4/mballoc.c |
4810 |
+@@ -3142,6 +3142,15 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac, |
4811 |
+ size = size >> bsbits; |
4812 |
+ start = start_off >> bsbits; |
4813 |
+ |
4814 |
++ /* |
4815 |
++ * For tiny groups (smaller than 8MB) the chosen allocation |
4816 |
++ * alignment may be larger than group size. Make sure the |
4817 |
++ * alignment does not move allocation to a different group which |
4818 |
++ * makes mballoc fail assertions later. |
4819 |
++ */ |
4820 |
++ start = max(start, rounddown(ac->ac_o_ex.fe_logical, |
4821 |
++ (ext4_lblk_t)EXT4_BLOCKS_PER_GROUP(ac->ac_sb))); |
4822 |
++ |
4823 |
+ /* don't cover already allocated blocks in selected range */ |
4824 |
+ if (ar->pleft && start <= ar->lleft) { |
4825 |
+ size -= ar->lleft + 1 - start; |
4826 |
+diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c |
4827 |
+index 159d259e5e5e9..edf78728ed322 100644 |
4828 |
+--- a/fs/ext4/namei.c |
4829 |
++++ b/fs/ext4/namei.c |
4830 |
+@@ -1726,7 +1726,8 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, |
4831 |
+ struct dx_hash_info *hinfo) |
4832 |
+ { |
4833 |
+ unsigned blocksize = dir->i_sb->s_blocksize; |
4834 |
+- unsigned count, continued; |
4835 |
++ unsigned continued; |
4836 |
++ int count; |
4837 |
+ struct buffer_head *bh2; |
4838 |
+ ext4_lblk_t newblock; |
4839 |
+ u32 hash2; |
4840 |
+diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c |
4841 |
+index 51fa706707a3b..c367129dcdc16 100644 |
4842 |
+--- a/fs/ext4/resize.c |
4843 |
++++ b/fs/ext4/resize.c |
4844 |
+@@ -51,6 +51,16 @@ int ext4_resize_begin(struct super_block *sb) |
4845 |
+ if (!capable(CAP_SYS_RESOURCE)) |
4846 |
+ return -EPERM; |
4847 |
+ |
4848 |
++ /* |
4849 |
++ * If the reserved GDT blocks is non-zero, the resize_inode feature |
4850 |
++ * should always be set. |
4851 |
++ */ |
4852 |
++ if (EXT4_SB(sb)->s_es->s_reserved_gdt_blocks && |
4853 |
++ !ext4_has_feature_resize_inode(sb)) { |
4854 |
++ ext4_error(sb, "resize_inode disabled but reserved GDT blocks non-zero"); |
4855 |
++ return -EFSCORRUPTED; |
4856 |
++ } |
4857 |
++ |
4858 |
+ /* |
4859 |
+ * If we are not using the primary superblock/GDT copy don't resize, |
4860 |
+ * because the user tools have no way of handling this. Probably a |
4861 |
+diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c |
4862 |
+index 585c52dbb2e39..13cf7c260a831 100644 |
4863 |
+--- a/fs/fuse/dev.c |
4864 |
++++ b/fs/fuse/dev.c |
4865 |
+@@ -992,7 +992,17 @@ static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, |
4866 |
+ |
4867 |
+ while (count) { |
4868 |
+ if (cs->write && cs->pipebufs && page) { |
4869 |
+- return fuse_ref_page(cs, page, offset, count); |
4870 |
++ /* |
4871 |
++ * Can't control lifetime of pipe buffers, so always |
4872 |
++ * copy user pages. |
4873 |
++ */ |
4874 |
++ if (cs->req->user_pages) { |
4875 |
++ err = fuse_copy_fill(cs); |
4876 |
++ if (err) |
4877 |
++ return err; |
4878 |
++ } else { |
4879 |
++ return fuse_ref_page(cs, page, offset, count); |
4880 |
++ } |
4881 |
+ } else if (!cs->len) { |
4882 |
+ if (cs->move_pages && page && |
4883 |
+ offset == 0 && count == PAGE_SIZE) { |
4884 |
+diff --git a/fs/fuse/file.c b/fs/fuse/file.c |
4885 |
+index 8aef8e56eb1b6..aa4f0d632bed4 100644 |
4886 |
+--- a/fs/fuse/file.c |
4887 |
++++ b/fs/fuse/file.c |
4888 |
+@@ -1319,6 +1319,7 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii, |
4889 |
+ (PAGE_SIZE - ret) & (PAGE_SIZE - 1); |
4890 |
+ } |
4891 |
+ |
4892 |
++ req->user_pages = true; |
4893 |
+ if (write) |
4894 |
+ req->in.argpages = 1; |
4895 |
+ else |
4896 |
+diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h |
4897 |
+index 7e4b0e298bc73..6104534ddb7e6 100644 |
4898 |
+--- a/fs/fuse/fuse_i.h |
4899 |
++++ b/fs/fuse/fuse_i.h |
4900 |
+@@ -310,6 +310,8 @@ struct fuse_req { |
4901 |
+ /** refcount */ |
4902 |
+ atomic_t count; |
4903 |
+ |
4904 |
++ bool user_pages; |
4905 |
++ |
4906 |
+ /** Unique ID for the interrupt request */ |
4907 |
+ u64 intr_unique; |
4908 |
+ |
4909 |
+diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c |
4910 |
+index f19cded49b29d..317d22f844924 100644 |
4911 |
+--- a/fs/nfs/pnfs.c |
4912 |
++++ b/fs/nfs/pnfs.c |
4913 |
+@@ -1753,6 +1753,12 @@ lookup_again: |
4914 |
+ /* Fallthrough */ |
4915 |
+ case -EAGAIN: |
4916 |
+ break; |
4917 |
++ case -ENODATA: |
4918 |
++ /* The server returned NFS4ERR_LAYOUTUNAVAILABLE */ |
4919 |
++ pnfs_layout_set_fail_bit( |
4920 |
++ lo, pnfs_iomode_to_fail_bit(iomode)); |
4921 |
++ lseg = NULL; |
4922 |
++ goto out_put_layout_hdr; |
4923 |
+ default: |
4924 |
+ if (!nfs_error_is_fatal(PTR_ERR(lseg))) { |
4925 |
+ pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); |
4926 |
+diff --git a/include/crypto/blake2s.h b/include/crypto/blake2s.h |
4927 |
+new file mode 100644 |
4928 |
+index 0000000000000..d439496fa6baa |
4929 |
+--- /dev/null |
4930 |
++++ b/include/crypto/blake2s.h |
4931 |
+@@ -0,0 +1,102 @@ |
4932 |
++/* SPDX-License-Identifier: GPL-2.0 OR MIT */ |
4933 |
++/* |
4934 |
++ * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@×××××.com>. All Rights Reserved. |
4935 |
++ */ |
4936 |
++ |
4937 |
++#ifndef _CRYPTO_BLAKE2S_H |
4938 |
++#define _CRYPTO_BLAKE2S_H |
4939 |
++ |
4940 |
++#include <linux/bug.h> |
4941 |
++#include <linux/types.h> |
4942 |
++#include <linux/kernel.h> |
4943 |
++#include <linux/string.h> |
4944 |
++ |
4945 |
++enum blake2s_lengths { |
4946 |
++ BLAKE2S_BLOCK_SIZE = 64, |
4947 |
++ BLAKE2S_HASH_SIZE = 32, |
4948 |
++ BLAKE2S_KEY_SIZE = 32, |
4949 |
++ |
4950 |
++ BLAKE2S_128_HASH_SIZE = 16, |
4951 |
++ BLAKE2S_160_HASH_SIZE = 20, |
4952 |
++ BLAKE2S_224_HASH_SIZE = 28, |
4953 |
++ BLAKE2S_256_HASH_SIZE = 32, |
4954 |
++}; |
4955 |
++ |
4956 |
++struct blake2s_state { |
4957 |
++ u32 h[8]; |
4958 |
++ u32 t[2]; |
4959 |
++ u32 f[2]; |
4960 |
++ u8 buf[BLAKE2S_BLOCK_SIZE]; |
4961 |
++ unsigned int buflen; |
4962 |
++ unsigned int outlen; |
4963 |
++}; |
4964 |
++ |
4965 |
++enum blake2s_iv { |
4966 |
++ BLAKE2S_IV0 = 0x6A09E667UL, |
4967 |
++ BLAKE2S_IV1 = 0xBB67AE85UL, |
4968 |
++ BLAKE2S_IV2 = 0x3C6EF372UL, |
4969 |
++ BLAKE2S_IV3 = 0xA54FF53AUL, |
4970 |
++ BLAKE2S_IV4 = 0x510E527FUL, |
4971 |
++ BLAKE2S_IV5 = 0x9B05688CUL, |
4972 |
++ BLAKE2S_IV6 = 0x1F83D9ABUL, |
4973 |
++ BLAKE2S_IV7 = 0x5BE0CD19UL, |
4974 |
++}; |
4975 |
++ |
4976 |
++void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen); |
4977 |
++void blake2s_final(struct blake2s_state *state, u8 *out); |
4978 |
++ |
4979 |
++static inline void blake2s_init_param(struct blake2s_state *state, |
4980 |
++ const u32 param) |
4981 |
++{ |
4982 |
++ *state = (struct blake2s_state){{ |
4983 |
++ BLAKE2S_IV0 ^ param, |
4984 |
++ BLAKE2S_IV1, |
4985 |
++ BLAKE2S_IV2, |
4986 |
++ BLAKE2S_IV3, |
4987 |
++ BLAKE2S_IV4, |
4988 |
++ BLAKE2S_IV5, |
4989 |
++ BLAKE2S_IV6, |
4990 |
++ BLAKE2S_IV7, |
4991 |
++ }}; |
4992 |
++} |
4993 |
++ |
4994 |
++static inline void blake2s_init(struct blake2s_state *state, |
4995 |
++ const size_t outlen) |
4996 |
++{ |
4997 |
++ blake2s_init_param(state, 0x01010000 | outlen); |
4998 |
++ state->outlen = outlen; |
4999 |
++} |
5000 |
++ |
5001 |
++static inline void blake2s_init_key(struct blake2s_state *state, |
5002 |
++ const size_t outlen, const void *key, |
5003 |
++ const size_t keylen) |
5004 |
++{ |
5005 |
++ WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE || |
5006 |
++ !key || !keylen || keylen > BLAKE2S_KEY_SIZE)); |
5007 |
++ |
5008 |
++ blake2s_init_param(state, 0x01010000 | keylen << 8 | outlen); |
5009 |
++ memcpy(state->buf, key, keylen); |
5010 |
++ state->buflen = BLAKE2S_BLOCK_SIZE; |
5011 |
++ state->outlen = outlen; |
5012 |
++} |
5013 |
++ |
5014 |
++static inline void blake2s(u8 *out, const u8 *in, const u8 *key, |
5015 |
++ const size_t outlen, const size_t inlen, |
5016 |
++ const size_t keylen) |
5017 |
++{ |
5018 |
++ struct blake2s_state state; |
5019 |
++ |
5020 |
++ WARN_ON(IS_ENABLED(DEBUG) && ((!in && inlen > 0) || !out || !outlen || |
5021 |
++ outlen > BLAKE2S_HASH_SIZE || keylen > BLAKE2S_KEY_SIZE || |
5022 |
++ (!key && keylen))); |
5023 |
++ |
5024 |
++ if (keylen) |
5025 |
++ blake2s_init_key(&state, outlen, key, keylen); |
5026 |
++ else |
5027 |
++ blake2s_init(&state, outlen); |
5028 |
++ |
5029 |
++ blake2s_update(&state, in, inlen); |
5030 |
++ blake2s_final(&state, out); |
5031 |
++} |
5032 |
++ |
5033 |
++#endif /* _CRYPTO_BLAKE2S_H */ |
5034 |
+diff --git a/include/crypto/chacha20.h b/include/crypto/chacha20.h |
5035 |
+index 20d20f681a72c..0b8deb5e82915 100644 |
5036 |
+--- a/include/crypto/chacha20.h |
5037 |
++++ b/include/crypto/chacha20.h |
5038 |
+@@ -16,11 +16,26 @@ struct chacha20_ctx { |
5039 |
+ u32 key[8]; |
5040 |
+ }; |
5041 |
+ |
5042 |
+-void chacha20_block(u32 *state, void *stream); |
5043 |
++void chacha20_block(u32 *state, u8 *stream); |
5044 |
+ void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv); |
5045 |
+ int crypto_chacha20_setkey(struct crypto_tfm *tfm, const u8 *key, |
5046 |
+ unsigned int keysize); |
5047 |
+ int crypto_chacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, |
5048 |
+ struct scatterlist *src, unsigned int nbytes); |
5049 |
+ |
5050 |
++enum chacha_constants { /* expand 32-byte k */ |
5051 |
++ CHACHA_CONSTANT_EXPA = 0x61707865U, |
5052 |
++ CHACHA_CONSTANT_ND_3 = 0x3320646eU, |
5053 |
++ CHACHA_CONSTANT_2_BY = 0x79622d32U, |
5054 |
++ CHACHA_CONSTANT_TE_K = 0x6b206574U |
5055 |
++}; |
5056 |
++ |
5057 |
++static inline void chacha_init_consts(u32 *state) |
5058 |
++{ |
5059 |
++ state[0] = CHACHA_CONSTANT_EXPA; |
5060 |
++ state[1] = CHACHA_CONSTANT_ND_3; |
5061 |
++ state[2] = CHACHA_CONSTANT_2_BY; |
5062 |
++ state[3] = CHACHA_CONSTANT_TE_K; |
5063 |
++} |
5064 |
++ |
5065 |
+ #endif |
5066 |
+diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h |
5067 |
+index 22f884c97387e..19b44179bb7c7 100644 |
5068 |
+--- a/include/crypto/drbg.h |
5069 |
++++ b/include/crypto/drbg.h |
5070 |
+@@ -105,6 +105,12 @@ struct drbg_test_data { |
5071 |
+ struct drbg_string *testentropy; /* TEST PARAMETER: test entropy */ |
5072 |
+ }; |
5073 |
+ |
5074 |
++enum drbg_seed_state { |
5075 |
++ DRBG_SEED_STATE_UNSEEDED, |
5076 |
++ DRBG_SEED_STATE_PARTIAL, /* Seeded with !rng_is_initialized() */ |
5077 |
++ DRBG_SEED_STATE_FULL, |
5078 |
++}; |
5079 |
++ |
5080 |
+ struct drbg_state { |
5081 |
+ struct mutex drbg_mutex; /* lock around DRBG */ |
5082 |
+ unsigned char *V; /* internal state 10.1.1.1 1a) */ |
5083 |
+@@ -129,14 +135,14 @@ struct drbg_state { |
5084 |
+ struct completion ctr_completion; /* CTR mode async handler */ |
5085 |
+ int ctr_async_err; /* CTR mode async error */ |
5086 |
+ |
5087 |
+- bool seeded; /* DRBG fully seeded? */ |
5088 |
++ enum drbg_seed_state seeded; /* DRBG fully seeded? */ |
5089 |
+ bool pr; /* Prediction resistance enabled? */ |
5090 |
+- struct work_struct seed_work; /* asynchronous seeding support */ |
5091 |
++ bool fips_primed; /* Continuous test primed? */ |
5092 |
++ unsigned char *prev; /* FIPS 140-2 continuous test value */ |
5093 |
+ struct crypto_rng *jent; |
5094 |
+ const struct drbg_state_ops *d_ops; |
5095 |
+ const struct drbg_core *core; |
5096 |
+ struct drbg_string test_data; |
5097 |
+- struct random_ready_callback random_ready; |
5098 |
+ }; |
5099 |
+ |
5100 |
+ static inline __u8 drbg_statelen(struct drbg_state *drbg) |
5101 |
+@@ -184,11 +190,7 @@ static inline size_t drbg_max_addtl(struct drbg_state *drbg) |
5102 |
+ static inline size_t drbg_max_requests(struct drbg_state *drbg) |
5103 |
+ { |
5104 |
+ /* SP800-90A requires 2**48 maximum requests before reseeding */ |
5105 |
+-#if (__BITS_PER_LONG == 32) |
5106 |
+- return SIZE_MAX; |
5107 |
+-#else |
5108 |
+- return (1UL<<48); |
5109 |
+-#endif |
5110 |
++ return (1<<20); |
5111 |
+ } |
5112 |
+ |
5113 |
+ /* |
5114 |
+diff --git a/include/crypto/internal/blake2s.h b/include/crypto/internal/blake2s.h |
5115 |
+new file mode 100644 |
5116 |
+index 0000000000000..3ba066845b699 |
5117 |
+--- /dev/null |
5118 |
++++ b/include/crypto/internal/blake2s.h |
5119 |
+@@ -0,0 +1,19 @@ |
5120 |
++/* SPDX-License-Identifier: GPL-2.0 OR MIT */ |
5121 |
++ |
5122 |
++#ifndef _CRYPTO_INTERNAL_BLAKE2S_H |
5123 |
++#define _CRYPTO_INTERNAL_BLAKE2S_H |
5124 |
++ |
5125 |
++#include <crypto/blake2s.h> |
5126 |
++ |
5127 |
++void blake2s_compress_generic(struct blake2s_state *state,const u8 *block, |
5128 |
++ size_t nblocks, const u32 inc); |
5129 |
++ |
5130 |
++void blake2s_compress_arch(struct blake2s_state *state,const u8 *block, |
5131 |
++ size_t nblocks, const u32 inc); |
5132 |
++ |
5133 |
++static inline void blake2s_set_lastblock(struct blake2s_state *state) |
5134 |
++{ |
5135 |
++ state->f[0] = -1; |
5136 |
++} |
5137 |
++ |
5138 |
++#endif /* _CRYPTO_INTERNAL_BLAKE2S_H */ |
5139 |
+diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h |
5140 |
+index 89f67c1c31606..9cf01d7bb7c0a 100644 |
5141 |
+--- a/include/linux/byteorder/generic.h |
5142 |
++++ b/include/linux/byteorder/generic.h |
5143 |
+@@ -155,6 +155,23 @@ static inline void le64_add_cpu(__le64 *var, u64 val) |
5144 |
+ *var = cpu_to_le64(le64_to_cpu(*var) + val); |
5145 |
+ } |
5146 |
+ |
5147 |
++/* XXX: this stuff can be optimized */ |
5148 |
++static inline void le32_to_cpu_array(u32 *buf, unsigned int words) |
5149 |
++{ |
5150 |
++ while (words--) { |
5151 |
++ __le32_to_cpus(buf); |
5152 |
++ buf++; |
5153 |
++ } |
5154 |
++} |
5155 |
++ |
5156 |
++static inline void cpu_to_le32_array(u32 *buf, unsigned int words) |
5157 |
++{ |
5158 |
++ while (words--) { |
5159 |
++ __cpu_to_le32s(buf); |
5160 |
++ buf++; |
5161 |
++ } |
5162 |
++} |
5163 |
++ |
5164 |
+ static inline void be16_add_cpu(__be16 *var, u16 val) |
5165 |
+ { |
5166 |
+ *var = cpu_to_be16(be16_to_cpu(*var) + val); |
5167 |
+diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h |
5168 |
+index 1ab0273560aeb..8160ad1885dc2 100644 |
5169 |
+--- a/include/linux/cpuhotplug.h |
5170 |
++++ b/include/linux/cpuhotplug.h |
5171 |
+@@ -29,6 +29,7 @@ enum cpuhp_state { |
5172 |
+ CPUHP_ACPI_CPUDRV_DEAD, |
5173 |
+ CPUHP_S390_PFAULT_DEAD, |
5174 |
+ CPUHP_BLK_MQ_DEAD, |
5175 |
++ CPUHP_RANDOM_PREPARE, |
5176 |
+ CPUHP_WORKQUEUE_PREP, |
5177 |
+ CPUHP_POWER_NUMA_PREPARE, |
5178 |
+ CPUHP_HRTIMERS_PREPARE, |
5179 |
+@@ -119,6 +120,7 @@ enum cpuhp_state { |
5180 |
+ CPUHP_AP_PERF_ARM_CCN_ONLINE, |
5181 |
+ CPUHP_AP_PERF_ARM_L2X0_ONLINE, |
5182 |
+ CPUHP_AP_WORKQUEUE_ONLINE, |
5183 |
++ CPUHP_AP_RANDOM_ONLINE, |
5184 |
+ CPUHP_AP_RCUTREE_ONLINE, |
5185 |
+ CPUHP_AP_NOTIFY_ONLINE, |
5186 |
+ CPUHP_AP_ONLINE_DYN, |
5187 |
+diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h |
5188 |
+index 34a0dc18f3271..48e28f7844fe9 100644 |
5189 |
+--- a/include/linux/hw_random.h |
5190 |
++++ b/include/linux/hw_random.h |
5191 |
+@@ -60,7 +60,5 @@ extern int devm_hwrng_register(struct device *dev, struct hwrng *rng); |
5192 |
+ /** Unregister a Hardware Random Number Generator driver. */ |
5193 |
+ extern void hwrng_unregister(struct hwrng *rng); |
5194 |
+ extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng); |
5195 |
+-/** Feed random bits into the pool. */ |
5196 |
+-extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy); |
5197 |
+ |
5198 |
+ #endif /* LINUX_HWRANDOM_H_ */ |
5199 |
+diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h |
5200 |
+index 722698a43d79c..659f58617b9e3 100644 |
5201 |
+--- a/include/linux/miscdevice.h |
5202 |
++++ b/include/linux/miscdevice.h |
5203 |
+@@ -31,6 +31,7 @@ |
5204 |
+ #define SGI_MMTIMER 153 |
5205 |
+ #define STORE_QUEUE_MINOR 155 /* unused */ |
5206 |
+ #define I2O_MINOR 166 |
5207 |
++#define HWRNG_MINOR 183 |
5208 |
+ #define MICROCODE_MINOR 184 |
5209 |
+ #define VFIO_MINOR 196 |
5210 |
+ #define TUN_MINOR 200 |
5211 |
+diff --git a/include/linux/mm.h b/include/linux/mm.h |
5212 |
+index 81ee5d0b26424..ebfe5b7711531 100644 |
5213 |
+--- a/include/linux/mm.h |
5214 |
++++ b/include/linux/mm.h |
5215 |
+@@ -2059,6 +2059,8 @@ extern int install_special_mapping(struct mm_struct *mm, |
5216 |
+ unsigned long addr, unsigned long len, |
5217 |
+ unsigned long flags, struct page **pages); |
5218 |
+ |
5219 |
++unsigned long randomize_page(unsigned long start, unsigned long range); |
5220 |
++ |
5221 |
+ extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); |
5222 |
+ |
5223 |
+ extern unsigned long mmap_region(struct file *file, unsigned long addr, |
5224 |
+diff --git a/include/linux/net.h b/include/linux/net.h |
5225 |
+index 54270c4707cf2..455aa9c1247ca 100644 |
5226 |
+--- a/include/linux/net.h |
5227 |
++++ b/include/linux/net.h |
5228 |
+@@ -274,6 +274,8 @@ do { \ |
5229 |
+ |
5230 |
+ #define net_get_random_once(buf, nbytes) \ |
5231 |
+ get_random_once((buf), (nbytes)) |
5232 |
++#define net_get_random_once_wait(buf, nbytes) \ |
5233 |
++ get_random_once_wait((buf), (nbytes)) |
5234 |
+ |
5235 |
+ int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, |
5236 |
+ size_t num, size_t len); |
5237 |
+diff --git a/include/linux/once.h b/include/linux/once.h |
5238 |
+index 285f12cb40e6a..9c98aaa87cbcd 100644 |
5239 |
+--- a/include/linux/once.h |
5240 |
++++ b/include/linux/once.h |
5241 |
+@@ -53,5 +53,7 @@ void __do_once_done(bool *done, struct static_key *once_key, |
5242 |
+ |
5243 |
+ #define get_random_once(buf, nbytes) \ |
5244 |
+ DO_ONCE(get_random_bytes, (buf), (nbytes)) |
5245 |
++#define get_random_once_wait(buf, nbytes) \ |
5246 |
++ DO_ONCE(get_random_bytes_wait, (buf), (nbytes)) \ |
5247 |
+ |
5248 |
+ #endif /* _LINUX_ONCE_H */ |
5249 |
+diff --git a/include/linux/prandom.h b/include/linux/prandom.h |
5250 |
+index e20339c78a84c..709e8e69fb39b 100644 |
5251 |
+--- a/include/linux/prandom.h |
5252 |
++++ b/include/linux/prandom.h |
5253 |
+@@ -10,6 +10,7 @@ |
5254 |
+ |
5255 |
+ #include <linux/types.h> |
5256 |
+ #include <linux/percpu.h> |
5257 |
++#include <linux/siphash.h> |
5258 |
+ |
5259 |
+ u32 prandom_u32(void); |
5260 |
+ void prandom_bytes(void *buf, size_t nbytes); |
5261 |
+@@ -21,15 +22,10 @@ void prandom_reseed_late(void); |
5262 |
+ * The core SipHash round function. Each line can be executed in |
5263 |
+ * parallel given enough CPU resources. |
5264 |
+ */ |
5265 |
+-#define PRND_SIPROUND(v0, v1, v2, v3) ( \ |
5266 |
+- v0 += v1, v1 = rol64(v1, 13), v2 += v3, v3 = rol64(v3, 16), \ |
5267 |
+- v1 ^= v0, v0 = rol64(v0, 32), v3 ^= v2, \ |
5268 |
+- v0 += v3, v3 = rol64(v3, 21), v2 += v1, v1 = rol64(v1, 17), \ |
5269 |
+- v3 ^= v0, v1 ^= v2, v2 = rol64(v2, 32) \ |
5270 |
+-) |
5271 |
++#define PRND_SIPROUND(v0, v1, v2, v3) SIPHASH_PERMUTATION(v0, v1, v2, v3) |
5272 |
+ |
5273 |
+-#define PRND_K0 (0x736f6d6570736575 ^ 0x6c7967656e657261) |
5274 |
+-#define PRND_K1 (0x646f72616e646f6d ^ 0x7465646279746573) |
5275 |
++#define PRND_K0 (SIPHASH_CONST_0 ^ SIPHASH_CONST_2) |
5276 |
++#define PRND_K1 (SIPHASH_CONST_1 ^ SIPHASH_CONST_3) |
5277 |
+ |
5278 |
+ #elif BITS_PER_LONG == 32 |
5279 |
+ /* |
5280 |
+@@ -37,14 +33,9 @@ void prandom_reseed_late(void); |
5281 |
+ * This is weaker, but 32-bit machines are not used for high-traffic |
5282 |
+ * applications, so there is less output for an attacker to analyze. |
5283 |
+ */ |
5284 |
+-#define PRND_SIPROUND(v0, v1, v2, v3) ( \ |
5285 |
+- v0 += v1, v1 = rol32(v1, 5), v2 += v3, v3 = rol32(v3, 8), \ |
5286 |
+- v1 ^= v0, v0 = rol32(v0, 16), v3 ^= v2, \ |
5287 |
+- v0 += v3, v3 = rol32(v3, 7), v2 += v1, v1 = rol32(v1, 13), \ |
5288 |
+- v3 ^= v0, v1 ^= v2, v2 = rol32(v2, 16) \ |
5289 |
+-) |
5290 |
+-#define PRND_K0 0x6c796765 |
5291 |
+-#define PRND_K1 0x74656462 |
5292 |
++#define PRND_SIPROUND(v0, v1, v2, v3) HSIPHASH_PERMUTATION(v0, v1, v2, v3) |
5293 |
++#define PRND_K0 (HSIPHASH_CONST_0 ^ HSIPHASH_CONST_2) |
5294 |
++#define PRND_K1 (HSIPHASH_CONST_1 ^ HSIPHASH_CONST_3) |
5295 |
+ |
5296 |
+ #else |
5297 |
+ #error Unsupported BITS_PER_LONG |
5298 |
+diff --git a/include/linux/random.h b/include/linux/random.h |
5299 |
+index 15cd754544686..291b493fd2e7d 100644 |
5300 |
+--- a/include/linux/random.h |
5301 |
++++ b/include/linux/random.h |
5302 |
+@@ -1,50 +1,78 @@ |
5303 |
+-/* |
5304 |
+- * include/linux/random.h |
5305 |
+- * |
5306 |
+- * Include file for the random number generator. |
5307 |
+- */ |
5308 |
++/* SPDX-License-Identifier: GPL-2.0 */ |
5309 |
++ |
5310 |
+ #ifndef _LINUX_RANDOM_H |
5311 |
+ #define _LINUX_RANDOM_H |
5312 |
+ |
5313 |
++#include <linux/bug.h> |
5314 |
++#include <linux/kernel.h> |
5315 |
+ #include <linux/list.h> |
5316 |
+ #include <linux/once.h> |
5317 |
+ |
5318 |
+ #include <uapi/linux/random.h> |
5319 |
+ |
5320 |
+-struct random_ready_callback { |
5321 |
+- struct list_head list; |
5322 |
+- void (*func)(struct random_ready_callback *rdy); |
5323 |
+- struct module *owner; |
5324 |
+-}; |
5325 |
++struct notifier_block; |
5326 |
+ |
5327 |
+-extern void add_device_randomness(const void *, unsigned int); |
5328 |
++void add_device_randomness(const void *buf, size_t len); |
5329 |
++void __init add_bootloader_randomness(const void *buf, size_t len); |
5330 |
++void add_input_randomness(unsigned int type, unsigned int code, |
5331 |
++ unsigned int value) __latent_entropy; |
5332 |
++void add_interrupt_randomness(int irq) __latent_entropy; |
5333 |
++void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy); |
5334 |
+ |
5335 |
+-#if defined(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) && !defined(__CHECKER__) |
5336 |
++#if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) |
5337 |
+ static inline void add_latent_entropy(void) |
5338 |
+ { |
5339 |
+- add_device_randomness((const void *)&latent_entropy, |
5340 |
+- sizeof(latent_entropy)); |
5341 |
++ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); |
5342 |
+ } |
5343 |
+ #else |
5344 |
+-static inline void add_latent_entropy(void) {} |
5345 |
++static inline void add_latent_entropy(void) { } |
5346 |
+ #endif |
5347 |
+ |
5348 |
+-extern void add_input_randomness(unsigned int type, unsigned int code, |
5349 |
+- unsigned int value) __latent_entropy; |
5350 |
+-extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy; |
5351 |
++void get_random_bytes(void *buf, size_t len); |
5352 |
++size_t __must_check get_random_bytes_arch(void *buf, size_t len); |
5353 |
++u32 get_random_u32(void); |
5354 |
++u64 get_random_u64(void); |
5355 |
++static inline unsigned int get_random_int(void) |
5356 |
++{ |
5357 |
++ return get_random_u32(); |
5358 |
++} |
5359 |
++static inline unsigned long get_random_long(void) |
5360 |
++{ |
5361 |
++#if BITS_PER_LONG == 64 |
5362 |
++ return get_random_u64(); |
5363 |
++#else |
5364 |
++ return get_random_u32(); |
5365 |
++#endif |
5366 |
++} |
5367 |
+ |
5368 |
+-extern void get_random_bytes(void *buf, int nbytes); |
5369 |
+-extern int add_random_ready_callback(struct random_ready_callback *rdy); |
5370 |
+-extern void del_random_ready_callback(struct random_ready_callback *rdy); |
5371 |
+-extern void get_random_bytes_arch(void *buf, int nbytes); |
5372 |
++int __init random_init(const char *command_line); |
5373 |
++bool rng_is_initialized(void); |
5374 |
++int wait_for_random_bytes(void); |
5375 |
++int register_random_ready_notifier(struct notifier_block *nb); |
5376 |
++int unregister_random_ready_notifier(struct notifier_block *nb); |
5377 |
+ |
5378 |
+-#ifndef MODULE |
5379 |
+-extern const struct file_operations random_fops, urandom_fops; |
5380 |
+-#endif |
5381 |
++/* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes). |
5382 |
++ * Returns the result of the call to wait_for_random_bytes. */ |
5383 |
++static inline int get_random_bytes_wait(void *buf, size_t nbytes) |
5384 |
++{ |
5385 |
++ int ret = wait_for_random_bytes(); |
5386 |
++ get_random_bytes(buf, nbytes); |
5387 |
++ return ret; |
5388 |
++} |
5389 |
+ |
5390 |
+-unsigned int get_random_int(void); |
5391 |
+-unsigned long get_random_long(void); |
5392 |
+-unsigned long randomize_page(unsigned long start, unsigned long range); |
5393 |
++#define declare_get_random_var_wait(name, ret_type) \ |
5394 |
++ static inline int get_random_ ## name ## _wait(ret_type *out) { \ |
5395 |
++ int ret = wait_for_random_bytes(); \ |
5396 |
++ if (unlikely(ret)) \ |
5397 |
++ return ret; \ |
5398 |
++ *out = get_random_ ## name(); \ |
5399 |
++ return 0; \ |
5400 |
++ } |
5401 |
++declare_get_random_var_wait(u32, u32) |
5402 |
++declare_get_random_var_wait(u64, u32) |
5403 |
++declare_get_random_var_wait(int, unsigned int) |
5404 |
++declare_get_random_var_wait(long, unsigned long) |
5405 |
++#undef declare_get_random_var |
5406 |
+ |
5407 |
+ /* |
5408 |
+ * This is designed to be standalone for just prandom |
5409 |
+@@ -56,30 +84,39 @@ unsigned long randomize_page(unsigned long start, unsigned long range); |
5410 |
+ #ifdef CONFIG_ARCH_RANDOM |
5411 |
+ # include <asm/archrandom.h> |
5412 |
+ #else |
5413 |
+-static inline bool arch_get_random_long(unsigned long *v) |
5414 |
+-{ |
5415 |
+- return 0; |
5416 |
+-} |
5417 |
+-static inline bool arch_get_random_int(unsigned int *v) |
5418 |
+-{ |
5419 |
+- return 0; |
5420 |
+-} |
5421 |
+-static inline bool arch_has_random(void) |
5422 |
+-{ |
5423 |
+- return 0; |
5424 |
+-} |
5425 |
+-static inline bool arch_get_random_seed_long(unsigned long *v) |
5426 |
+-{ |
5427 |
+- return 0; |
5428 |
+-} |
5429 |
+-static inline bool arch_get_random_seed_int(unsigned int *v) |
5430 |
++static inline bool __must_check arch_get_random_long(unsigned long *v) { return false; } |
5431 |
++static inline bool __must_check arch_get_random_int(unsigned int *v) { return false; } |
5432 |
++static inline bool __must_check arch_get_random_seed_long(unsigned long *v) { return false; } |
5433 |
++static inline bool __must_check arch_get_random_seed_int(unsigned int *v) { return false; } |
5434 |
++#endif |
5435 |
++ |
5436 |
++/* |
5437 |
++ * Called from the boot CPU during startup; not valid to call once |
5438 |
++ * secondary CPUs are up and preemption is possible. |
5439 |
++ */ |
5440 |
++#ifndef arch_get_random_seed_long_early |
5441 |
++static inline bool __init arch_get_random_seed_long_early(unsigned long *v) |
5442 |
+ { |
5443 |
+- return 0; |
5444 |
++ WARN_ON(system_state != SYSTEM_BOOTING); |
5445 |
++ return arch_get_random_seed_long(v); |
5446 |
+ } |
5447 |
+-static inline bool arch_has_random_seed(void) |
5448 |
++#endif |
5449 |
++ |
5450 |
++#ifndef arch_get_random_long_early |
5451 |
++static inline bool __init arch_get_random_long_early(unsigned long *v) |
5452 |
+ { |
5453 |
+- return 0; |
5454 |
++ WARN_ON(system_state != SYSTEM_BOOTING); |
5455 |
++ return arch_get_random_long(v); |
5456 |
+ } |
5457 |
+ #endif |
5458 |
+ |
5459 |
++#ifdef CONFIG_SMP |
5460 |
++int random_prepare_cpu(unsigned int cpu); |
5461 |
++int random_online_cpu(unsigned int cpu); |
5462 |
++#endif |
5463 |
++ |
5464 |
++#ifndef MODULE |
5465 |
++extern const struct file_operations random_fops, urandom_fops; |
5466 |
++#endif |
5467 |
++ |
5468 |
+ #endif /* _LINUX_RANDOM_H */ |
5469 |
+diff --git a/include/linux/siphash.h b/include/linux/siphash.h |
5470 |
+index 0cda61855d907..0bb5ecd507bef 100644 |
5471 |
+--- a/include/linux/siphash.h |
5472 |
++++ b/include/linux/siphash.h |
5473 |
+@@ -136,4 +136,32 @@ static inline u32 hsiphash(const void *data, size_t len, |
5474 |
+ return ___hsiphash_aligned(data, len, key); |
5475 |
+ } |
5476 |
+ |
5477 |
++/* |
5478 |
++ * These macros expose the raw SipHash and HalfSipHash permutations. |
5479 |
++ * Do not use them directly! If you think you have a use for them, |
5480 |
++ * be sure to CC the maintainer of this file explaining why. |
5481 |
++ */ |
5482 |
++ |
5483 |
++#define SIPHASH_PERMUTATION(a, b, c, d) ( \ |
5484 |
++ (a) += (b), (b) = rol64((b), 13), (b) ^= (a), (a) = rol64((a), 32), \ |
5485 |
++ (c) += (d), (d) = rol64((d), 16), (d) ^= (c), \ |
5486 |
++ (a) += (d), (d) = rol64((d), 21), (d) ^= (a), \ |
5487 |
++ (c) += (b), (b) = rol64((b), 17), (b) ^= (c), (c) = rol64((c), 32)) |
5488 |
++ |
5489 |
++#define SIPHASH_CONST_0 0x736f6d6570736575ULL |
5490 |
++#define SIPHASH_CONST_1 0x646f72616e646f6dULL |
5491 |
++#define SIPHASH_CONST_2 0x6c7967656e657261ULL |
5492 |
++#define SIPHASH_CONST_3 0x7465646279746573ULL |
5493 |
++ |
5494 |
++#define HSIPHASH_PERMUTATION(a, b, c, d) ( \ |
5495 |
++ (a) += (b), (b) = rol32((b), 5), (b) ^= (a), (a) = rol32((a), 16), \ |
5496 |
++ (c) += (d), (d) = rol32((d), 8), (d) ^= (c), \ |
5497 |
++ (a) += (d), (d) = rol32((d), 7), (d) ^= (a), \ |
5498 |
++ (c) += (b), (b) = rol32((b), 13), (b) ^= (c), (c) = rol32((c), 16)) |
5499 |
++ |
5500 |
++#define HSIPHASH_CONST_0 0U |
5501 |
++#define HSIPHASH_CONST_1 0U |
5502 |
++#define HSIPHASH_CONST_2 0x6c796765U |
5503 |
++#define HSIPHASH_CONST_3 0x74656462U |
5504 |
++ |
5505 |
+ #endif /* _LINUX_SIPHASH_H */ |
5506 |
+diff --git a/include/linux/swab.h b/include/linux/swab.h |
5507 |
+index 9ad3c60f6cae7..f66e6f8bf049d 100644 |
5508 |
+--- a/include/linux/swab.h |
5509 |
++++ b/include/linux/swab.h |
5510 |
+@@ -6,6 +6,7 @@ |
5511 |
+ # define swab16 __swab16 |
5512 |
+ # define swab32 __swab32 |
5513 |
+ # define swab64 __swab64 |
5514 |
++# define swab __swab |
5515 |
+ # define swahw32 __swahw32 |
5516 |
+ # define swahb32 __swahb32 |
5517 |
+ # define swab16p __swab16p |
5518 |
+diff --git a/include/linux/timex.h b/include/linux/timex.h |
5519 |
+index 39c25dbebfe80..c7616cfb48d20 100644 |
5520 |
+--- a/include/linux/timex.h |
5521 |
++++ b/include/linux/timex.h |
5522 |
+@@ -62,6 +62,8 @@ |
5523 |
+ #include <linux/types.h> |
5524 |
+ #include <linux/param.h> |
5525 |
+ |
5526 |
++unsigned long random_get_entropy_fallback(void); |
5527 |
++ |
5528 |
+ #include <asm/timex.h> |
5529 |
+ |
5530 |
+ #ifndef random_get_entropy |
5531 |
+@@ -74,8 +76,14 @@ |
5532 |
+ * |
5533 |
+ * By default we use get_cycles() for this purpose, but individual |
5534 |
+ * architectures may override this in their asm/timex.h header file. |
5535 |
++ * If a given arch does not have get_cycles(), then we fallback to |
5536 |
++ * using random_get_entropy_fallback(). |
5537 |
+ */ |
5538 |
+-#define random_get_entropy() get_cycles() |
5539 |
++#ifdef get_cycles |
5540 |
++#define random_get_entropy() ((unsigned long)get_cycles()) |
5541 |
++#else |
5542 |
++#define random_get_entropy() random_get_entropy_fallback() |
5543 |
++#endif |
5544 |
+ #endif |
5545 |
+ |
5546 |
+ /* |
5547 |
+diff --git a/include/linux/uuid.h b/include/linux/uuid.h |
5548 |
+index 2d095fc602045..c77fb14868b70 100644 |
5549 |
+--- a/include/linux/uuid.h |
5550 |
++++ b/include/linux/uuid.h |
5551 |
+@@ -23,6 +23,7 @@ |
5552 |
+ * not including trailing NUL. |
5553 |
+ */ |
5554 |
+ #define UUID_STRING_LEN 36 |
5555 |
++#define UUID_SIZE 16 |
5556 |
+ |
5557 |
+ static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2) |
5558 |
+ { |
5559 |
+diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h |
5560 |
+index 8e880f7f67b24..b95c511139b9d 100644 |
5561 |
+--- a/include/linux/workqueue.h |
5562 |
++++ b/include/linux/workqueue.h |
5563 |
+@@ -359,6 +359,8 @@ extern struct workqueue_struct *system_freezable_wq; |
5564 |
+ extern struct workqueue_struct *system_power_efficient_wq; |
5565 |
+ extern struct workqueue_struct *system_freezable_power_efficient_wq; |
5566 |
+ |
5567 |
++extern bool wq_online; |
5568 |
++ |
5569 |
+ extern struct workqueue_struct * |
5570 |
+ __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active, |
5571 |
+ struct lock_class_key *key, const char *lock_name, ...) __printf(1, 6); |
5572 |
+@@ -598,7 +600,7 @@ static inline bool schedule_delayed_work(struct delayed_work *dwork, |
5573 |
+ */ |
5574 |
+ static inline bool keventd_up(void) |
5575 |
+ { |
5576 |
+- return system_wq != NULL; |
5577 |
++ return wq_online; |
5578 |
+ } |
5579 |
+ |
5580 |
+ #ifndef CONFIG_SMP |
5581 |
+@@ -635,4 +637,7 @@ int workqueue_online_cpu(unsigned int cpu); |
5582 |
+ int workqueue_offline_cpu(unsigned int cpu); |
5583 |
+ #endif |
5584 |
+ |
5585 |
++int __init workqueue_init_early(void); |
5586 |
++int __init workqueue_init(void); |
5587 |
++ |
5588 |
+ #endif |
5589 |
+diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h |
5590 |
+index fc445e7ccadf4..c3cf2021bb3b3 100644 |
5591 |
+--- a/include/net/inet_hashtables.h |
5592 |
++++ b/include/net/inet_hashtables.h |
5593 |
+@@ -382,7 +382,7 @@ static inline void sk_rcv_saddr_set(struct sock *sk, __be32 addr) |
5594 |
+ } |
5595 |
+ |
5596 |
+ int __inet_hash_connect(struct inet_timewait_death_row *death_row, |
5597 |
+- struct sock *sk, u32 port_offset, |
5598 |
++ struct sock *sk, u64 port_offset, |
5599 |
+ int (*check_established)(struct inet_timewait_death_row *, |
5600 |
+ struct sock *, __u16, |
5601 |
+ struct inet_timewait_sock **)); |
5602 |
+diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h |
5603 |
+index 3f36d45b714a4..542a80c051074 100644 |
5604 |
+--- a/include/net/secure_seq.h |
5605 |
++++ b/include/net/secure_seq.h |
5606 |
+@@ -3,8 +3,8 @@ |
5607 |
+ |
5608 |
+ #include <linux/types.h> |
5609 |
+ |
5610 |
+-u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport); |
5611 |
+-u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, |
5612 |
++u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport); |
5613 |
++u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, |
5614 |
+ __be16 dport); |
5615 |
+ __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr, |
5616 |
+ __be16 sport, __be16 dport); |
5617 |
+diff --git a/include/trace/events/random.h b/include/trace/events/random.h |
5618 |
+deleted file mode 100644 |
5619 |
+index 4684de344c5d9..0000000000000 |
5620 |
+--- a/include/trace/events/random.h |
5621 |
++++ /dev/null |
5622 |
+@@ -1,315 +0,0 @@ |
5623 |
+-#undef TRACE_SYSTEM |
5624 |
+-#define TRACE_SYSTEM random |
5625 |
+- |
5626 |
+-#if !defined(_TRACE_RANDOM_H) || defined(TRACE_HEADER_MULTI_READ) |
5627 |
+-#define _TRACE_RANDOM_H |
5628 |
+- |
5629 |
+-#include <linux/writeback.h> |
5630 |
+-#include <linux/tracepoint.h> |
5631 |
+- |
5632 |
+-TRACE_EVENT(add_device_randomness, |
5633 |
+- TP_PROTO(int bytes, unsigned long IP), |
5634 |
+- |
5635 |
+- TP_ARGS(bytes, IP), |
5636 |
+- |
5637 |
+- TP_STRUCT__entry( |
5638 |
+- __field( int, bytes ) |
5639 |
+- __field(unsigned long, IP ) |
5640 |
+- ), |
5641 |
+- |
5642 |
+- TP_fast_assign( |
5643 |
+- __entry->bytes = bytes; |
5644 |
+- __entry->IP = IP; |
5645 |
+- ), |
5646 |
+- |
5647 |
+- TP_printk("bytes %d caller %pS", |
5648 |
+- __entry->bytes, (void *)__entry->IP) |
5649 |
+-); |
5650 |
+- |
5651 |
+-DECLARE_EVENT_CLASS(random__mix_pool_bytes, |
5652 |
+- TP_PROTO(const char *pool_name, int bytes, unsigned long IP), |
5653 |
+- |
5654 |
+- TP_ARGS(pool_name, bytes, IP), |
5655 |
+- |
5656 |
+- TP_STRUCT__entry( |
5657 |
+- __field( const char *, pool_name ) |
5658 |
+- __field( int, bytes ) |
5659 |
+- __field(unsigned long, IP ) |
5660 |
+- ), |
5661 |
+- |
5662 |
+- TP_fast_assign( |
5663 |
+- __entry->pool_name = pool_name; |
5664 |
+- __entry->bytes = bytes; |
5665 |
+- __entry->IP = IP; |
5666 |
+- ), |
5667 |
+- |
5668 |
+- TP_printk("%s pool: bytes %d caller %pS", |
5669 |
+- __entry->pool_name, __entry->bytes, (void *)__entry->IP) |
5670 |
+-); |
5671 |
+- |
5672 |
+-DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes, |
5673 |
+- TP_PROTO(const char *pool_name, int bytes, unsigned long IP), |
5674 |
+- |
5675 |
+- TP_ARGS(pool_name, bytes, IP) |
5676 |
+-); |
5677 |
+- |
5678 |
+-DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes_nolock, |
5679 |
+- TP_PROTO(const char *pool_name, int bytes, unsigned long IP), |
5680 |
+- |
5681 |
+- TP_ARGS(pool_name, bytes, IP) |
5682 |
+-); |
5683 |
+- |
5684 |
+-TRACE_EVENT(credit_entropy_bits, |
5685 |
+- TP_PROTO(const char *pool_name, int bits, int entropy_count, |
5686 |
+- int entropy_total, unsigned long IP), |
5687 |
+- |
5688 |
+- TP_ARGS(pool_name, bits, entropy_count, entropy_total, IP), |
5689 |
+- |
5690 |
+- TP_STRUCT__entry( |
5691 |
+- __field( const char *, pool_name ) |
5692 |
+- __field( int, bits ) |
5693 |
+- __field( int, entropy_count ) |
5694 |
+- __field( int, entropy_total ) |
5695 |
+- __field(unsigned long, IP ) |
5696 |
+- ), |
5697 |
+- |
5698 |
+- TP_fast_assign( |
5699 |
+- __entry->pool_name = pool_name; |
5700 |
+- __entry->bits = bits; |
5701 |
+- __entry->entropy_count = entropy_count; |
5702 |
+- __entry->entropy_total = entropy_total; |
5703 |
+- __entry->IP = IP; |
5704 |
+- ), |
5705 |
+- |
5706 |
+- TP_printk("%s pool: bits %d entropy_count %d entropy_total %d " |
5707 |
+- "caller %pS", __entry->pool_name, __entry->bits, |
5708 |
+- __entry->entropy_count, __entry->entropy_total, |
5709 |
+- (void *)__entry->IP) |
5710 |
+-); |
5711 |
+- |
5712 |
+-TRACE_EVENT(push_to_pool, |
5713 |
+- TP_PROTO(const char *pool_name, int pool_bits, int input_bits), |
5714 |
+- |
5715 |
+- TP_ARGS(pool_name, pool_bits, input_bits), |
5716 |
+- |
5717 |
+- TP_STRUCT__entry( |
5718 |
+- __field( const char *, pool_name ) |
5719 |
+- __field( int, pool_bits ) |
5720 |
+- __field( int, input_bits ) |
5721 |
+- ), |
5722 |
+- |
5723 |
+- TP_fast_assign( |
5724 |
+- __entry->pool_name = pool_name; |
5725 |
+- __entry->pool_bits = pool_bits; |
5726 |
+- __entry->input_bits = input_bits; |
5727 |
+- ), |
5728 |
+- |
5729 |
+- TP_printk("%s: pool_bits %d input_pool_bits %d", |
5730 |
+- __entry->pool_name, __entry->pool_bits, |
5731 |
+- __entry->input_bits) |
5732 |
+-); |
5733 |
+- |
5734 |
+-TRACE_EVENT(debit_entropy, |
5735 |
+- TP_PROTO(const char *pool_name, int debit_bits), |
5736 |
+- |
5737 |
+- TP_ARGS(pool_name, debit_bits), |
5738 |
+- |
5739 |
+- TP_STRUCT__entry( |
5740 |
+- __field( const char *, pool_name ) |
5741 |
+- __field( int, debit_bits ) |
5742 |
+- ), |
5743 |
+- |
5744 |
+- TP_fast_assign( |
5745 |
+- __entry->pool_name = pool_name; |
5746 |
+- __entry->debit_bits = debit_bits; |
5747 |
+- ), |
5748 |
+- |
5749 |
+- TP_printk("%s: debit_bits %d", __entry->pool_name, |
5750 |
+- __entry->debit_bits) |
5751 |
+-); |
5752 |
+- |
5753 |
+-TRACE_EVENT(add_input_randomness, |
5754 |
+- TP_PROTO(int input_bits), |
5755 |
+- |
5756 |
+- TP_ARGS(input_bits), |
5757 |
+- |
5758 |
+- TP_STRUCT__entry( |
5759 |
+- __field( int, input_bits ) |
5760 |
+- ), |
5761 |
+- |
5762 |
+- TP_fast_assign( |
5763 |
+- __entry->input_bits = input_bits; |
5764 |
+- ), |
5765 |
+- |
5766 |
+- TP_printk("input_pool_bits %d", __entry->input_bits) |
5767 |
+-); |
5768 |
+- |
5769 |
+-TRACE_EVENT(add_disk_randomness, |
5770 |
+- TP_PROTO(dev_t dev, int input_bits), |
5771 |
+- |
5772 |
+- TP_ARGS(dev, input_bits), |
5773 |
+- |
5774 |
+- TP_STRUCT__entry( |
5775 |
+- __field( dev_t, dev ) |
5776 |
+- __field( int, input_bits ) |
5777 |
+- ), |
5778 |
+- |
5779 |
+- TP_fast_assign( |
5780 |
+- __entry->dev = dev; |
5781 |
+- __entry->input_bits = input_bits; |
5782 |
+- ), |
5783 |
+- |
5784 |
+- TP_printk("dev %d,%d input_pool_bits %d", MAJOR(__entry->dev), |
5785 |
+- MINOR(__entry->dev), __entry->input_bits) |
5786 |
+-); |
5787 |
+- |
5788 |
+-TRACE_EVENT(xfer_secondary_pool, |
5789 |
+- TP_PROTO(const char *pool_name, int xfer_bits, int request_bits, |
5790 |
+- int pool_entropy, int input_entropy), |
5791 |
+- |
5792 |
+- TP_ARGS(pool_name, xfer_bits, request_bits, pool_entropy, |
5793 |
+- input_entropy), |
5794 |
+- |
5795 |
+- TP_STRUCT__entry( |
5796 |
+- __field( const char *, pool_name ) |
5797 |
+- __field( int, xfer_bits ) |
5798 |
+- __field( int, request_bits ) |
5799 |
+- __field( int, pool_entropy ) |
5800 |
+- __field( int, input_entropy ) |
5801 |
+- ), |
5802 |
+- |
5803 |
+- TP_fast_assign( |
5804 |
+- __entry->pool_name = pool_name; |
5805 |
+- __entry->xfer_bits = xfer_bits; |
5806 |
+- __entry->request_bits = request_bits; |
5807 |
+- __entry->pool_entropy = pool_entropy; |
5808 |
+- __entry->input_entropy = input_entropy; |
5809 |
+- ), |
5810 |
+- |
5811 |
+- TP_printk("pool %s xfer_bits %d request_bits %d pool_entropy %d " |
5812 |
+- "input_entropy %d", __entry->pool_name, __entry->xfer_bits, |
5813 |
+- __entry->request_bits, __entry->pool_entropy, |
5814 |
+- __entry->input_entropy) |
5815 |
+-); |
5816 |
+- |
5817 |
+-DECLARE_EVENT_CLASS(random__get_random_bytes, |
5818 |
+- TP_PROTO(int nbytes, unsigned long IP), |
5819 |
+- |
5820 |
+- TP_ARGS(nbytes, IP), |
5821 |
+- |
5822 |
+- TP_STRUCT__entry( |
5823 |
+- __field( int, nbytes ) |
5824 |
+- __field(unsigned long, IP ) |
5825 |
+- ), |
5826 |
+- |
5827 |
+- TP_fast_assign( |
5828 |
+- __entry->nbytes = nbytes; |
5829 |
+- __entry->IP = IP; |
5830 |
+- ), |
5831 |
+- |
5832 |
+- TP_printk("nbytes %d caller %pS", __entry->nbytes, (void *)__entry->IP) |
5833 |
+-); |
5834 |
+- |
5835 |
+-DEFINE_EVENT(random__get_random_bytes, get_random_bytes, |
5836 |
+- TP_PROTO(int nbytes, unsigned long IP), |
5837 |
+- |
5838 |
+- TP_ARGS(nbytes, IP) |
5839 |
+-); |
5840 |
+- |
5841 |
+-DEFINE_EVENT(random__get_random_bytes, get_random_bytes_arch, |
5842 |
+- TP_PROTO(int nbytes, unsigned long IP), |
5843 |
+- |
5844 |
+- TP_ARGS(nbytes, IP) |
5845 |
+-); |
5846 |
+- |
5847 |
+-DECLARE_EVENT_CLASS(random__extract_entropy, |
5848 |
+- TP_PROTO(const char *pool_name, int nbytes, int entropy_count, |
5849 |
+- unsigned long IP), |
5850 |
+- |
5851 |
+- TP_ARGS(pool_name, nbytes, entropy_count, IP), |
5852 |
+- |
5853 |
+- TP_STRUCT__entry( |
5854 |
+- __field( const char *, pool_name ) |
5855 |
+- __field( int, nbytes ) |
5856 |
+- __field( int, entropy_count ) |
5857 |
+- __field(unsigned long, IP ) |
5858 |
+- ), |
5859 |
+- |
5860 |
+- TP_fast_assign( |
5861 |
+- __entry->pool_name = pool_name; |
5862 |
+- __entry->nbytes = nbytes; |
5863 |
+- __entry->entropy_count = entropy_count; |
5864 |
+- __entry->IP = IP; |
5865 |
+- ), |
5866 |
+- |
5867 |
+- TP_printk("%s pool: nbytes %d entropy_count %d caller %pS", |
5868 |
+- __entry->pool_name, __entry->nbytes, __entry->entropy_count, |
5869 |
+- (void *)__entry->IP) |
5870 |
+-); |
5871 |
+- |
5872 |
+- |
5873 |
+-DEFINE_EVENT(random__extract_entropy, extract_entropy, |
5874 |
+- TP_PROTO(const char *pool_name, int nbytes, int entropy_count, |
5875 |
+- unsigned long IP), |
5876 |
+- |
5877 |
+- TP_ARGS(pool_name, nbytes, entropy_count, IP) |
5878 |
+-); |
5879 |
+- |
5880 |
+-DEFINE_EVENT(random__extract_entropy, extract_entropy_user, |
5881 |
+- TP_PROTO(const char *pool_name, int nbytes, int entropy_count, |
5882 |
+- unsigned long IP), |
5883 |
+- |
5884 |
+- TP_ARGS(pool_name, nbytes, entropy_count, IP) |
5885 |
+-); |
5886 |
+- |
5887 |
+-TRACE_EVENT(random_read, |
5888 |
+- TP_PROTO(int got_bits, int need_bits, int pool_left, int input_left), |
5889 |
+- |
5890 |
+- TP_ARGS(got_bits, need_bits, pool_left, input_left), |
5891 |
+- |
5892 |
+- TP_STRUCT__entry( |
5893 |
+- __field( int, got_bits ) |
5894 |
+- __field( int, need_bits ) |
5895 |
+- __field( int, pool_left ) |
5896 |
+- __field( int, input_left ) |
5897 |
+- ), |
5898 |
+- |
5899 |
+- TP_fast_assign( |
5900 |
+- __entry->got_bits = got_bits; |
5901 |
+- __entry->need_bits = need_bits; |
5902 |
+- __entry->pool_left = pool_left; |
5903 |
+- __entry->input_left = input_left; |
5904 |
+- ), |
5905 |
+- |
5906 |
+- TP_printk("got_bits %d still_needed_bits %d " |
5907 |
+- "blocking_pool_entropy_left %d input_entropy_left %d", |
5908 |
+- __entry->got_bits, __entry->got_bits, __entry->pool_left, |
5909 |
+- __entry->input_left) |
5910 |
+-); |
5911 |
+- |
5912 |
+-TRACE_EVENT(urandom_read, |
5913 |
+- TP_PROTO(int got_bits, int pool_left, int input_left), |
5914 |
+- |
5915 |
+- TP_ARGS(got_bits, pool_left, input_left), |
5916 |
+- |
5917 |
+- TP_STRUCT__entry( |
5918 |
+- __field( int, got_bits ) |
5919 |
+- __field( int, pool_left ) |
5920 |
+- __field( int, input_left ) |
5921 |
+- ), |
5922 |
+- |
5923 |
+- TP_fast_assign( |
5924 |
+- __entry->got_bits = got_bits; |
5925 |
+- __entry->pool_left = pool_left; |
5926 |
+- __entry->input_left = input_left; |
5927 |
+- ), |
5928 |
+- |
5929 |
+- TP_printk("got_bits %d nonblocking_pool_entropy_left %d " |
5930 |
+- "input_entropy_left %d", __entry->got_bits, |
5931 |
+- __entry->pool_left, __entry->input_left) |
5932 |
+-); |
5933 |
+- |
5934 |
+-#endif /* _TRACE_RANDOM_H */ |
5935 |
+- |
5936 |
+-/* This part must be outside protection */ |
5937 |
+-#include <trace/define_trace.h> |
5938 |
+diff --git a/include/uapi/linux/random.h b/include/uapi/linux/random.h |
5939 |
+index b455b0d86f269..b01d118750ab2 100644 |
5940 |
+--- a/include/uapi/linux/random.h |
5941 |
++++ b/include/uapi/linux/random.h |
5942 |
+@@ -47,9 +47,11 @@ struct rand_pool_info { |
5943 |
+ * Flags for getrandom(2) |
5944 |
+ * |
5945 |
+ * GRND_NONBLOCK Don't block and return EAGAIN instead |
5946 |
+- * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom |
5947 |
++ * GRND_RANDOM No effect |
5948 |
++ * GRND_INSECURE Return non-cryptographic random bytes |
5949 |
+ */ |
5950 |
+ #define GRND_NONBLOCK 0x0001 |
5951 |
+ #define GRND_RANDOM 0x0002 |
5952 |
++#define GRND_INSECURE 0x0004 |
5953 |
+ |
5954 |
+ #endif /* _UAPI_LINUX_RANDOM_H */ |
5955 |
+diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h |
5956 |
+index 8f3a8f606fd95..1f42d110987a4 100644 |
5957 |
+--- a/include/uapi/linux/swab.h |
5958 |
++++ b/include/uapi/linux/swab.h |
5959 |
+@@ -3,6 +3,7 @@ |
5960 |
+ |
5961 |
+ #include <linux/types.h> |
5962 |
+ #include <linux/compiler.h> |
5963 |
++#include <asm/bitsperlong.h> |
5964 |
+ #include <asm/swab.h> |
5965 |
+ |
5966 |
+ /* |
5967 |
+@@ -131,6 +132,15 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val) |
5968 |
+ __fswab64(x)) |
5969 |
+ #endif |
5970 |
+ |
5971 |
++static __always_inline unsigned long __swab(const unsigned long y) |
5972 |
++{ |
5973 |
++#if BITS_PER_LONG == 64 |
5974 |
++ return __swab64(y); |
5975 |
++#else /* BITS_PER_LONG == 32 */ |
5976 |
++ return __swab32(y); |
5977 |
++#endif |
5978 |
++} |
5979 |
++ |
5980 |
+ /** |
5981 |
+ * __swahw32 - return a word-swapped 32-bit value |
5982 |
+ * @x: value to wordswap |
5983 |
+diff --git a/init/main.c b/init/main.c |
5984 |
+index 0c01d4e10d2f3..30226a836c8b5 100644 |
5985 |
+--- a/init/main.c |
5986 |
++++ b/init/main.c |
5987 |
+@@ -490,6 +490,7 @@ asmlinkage __visible void __init start_kernel(void) |
5988 |
+ /* |
5989 |
+ * Set up the the initial canary ASAP: |
5990 |
+ */ |
5991 |
++ add_latent_entropy(); |
5992 |
+ boot_init_stack_canary(); |
5993 |
+ |
5994 |
+ cgroup_init_early(); |
5995 |
+@@ -553,6 +554,14 @@ asmlinkage __visible void __init start_kernel(void) |
5996 |
+ "Interrupts were enabled *very* early, fixing it\n")) |
5997 |
+ local_irq_disable(); |
5998 |
+ idr_init_cache(); |
5999 |
++ |
6000 |
++ /* |
6001 |
++ * Allow workqueue creation and work item queueing/cancelling |
6002 |
++ * early. Work item execution depends on kthreads and starts after |
6003 |
++ * workqueue_init(). |
6004 |
++ */ |
6005 |
++ workqueue_init_early(); |
6006 |
++ |
6007 |
+ rcu_init(); |
6008 |
+ |
6009 |
+ /* trace_printk() and trace points may be used after this */ |
6010 |
+@@ -570,6 +579,17 @@ asmlinkage __visible void __init start_kernel(void) |
6011 |
+ softirq_init(); |
6012 |
+ timekeeping_init(); |
6013 |
+ time_init(); |
6014 |
++ |
6015 |
++ /* |
6016 |
++ * For best initial stack canary entropy, prepare it after: |
6017 |
++ * - setup_arch() for any UEFI RNG entropy and boot cmdline access |
6018 |
++ * - timekeeping_init() for ktime entropy used in random_init() |
6019 |
++ * - time_init() for making random_get_entropy() work on some platforms |
6020 |
++ * - random_init() to initialize the RNG from from early entropy sources |
6021 |
++ */ |
6022 |
++ random_init(command_line); |
6023 |
++ boot_init_stack_canary(); |
6024 |
++ |
6025 |
+ sched_clock_postinit(); |
6026 |
+ printk_nmi_init(); |
6027 |
+ perf_event_init(); |
6028 |
+@@ -1011,6 +1031,8 @@ static noinline void __init kernel_init_freeable(void) |
6029 |
+ |
6030 |
+ smp_prepare_cpus(setup_max_cpus); |
6031 |
+ |
6032 |
++ workqueue_init(); |
6033 |
++ |
6034 |
+ do_pre_smp_initcalls(); |
6035 |
+ lockup_detector_init(); |
6036 |
+ |
6037 |
+diff --git a/kernel/cpu.c b/kernel/cpu.c |
6038 |
+index e005209f279e1..5ddac8914515a 100644 |
6039 |
+--- a/kernel/cpu.c |
6040 |
++++ b/kernel/cpu.c |
6041 |
+@@ -26,6 +26,7 @@ |
6042 |
+ #include <linux/smpboot.h> |
6043 |
+ #include <linux/relay.h> |
6044 |
+ #include <linux/slab.h> |
6045 |
++#include <linux/random.h> |
6046 |
+ |
6047 |
+ #include <trace/events/power.h> |
6048 |
+ #define CREATE_TRACE_POINTS |
6049 |
+@@ -1404,6 +1405,11 @@ static struct cpuhp_step cpuhp_bp_states[] = { |
6050 |
+ .startup.single = perf_event_init_cpu, |
6051 |
+ .teardown.single = perf_event_exit_cpu, |
6052 |
+ }, |
6053 |
++ [CPUHP_RANDOM_PREPARE] = { |
6054 |
++ .name = "random:prepare", |
6055 |
++ .startup.single = random_prepare_cpu, |
6056 |
++ .teardown.single = NULL, |
6057 |
++ }, |
6058 |
+ [CPUHP_WORKQUEUE_PREP] = { |
6059 |
+ .name = "workqueue:prepare", |
6060 |
+ .startup.single = workqueue_prepare_cpu, |
6061 |
+@@ -1529,6 +1535,11 @@ static struct cpuhp_step cpuhp_ap_states[] = { |
6062 |
+ .startup.single = workqueue_online_cpu, |
6063 |
+ .teardown.single = workqueue_offline_cpu, |
6064 |
+ }, |
6065 |
++ [CPUHP_AP_RANDOM_ONLINE] = { |
6066 |
++ .name = "random:online", |
6067 |
++ .startup.single = random_online_cpu, |
6068 |
++ .teardown.single = NULL, |
6069 |
++ }, |
6070 |
+ [CPUHP_AP_RCUTREE_ONLINE] = { |
6071 |
+ .name = "RCU/tree:online", |
6072 |
+ .startup.single = rcutree_online_cpu, |
6073 |
+diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c |
6074 |
+index d3f24905852c9..374c45fbe3db6 100644 |
6075 |
+--- a/kernel/irq/handle.c |
6076 |
++++ b/kernel/irq/handle.c |
6077 |
+@@ -184,7 +184,7 @@ irqreturn_t handle_irq_event_percpu(struct irq_desc *desc) |
6078 |
+ |
6079 |
+ retval = __handle_irq_event_percpu(desc, &flags); |
6080 |
+ |
6081 |
+- add_interrupt_randomness(desc->irq_data.irq, flags); |
6082 |
++ add_interrupt_randomness(desc->irq_data.irq); |
6083 |
+ |
6084 |
+ if (!noirqdebug) |
6085 |
+ note_interrupt(desc, retval); |
6086 |
+diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c |
6087 |
+index bcba817f7af20..828728639e0dd 100644 |
6088 |
+--- a/kernel/time/timekeeping.c |
6089 |
++++ b/kernel/time/timekeeping.c |
6090 |
+@@ -19,6 +19,7 @@ |
6091 |
+ #include <linux/clocksource.h> |
6092 |
+ #include <linux/jiffies.h> |
6093 |
+ #include <linux/time.h> |
6094 |
++#include <linux/timex.h> |
6095 |
+ #include <linux/tick.h> |
6096 |
+ #include <linux/stop_machine.h> |
6097 |
+ #include <linux/pvclock_gtod.h> |
6098 |
+@@ -2269,6 +2270,21 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, |
6099 |
+ return base; |
6100 |
+ } |
6101 |
+ |
6102 |
++/** |
6103 |
++ * random_get_entropy_fallback - Returns the raw clock source value, |
6104 |
++ * used by random.c for platforms with no valid random_get_entropy(). |
6105 |
++ */ |
6106 |
++unsigned long random_get_entropy_fallback(void) |
6107 |
++{ |
6108 |
++ struct tk_read_base *tkr = &tk_core.timekeeper.tkr_mono; |
6109 |
++ struct clocksource *clock = READ_ONCE(tkr->clock); |
6110 |
++ |
6111 |
++ if (unlikely(timekeeping_suspended || !clock)) |
6112 |
++ return 0; |
6113 |
++ return clock->read(clock); |
6114 |
++} |
6115 |
++EXPORT_SYMBOL_GPL(random_get_entropy_fallback); |
6116 |
++ |
6117 |
+ /** |
6118 |
+ * do_adjtimex() - Accessor function to NTP __do_adjtimex function |
6119 |
+ */ |
6120 |
+diff --git a/kernel/workqueue.c b/kernel/workqueue.c |
6121 |
+index b3476a21a7b31..df96f797939e4 100644 |
6122 |
+--- a/kernel/workqueue.c |
6123 |
++++ b/kernel/workqueue.c |
6124 |
+@@ -292,6 +292,8 @@ module_param_named(disable_numa, wq_disable_numa, bool, 0444); |
6125 |
+ static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT); |
6126 |
+ module_param_named(power_efficient, wq_power_efficient, bool, 0444); |
6127 |
+ |
6128 |
++bool wq_online; /* can kworkers be created yet? */ |
6129 |
++ |
6130 |
+ static bool wq_numa_enabled; /* unbound NUMA affinity enabled */ |
6131 |
+ |
6132 |
+ /* buf for wq_update_unbound_numa_attrs(), protected by CPU hotplug exclusion */ |
6133 |
+@@ -2588,6 +2590,9 @@ void flush_workqueue(struct workqueue_struct *wq) |
6134 |
+ }; |
6135 |
+ int next_color; |
6136 |
+ |
6137 |
++ if (WARN_ON(!wq_online)) |
6138 |
++ return; |
6139 |
++ |
6140 |
+ lock_map_acquire(&wq->lockdep_map); |
6141 |
+ lock_map_release(&wq->lockdep_map); |
6142 |
+ |
6143 |
+@@ -2848,6 +2853,9 @@ bool flush_work(struct work_struct *work) |
6144 |
+ { |
6145 |
+ struct wq_barrier barr; |
6146 |
+ |
6147 |
++ if (WARN_ON(!wq_online)) |
6148 |
++ return false; |
6149 |
++ |
6150 |
+ lock_map_acquire(&work->lockdep_map); |
6151 |
+ lock_map_release(&work->lockdep_map); |
6152 |
+ |
6153 |
+@@ -2918,7 +2926,13 @@ static bool __cancel_work_timer(struct work_struct *work, bool is_dwork) |
6154 |
+ mark_work_canceling(work); |
6155 |
+ local_irq_restore(flags); |
6156 |
+ |
6157 |
+- flush_work(work); |
6158 |
++ /* |
6159 |
++ * This allows canceling during early boot. We know that @work |
6160 |
++ * isn't executing. |
6161 |
++ */ |
6162 |
++ if (wq_online) |
6163 |
++ flush_work(work); |
6164 |
++ |
6165 |
+ clear_work_data(work); |
6166 |
+ |
6167 |
+ /* |
6168 |
+@@ -3368,7 +3382,7 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) |
6169 |
+ goto fail; |
6170 |
+ |
6171 |
+ /* create and start the initial worker */ |
6172 |
+- if (!create_worker(pool)) |
6173 |
++ if (wq_online && !create_worker(pool)) |
6174 |
+ goto fail; |
6175 |
+ |
6176 |
+ /* install */ |
6177 |
+@@ -3439,6 +3453,7 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) |
6178 |
+ { |
6179 |
+ struct workqueue_struct *wq = pwq->wq; |
6180 |
+ bool freezable = wq->flags & WQ_FREEZABLE; |
6181 |
++ unsigned long flags; |
6182 |
+ |
6183 |
+ /* for @wq->saved_max_active */ |
6184 |
+ lockdep_assert_held(&wq->mutex); |
6185 |
+@@ -3447,7 +3462,8 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) |
6186 |
+ if (!freezable && pwq->max_active == wq->saved_max_active) |
6187 |
+ return; |
6188 |
+ |
6189 |
+- spin_lock_irq(&pwq->pool->lock); |
6190 |
++ /* this function can be called during early boot w/ irq disabled */ |
6191 |
++ spin_lock_irqsave(&pwq->pool->lock, flags); |
6192 |
+ |
6193 |
+ /* |
6194 |
+ * During [un]freezing, the caller is responsible for ensuring that |
6195 |
+@@ -3477,7 +3493,7 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) |
6196 |
+ pwq->max_active = 0; |
6197 |
+ } |
6198 |
+ |
6199 |
+- spin_unlock_irq(&pwq->pool->lock); |
6200 |
++ spin_unlock_irqrestore(&pwq->pool->lock, flags); |
6201 |
+ } |
6202 |
+ |
6203 |
+ /* initialize newly alloced @pwq which is associated with @wq and @pool */ |
6204 |
+@@ -5550,7 +5566,17 @@ static void __init wq_numa_init(void) |
6205 |
+ wq_numa_enabled = true; |
6206 |
+ } |
6207 |
+ |
6208 |
+-static int __init init_workqueues(void) |
6209 |
++/** |
6210 |
++ * workqueue_init_early - early init for workqueue subsystem |
6211 |
++ * |
6212 |
++ * This is the first half of two-staged workqueue subsystem initialization |
6213 |
++ * and invoked as soon as the bare basics - memory allocation, cpumasks and |
6214 |
++ * idr are up. It sets up all the data structures and system workqueues |
6215 |
++ * and allows early boot code to create workqueues and queue/cancel work |
6216 |
++ * items. Actual work item execution starts only after kthreads can be |
6217 |
++ * created and scheduled right before early initcalls. |
6218 |
++ */ |
6219 |
++int __init workqueue_init_early(void) |
6220 |
+ { |
6221 |
+ int std_nice[NR_STD_WORKER_POOLS] = { 0, HIGHPRI_NICE_LEVEL }; |
6222 |
+ int i, cpu; |
6223 |
+@@ -5583,16 +5609,6 @@ static int __init init_workqueues(void) |
6224 |
+ } |
6225 |
+ } |
6226 |
+ |
6227 |
+- /* create the initial worker */ |
6228 |
+- for_each_online_cpu(cpu) { |
6229 |
+- struct worker_pool *pool; |
6230 |
+- |
6231 |
+- for_each_cpu_worker_pool(pool, cpu) { |
6232 |
+- pool->flags &= ~POOL_DISASSOCIATED; |
6233 |
+- BUG_ON(!create_worker(pool)); |
6234 |
+- } |
6235 |
+- } |
6236 |
+- |
6237 |
+ /* create default unbound and ordered wq attrs */ |
6238 |
+ for (i = 0; i < NR_STD_WORKER_POOLS; i++) { |
6239 |
+ struct workqueue_attrs *attrs; |
6240 |
+@@ -5629,8 +5645,36 @@ static int __init init_workqueues(void) |
6241 |
+ !system_power_efficient_wq || |
6242 |
+ !system_freezable_power_efficient_wq); |
6243 |
+ |
6244 |
++ return 0; |
6245 |
++} |
6246 |
++ |
6247 |
++/** |
6248 |
++ * workqueue_init - bring workqueue subsystem fully online |
6249 |
++ * |
6250 |
++ * This is the latter half of two-staged workqueue subsystem initialization |
6251 |
++ * and invoked as soon as kthreads can be created and scheduled. |
6252 |
++ * Workqueues have been created and work items queued on them, but there |
6253 |
++ * are no kworkers executing the work items yet. Populate the worker pools |
6254 |
++ * with the initial workers and enable future kworker creations. |
6255 |
++ */ |
6256 |
++int __init workqueue_init(void) |
6257 |
++{ |
6258 |
++ struct worker_pool *pool; |
6259 |
++ int cpu, bkt; |
6260 |
++ |
6261 |
++ /* create the initial workers */ |
6262 |
++ for_each_online_cpu(cpu) { |
6263 |
++ for_each_cpu_worker_pool(pool, cpu) { |
6264 |
++ pool->flags &= ~POOL_DISASSOCIATED; |
6265 |
++ BUG_ON(!create_worker(pool)); |
6266 |
++ } |
6267 |
++ } |
6268 |
++ |
6269 |
++ hash_for_each(unbound_pool_hash, bkt, pool, hash_node) |
6270 |
++ BUG_ON(!create_worker(pool)); |
6271 |
++ |
6272 |
++ wq_online = true; |
6273 |
+ wq_watchdog_init(); |
6274 |
+ |
6275 |
+ return 0; |
6276 |
+ } |
6277 |
+-early_initcall(init_workqueues); |
6278 |
+diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug |
6279 |
+index e7addfcd302f4..95be8e1b12f60 100644 |
6280 |
+--- a/lib/Kconfig.debug |
6281 |
++++ b/lib/Kconfig.debug |
6282 |
+@@ -1177,6 +1177,33 @@ config STACKTRACE |
6283 |
+ It is also used by various kernel debugging features that require |
6284 |
+ stack trace generation. |
6285 |
+ |
6286 |
++config WARN_ALL_UNSEEDED_RANDOM |
6287 |
++ bool "Warn for all uses of unseeded randomness" |
6288 |
++ default n |
6289 |
++ help |
6290 |
++ Some parts of the kernel contain bugs relating to their use of |
6291 |
++ cryptographically secure random numbers before it's actually possible |
6292 |
++ to generate those numbers securely. This setting ensures that these |
6293 |
++ flaws don't go unnoticed, by enabling a message, should this ever |
6294 |
++ occur. This will allow people with obscure setups to know when things |
6295 |
++ are going wrong, so that they might contact developers about fixing |
6296 |
++ it. |
6297 |
++ |
6298 |
++ Unfortunately, on some models of some architectures getting |
6299 |
++ a fully seeded CRNG is extremely difficult, and so this can |
6300 |
++ result in dmesg getting spammed for a surprisingly long |
6301 |
++ time. This is really bad from a security perspective, and |
6302 |
++ so architecture maintainers really need to do what they can |
6303 |
++ to get the CRNG seeded sooner after the system is booted. |
6304 |
++ However, since users cannot do anything actionable to |
6305 |
++ address this, by default this option is disabled. |
6306 |
++ |
6307 |
++ Say Y here if you want to receive warnings for all uses of |
6308 |
++ unseeded randomness. This will be of use primarily for |
6309 |
++ those developers interersted in improving the security of |
6310 |
++ Linux kernels running on their architecture (or |
6311 |
++ subarchitecture). |
6312 |
++ |
6313 |
+ config DEBUG_KOBJECT |
6314 |
+ bool "kobject debugging" |
6315 |
+ depends on DEBUG_KERNEL |
6316 |
+diff --git a/lib/Makefile b/lib/Makefile |
6317 |
+index 7a55c52052810..775d6ef6d2eff 100644 |
6318 |
+--- a/lib/Makefile |
6319 |
++++ b/lib/Makefile |
6320 |
+@@ -234,3 +234,5 @@ KASAN_SANITIZE_ubsan.o := n |
6321 |
+ CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) |
6322 |
+ |
6323 |
+ obj-$(CONFIG_SBITMAP) += sbitmap.o |
6324 |
++ |
6325 |
++obj-y += crypto/ |
6326 |
+diff --git a/lib/chacha20.c b/lib/chacha20.c |
6327 |
+index 250ceed9ec9a8..5f6c222e939a9 100644 |
6328 |
+--- a/lib/chacha20.c |
6329 |
++++ b/lib/chacha20.c |
6330 |
+@@ -21,9 +21,9 @@ static inline u32 rotl32(u32 v, u8 n) |
6331 |
+ return (v << n) | (v >> (sizeof(v) * 8 - n)); |
6332 |
+ } |
6333 |
+ |
6334 |
+-extern void chacha20_block(u32 *state, void *stream) |
6335 |
++void chacha20_block(u32 *state, u8 *stream) |
6336 |
+ { |
6337 |
+- u32 x[16], *out = stream; |
6338 |
++ u32 x[16]; |
6339 |
+ int i; |
6340 |
+ |
6341 |
+ for (i = 0; i < ARRAY_SIZE(x); i++) |
6342 |
+@@ -72,7 +72,7 @@ extern void chacha20_block(u32 *state, void *stream) |
6343 |
+ } |
6344 |
+ |
6345 |
+ for (i = 0; i < ARRAY_SIZE(x); i++) |
6346 |
+- out[i] = cpu_to_le32(x[i] + state[i]); |
6347 |
++ put_unaligned_le32(x[i] + state[i], &stream[i * sizeof(u32)]); |
6348 |
+ |
6349 |
+ state[12]++; |
6350 |
+ } |
6351 |
+diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile |
6352 |
+new file mode 100644 |
6353 |
+index 0000000000000..d0bca68618f03 |
6354 |
+--- /dev/null |
6355 |
++++ b/lib/crypto/Makefile |
6356 |
+@@ -0,0 +1,7 @@ |
6357 |
++# SPDX-License-Identifier: GPL-2.0 |
6358 |
++ |
6359 |
++obj-y += libblake2s.o |
6360 |
++libblake2s-y += blake2s.o blake2s-generic.o |
6361 |
++ifneq ($(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS),y) |
6362 |
++libblake2s-y += blake2s-selftest.o |
6363 |
++endif |
6364 |
+diff --git a/lib/crypto/blake2s-generic.c b/lib/crypto/blake2s-generic.c |
6365 |
+new file mode 100644 |
6366 |
+index 0000000000000..04ff8df245136 |
6367 |
+--- /dev/null |
6368 |
++++ b/lib/crypto/blake2s-generic.c |
6369 |
+@@ -0,0 +1,111 @@ |
6370 |
++// SPDX-License-Identifier: GPL-2.0 OR MIT |
6371 |
++/* |
6372 |
++ * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@×××××.com>. All Rights Reserved. |
6373 |
++ * |
6374 |
++ * This is an implementation of the BLAKE2s hash and PRF functions. |
6375 |
++ * |
6376 |
++ * Information: https://blake2.net/ |
6377 |
++ * |
6378 |
++ */ |
6379 |
++ |
6380 |
++#include <crypto/internal/blake2s.h> |
6381 |
++#include <linux/types.h> |
6382 |
++#include <linux/string.h> |
6383 |
++#include <linux/kernel.h> |
6384 |
++#include <linux/module.h> |
6385 |
++#include <linux/init.h> |
6386 |
++#include <linux/bug.h> |
6387 |
++#include <asm/unaligned.h> |
6388 |
++ |
6389 |
++static const u8 blake2s_sigma[10][16] = { |
6390 |
++ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
6391 |
++ { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, |
6392 |
++ { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, |
6393 |
++ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, |
6394 |
++ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, |
6395 |
++ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, |
6396 |
++ { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, |
6397 |
++ { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, |
6398 |
++ { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, |
6399 |
++ { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, |
6400 |
++}; |
6401 |
++ |
6402 |
++static inline void blake2s_increment_counter(struct blake2s_state *state, |
6403 |
++ const u32 inc) |
6404 |
++{ |
6405 |
++ state->t[0] += inc; |
6406 |
++ state->t[1] += (state->t[0] < inc); |
6407 |
++} |
6408 |
++ |
6409 |
++void blake2s_compress_generic(struct blake2s_state *state,const u8 *block, |
6410 |
++ size_t nblocks, const u32 inc) |
6411 |
++{ |
6412 |
++ u32 m[16]; |
6413 |
++ u32 v[16]; |
6414 |
++ int i; |
6415 |
++ |
6416 |
++ WARN_ON(IS_ENABLED(DEBUG) && |
6417 |
++ (nblocks > 1 && inc != BLAKE2S_BLOCK_SIZE)); |
6418 |
++ |
6419 |
++ while (nblocks > 0) { |
6420 |
++ blake2s_increment_counter(state, inc); |
6421 |
++ memcpy(m, block, BLAKE2S_BLOCK_SIZE); |
6422 |
++ le32_to_cpu_array(m, ARRAY_SIZE(m)); |
6423 |
++ memcpy(v, state->h, 32); |
6424 |
++ v[ 8] = BLAKE2S_IV0; |
6425 |
++ v[ 9] = BLAKE2S_IV1; |
6426 |
++ v[10] = BLAKE2S_IV2; |
6427 |
++ v[11] = BLAKE2S_IV3; |
6428 |
++ v[12] = BLAKE2S_IV4 ^ state->t[0]; |
6429 |
++ v[13] = BLAKE2S_IV5 ^ state->t[1]; |
6430 |
++ v[14] = BLAKE2S_IV6 ^ state->f[0]; |
6431 |
++ v[15] = BLAKE2S_IV7 ^ state->f[1]; |
6432 |
++ |
6433 |
++#define G(r, i, a, b, c, d) do { \ |
6434 |
++ a += b + m[blake2s_sigma[r][2 * i + 0]]; \ |
6435 |
++ d = ror32(d ^ a, 16); \ |
6436 |
++ c += d; \ |
6437 |
++ b = ror32(b ^ c, 12); \ |
6438 |
++ a += b + m[blake2s_sigma[r][2 * i + 1]]; \ |
6439 |
++ d = ror32(d ^ a, 8); \ |
6440 |
++ c += d; \ |
6441 |
++ b = ror32(b ^ c, 7); \ |
6442 |
++} while (0) |
6443 |
++ |
6444 |
++#define ROUND(r) do { \ |
6445 |
++ G(r, 0, v[0], v[ 4], v[ 8], v[12]); \ |
6446 |
++ G(r, 1, v[1], v[ 5], v[ 9], v[13]); \ |
6447 |
++ G(r, 2, v[2], v[ 6], v[10], v[14]); \ |
6448 |
++ G(r, 3, v[3], v[ 7], v[11], v[15]); \ |
6449 |
++ G(r, 4, v[0], v[ 5], v[10], v[15]); \ |
6450 |
++ G(r, 5, v[1], v[ 6], v[11], v[12]); \ |
6451 |
++ G(r, 6, v[2], v[ 7], v[ 8], v[13]); \ |
6452 |
++ G(r, 7, v[3], v[ 4], v[ 9], v[14]); \ |
6453 |
++} while (0) |
6454 |
++ ROUND(0); |
6455 |
++ ROUND(1); |
6456 |
++ ROUND(2); |
6457 |
++ ROUND(3); |
6458 |
++ ROUND(4); |
6459 |
++ ROUND(5); |
6460 |
++ ROUND(6); |
6461 |
++ ROUND(7); |
6462 |
++ ROUND(8); |
6463 |
++ ROUND(9); |
6464 |
++ |
6465 |
++#undef G |
6466 |
++#undef ROUND |
6467 |
++ |
6468 |
++ for (i = 0; i < 8; ++i) |
6469 |
++ state->h[i] ^= v[i] ^ v[i + 8]; |
6470 |
++ |
6471 |
++ block += BLAKE2S_BLOCK_SIZE; |
6472 |
++ --nblocks; |
6473 |
++ } |
6474 |
++} |
6475 |
++ |
6476 |
++EXPORT_SYMBOL(blake2s_compress_generic); |
6477 |
++ |
6478 |
++MODULE_LICENSE("GPL v2"); |
6479 |
++MODULE_DESCRIPTION("BLAKE2s hash function"); |
6480 |
++MODULE_AUTHOR("Jason A. Donenfeld <Jason@×××××.com>"); |
6481 |
+diff --git a/lib/crypto/blake2s-selftest.c b/lib/crypto/blake2s-selftest.c |
6482 |
+new file mode 100644 |
6483 |
+index 0000000000000..7a9edc96ddddf |
6484 |
+--- /dev/null |
6485 |
++++ b/lib/crypto/blake2s-selftest.c |
6486 |
+@@ -0,0 +1,591 @@ |
6487 |
++// SPDX-License-Identifier: GPL-2.0 OR MIT |
6488 |
++/* |
6489 |
++ * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@×××××.com>. All Rights Reserved. |
6490 |
++ */ |
6491 |
++ |
6492 |
++#include <crypto/blake2s.h> |
6493 |
++#include <linux/string.h> |
6494 |
++ |
6495 |
++/* |
6496 |
++ * blake2s_testvecs[] generated with the program below (using libb2-dev and |
6497 |
++ * libssl-dev [OpenSSL]) |
6498 |
++ * |
6499 |
++ * #include <blake2.h> |
6500 |
++ * #include <stdint.h> |
6501 |
++ * #include <stdio.h> |
6502 |
++ * |
6503 |
++ * #include <openssl/evp.h> |
6504 |
++ * |
6505 |
++ * #define BLAKE2S_TESTVEC_COUNT 256 |
6506 |
++ * |
6507 |
++ * static void print_vec(const uint8_t vec[], int len) |
6508 |
++ * { |
6509 |
++ * int i; |
6510 |
++ * |
6511 |
++ * printf(" { "); |
6512 |
++ * for (i = 0; i < len; i++) { |
6513 |
++ * if (i && (i % 12) == 0) |
6514 |
++ * printf("\n "); |
6515 |
++ * printf("0x%02x, ", vec[i]); |
6516 |
++ * } |
6517 |
++ * printf("},\n"); |
6518 |
++ * } |
6519 |
++ * |
6520 |
++ * int main(void) |
6521 |
++ * { |
6522 |
++ * uint8_t key[BLAKE2S_KEYBYTES]; |
6523 |
++ * uint8_t buf[BLAKE2S_TESTVEC_COUNT]; |
6524 |
++ * uint8_t hash[BLAKE2S_OUTBYTES]; |
6525 |
++ * int i, j; |
6526 |
++ * |
6527 |
++ * key[0] = key[1] = 1; |
6528 |
++ * for (i = 2; i < BLAKE2S_KEYBYTES; ++i) |
6529 |
++ * key[i] = key[i - 2] + key[i - 1]; |
6530 |
++ * |
6531 |
++ * for (i = 0; i < BLAKE2S_TESTVEC_COUNT; ++i) |
6532 |
++ * buf[i] = (uint8_t)i; |
6533 |
++ * |
6534 |
++ * printf("static const u8 blake2s_testvecs[][BLAKE2S_HASH_SIZE] __initconst = {\n"); |
6535 |
++ * |
6536 |
++ * for (i = 0; i < BLAKE2S_TESTVEC_COUNT; ++i) { |
6537 |
++ * int outlen = 1 + i % BLAKE2S_OUTBYTES; |
6538 |
++ * int keylen = (13 * i) % (BLAKE2S_KEYBYTES + 1); |
6539 |
++ * |
6540 |
++ * blake2s(hash, buf, key + BLAKE2S_KEYBYTES - keylen, outlen, i, |
6541 |
++ * keylen); |
6542 |
++ * print_vec(hash, outlen); |
6543 |
++ * } |
6544 |
++ * printf("};\n\n"); |
6545 |
++ * |
6546 |
++ * return 0; |
6547 |
++ *} |
6548 |
++ */ |
6549 |
++static const u8 blake2s_testvecs[][BLAKE2S_HASH_SIZE] __initconst = { |
6550 |
++ { 0xa1, }, |
6551 |
++ { 0x7c, 0x89, }, |
6552 |
++ { 0x74, 0x0e, 0xd4, }, |
6553 |
++ { 0x47, 0x0c, 0x21, 0x15, }, |
6554 |
++ { 0x18, 0xd6, 0x9c, 0xa6, 0xc4, }, |
6555 |
++ { 0x13, 0x5d, 0x16, 0x63, 0x2e, 0xf9, }, |
6556 |
++ { 0x2c, 0xb5, 0x04, 0xb7, 0x99, 0xe2, 0x73, }, |
6557 |
++ { 0x9a, 0x0f, 0xd2, 0x39, 0xd6, 0x68, 0x1b, 0x92, }, |
6558 |
++ { 0xc8, 0xde, 0x7a, 0xea, 0x2f, 0xf4, 0xd2, 0xe3, 0x2b, }, |
6559 |
++ { 0x5b, 0xf9, 0x43, 0x52, 0x0c, 0x12, 0xba, 0xb5, 0x93, 0x9f, }, |
6560 |
++ { 0xc6, 0x2c, 0x4e, 0x80, 0xfc, 0x32, 0x5b, 0x33, 0xb8, 0xb8, 0x0a, }, |
6561 |
++ { 0xa7, 0x5c, 0xfd, 0x3a, 0xcc, 0xbf, 0x90, 0xca, 0xb7, 0x97, 0xde, 0xd8, }, |
6562 |
++ { 0x66, 0xca, 0x3c, 0xc4, 0x19, 0xef, 0x92, 0x66, 0x3f, 0x21, 0x8f, 0xda, |
6563 |
++ 0xb7, }, |
6564 |
++ { 0xba, 0xe5, 0xbb, 0x30, 0x25, 0x94, 0x6d, 0xc3, 0x89, 0x09, 0xc4, 0x25, |
6565 |
++ 0x52, 0x3e, }, |
6566 |
++ { 0xa2, 0xef, 0x0e, 0x52, 0x0b, 0x5f, 0xa2, 0x01, 0x6d, 0x0a, 0x25, 0xbc, |
6567 |
++ 0x57, 0xe2, 0x27, }, |
6568 |
++ { 0x4f, 0xe0, 0xf9, 0x52, 0x12, 0xda, 0x84, 0xb7, 0xab, 0xae, 0xb0, 0xa6, |
6569 |
++ 0x47, 0x2a, 0xc7, 0xf5, }, |
6570 |
++ { 0x56, 0xe7, 0xa8, 0x1c, 0x4c, 0xca, 0xed, 0x90, 0x31, 0xec, 0x87, 0x43, |
6571 |
++ 0xe7, 0x72, 0x08, 0xec, 0xbe, }, |
6572 |
++ { 0x7e, 0xdf, 0x80, 0x1c, 0x93, 0x33, 0xfd, 0x53, 0x44, 0xba, 0xfd, 0x96, |
6573 |
++ 0xe1, 0xbb, 0xb5, 0x65, 0xa5, 0x00, }, |
6574 |
++ { 0xec, 0x6b, 0xed, 0xf7, 0x7b, 0x62, 0x1d, 0x7d, 0xf4, 0x82, 0xf3, 0x1e, |
6575 |
++ 0x18, 0xff, 0x2b, 0xc4, 0x06, 0x20, 0x2a, }, |
6576 |
++ { 0x74, 0x98, 0xd7, 0x68, 0x63, 0xed, 0x87, 0xe4, 0x5d, 0x8d, 0x9e, 0x1d, |
6577 |
++ 0xfd, 0x2a, 0xbb, 0x86, 0xac, 0xe9, 0x2a, 0x89, }, |
6578 |
++ { 0x89, 0xc3, 0x88, 0xce, 0x2b, 0x33, 0x1e, 0x10, 0xd1, 0x37, 0x20, 0x86, |
6579 |
++ 0x28, 0x43, 0x70, 0xd9, 0xfb, 0x96, 0xd9, 0xb5, 0xd3, }, |
6580 |
++ { 0xcb, 0x56, 0x74, 0x41, 0x8d, 0x80, 0x01, 0x9a, 0x6b, 0x38, 0xe1, 0x41, |
6581 |
++ 0xad, 0x9c, 0x62, 0x74, 0xce, 0x35, 0xd5, 0x6c, 0x89, 0x6e, }, |
6582 |
++ { 0x79, 0xaf, 0x94, 0x59, 0x99, 0x26, 0xe1, 0xc9, 0x34, 0xfe, 0x7c, 0x22, |
6583 |
++ 0xf7, 0x43, 0xd7, 0x65, 0xd4, 0x48, 0x18, 0xac, 0x3d, 0xfd, 0x93, }, |
6584 |
++ { 0x85, 0x0d, 0xff, 0xb8, 0x3e, 0x87, 0x41, 0xb0, 0x95, 0xd3, 0x3d, 0x00, |
6585 |
++ 0x47, 0x55, 0x9e, 0xd2, 0x69, 0xea, 0xbf, 0xe9, 0x7a, 0x2d, 0x61, 0x45, }, |
6586 |
++ { 0x03, 0xe0, 0x85, 0xec, 0x54, 0xb5, 0x16, 0x53, 0xa8, 0xc4, 0x71, 0xe9, |
6587 |
++ 0x6a, 0xe7, 0xcb, 0xc4, 0x15, 0x02, 0xfc, 0x34, 0xa4, 0xa4, 0x28, 0x13, |
6588 |
++ 0xd1, }, |
6589 |
++ { 0xe3, 0x34, 0x4b, 0xe1, 0xd0, 0x4b, 0x55, 0x61, 0x8f, 0xc0, 0x24, 0x05, |
6590 |
++ 0xe6, 0xe0, 0x3d, 0x70, 0x24, 0x4d, 0xda, 0xb8, 0x91, 0x05, 0x29, 0x07, |
6591 |
++ 0x01, 0x3e, }, |
6592 |
++ { 0x61, 0xff, 0x01, 0x72, 0xb1, 0x4d, 0xf6, 0xfe, 0xd1, 0xd1, 0x08, 0x74, |
6593 |
++ 0xe6, 0x91, 0x44, 0xeb, 0x61, 0xda, 0x40, 0xaf, 0xfc, 0x8c, 0x91, 0x6b, |
6594 |
++ 0xec, 0x13, 0xed, }, |
6595 |
++ { 0xd4, 0x40, 0xd2, 0xa0, 0x7f, 0xc1, 0x58, 0x0c, 0x85, 0xa0, 0x86, 0xc7, |
6596 |
++ 0x86, 0xb9, 0x61, 0xc9, 0xea, 0x19, 0x86, 0x1f, 0xab, 0x07, 0xce, 0x37, |
6597 |
++ 0x72, 0x67, 0x09, 0xfc, }, |
6598 |
++ { 0x9e, 0xf8, 0x18, 0x67, 0x93, 0x10, 0x9b, 0x39, 0x75, 0xe8, 0x8b, 0x38, |
6599 |
++ 0x82, 0x7d, 0xb8, 0xb7, 0xa5, 0xaf, 0xe6, 0x6a, 0x22, 0x5e, 0x1f, 0x9c, |
6600 |
++ 0x95, 0x29, 0x19, 0xf2, 0x4b, }, |
6601 |
++ { 0xc8, 0x62, 0x25, 0xf5, 0x98, 0xc9, 0xea, 0xe5, 0x29, 0x3a, 0xd3, 0x22, |
6602 |
++ 0xeb, 0xeb, 0x07, 0x7c, 0x15, 0x07, 0xee, 0x15, 0x61, 0xbb, 0x05, 0x30, |
6603 |
++ 0x99, 0x7f, 0x11, 0xf6, 0x0a, 0x1d, }, |
6604 |
++ { 0x68, 0x70, 0xf7, 0x90, 0xa1, 0x8b, 0x1f, 0x0f, 0xbb, 0xce, 0xd2, 0x0e, |
6605 |
++ 0x33, 0x1f, 0x7f, 0xa9, 0x78, 0xa8, 0xa6, 0x81, 0x66, 0xab, 0x8d, 0xcd, |
6606 |
++ 0x58, 0x55, 0x3a, 0x0b, 0x7a, 0xdb, 0xb5, }, |
6607 |
++ { 0xdd, 0x35, 0xd2, 0xb4, 0xf6, 0xc7, 0xea, 0xab, 0x64, 0x24, 0x4e, 0xfe, |
6608 |
++ 0xe5, 0x3d, 0x4e, 0x95, 0x8b, 0x6d, 0x6c, 0xbc, 0xb0, 0xf8, 0x88, 0x61, |
6609 |
++ 0x09, 0xb7, 0x78, 0xa3, 0x31, 0xfe, 0xd9, 0x2f, }, |
6610 |
++ { 0x0a, }, |
6611 |
++ { 0x6e, 0xd4, }, |
6612 |
++ { 0x64, 0xe9, 0xd1, }, |
6613 |
++ { 0x30, 0xdd, 0x71, 0xef, }, |
6614 |
++ { 0x11, 0xb5, 0x0c, 0x87, 0xc9, }, |
6615 |
++ { 0x06, 0x1c, 0x6d, 0x04, 0x82, 0xd0, }, |
6616 |
++ { 0x5c, 0x42, 0x0b, 0xee, 0xc5, 0x9c, 0xb2, }, |
6617 |
++ { 0xe8, 0x29, 0xd6, 0xb4, 0x5d, 0xf7, 0x2b, 0x93, }, |
6618 |
++ { 0x18, 0xca, 0x27, 0x72, 0x43, 0x39, 0x16, 0xbc, 0x6a, }, |
6619 |
++ { 0x39, 0x8f, 0xfd, 0x64, 0xf5, 0x57, 0x23, 0xb0, 0x45, 0xf8, }, |
6620 |
++ { 0xbb, 0x3a, 0x78, 0x6b, 0x02, 0x1d, 0x0b, 0x16, 0xe3, 0xb2, 0x9a, }, |
6621 |
++ { 0xb8, 0xb4, 0x0b, 0xe5, 0xd4, 0x1d, 0x0d, 0x85, 0x49, 0x91, 0x35, 0xfa, }, |
6622 |
++ { 0x6d, 0x48, 0x2a, 0x0c, 0x42, 0x08, 0xbd, 0xa9, 0x78, 0x6f, 0x18, 0xaf, |
6623 |
++ 0xe2, }, |
6624 |
++ { 0x10, 0x45, 0xd4, 0x58, 0x88, 0xec, 0x4e, 0x1e, 0xf6, 0x14, 0x92, 0x64, |
6625 |
++ 0x7e, 0xb0, }, |
6626 |
++ { 0x8b, 0x0b, 0x95, 0xee, 0x92, 0xc6, 0x3b, 0x91, 0xf1, 0x1e, 0xeb, 0x51, |
6627 |
++ 0x98, 0x0a, 0x8d, }, |
6628 |
++ { 0xa3, 0x50, 0x4d, 0xa5, 0x1d, 0x03, 0x68, 0xe9, 0x57, 0x78, 0xd6, 0x04, |
6629 |
++ 0xf1, 0xc3, 0x94, 0xd8, }, |
6630 |
++ { 0xb8, 0x66, 0x6e, 0xdd, 0x46, 0x15, 0xae, 0x3d, 0x83, 0x7e, 0xcf, 0xe7, |
6631 |
++ 0x2c, 0xe8, 0x8f, 0xc7, 0x34, }, |
6632 |
++ { 0x2e, 0xc0, 0x1f, 0x29, 0xea, 0xf6, 0xb9, 0xe2, 0xc2, 0x93, 0xeb, 0x41, |
6633 |
++ 0x0d, 0xf0, 0x0a, 0x13, 0x0e, 0xa2, }, |
6634 |
++ { 0x71, 0xb8, 0x33, 0xa9, 0x1b, 0xac, 0xf1, 0xb5, 0x42, 0x8f, 0x5e, 0x81, |
6635 |
++ 0x34, 0x43, 0xb7, 0xa4, 0x18, 0x5c, 0x47, }, |
6636 |
++ { 0xda, 0x45, 0xb8, 0x2e, 0x82, 0x1e, 0xc0, 0x59, 0x77, 0x9d, 0xfa, 0xb4, |
6637 |
++ 0x1c, 0x5e, 0xa0, 0x2b, 0x33, 0x96, 0x5a, 0x58, }, |
6638 |
++ { 0xe3, 0x09, 0x05, 0xa9, 0xeb, 0x48, 0x13, 0xad, 0x71, 0x88, 0x81, 0x9a, |
6639 |
++ 0x3e, 0x2c, 0xe1, 0x23, 0x99, 0x13, 0x35, 0x9f, 0xb5, }, |
6640 |
++ { 0xb7, 0x86, 0x2d, 0x16, 0xe1, 0x04, 0x00, 0x47, 0x47, 0x61, 0x31, 0xfb, |
6641 |
++ 0x14, 0xac, 0xd8, 0xe9, 0xe3, 0x49, 0xbd, 0xf7, 0x9c, 0x3f, }, |
6642 |
++ { 0x7f, 0xd9, 0x95, 0xa8, 0xa7, 0xa0, 0xcc, 0xba, 0xef, 0xb1, 0x0a, 0xa9, |
6643 |
++ 0x21, 0x62, 0x08, 0x0f, 0x1b, 0xff, 0x7b, 0x9d, 0xae, 0xb2, 0x95, }, |
6644 |
++ { 0x85, 0x99, 0xea, 0x33, 0xe0, 0x56, 0xff, 0x13, 0xc6, 0x61, 0x8c, 0xf9, |
6645 |
++ 0x57, 0x05, 0x03, 0x11, 0xf9, 0xfb, 0x3a, 0xf7, 0xce, 0xbb, 0x52, 0x30, }, |
6646 |
++ { 0xb2, 0x72, 0x9c, 0xf8, 0x77, 0x4e, 0x8f, 0x6b, 0x01, 0x6c, 0xff, 0x4e, |
6647 |
++ 0x4f, 0x02, 0xd2, 0xbc, 0xeb, 0x51, 0x28, 0x99, 0x50, 0xab, 0xc4, 0x42, |
6648 |
++ 0xe3, }, |
6649 |
++ { 0x8b, 0x0a, 0xb5, 0x90, 0x8f, 0xf5, 0x7b, 0xdd, 0xba, 0x47, 0x37, 0xc9, |
6650 |
++ 0x2a, 0xd5, 0x4b, 0x25, 0x08, 0x8b, 0x02, 0x17, 0xa7, 0x9e, 0x6b, 0x6e, |
6651 |
++ 0xe3, 0x90, }, |
6652 |
++ { 0x90, 0xdd, 0xf7, 0x75, 0xa7, 0xa3, 0x99, 0x5e, 0x5b, 0x7d, 0x75, 0xc3, |
6653 |
++ 0x39, 0x6b, 0xa0, 0xe2, 0x44, 0x53, 0xb1, 0x9e, 0xc8, 0xf1, 0x77, 0x10, |
6654 |
++ 0x58, 0x06, 0x9a, }, |
6655 |
++ { 0x99, 0x52, 0xf0, 0x49, 0xa8, 0x8c, 0xec, 0xa6, 0x97, 0x32, 0x13, 0xb5, |
6656 |
++ 0xf7, 0xa3, 0x8e, 0xfb, 0x4b, 0x59, 0x31, 0x3d, 0x01, 0x59, 0x98, 0x5d, |
6657 |
++ 0x53, 0x03, 0x1a, 0x39, }, |
6658 |
++ { 0x9f, 0xe0, 0xc2, 0xe5, 0x5d, 0x93, 0xd6, 0x9b, 0x47, 0x8f, 0x9b, 0xe0, |
6659 |
++ 0x26, 0x35, 0x84, 0x20, 0x1d, 0xc5, 0x53, 0x10, 0x0f, 0x22, 0xb9, 0xb5, |
6660 |
++ 0xd4, 0x36, 0xb1, 0xac, 0x73, }, |
6661 |
++ { 0x30, 0x32, 0x20, 0x3b, 0x10, 0x28, 0xec, 0x1f, 0x4f, 0x9b, 0x47, 0x59, |
6662 |
++ 0xeb, 0x7b, 0xee, 0x45, 0xfb, 0x0c, 0x49, 0xd8, 0x3d, 0x69, 0xbd, 0x90, |
6663 |
++ 0x2c, 0xf0, 0x9e, 0x8d, 0xbf, 0xd5, }, |
6664 |
++ { 0x2a, 0x37, 0x73, 0x7f, 0xf9, 0x96, 0x19, 0xaa, 0x25, 0xd8, 0x13, 0x28, |
6665 |
++ 0x01, 0x29, 0x89, 0xdf, 0x6e, 0x0c, 0x9b, 0x43, 0x44, 0x51, 0xe9, 0x75, |
6666 |
++ 0x26, 0x0c, 0xb7, 0x87, 0x66, 0x0b, 0x5f, }, |
6667 |
++ { 0x23, 0xdf, 0x96, 0x68, 0x91, 0x86, 0xd0, 0x93, 0x55, 0x33, 0x24, 0xf6, |
6668 |
++ 0xba, 0x08, 0x75, 0x5b, 0x59, 0x11, 0x69, 0xb8, 0xb9, 0xe5, 0x2c, 0x77, |
6669 |
++ 0x02, 0xf6, 0x47, 0xee, 0x81, 0xdd, 0xb9, 0x06, }, |
6670 |
++ { 0x9d, }, |
6671 |
++ { 0x9d, 0x7d, }, |
6672 |
++ { 0xfd, 0xc3, 0xda, }, |
6673 |
++ { 0xe8, 0x82, 0xcd, 0x21, }, |
6674 |
++ { 0xc3, 0x1d, 0x42, 0x4c, 0x74, }, |
6675 |
++ { 0xe9, 0xda, 0xf1, 0xa2, 0xe5, 0x7c, }, |
6676 |
++ { 0x52, 0xb8, 0x6f, 0x81, 0x5c, 0x3a, 0x4c, }, |
6677 |
++ { 0x5b, 0x39, 0x26, 0xfc, 0x92, 0x5e, 0xe0, 0x49, }, |
6678 |
++ { 0x59, 0xe4, 0x7c, 0x93, 0x1c, 0xf9, 0x28, 0x93, 0xde, }, |
6679 |
++ { 0xde, 0xdf, 0xb2, 0x43, 0x61, 0x0b, 0x86, 0x16, 0x4c, 0x2e, }, |
6680 |
++ { 0x14, 0x8f, 0x75, 0x51, 0xaf, 0xb9, 0xee, 0x51, 0x5a, 0xae, 0x23, }, |
6681 |
++ { 0x43, 0x5f, 0x50, 0xd5, 0x70, 0xb0, 0x5b, 0x87, 0xf5, 0xd9, 0xb3, 0x6d, }, |
6682 |
++ { 0x66, 0x0a, 0x64, 0x93, 0x79, 0x71, 0x94, 0x40, 0xb7, 0x68, 0x2d, 0xd3, |
6683 |
++ 0x63, }, |
6684 |
++ { 0x15, 0x00, 0xc4, 0x0c, 0x7d, 0x1b, 0x10, 0xa9, 0x73, 0x1b, 0x90, 0x6f, |
6685 |
++ 0xe6, 0xa9, }, |
6686 |
++ { 0x34, 0x75, 0xf3, 0x86, 0x8f, 0x56, 0xcf, 0x2a, 0x0a, 0xf2, 0x62, 0x0a, |
6687 |
++ 0xf6, 0x0e, 0x20, }, |
6688 |
++ { 0xb1, 0xde, 0xc9, 0xf5, 0xdb, 0xf3, 0x2f, 0x4c, 0xd6, 0x41, 0x7d, 0x39, |
6689 |
++ 0x18, 0x3e, 0xc7, 0xc3, }, |
6690 |
++ { 0xc5, 0x89, 0xb2, 0xf8, 0xb8, 0xc0, 0xa3, 0xb9, 0x3b, 0x10, 0x6d, 0x7c, |
6691 |
++ 0x92, 0xfc, 0x7f, 0x34, 0x41, }, |
6692 |
++ { 0xc4, 0xd8, 0xef, 0xba, 0xef, 0xd2, 0xaa, 0xc5, 0x6c, 0x8e, 0x3e, 0xbb, |
6693 |
++ 0x12, 0xfc, 0x0f, 0x72, 0xbf, 0x0f, }, |
6694 |
++ { 0xdd, 0x91, 0xd1, 0x15, 0x9e, 0x7d, 0xf8, 0xc1, 0xb9, 0x14, 0x63, 0x96, |
6695 |
++ 0xb5, 0xcb, 0x83, 0x1d, 0x35, 0x1c, 0xec, }, |
6696 |
++ { 0xa9, 0xf8, 0x52, 0xc9, 0x67, 0x76, 0x2b, 0xad, 0xfb, 0xd8, 0x3a, 0xa6, |
6697 |
++ 0x74, 0x02, 0xae, 0xb8, 0x25, 0x2c, 0x63, 0x49, }, |
6698 |
++ { 0x77, 0x1f, 0x66, 0x70, 0xfd, 0x50, 0x29, 0xaa, 0xeb, 0xdc, 0xee, 0xba, |
6699 |
++ 0x75, 0x98, 0xdc, 0x93, 0x12, 0x3f, 0xdc, 0x7c, 0x38, }, |
6700 |
++ { 0xe2, 0xe1, 0x89, 0x5c, 0x37, 0x38, 0x6a, 0xa3, 0x40, 0xac, 0x3f, 0xb0, |
6701 |
++ 0xca, 0xfc, 0xa7, 0xf3, 0xea, 0xf9, 0x0f, 0x5d, 0x8e, 0x39, }, |
6702 |
++ { 0x0f, 0x67, 0xc8, 0x38, 0x01, 0xb1, 0xb7, 0xb8, 0xa2, 0xe7, 0x0a, 0x6d, |
6703 |
++ 0xd2, 0x63, 0x69, 0x9e, 0xcc, 0xf0, 0xf2, 0xbe, 0x9b, 0x98, 0xdd, }, |
6704 |
++ { 0x13, 0xe1, 0x36, 0x30, 0xfe, 0xc6, 0x01, 0x8a, 0xa1, 0x63, 0x96, 0x59, |
6705 |
++ 0xc2, 0xa9, 0x68, 0x3f, 0x58, 0xd4, 0x19, 0x0c, 0x40, 0xf3, 0xde, 0x02, }, |
6706 |
++ { 0xa3, 0x9e, 0xce, 0xda, 0x42, 0xee, 0x8c, 0x6c, 0x5a, 0x7d, 0xdc, 0x89, |
6707 |
++ 0x02, 0x77, 0xdd, 0xe7, 0x95, 0xbb, 0xff, 0x0d, 0xa4, 0xb5, 0x38, 0x1e, |
6708 |
++ 0xaf, }, |
6709 |
++ { 0x9a, 0xf6, 0xb5, 0x9a, 0x4f, 0xa9, 0x4f, 0x2c, 0x35, 0x3c, 0x24, 0xdc, |
6710 |
++ 0x97, 0x6f, 0xd9, 0xa1, 0x7d, 0x1a, 0x85, 0x0b, 0xf5, 0xda, 0x2e, 0xe7, |
6711 |
++ 0xb1, 0x1d, }, |
6712 |
++ { 0x84, 0x1e, 0x8e, 0x3d, 0x45, 0xa5, 0xf2, 0x27, 0xf3, 0x31, 0xfe, 0xb9, |
6713 |
++ 0xfb, 0xc5, 0x45, 0x99, 0x99, 0xdd, 0x93, 0x43, 0x02, 0xee, 0x58, 0xaf, |
6714 |
++ 0xee, 0x6a, 0xbe, }, |
6715 |
++ { 0x07, 0x2f, 0xc0, 0xa2, 0x04, 0xc4, 0xab, 0x7c, 0x26, 0xbb, 0xa8, 0xd8, |
6716 |
++ 0xe3, 0x1c, 0x75, 0x15, 0x64, 0x5d, 0x02, 0x6a, 0xf0, 0x86, 0xe9, 0xcd, |
6717 |
++ 0x5c, 0xef, 0xa3, 0x25, }, |
6718 |
++ { 0x2f, 0x3b, 0x1f, 0xb5, 0x91, 0x8f, 0x86, 0xe0, 0xdc, 0x31, 0x48, 0xb6, |
6719 |
++ 0xa1, 0x8c, 0xfd, 0x75, 0xbb, 0x7d, 0x3d, 0xc1, 0xf0, 0x10, 0x9a, 0xd8, |
6720 |
++ 0x4b, 0x0e, 0xe3, 0x94, 0x9f, }, |
6721 |
++ { 0x29, 0xbb, 0x8f, 0x6c, 0xd1, 0xf2, 0xb6, 0xaf, 0xe5, 0xe3, 0x2d, 0xdc, |
6722 |
++ 0x6f, 0xa4, 0x53, 0x88, 0xd8, 0xcf, 0x4d, 0x45, 0x42, 0x62, 0xdb, 0xdf, |
6723 |
++ 0xf8, 0x45, 0xc2, 0x13, 0xec, 0x35, }, |
6724 |
++ { 0x06, 0x3c, 0xe3, 0x2c, 0x15, 0xc6, 0x43, 0x03, 0x81, 0xfb, 0x08, 0x76, |
6725 |
++ 0x33, 0xcb, 0x02, 0xc1, 0xba, 0x33, 0xe5, 0xe0, 0xd1, 0x92, 0xa8, 0x46, |
6726 |
++ 0x28, 0x3f, 0x3e, 0x9d, 0x2c, 0x44, 0x54, }, |
6727 |
++ { 0xea, 0xbb, 0x96, 0xf8, 0xd1, 0x8b, 0x04, 0x11, 0x40, 0x78, 0x42, 0x02, |
6728 |
++ 0x19, 0xd1, 0xbc, 0x65, 0x92, 0xd3, 0xc3, 0xd6, 0xd9, 0x19, 0xe7, 0xc3, |
6729 |
++ 0x40, 0x97, 0xbd, 0xd4, 0xed, 0xfa, 0x5e, 0x28, }, |
6730 |
++ { 0x02, }, |
6731 |
++ { 0x52, 0xa8, }, |
6732 |
++ { 0x38, 0x25, 0x0d, }, |
6733 |
++ { 0xe3, 0x04, 0xd4, 0x92, }, |
6734 |
++ { 0x97, 0xdb, 0xf7, 0x81, 0xca, }, |
6735 |
++ { 0x8a, 0x56, 0x9d, 0x62, 0x56, 0xcc, }, |
6736 |
++ { 0xa1, 0x8e, 0x3c, 0x72, 0x8f, 0x63, 0x03, }, |
6737 |
++ { 0xf7, 0xf3, 0x39, 0x09, 0x0a, 0xa1, 0xbb, 0x23, }, |
6738 |
++ { 0x6b, 0x03, 0xc0, 0xe9, 0xd9, 0x83, 0x05, 0x22, 0x01, }, |
6739 |
++ { 0x1b, 0x4b, 0xf5, 0xd6, 0x4f, 0x05, 0x75, 0x91, 0x4c, 0x7f, }, |
6740 |
++ { 0x4c, 0x8c, 0x25, 0x20, 0x21, 0xcb, 0xc2, 0x4b, 0x3a, 0x5b, 0x8d, }, |
6741 |
++ { 0x56, 0xe2, 0x77, 0xa0, 0xb6, 0x9f, 0x81, 0xec, 0x83, 0x75, 0xc4, 0xf9, }, |
6742 |
++ { 0x71, 0x70, 0x0f, 0xad, 0x4d, 0x35, 0x81, 0x9d, 0x88, 0x69, 0xf9, 0xaa, |
6743 |
++ 0xd3, }, |
6744 |
++ { 0x50, 0x6e, 0x86, 0x6e, 0x43, 0xc0, 0xc2, 0x44, 0xc2, 0xe2, 0xa0, 0x1c, |
6745 |
++ 0xb7, 0x9a, }, |
6746 |
++ { 0xe4, 0x7e, 0x72, 0xc6, 0x12, 0x8e, 0x7c, 0xfc, 0xbd, 0xe2, 0x08, 0x31, |
6747 |
++ 0x3d, 0x47, 0x3d, }, |
6748 |
++ { 0x08, 0x97, 0x5b, 0x80, 0xae, 0xc4, 0x1d, 0x50, 0x77, 0xdf, 0x1f, 0xd0, |
6749 |
++ 0x24, 0xf0, 0x17, 0xc0, }, |
6750 |
++ { 0x01, 0xb6, 0x29, 0xf4, 0xaf, 0x78, 0x5f, 0xb6, 0x91, 0xdd, 0x76, 0x76, |
6751 |
++ 0xd2, 0xfd, 0x0c, 0x47, 0x40, }, |
6752 |
++ { 0xa1, 0xd8, 0x09, 0x97, 0x7a, 0xa6, 0xc8, 0x94, 0xf6, 0x91, 0x7b, 0xae, |
6753 |
++ 0x2b, 0x9f, 0x0d, 0x83, 0x48, 0xf7, }, |
6754 |
++ { 0x12, 0xd5, 0x53, 0x7d, 0x9a, 0xb0, 0xbe, 0xd9, 0xed, 0xe9, 0x9e, 0xee, |
6755 |
++ 0x61, 0x5b, 0x42, 0xf2, 0xc0, 0x73, 0xc0, }, |
6756 |
++ { 0xd5, 0x77, 0xd6, 0x5c, 0x6e, 0xa5, 0x69, 0x2b, 0x3b, 0x8c, 0xd6, 0x7d, |
6757 |
++ 0x1d, 0xbe, 0x2c, 0xa1, 0x02, 0x21, 0xcd, 0x29, }, |
6758 |
++ { 0xa4, 0x98, 0x80, 0xca, 0x22, 0xcf, 0x6a, 0xab, 0x5e, 0x40, 0x0d, 0x61, |
6759 |
++ 0x08, 0x21, 0xef, 0xc0, 0x6c, 0x52, 0xb4, 0xb0, 0x53, }, |
6760 |
++ { 0xbf, 0xaf, 0x8f, 0x3b, 0x7a, 0x97, 0x33, 0xe5, 0xca, 0x07, 0x37, 0xfd, |
6761 |
++ 0x15, 0xdf, 0xce, 0x26, 0x2a, 0xb1, 0xa7, 0x0b, 0xb3, 0xac, }, |
6762 |
++ { 0x16, 0x22, 0xe1, 0xbc, 0x99, 0x4e, 0x01, 0xf0, 0xfa, 0xff, 0x8f, 0xa5, |
6763 |
++ 0x0c, 0x61, 0xb0, 0xad, 0xcc, 0xb1, 0xe1, 0x21, 0x46, 0xfa, 0x2e, }, |
6764 |
++ { 0x11, 0x5b, 0x0b, 0x2b, 0xe6, 0x14, 0xc1, 0xd5, 0x4d, 0x71, 0x5e, 0x17, |
6765 |
++ 0xea, 0x23, 0xdd, 0x6c, 0xbd, 0x1d, 0xbe, 0x12, 0x1b, 0xee, 0x4c, 0x1a, }, |
6766 |
++ { 0x40, 0x88, 0x22, 0xf3, 0x20, 0x6c, 0xed, 0xe1, 0x36, 0x34, 0x62, 0x2c, |
6767 |
++ 0x98, 0x83, 0x52, 0xe2, 0x25, 0xee, 0xe9, 0xf5, 0xe1, 0x17, 0xf0, 0x5c, |
6768 |
++ 0xae, }, |
6769 |
++ { 0xc3, 0x76, 0x37, 0xde, 0x95, 0x8c, 0xca, 0x2b, 0x0c, 0x23, 0xe7, 0xb5, |
6770 |
++ 0x38, 0x70, 0x61, 0xcc, 0xff, 0xd3, 0x95, 0x7b, 0xf3, 0xff, 0x1f, 0x9d, |
6771 |
++ 0x59, 0x00, }, |
6772 |
++ { 0x0c, 0x19, 0x52, 0x05, 0x22, 0x53, 0xcb, 0x48, 0xd7, 0x10, 0x0e, 0x7e, |
6773 |
++ 0x14, 0x69, 0xb5, 0xa2, 0x92, 0x43, 0xa3, 0x9e, 0x4b, 0x8f, 0x51, 0x2c, |
6774 |
++ 0x5a, 0x2c, 0x3b, }, |
6775 |
++ { 0xe1, 0x9d, 0x70, 0x70, 0x28, 0xec, 0x86, 0x40, 0x55, 0x33, 0x56, 0xda, |
6776 |
++ 0x88, 0xca, 0xee, 0xc8, 0x6a, 0x20, 0xb1, 0xe5, 0x3d, 0x57, 0xf8, 0x3c, |
6777 |
++ 0x10, 0x07, 0x2a, 0xc4, }, |
6778 |
++ { 0x0b, 0xae, 0xf1, 0xc4, 0x79, 0xee, 0x1b, 0x3d, 0x27, 0x35, 0x8d, 0x14, |
6779 |
++ 0xd6, 0xae, 0x4e, 0x3c, 0xe9, 0x53, 0x50, 0xb5, 0xcc, 0x0c, 0xf7, 0xdf, |
6780 |
++ 0xee, 0xa1, 0x74, 0xd6, 0x71, }, |
6781 |
++ { 0xe6, 0xa4, 0xf4, 0x99, 0x98, 0xb9, 0x80, 0xea, 0x96, 0x7f, 0x4f, 0x33, |
6782 |
++ 0xcf, 0x74, 0x25, 0x6f, 0x17, 0x6c, 0xbf, 0xf5, 0x5c, 0x38, 0xd0, 0xff, |
6783 |
++ 0x96, 0xcb, 0x13, 0xf9, 0xdf, 0xfd, }, |
6784 |
++ { 0xbe, 0x92, 0xeb, 0xba, 0x44, 0x2c, 0x24, 0x74, 0xd4, 0x03, 0x27, 0x3c, |
6785 |
++ 0x5d, 0x5b, 0x03, 0x30, 0x87, 0x63, 0x69, 0xe0, 0xb8, 0x94, 0xf4, 0x44, |
6786 |
++ 0x7e, 0xad, 0xcd, 0x20, 0x12, 0x16, 0x79, }, |
6787 |
++ { 0x30, 0xf1, 0xc4, 0x8e, 0x05, 0x90, 0x2a, 0x97, 0x63, 0x94, 0x46, 0xff, |
6788 |
++ 0xce, 0xd8, 0x67, 0xa7, 0xac, 0x33, 0x8c, 0x95, 0xb7, 0xcd, 0xa3, 0x23, |
6789 |
++ 0x98, 0x9d, 0x76, 0x6c, 0x9d, 0xa8, 0xd6, 0x8a, }, |
6790 |
++ { 0xbe, }, |
6791 |
++ { 0x17, 0x6c, }, |
6792 |
++ { 0x1a, 0x42, 0x4f, }, |
6793 |
++ { 0xba, 0xaf, 0xb7, 0x65, }, |
6794 |
++ { 0xc2, 0x63, 0x43, 0x6a, 0xea, }, |
6795 |
++ { 0xe4, 0x4d, 0xad, 0xf2, 0x0b, 0x02, }, |
6796 |
++ { 0x04, 0xc7, 0xc4, 0x7f, 0xa9, 0x2b, 0xce, }, |
6797 |
++ { 0x66, 0xf6, 0x67, 0xcb, 0x03, 0x53, 0xc8, 0xf1, }, |
6798 |
++ { 0x56, 0xa3, 0x60, 0x78, 0xc9, 0x5f, 0x70, 0x1b, 0x5e, }, |
6799 |
++ { 0x99, 0xff, 0x81, 0x7c, 0x13, 0x3c, 0x29, 0x79, 0x4b, 0x65, }, |
6800 |
++ { 0x51, 0x10, 0x50, 0x93, 0x01, 0x93, 0xb7, 0x01, 0xc9, 0x18, 0xb7, }, |
6801 |
++ { 0x8e, 0x3c, 0x42, 0x1e, 0x5e, 0x7d, 0xc1, 0x50, 0x70, 0x1f, 0x00, 0x98, }, |
6802 |
++ { 0x5f, 0xd9, 0x9b, 0xc8, 0xd7, 0xb2, 0x72, 0x62, 0x1a, 0x1e, 0xba, 0x92, |
6803 |
++ 0xe9, }, |
6804 |
++ { 0x70, 0x2b, 0xba, 0xfe, 0xad, 0x5d, 0x96, 0x3f, 0x27, 0xc2, 0x41, 0x6d, |
6805 |
++ 0xc4, 0xb3, }, |
6806 |
++ { 0xae, 0xe0, 0xd5, 0xd4, 0xc7, 0xae, 0x15, 0x5e, 0xdc, 0xdd, 0x33, 0x60, |
6807 |
++ 0xd7, 0xd3, 0x5e, }, |
6808 |
++ { 0x79, 0x8e, 0xbc, 0x9e, 0x20, 0xb9, 0x19, 0x4b, 0x63, 0x80, 0xf3, 0x16, |
6809 |
++ 0xaf, 0x39, 0xbd, 0x92, }, |
6810 |
++ { 0xc2, 0x0e, 0x85, 0xa0, 0x0b, 0x9a, 0xb0, 0xec, 0xde, 0x38, 0xd3, 0x10, |
6811 |
++ 0xd9, 0xa7, 0x66, 0x27, 0xcf, }, |
6812 |
++ { 0x0e, 0x3b, 0x75, 0x80, 0x67, 0x14, 0x0c, 0x02, 0x90, 0xd6, 0xb3, 0x02, |
6813 |
++ 0x81, 0xf6, 0xa6, 0x87, 0xce, 0x58, }, |
6814 |
++ { 0x79, 0xb5, 0xe9, 0x5d, 0x52, 0x4d, 0xf7, 0x59, 0xf4, 0x2e, 0x27, 0xdd, |
6815 |
++ 0xb3, 0xed, 0x57, 0x5b, 0x82, 0xea, 0x6f, }, |
6816 |
++ { 0xa2, 0x97, 0xf5, 0x80, 0x02, 0x3d, 0xde, 0xa3, 0xf9, 0xf6, 0xab, 0xe3, |
6817 |
++ 0x57, 0x63, 0x7b, 0x9b, 0x10, 0x42, 0x6f, 0xf2, }, |
6818 |
++ { 0x12, 0x7a, 0xfc, 0xb7, 0x67, 0x06, 0x0c, 0x78, 0x1a, 0xfe, 0x88, 0x4f, |
6819 |
++ 0xc6, 0xac, 0x52, 0x96, 0x64, 0x28, 0x97, 0x84, 0x06, }, |
6820 |
++ { 0xc5, 0x04, 0x44, 0x6b, 0xb2, 0xa5, 0xa4, 0x66, 0xe1, 0x76, 0xa2, 0x51, |
6821 |
++ 0xf9, 0x59, 0x69, 0x97, 0x56, 0x0b, 0xbf, 0x50, 0xb3, 0x34, }, |
6822 |
++ { 0x21, 0x32, 0x6b, 0x42, 0xb5, 0xed, 0x71, 0x8d, 0xf7, 0x5a, 0x35, 0xe3, |
6823 |
++ 0x90, 0xe2, 0xee, 0xaa, 0x89, 0xf6, 0xc9, 0x9c, 0x4d, 0x73, 0xf4, }, |
6824 |
++ { 0x4c, 0xa6, 0x09, 0xf4, 0x48, 0xe7, 0x46, 0xbc, 0x49, 0xfc, 0xe5, 0xda, |
6825 |
++ 0xd1, 0x87, 0x13, 0x17, 0x4c, 0x59, 0x71, 0x26, 0x5b, 0x2c, 0x42, 0xb7, }, |
6826 |
++ { 0x13, 0x63, 0xf3, 0x40, 0x02, 0xe5, 0xa3, 0x3a, 0x5e, 0x8e, 0xf8, 0xb6, |
6827 |
++ 0x8a, 0x49, 0x60, 0x76, 0x34, 0x72, 0x94, 0x73, 0xf6, 0xd9, 0x21, 0x6a, |
6828 |
++ 0x26, }, |
6829 |
++ { 0xdf, 0x75, 0x16, 0x10, 0x1b, 0x5e, 0x81, 0xc3, 0xc8, 0xde, 0x34, 0x24, |
6830 |
++ 0xb0, 0x98, 0xeb, 0x1b, 0x8f, 0xa1, 0x9b, 0x05, 0xee, 0xa5, 0xe9, 0x35, |
6831 |
++ 0xf4, 0x1d, }, |
6832 |
++ { 0xcd, 0x21, 0x93, 0x6e, 0x5b, 0xa0, 0x26, 0x2b, 0x21, 0x0e, 0xa0, 0xb9, |
6833 |
++ 0x1c, 0xb5, 0xbb, 0xb8, 0xf8, 0x1e, 0xff, 0x5c, 0xa8, 0xf9, 0x39, 0x46, |
6834 |
++ 0x4e, 0x29, 0x26, }, |
6835 |
++ { 0x73, 0x7f, 0x0e, 0x3b, 0x0b, 0x5c, 0xf9, 0x60, 0xaa, 0x88, 0xa1, 0x09, |
6836 |
++ 0xb1, 0x5d, 0x38, 0x7b, 0x86, 0x8f, 0x13, 0x7a, 0x8d, 0x72, 0x7a, 0x98, |
6837 |
++ 0x1a, 0x5b, 0xff, 0xc9, }, |
6838 |
++ { 0xd3, 0x3c, 0x61, 0x71, 0x44, 0x7e, 0x31, 0x74, 0x98, 0x9d, 0x9a, 0xd2, |
6839 |
++ 0x27, 0xf3, 0x46, 0x43, 0x42, 0x51, 0xd0, 0x5f, 0xe9, 0x1c, 0x5c, 0x69, |
6840 |
++ 0xbf, 0xf6, 0xbe, 0x3c, 0x40, }, |
6841 |
++ { 0x31, 0x99, 0x31, 0x9f, 0xaa, 0x43, 0x2e, 0x77, 0x3e, 0x74, 0x26, 0x31, |
6842 |
++ 0x5e, 0x61, 0xf1, 0x87, 0xe2, 0xeb, 0x9b, 0xcd, 0xd0, 0x3a, 0xee, 0x20, |
6843 |
++ 0x7e, 0x10, 0x0a, 0x0b, 0x7e, 0xfa, }, |
6844 |
++ { 0xa4, 0x27, 0x80, 0x67, 0x81, 0x2a, 0xa7, 0x62, 0xf7, 0x6e, 0xda, 0xd4, |
6845 |
++ 0x5c, 0x39, 0x74, 0xad, 0x7e, 0xbe, 0xad, 0xa5, 0x84, 0x7f, 0xa9, 0x30, |
6846 |
++ 0x5d, 0xdb, 0xe2, 0x05, 0x43, 0xf7, 0x1b, }, |
6847 |
++ { 0x0b, 0x37, 0xd8, 0x02, 0xe1, 0x83, 0xd6, 0x80, 0xf2, 0x35, 0xc2, 0xb0, |
6848 |
++ 0x37, 0xef, 0xef, 0x5e, 0x43, 0x93, 0xf0, 0x49, 0x45, 0x0a, 0xef, 0xb5, |
6849 |
++ 0x76, 0x70, 0x12, 0x44, 0xc4, 0xdb, 0xf5, 0x7a, }, |
6850 |
++ { 0x1f, }, |
6851 |
++ { 0x82, 0x60, }, |
6852 |
++ { 0xcc, 0xe3, 0x08, }, |
6853 |
++ { 0x56, 0x17, 0xe4, 0x59, }, |
6854 |
++ { 0xe2, 0xd7, 0x9e, 0xc4, 0x4c, }, |
6855 |
++ { 0xb2, 0xad, 0xd3, 0x78, 0x58, 0x5a, }, |
6856 |
++ { 0xce, 0x43, 0xb4, 0x02, 0x96, 0xab, 0x3c, }, |
6857 |
++ { 0xe6, 0x05, 0x1a, 0x73, 0x22, 0x32, 0xbb, 0x77, }, |
6858 |
++ { 0x23, 0xe7, 0xda, 0xfe, 0x2c, 0xef, 0x8c, 0x22, 0xec, }, |
6859 |
++ { 0xe9, 0x8e, 0x55, 0x38, 0xd1, 0xd7, 0x35, 0x23, 0x98, 0xc7, }, |
6860 |
++ { 0xb5, 0x81, 0x1a, 0xe5, 0xb5, 0xa5, 0xd9, 0x4d, 0xca, 0x41, 0xe7, }, |
6861 |
++ { 0x41, 0x16, 0x16, 0x95, 0x8d, 0x9e, 0x0c, 0xea, 0x8c, 0x71, 0x9a, 0xc1, }, |
6862 |
++ { 0x7c, 0x33, 0xc0, 0xa4, 0x00, 0x62, 0xea, 0x60, 0x67, 0xe4, 0x20, 0xbc, |
6863 |
++ 0x5b, }, |
6864 |
++ { 0xdb, 0xb1, 0xdc, 0xfd, 0x08, 0xc0, 0xde, 0x82, 0xd1, 0xde, 0x38, 0xc0, |
6865 |
++ 0x90, 0x48, }, |
6866 |
++ { 0x37, 0x18, 0x2e, 0x0d, 0x61, 0xaa, 0x61, 0xd7, 0x86, 0x20, 0x16, 0x60, |
6867 |
++ 0x04, 0xd9, 0xd5, }, |
6868 |
++ { 0xb0, 0xcf, 0x2c, 0x4c, 0x5e, 0x5b, 0x4f, 0x2a, 0x23, 0x25, 0x58, 0x47, |
6869 |
++ 0xe5, 0x31, 0x06, 0x70, }, |
6870 |
++ { 0x91, 0xa0, 0xa3, 0x86, 0x4e, 0xe0, 0x72, 0x38, 0x06, 0x67, 0x59, 0x5c, |
6871 |
++ 0x70, 0x25, 0xdb, 0x33, 0x27, }, |
6872 |
++ { 0x44, 0x58, 0x66, 0xb8, 0x58, 0xc7, 0x13, 0xed, 0x4c, 0xc0, 0xf4, 0x9a, |
6873 |
++ 0x1e, 0x67, 0x75, 0x33, 0xb6, 0xb8, }, |
6874 |
++ { 0x7f, 0x98, 0x4a, 0x8e, 0x50, 0xa2, 0x5c, 0xcd, 0x59, 0xde, 0x72, 0xb3, |
6875 |
++ 0x9d, 0xc3, 0x09, 0x8a, 0xab, 0x56, 0xf1, }, |
6876 |
++ { 0x80, 0x96, 0x49, 0x1a, 0x59, 0xa2, 0xc5, 0xd5, 0xa7, 0x20, 0x8a, 0xb7, |
6877 |
++ 0x27, 0x62, 0x84, 0x43, 0xc6, 0xe1, 0x1b, 0x5d, }, |
6878 |
++ { 0x6b, 0xb7, 0x2b, 0x26, 0x62, 0x14, 0x70, 0x19, 0x3d, 0x4d, 0xac, 0xac, |
6879 |
++ 0x63, 0x58, 0x5e, 0x94, 0xb5, 0xb7, 0xe8, 0xe8, 0xa2, }, |
6880 |
++ { 0x20, 0xa8, 0xc0, 0xfd, 0x63, 0x3d, 0x6e, 0x98, 0xcf, 0x0c, 0x49, 0x98, |
6881 |
++ 0xe4, 0x5a, 0xfe, 0x8c, 0xaa, 0x70, 0x82, 0x1c, 0x7b, 0x74, }, |
6882 |
++ { 0xc8, 0xe8, 0xdd, 0xdf, 0x69, 0x30, 0x01, 0xc2, 0x0f, 0x7e, 0x2f, 0x11, |
6883 |
++ 0xcc, 0x3e, 0x17, 0xa5, 0x69, 0x40, 0x3f, 0x0e, 0x79, 0x7f, 0xcf, }, |
6884 |
++ { 0xdb, 0x61, 0xc0, 0xe2, 0x2e, 0x49, 0x07, 0x31, 0x1d, 0x91, 0x42, 0x8a, |
6885 |
++ 0xfc, 0x5e, 0xd3, 0xf8, 0x56, 0x1f, 0x2b, 0x73, 0xfd, 0x9f, 0xb2, 0x8e, }, |
6886 |
++ { 0x0c, 0x89, 0x55, 0x0c, 0x1f, 0x59, 0x2c, 0x9d, 0x1b, 0x29, 0x1d, 0x41, |
6887 |
++ 0x1d, 0xe6, 0x47, 0x8f, 0x8c, 0x2b, 0xea, 0x8f, 0xf0, 0xff, 0x21, 0x70, |
6888 |
++ 0x88, }, |
6889 |
++ { 0x12, 0x18, 0x95, 0xa6, 0x59, 0xb1, 0x31, 0x24, 0x45, 0x67, 0x55, 0xa4, |
6890 |
++ 0x1a, 0x2d, 0x48, 0x67, 0x1b, 0x43, 0x88, 0x2d, 0x8e, 0xa0, 0x70, 0xb3, |
6891 |
++ 0xc6, 0xbb, }, |
6892 |
++ { 0xe7, 0xb1, 0x1d, 0xb2, 0x76, 0x4d, 0x68, 0x68, 0x68, 0x23, 0x02, 0x55, |
6893 |
++ 0x3a, 0xe2, 0xe5, 0xd5, 0x4b, 0x43, 0xf9, 0x34, 0x77, 0x5c, 0xa1, 0xf5, |
6894 |
++ 0x55, 0xfd, 0x4f, }, |
6895 |
++ { 0x8c, 0x87, 0x5a, 0x08, 0x3a, 0x73, 0xad, 0x61, 0xe1, 0xe7, 0x99, 0x7e, |
6896 |
++ 0xf0, 0x5d, 0xe9, 0x5d, 0x16, 0x43, 0x80, 0x2f, 0xd0, 0x66, 0x34, 0xe2, |
6897 |
++ 0x42, 0x64, 0x3b, 0x1a, }, |
6898 |
++ { 0x39, 0xc1, 0x99, 0xcf, 0x22, 0xbf, 0x16, 0x8f, 0x9f, 0x80, 0x7f, 0x95, |
6899 |
++ 0x0a, 0x05, 0x67, 0x27, 0xe7, 0x15, 0xdf, 0x9d, 0xb2, 0xfe, 0x1c, 0xb5, |
6900 |
++ 0x1d, 0x60, 0x8f, 0x8a, 0x1d, }, |
6901 |
++ { 0x9b, 0x6e, 0x08, 0x09, 0x06, 0x73, 0xab, 0x68, 0x02, 0x62, 0x1a, 0xe4, |
6902 |
++ 0xd4, 0xdf, 0xc7, 0x02, 0x4c, 0x6a, 0x5f, 0xfd, 0x23, 0xac, 0xae, 0x6d, |
6903 |
++ 0x43, 0xa4, 0x7a, 0x50, 0x60, 0x3c, }, |
6904 |
++ { 0x1d, 0xb4, 0xc6, 0xe1, 0xb1, 0x4b, 0xe3, 0xf2, 0xe2, 0x1a, 0x73, 0x1b, |
6905 |
++ 0xa0, 0x92, 0xa7, 0xf5, 0xff, 0x8f, 0x8b, 0x5d, 0xdf, 0xa8, 0x04, 0xb3, |
6906 |
++ 0xb0, 0xf7, 0xcc, 0x12, 0xfa, 0x35, 0x46, }, |
6907 |
++ { 0x49, 0x45, 0x97, 0x11, 0x0f, 0x1c, 0x60, 0x8e, 0xe8, 0x47, 0x30, 0xcf, |
6908 |
++ 0x60, 0xa8, 0x71, 0xc5, 0x1b, 0xe9, 0x39, 0x4d, 0x49, 0xb6, 0x12, 0x1f, |
6909 |
++ 0x24, 0xab, 0x37, 0xff, 0x83, 0xc2, 0xe1, 0x3a, }, |
6910 |
++ { 0x60, }, |
6911 |
++ { 0x24, 0x26, }, |
6912 |
++ { 0x47, 0xeb, 0xc9, }, |
6913 |
++ { 0x4a, 0xd0, 0xbc, 0xf0, }, |
6914 |
++ { 0x8e, 0x2b, 0xc9, 0x85, 0x3c, }, |
6915 |
++ { 0xa2, 0x07, 0x15, 0xb8, 0x12, 0x74, }, |
6916 |
++ { 0x0f, 0xdb, 0x5b, 0x33, 0x69, 0xfe, 0x4b, }, |
6917 |
++ { 0xa2, 0x86, 0x54, 0xf4, 0xfd, 0xb2, 0xd4, 0xe6, }, |
6918 |
++ { 0xbb, 0x84, 0x78, 0x49, 0x27, 0x8e, 0x61, 0xda, 0x60, }, |
6919 |
++ { 0x04, 0xc3, 0xcd, 0xaa, 0x8f, 0xa7, 0x03, 0xc9, 0xf9, 0xb6, }, |
6920 |
++ { 0xf8, 0x27, 0x1d, 0x61, 0xdc, 0x21, 0x42, 0xdd, 0xad, 0x92, 0x40, }, |
6921 |
++ { 0x12, 0x87, 0xdf, 0xc2, 0x41, 0x45, 0x5a, 0x36, 0x48, 0x5b, 0x51, 0x2b, }, |
6922 |
++ { 0xbb, 0x37, 0x5d, 0x1f, 0xf1, 0x68, 0x7a, 0xc4, 0xa5, 0xd2, 0xa4, 0x91, |
6923 |
++ 0x8d, }, |
6924 |
++ { 0x5b, 0x27, 0xd1, 0x04, 0x54, 0x52, 0x9f, 0xa3, 0x47, 0x86, 0x33, 0x33, |
6925 |
++ 0xbf, 0xa0, }, |
6926 |
++ { 0xcf, 0x04, 0xea, 0xf8, 0x03, 0x2a, 0x43, 0xff, 0xa6, 0x68, 0x21, 0x4c, |
6927 |
++ 0xd5, 0x4b, 0xed, }, |
6928 |
++ { 0xaf, 0xb8, 0xbc, 0x63, 0x0f, 0x18, 0x4d, 0xe2, 0x7a, 0xdd, 0x46, 0x44, |
6929 |
++ 0xc8, 0x24, 0x0a, 0xb7, }, |
6930 |
++ { 0x3e, 0xdc, 0x36, 0xe4, 0x89, 0xb1, 0xfa, 0xc6, 0x40, 0x93, 0x2e, 0x75, |
6931 |
++ 0xb2, 0x15, 0xd1, 0xb1, 0x10, }, |
6932 |
++ { 0x6c, 0xd8, 0x20, 0x3b, 0x82, 0x79, 0xf9, 0xc8, 0xbc, 0x9d, 0xe0, 0x35, |
6933 |
++ 0xbe, 0x1b, 0x49, 0x1a, 0xbc, 0x3a, }, |
6934 |
++ { 0x78, 0x65, 0x2c, 0xbe, 0x35, 0x67, 0xdc, 0x78, 0xd4, 0x41, 0xf6, 0xc9, |
6935 |
++ 0xde, 0xde, 0x1f, 0x18, 0x13, 0x31, 0x11, }, |
6936 |
++ { 0x8a, 0x7f, 0xb1, 0x33, 0x8f, 0x0c, 0x3c, 0x0a, 0x06, 0x61, 0xf0, 0x47, |
6937 |
++ 0x29, 0x1b, 0x29, 0xbc, 0x1c, 0x47, 0xef, 0x7a, }, |
6938 |
++ { 0x65, 0x91, 0xf1, 0xe6, 0xb3, 0x96, 0xd3, 0x8c, 0xc2, 0x4a, 0x59, 0x35, |
6939 |
++ 0x72, 0x8e, 0x0b, 0x9a, 0x87, 0xca, 0x34, 0x7b, 0x63, }, |
6940 |
++ { 0x5f, 0x08, 0x87, 0x80, 0x56, 0x25, 0x89, 0x77, 0x61, 0x8c, 0x64, 0xa1, |
6941 |
++ 0x59, 0x6d, 0x59, 0x62, 0xe8, 0x4a, 0xc8, 0x58, 0x99, 0xd1, }, |
6942 |
++ { 0x23, 0x87, 0x1d, 0xed, 0x6f, 0xf2, 0x91, 0x90, 0xe2, 0xfe, 0x43, 0x21, |
6943 |
++ 0xaf, 0x97, 0xc6, 0xbc, 0xd7, 0x15, 0xc7, 0x2d, 0x08, 0x77, 0x91, }, |
6944 |
++ { 0x90, 0x47, 0x9a, 0x9e, 0x3a, 0xdf, 0xf3, 0xc9, 0x4c, 0x1e, 0xa7, 0xd4, |
6945 |
++ 0x6a, 0x32, 0x90, 0xfe, 0xb7, 0xb6, 0x7b, 0xfa, 0x96, 0x61, 0xfb, 0xa4, }, |
6946 |
++ { 0xb1, 0x67, 0x60, 0x45, 0xb0, 0x96, 0xc5, 0x15, 0x9f, 0x4d, 0x26, 0xd7, |
6947 |
++ 0x9d, 0xf1, 0xf5, 0x6d, 0x21, 0x00, 0x94, 0x31, 0x64, 0x94, 0xd3, 0xa7, |
6948 |
++ 0xd3, }, |
6949 |
++ { 0x02, 0x3e, 0xaf, 0xf3, 0x79, 0x73, 0xa5, 0xf5, 0xcc, 0x7a, 0x7f, 0xfb, |
6950 |
++ 0x79, 0x2b, 0x85, 0x8c, 0x88, 0x72, 0x06, 0xbe, 0xfe, 0xaf, 0xc1, 0x16, |
6951 |
++ 0xa6, 0xd6, }, |
6952 |
++ { 0x2a, 0xb0, 0x1a, 0xe5, 0xaa, 0x6e, 0xb3, 0xae, 0x53, 0x85, 0x33, 0x80, |
6953 |
++ 0x75, 0xae, 0x30, 0xe6, 0xb8, 0x72, 0x42, 0xf6, 0x25, 0x4f, 0x38, 0x88, |
6954 |
++ 0x55, 0xd1, 0xa9, }, |
6955 |
++ { 0x90, 0xd8, 0x0c, 0xc0, 0x93, 0x4b, 0x4f, 0x9e, 0x65, 0x6c, 0xa1, 0x54, |
6956 |
++ 0xa6, 0xf6, 0x6e, 0xca, 0xd2, 0xbb, 0x7e, 0x6a, 0x1c, 0xd3, 0xce, 0x46, |
6957 |
++ 0xef, 0xb0, 0x00, 0x8d, }, |
6958 |
++ { 0xed, 0x9c, 0x49, 0xcd, 0xc2, 0xde, 0x38, 0x0e, 0xe9, 0x98, 0x6c, 0xc8, |
6959 |
++ 0x90, 0x9e, 0x3c, 0xd4, 0xd3, 0xeb, 0x88, 0x32, 0xc7, 0x28, 0xe3, 0x94, |
6960 |
++ 0x1c, 0x9f, 0x8b, 0xf3, 0xcb, }, |
6961 |
++ { 0xac, 0xe7, 0x92, 0x16, 0xb4, 0x14, 0xa0, 0xe4, 0x04, 0x79, 0xa2, 0xf4, |
6962 |
++ 0x31, 0xe6, 0x0c, 0x26, 0xdc, 0xbf, 0x2f, 0x69, 0x1b, 0x55, 0x94, 0x67, |
6963 |
++ 0xda, 0x0c, 0xd7, 0x32, 0x1f, 0xef, }, |
6964 |
++ { 0x68, 0x63, 0x85, 0x57, 0x95, 0x9e, 0x42, 0x27, 0x41, 0x43, 0x42, 0x02, |
6965 |
++ 0xa5, 0x78, 0xa7, 0xc6, 0x43, 0xc1, 0x6a, 0xba, 0x70, 0x80, 0xcd, 0x04, |
6966 |
++ 0xb6, 0x78, 0x76, 0x29, 0xf3, 0xe8, 0xa0, }, |
6967 |
++ { 0xe6, 0xac, 0x8d, 0x9d, 0xf0, 0xc0, 0xf7, 0xf7, 0xe3, 0x3e, 0x4e, 0x28, |
6968 |
++ 0x0f, 0x59, 0xb2, 0x67, 0x9e, 0x84, 0x34, 0x42, 0x96, 0x30, 0x2b, 0xca, |
6969 |
++ 0x49, 0xb6, 0xc5, 0x9a, 0x84, 0x59, 0xa7, 0x81, }, |
6970 |
++ { 0x7e, }, |
6971 |
++ { 0x1e, 0x21, }, |
6972 |
++ { 0x26, 0xd3, 0xdd, }, |
6973 |
++ { 0x2c, 0xd4, 0xb3, 0x3d, }, |
6974 |
++ { 0x86, 0x7b, 0x76, 0x3c, 0xf0, }, |
6975 |
++ { 0x12, 0xc3, 0x70, 0x1d, 0x55, 0x18, }, |
6976 |
++ { 0x96, 0xc2, 0xbd, 0x61, 0x55, 0xf4, 0x24, }, |
6977 |
++ { 0x20, 0x51, 0xf7, 0x86, 0x58, 0x8f, 0x07, 0x2a, }, |
6978 |
++ { 0x93, 0x15, 0xa8, 0x1d, 0xda, 0x97, 0xee, 0x0e, 0x6c, }, |
6979 |
++ { 0x39, 0x93, 0xdf, 0xd5, 0x0e, 0xca, 0xdc, 0x7a, 0x92, 0xce, }, |
6980 |
++ { 0x60, 0xd5, 0xfd, 0xf5, 0x1b, 0x26, 0x82, 0x26, 0x73, 0x02, 0xbc, }, |
6981 |
++ { 0x98, 0xf2, 0x34, 0xe1, 0xf5, 0xfb, 0x00, 0xac, 0x10, 0x4a, 0x38, 0x9f, }, |
6982 |
++ { 0xda, 0x3a, 0x92, 0x8a, 0xd0, 0xcd, 0x12, 0xcd, 0x15, 0xbb, 0xab, 0x77, |
6983 |
++ 0x66, }, |
6984 |
++ { 0xa2, 0x92, 0x1a, 0xe5, 0xca, 0x0c, 0x30, 0x75, 0xeb, 0xaf, 0x00, 0x31, |
6985 |
++ 0x55, 0x66, }, |
6986 |
++ { 0x06, 0xea, 0xfd, 0x3e, 0x86, 0x38, 0x62, 0x4e, 0xa9, 0x12, 0xa4, 0x12, |
6987 |
++ 0x43, 0xbf, 0xa1, }, |
6988 |
++ { 0xe4, 0x71, 0x7b, 0x94, 0xdb, 0xa0, 0xd2, 0xff, 0x9b, 0xeb, 0xad, 0x8e, |
6989 |
++ 0x95, 0x8a, 0xc5, 0xed, }, |
6990 |
++ { 0x25, 0x5a, 0x77, 0x71, 0x41, 0x0e, 0x7a, 0xe9, 0xed, 0x0c, 0x10, 0xef, |
6991 |
++ 0xf6, 0x2b, 0x3a, 0xba, 0x60, }, |
6992 |
++ { 0xee, 0xe2, 0xa3, 0x67, 0x64, 0x1d, 0xc6, 0x04, 0xc4, 0xe1, 0x68, 0xd2, |
6993 |
++ 0x6e, 0xd2, 0x91, 0x75, 0x53, 0x07, }, |
6994 |
++ { 0xe0, 0xf6, 0x4d, 0x8f, 0x68, 0xfc, 0x06, 0x7e, 0x18, 0x79, 0x7f, 0x2b, |
6995 |
++ 0x6d, 0xef, 0x46, 0x7f, 0xab, 0xb2, 0xad, }, |
6996 |
++ { 0x3d, 0x35, 0x88, 0x9f, 0x2e, 0xcf, 0x96, 0x45, 0x07, 0x60, 0x71, 0x94, |
6997 |
++ 0x00, 0x8d, 0xbf, 0xf4, 0xef, 0x46, 0x2e, 0x3c, }, |
6998 |
++ { 0x43, 0xcf, 0x98, 0xf7, 0x2d, 0xf4, 0x17, 0xe7, 0x8c, 0x05, 0x2d, 0x9b, |
6999 |
++ 0x24, 0xfb, 0x4d, 0xea, 0x4a, 0xec, 0x01, 0x25, 0x29, }, |
7000 |
++ { 0x8e, 0x73, 0x9a, 0x78, 0x11, 0xfe, 0x48, 0xa0, 0x3b, 0x1a, 0x26, 0xdf, |
7001 |
++ 0x25, 0xe9, 0x59, 0x1c, 0x70, 0x07, 0x9f, 0xdc, 0xa0, 0xa6, }, |
7002 |
++ { 0xe8, 0x47, 0x71, 0xc7, 0x3e, 0xdf, 0xb5, 0x13, 0xb9, 0x85, 0x13, 0xa8, |
7003 |
++ 0x54, 0x47, 0x6e, 0x59, 0x96, 0x09, 0x13, 0x5f, 0x82, 0x16, 0x0b, }, |
7004 |
++ { 0xfb, 0xc0, 0x8c, 0x03, 0x21, 0xb3, 0xc4, 0xb5, 0x43, 0x32, 0x6c, 0xea, |
7005 |
++ 0x7f, 0xa8, 0x43, 0x91, 0xe8, 0x4e, 0x3f, 0xbf, 0x45, 0x58, 0x6a, 0xa3, }, |
7006 |
++ { 0x55, 0xf8, 0xf3, 0x00, 0x76, 0x09, 0xef, 0x69, 0x5d, 0xd2, 0x8a, 0xf2, |
7007 |
++ 0x65, 0xc3, 0xcb, 0x9b, 0x43, 0xfd, 0xb1, 0x7e, 0x7f, 0xa1, 0x94, 0xb0, |
7008 |
++ 0xd7, }, |
7009 |
++ { 0xaa, 0x13, 0xc1, 0x51, 0x40, 0x6d, 0x8d, 0x4c, 0x0a, 0x95, 0x64, 0x7b, |
7010 |
++ 0xd1, 0x96, 0xb6, 0x56, 0xb4, 0x5b, 0xcf, 0xd6, 0xd9, 0x15, 0x97, 0xdd, |
7011 |
++ 0xb6, 0xef, }, |
7012 |
++ { 0xaf, 0xb7, 0x36, 0xb0, 0x04, 0xdb, 0xd7, 0x9c, 0x9a, 0x44, 0xc4, 0xf6, |
7013 |
++ 0x1f, 0x12, 0x21, 0x2d, 0x59, 0x30, 0x54, 0xab, 0x27, 0x61, 0xa3, 0x57, |
7014 |
++ 0xef, 0xf8, 0x53, }, |
7015 |
++ { 0x97, 0x34, 0x45, 0x3e, 0xce, 0x7c, 0x35, 0xa2, 0xda, 0x9f, 0x4b, 0x46, |
7016 |
++ 0x6c, 0x11, 0x67, 0xff, 0x2f, 0x76, 0x58, 0x15, 0x71, 0xfa, 0x44, 0x89, |
7017 |
++ 0x89, 0xfd, 0xf7, 0x99, }, |
7018 |
++ { 0x1f, 0xb1, 0x62, 0xeb, 0x83, 0xc5, 0x9c, 0x89, 0xf9, 0x2c, 0xd2, 0x03, |
7019 |
++ 0x61, 0xbc, 0xbb, 0xa5, 0x74, 0x0e, 0x9b, 0x7e, 0x82, 0x3e, 0x70, 0x0a, |
7020 |
++ 0xa9, 0x8f, 0x2b, 0x59, 0xfb, }, |
7021 |
++ { 0xf8, 0xca, 0x5e, 0x3a, 0x4f, 0x9e, 0x10, 0x69, 0x10, 0xd5, 0x4c, 0xeb, |
7022 |
++ 0x1a, 0x0f, 0x3c, 0x6a, 0x98, 0xf5, 0xb0, 0x97, 0x5b, 0x37, 0x2f, 0x0d, |
7023 |
++ 0xbd, 0x42, 0x4b, 0x69, 0xa1, 0x82, }, |
7024 |
++ { 0x12, 0x8c, 0x6d, 0x52, 0x08, 0xef, 0x74, 0xb2, 0xe6, 0xaa, 0xd3, 0xb0, |
7025 |
++ 0x26, 0xb0, 0xd9, 0x94, 0xb6, 0x11, 0x45, 0x0e, 0x36, 0x71, 0x14, 0x2d, |
7026 |
++ 0x41, 0x8c, 0x21, 0x53, 0x31, 0xe9, 0x68, }, |
7027 |
++ { 0xee, 0xea, 0x0d, 0x89, 0x47, 0x7e, 0x72, 0xd1, 0xd8, 0xce, 0x58, 0x4c, |
7028 |
++ 0x94, 0x1f, 0x0d, 0x51, 0x08, 0xa3, 0xb6, 0x3d, 0xe7, 0x82, 0x46, 0x92, |
7029 |
++ 0xd6, 0x98, 0x6b, 0x07, 0x10, 0x65, 0x52, 0x65, }, |
7030 |
++}; |
7031 |
++ |
7032 |
++bool __init blake2s_selftest(void) |
7033 |
++{ |
7034 |
++ u8 key[BLAKE2S_KEY_SIZE]; |
7035 |
++ u8 buf[ARRAY_SIZE(blake2s_testvecs)]; |
7036 |
++ u8 hash[BLAKE2S_HASH_SIZE]; |
7037 |
++ struct blake2s_state state; |
7038 |
++ bool success = true; |
7039 |
++ int i, l; |
7040 |
++ |
7041 |
++ key[0] = key[1] = 1; |
7042 |
++ for (i = 2; i < sizeof(key); ++i) |
7043 |
++ key[i] = key[i - 2] + key[i - 1]; |
7044 |
++ |
7045 |
++ for (i = 0; i < sizeof(buf); ++i) |
7046 |
++ buf[i] = (u8)i; |
7047 |
++ |
7048 |
++ for (i = l = 0; i < ARRAY_SIZE(blake2s_testvecs); l = (l + 37) % ++i) { |
7049 |
++ int outlen = 1 + i % BLAKE2S_HASH_SIZE; |
7050 |
++ int keylen = (13 * i) % (BLAKE2S_KEY_SIZE + 1); |
7051 |
++ |
7052 |
++ blake2s(hash, buf, key + BLAKE2S_KEY_SIZE - keylen, outlen, i, |
7053 |
++ keylen); |
7054 |
++ if (memcmp(hash, blake2s_testvecs[i], outlen)) { |
7055 |
++ pr_err("blake2s self-test %d: FAIL\n", i + 1); |
7056 |
++ success = false; |
7057 |
++ } |
7058 |
++ |
7059 |
++ if (!keylen) |
7060 |
++ blake2s_init(&state, outlen); |
7061 |
++ else |
7062 |
++ blake2s_init_key(&state, outlen, |
7063 |
++ key + BLAKE2S_KEY_SIZE - keylen, |
7064 |
++ keylen); |
7065 |
++ |
7066 |
++ blake2s_update(&state, buf, l); |
7067 |
++ blake2s_update(&state, buf + l, i - l); |
7068 |
++ blake2s_final(&state, hash); |
7069 |
++ if (memcmp(hash, blake2s_testvecs[i], outlen)) { |
7070 |
++ pr_err("blake2s init/update/final self-test %d: FAIL\n", |
7071 |
++ i + 1); |
7072 |
++ success = false; |
7073 |
++ } |
7074 |
++ } |
7075 |
++ |
7076 |
++ return success; |
7077 |
++} |
7078 |
+diff --git a/lib/crypto/blake2s.c b/lib/crypto/blake2s.c |
7079 |
+new file mode 100644 |
7080 |
+index 0000000000000..536fce87555b3 |
7081 |
+--- /dev/null |
7082 |
++++ b/lib/crypto/blake2s.c |
7083 |
+@@ -0,0 +1,78 @@ |
7084 |
++// SPDX-License-Identifier: GPL-2.0 OR MIT |
7085 |
++/* |
7086 |
++ * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@×××××.com>. All Rights Reserved. |
7087 |
++ * |
7088 |
++ * This is an implementation of the BLAKE2s hash and PRF functions. |
7089 |
++ * |
7090 |
++ * Information: https://blake2.net/ |
7091 |
++ * |
7092 |
++ */ |
7093 |
++ |
7094 |
++#include <crypto/internal/blake2s.h> |
7095 |
++#include <linux/types.h> |
7096 |
++#include <linux/string.h> |
7097 |
++#include <linux/kernel.h> |
7098 |
++#include <linux/module.h> |
7099 |
++#include <linux/init.h> |
7100 |
++#include <linux/bug.h> |
7101 |
++#include <asm/unaligned.h> |
7102 |
++ |
7103 |
++bool blake2s_selftest(void); |
7104 |
++ |
7105 |
++void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen) |
7106 |
++{ |
7107 |
++ const size_t fill = BLAKE2S_BLOCK_SIZE - state->buflen; |
7108 |
++ |
7109 |
++ if (unlikely(!inlen)) |
7110 |
++ return; |
7111 |
++ if (inlen > fill) { |
7112 |
++ memcpy(state->buf + state->buflen, in, fill); |
7113 |
++ blake2s_compress_generic(state, state->buf, 1, |
7114 |
++ BLAKE2S_BLOCK_SIZE); |
7115 |
++ state->buflen = 0; |
7116 |
++ in += fill; |
7117 |
++ inlen -= fill; |
7118 |
++ } |
7119 |
++ if (inlen > BLAKE2S_BLOCK_SIZE) { |
7120 |
++ const size_t nblocks = DIV_ROUND_UP(inlen, BLAKE2S_BLOCK_SIZE); |
7121 |
++ /* Hash one less (full) block than strictly possible */ |
7122 |
++ blake2s_compress_generic(state, in, nblocks - 1, |
7123 |
++ BLAKE2S_BLOCK_SIZE); |
7124 |
++ in += BLAKE2S_BLOCK_SIZE * (nblocks - 1); |
7125 |
++ inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1); |
7126 |
++ } |
7127 |
++ memcpy(state->buf + state->buflen, in, inlen); |
7128 |
++ state->buflen += inlen; |
7129 |
++} |
7130 |
++EXPORT_SYMBOL(blake2s_update); |
7131 |
++ |
7132 |
++void blake2s_final(struct blake2s_state *state, u8 *out) |
7133 |
++{ |
7134 |
++ WARN_ON(IS_ENABLED(DEBUG) && !out); |
7135 |
++ blake2s_set_lastblock(state); |
7136 |
++ memset(state->buf + state->buflen, 0, |
7137 |
++ BLAKE2S_BLOCK_SIZE - state->buflen); /* Padding */ |
7138 |
++ blake2s_compress_generic(state, state->buf, 1, state->buflen); |
7139 |
++ cpu_to_le32_array(state->h, ARRAY_SIZE(state->h)); |
7140 |
++ memcpy(out, state->h, state->outlen); |
7141 |
++ memzero_explicit(state, sizeof(*state)); |
7142 |
++} |
7143 |
++EXPORT_SYMBOL(blake2s_final); |
7144 |
++ |
7145 |
++static int __init mod_init(void) |
7146 |
++{ |
7147 |
++ if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) && |
7148 |
++ WARN_ON(!blake2s_selftest())) |
7149 |
++ return -ENODEV; |
7150 |
++ return 0; |
7151 |
++} |
7152 |
++ |
7153 |
++static void __exit mod_exit(void) |
7154 |
++{ |
7155 |
++} |
7156 |
++ |
7157 |
++module_init(mod_init); |
7158 |
++module_exit(mod_exit); |
7159 |
++MODULE_LICENSE("GPL v2"); |
7160 |
++MODULE_DESCRIPTION("BLAKE2s hash function"); |
7161 |
++MODULE_AUTHOR("Jason A. Donenfeld <Jason@×××××.com>"); |
7162 |
+diff --git a/lib/find_bit.c b/lib/find_bit.c |
7163 |
+index 18072ea9c20eb..479d0a9cf69fc 100644 |
7164 |
+--- a/lib/find_bit.c |
7165 |
++++ b/lib/find_bit.c |
7166 |
+@@ -133,18 +133,6 @@ EXPORT_SYMBOL(find_last_bit); |
7167 |
+ |
7168 |
+ #ifdef __BIG_ENDIAN |
7169 |
+ |
7170 |
+-/* include/linux/byteorder does not support "unsigned long" type */ |
7171 |
+-static inline unsigned long ext2_swab(const unsigned long y) |
7172 |
+-{ |
7173 |
+-#if BITS_PER_LONG == 64 |
7174 |
+- return (unsigned long) __swab64((u64) y); |
7175 |
+-#elif BITS_PER_LONG == 32 |
7176 |
+- return (unsigned long) __swab32((u32) y); |
7177 |
+-#else |
7178 |
+-#error BITS_PER_LONG not defined |
7179 |
+-#endif |
7180 |
+-} |
7181 |
+- |
7182 |
+ #if !defined(find_next_bit_le) || !defined(find_next_zero_bit_le) |
7183 |
+ static unsigned long _find_next_bit_le(const unsigned long *addr, |
7184 |
+ unsigned long nbits, unsigned long start, unsigned long invert) |
7185 |
+@@ -157,7 +145,7 @@ static unsigned long _find_next_bit_le(const unsigned long *addr, |
7186 |
+ tmp = addr[start / BITS_PER_LONG] ^ invert; |
7187 |
+ |
7188 |
+ /* Handle 1st word. */ |
7189 |
+- tmp &= ext2_swab(BITMAP_FIRST_WORD_MASK(start)); |
7190 |
++ tmp &= swab(BITMAP_FIRST_WORD_MASK(start)); |
7191 |
+ start = round_down(start, BITS_PER_LONG); |
7192 |
+ |
7193 |
+ while (!tmp) { |
7194 |
+@@ -168,7 +156,7 @@ static unsigned long _find_next_bit_le(const unsigned long *addr, |
7195 |
+ tmp = addr[start / BITS_PER_LONG] ^ invert; |
7196 |
+ } |
7197 |
+ |
7198 |
+- return min(start + __ffs(ext2_swab(tmp)), nbits); |
7199 |
++ return min(start + __ffs(swab(tmp)), nbits); |
7200 |
+ } |
7201 |
+ #endif |
7202 |
+ |
7203 |
+diff --git a/lib/random32.c b/lib/random32.c |
7204 |
+index 3c5b67b69cbaa..7e630025cbc3b 100644 |
7205 |
+--- a/lib/random32.c |
7206 |
++++ b/lib/random32.c |
7207 |
+@@ -37,6 +37,9 @@ |
7208 |
+ #include <linux/jiffies.h> |
7209 |
+ #include <linux/random.h> |
7210 |
+ #include <linux/sched.h> |
7211 |
++#include <linux/bitops.h> |
7212 |
++#include <linux/slab.h> |
7213 |
++#include <linux/notifier.h> |
7214 |
+ #include <asm/unaligned.h> |
7215 |
+ |
7216 |
+ /** |
7217 |
+@@ -543,9 +546,11 @@ static void prandom_reseed(unsigned long dontcare) |
7218 |
+ * To avoid worrying about whether it's safe to delay that interrupt |
7219 |
+ * long enough to seed all CPUs, just schedule an immediate timer event. |
7220 |
+ */ |
7221 |
+-static void prandom_timer_start(struct random_ready_callback *unused) |
7222 |
++static int prandom_timer_start(struct notifier_block *nb, |
7223 |
++ unsigned long action, void *data) |
7224 |
+ { |
7225 |
+ mod_timer(&seed_timer, jiffies); |
7226 |
++ return 0; |
7227 |
+ } |
7228 |
+ |
7229 |
+ /* |
7230 |
+@@ -554,13 +559,13 @@ static void prandom_timer_start(struct random_ready_callback *unused) |
7231 |
+ */ |
7232 |
+ static int __init prandom_init_late(void) |
7233 |
+ { |
7234 |
+- static struct random_ready_callback random_ready = { |
7235 |
+- .func = prandom_timer_start |
7236 |
++ static struct notifier_block random_ready = { |
7237 |
++ .notifier_call = prandom_timer_start |
7238 |
+ }; |
7239 |
+- int ret = add_random_ready_callback(&random_ready); |
7240 |
++ int ret = register_random_ready_notifier(&random_ready); |
7241 |
+ |
7242 |
+ if (ret == -EALREADY) { |
7243 |
+- prandom_timer_start(&random_ready); |
7244 |
++ prandom_timer_start(&random_ready, 0, NULL); |
7245 |
+ ret = 0; |
7246 |
+ } |
7247 |
+ return ret; |
7248 |
+diff --git a/lib/sha1.c b/lib/sha1.c |
7249 |
+index 5a56dfd7b99de..8aa4ee352ad58 100644 |
7250 |
+--- a/lib/sha1.c |
7251 |
++++ b/lib/sha1.c |
7252 |
+@@ -9,6 +9,7 @@ |
7253 |
+ #include <linux/export.h> |
7254 |
+ #include <linux/bitops.h> |
7255 |
+ #include <linux/cryptohash.h> |
7256 |
++#include <linux/string.h> |
7257 |
+ #include <asm/unaligned.h> |
7258 |
+ |
7259 |
+ /* |
7260 |
+@@ -54,7 +55,8 @@ |
7261 |
+ #define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ |
7262 |
+ __u32 TEMP = input(t); setW(t, TEMP); \ |
7263 |
+ E += TEMP + rol32(A,5) + (fn) + (constant); \ |
7264 |
+- B = ror32(B, 2); } while (0) |
7265 |
++ B = ror32(B, 2); \ |
7266 |
++ TEMP = E; E = D; D = C; C = B; B = A; A = TEMP; } while (0) |
7267 |
+ |
7268 |
+ #define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) |
7269 |
+ #define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) |
7270 |
+@@ -81,6 +83,7 @@ |
7271 |
+ void sha_transform(__u32 *digest, const char *data, __u32 *array) |
7272 |
+ { |
7273 |
+ __u32 A, B, C, D, E; |
7274 |
++ unsigned int i = 0; |
7275 |
+ |
7276 |
+ A = digest[0]; |
7277 |
+ B = digest[1]; |
7278 |
+@@ -89,94 +92,24 @@ void sha_transform(__u32 *digest, const char *data, __u32 *array) |
7279 |
+ E = digest[4]; |
7280 |
+ |
7281 |
+ /* Round 1 - iterations 0-16 take their input from 'data' */ |
7282 |
+- T_0_15( 0, A, B, C, D, E); |
7283 |
+- T_0_15( 1, E, A, B, C, D); |
7284 |
+- T_0_15( 2, D, E, A, B, C); |
7285 |
+- T_0_15( 3, C, D, E, A, B); |
7286 |
+- T_0_15( 4, B, C, D, E, A); |
7287 |
+- T_0_15( 5, A, B, C, D, E); |
7288 |
+- T_0_15( 6, E, A, B, C, D); |
7289 |
+- T_0_15( 7, D, E, A, B, C); |
7290 |
+- T_0_15( 8, C, D, E, A, B); |
7291 |
+- T_0_15( 9, B, C, D, E, A); |
7292 |
+- T_0_15(10, A, B, C, D, E); |
7293 |
+- T_0_15(11, E, A, B, C, D); |
7294 |
+- T_0_15(12, D, E, A, B, C); |
7295 |
+- T_0_15(13, C, D, E, A, B); |
7296 |
+- T_0_15(14, B, C, D, E, A); |
7297 |
+- T_0_15(15, A, B, C, D, E); |
7298 |
++ for (; i < 16; ++i) |
7299 |
++ T_0_15(i, A, B, C, D, E); |
7300 |
+ |
7301 |
+ /* Round 1 - tail. Input from 512-bit mixing array */ |
7302 |
+- T_16_19(16, E, A, B, C, D); |
7303 |
+- T_16_19(17, D, E, A, B, C); |
7304 |
+- T_16_19(18, C, D, E, A, B); |
7305 |
+- T_16_19(19, B, C, D, E, A); |
7306 |
++ for (; i < 20; ++i) |
7307 |
++ T_16_19(i, A, B, C, D, E); |
7308 |
+ |
7309 |
+ /* Round 2 */ |
7310 |
+- T_20_39(20, A, B, C, D, E); |
7311 |
+- T_20_39(21, E, A, B, C, D); |
7312 |
+- T_20_39(22, D, E, A, B, C); |
7313 |
+- T_20_39(23, C, D, E, A, B); |
7314 |
+- T_20_39(24, B, C, D, E, A); |
7315 |
+- T_20_39(25, A, B, C, D, E); |
7316 |
+- T_20_39(26, E, A, B, C, D); |
7317 |
+- T_20_39(27, D, E, A, B, C); |
7318 |
+- T_20_39(28, C, D, E, A, B); |
7319 |
+- T_20_39(29, B, C, D, E, A); |
7320 |
+- T_20_39(30, A, B, C, D, E); |
7321 |
+- T_20_39(31, E, A, B, C, D); |
7322 |
+- T_20_39(32, D, E, A, B, C); |
7323 |
+- T_20_39(33, C, D, E, A, B); |
7324 |
+- T_20_39(34, B, C, D, E, A); |
7325 |
+- T_20_39(35, A, B, C, D, E); |
7326 |
+- T_20_39(36, E, A, B, C, D); |
7327 |
+- T_20_39(37, D, E, A, B, C); |
7328 |
+- T_20_39(38, C, D, E, A, B); |
7329 |
+- T_20_39(39, B, C, D, E, A); |
7330 |
++ for (; i < 40; ++i) |
7331 |
++ T_20_39(i, A, B, C, D, E); |
7332 |
+ |
7333 |
+ /* Round 3 */ |
7334 |
+- T_40_59(40, A, B, C, D, E); |
7335 |
+- T_40_59(41, E, A, B, C, D); |
7336 |
+- T_40_59(42, D, E, A, B, C); |
7337 |
+- T_40_59(43, C, D, E, A, B); |
7338 |
+- T_40_59(44, B, C, D, E, A); |
7339 |
+- T_40_59(45, A, B, C, D, E); |
7340 |
+- T_40_59(46, E, A, B, C, D); |
7341 |
+- T_40_59(47, D, E, A, B, C); |
7342 |
+- T_40_59(48, C, D, E, A, B); |
7343 |
+- T_40_59(49, B, C, D, E, A); |
7344 |
+- T_40_59(50, A, B, C, D, E); |
7345 |
+- T_40_59(51, E, A, B, C, D); |
7346 |
+- T_40_59(52, D, E, A, B, C); |
7347 |
+- T_40_59(53, C, D, E, A, B); |
7348 |
+- T_40_59(54, B, C, D, E, A); |
7349 |
+- T_40_59(55, A, B, C, D, E); |
7350 |
+- T_40_59(56, E, A, B, C, D); |
7351 |
+- T_40_59(57, D, E, A, B, C); |
7352 |
+- T_40_59(58, C, D, E, A, B); |
7353 |
+- T_40_59(59, B, C, D, E, A); |
7354 |
++ for (; i < 60; ++i) |
7355 |
++ T_40_59(i, A, B, C, D, E); |
7356 |
+ |
7357 |
+ /* Round 4 */ |
7358 |
+- T_60_79(60, A, B, C, D, E); |
7359 |
+- T_60_79(61, E, A, B, C, D); |
7360 |
+- T_60_79(62, D, E, A, B, C); |
7361 |
+- T_60_79(63, C, D, E, A, B); |
7362 |
+- T_60_79(64, B, C, D, E, A); |
7363 |
+- T_60_79(65, A, B, C, D, E); |
7364 |
+- T_60_79(66, E, A, B, C, D); |
7365 |
+- T_60_79(67, D, E, A, B, C); |
7366 |
+- T_60_79(68, C, D, E, A, B); |
7367 |
+- T_60_79(69, B, C, D, E, A); |
7368 |
+- T_60_79(70, A, B, C, D, E); |
7369 |
+- T_60_79(71, E, A, B, C, D); |
7370 |
+- T_60_79(72, D, E, A, B, C); |
7371 |
+- T_60_79(73, C, D, E, A, B); |
7372 |
+- T_60_79(74, B, C, D, E, A); |
7373 |
+- T_60_79(75, A, B, C, D, E); |
7374 |
+- T_60_79(76, E, A, B, C, D); |
7375 |
+- T_60_79(77, D, E, A, B, C); |
7376 |
+- T_60_79(78, C, D, E, A, B); |
7377 |
+- T_60_79(79, B, C, D, E, A); |
7378 |
++ for (; i < 80; ++i) |
7379 |
++ T_60_79(i, A, B, C, D, E); |
7380 |
+ |
7381 |
+ digest[0] += A; |
7382 |
+ digest[1] += B; |
7383 |
+diff --git a/lib/siphash.c b/lib/siphash.c |
7384 |
+index e632ee40aac1a..5b34b5c839887 100644 |
7385 |
+--- a/lib/siphash.c |
7386 |
++++ b/lib/siphash.c |
7387 |
+@@ -18,19 +18,13 @@ |
7388 |
+ #include <asm/word-at-a-time.h> |
7389 |
+ #endif |
7390 |
+ |
7391 |
+-#define SIPROUND \ |
7392 |
+- do { \ |
7393 |
+- v0 += v1; v1 = rol64(v1, 13); v1 ^= v0; v0 = rol64(v0, 32); \ |
7394 |
+- v2 += v3; v3 = rol64(v3, 16); v3 ^= v2; \ |
7395 |
+- v0 += v3; v3 = rol64(v3, 21); v3 ^= v0; \ |
7396 |
+- v2 += v1; v1 = rol64(v1, 17); v1 ^= v2; v2 = rol64(v2, 32); \ |
7397 |
+- } while (0) |
7398 |
++#define SIPROUND SIPHASH_PERMUTATION(v0, v1, v2, v3) |
7399 |
+ |
7400 |
+ #define PREAMBLE(len) \ |
7401 |
+- u64 v0 = 0x736f6d6570736575ULL; \ |
7402 |
+- u64 v1 = 0x646f72616e646f6dULL; \ |
7403 |
+- u64 v2 = 0x6c7967656e657261ULL; \ |
7404 |
+- u64 v3 = 0x7465646279746573ULL; \ |
7405 |
++ u64 v0 = SIPHASH_CONST_0; \ |
7406 |
++ u64 v1 = SIPHASH_CONST_1; \ |
7407 |
++ u64 v2 = SIPHASH_CONST_2; \ |
7408 |
++ u64 v3 = SIPHASH_CONST_3; \ |
7409 |
+ u64 b = ((u64)(len)) << 56; \ |
7410 |
+ v3 ^= key->key[1]; \ |
7411 |
+ v2 ^= key->key[0]; \ |
7412 |
+@@ -389,19 +383,13 @@ u32 hsiphash_4u32(const u32 first, const u32 second, const u32 third, |
7413 |
+ } |
7414 |
+ EXPORT_SYMBOL(hsiphash_4u32); |
7415 |
+ #else |
7416 |
+-#define HSIPROUND \ |
7417 |
+- do { \ |
7418 |
+- v0 += v1; v1 = rol32(v1, 5); v1 ^= v0; v0 = rol32(v0, 16); \ |
7419 |
+- v2 += v3; v3 = rol32(v3, 8); v3 ^= v2; \ |
7420 |
+- v0 += v3; v3 = rol32(v3, 7); v3 ^= v0; \ |
7421 |
+- v2 += v1; v1 = rol32(v1, 13); v1 ^= v2; v2 = rol32(v2, 16); \ |
7422 |
+- } while (0) |
7423 |
++#define HSIPROUND HSIPHASH_PERMUTATION(v0, v1, v2, v3) |
7424 |
+ |
7425 |
+ #define HPREAMBLE(len) \ |
7426 |
+- u32 v0 = 0; \ |
7427 |
+- u32 v1 = 0; \ |
7428 |
+- u32 v2 = 0x6c796765U; \ |
7429 |
+- u32 v3 = 0x74656462U; \ |
7430 |
++ u32 v0 = HSIPHASH_CONST_0; \ |
7431 |
++ u32 v1 = HSIPHASH_CONST_1; \ |
7432 |
++ u32 v2 = HSIPHASH_CONST_2; \ |
7433 |
++ u32 v3 = HSIPHASH_CONST_3; \ |
7434 |
+ u32 b = ((u32)(len)) << 24; \ |
7435 |
+ v3 ^= key->key[1]; \ |
7436 |
+ v2 ^= key->key[0]; \ |
7437 |
+diff --git a/lib/swiotlb.c b/lib/swiotlb.c |
7438 |
+index 74b5b88621989..277a2f6fde6b1 100644 |
7439 |
+--- a/lib/swiotlb.c |
7440 |
++++ b/lib/swiotlb.c |
7441 |
+@@ -532,9 +532,14 @@ found: |
7442 |
+ */ |
7443 |
+ for (i = 0; i < nslots; i++) |
7444 |
+ io_tlb_orig_addr[index+i] = orig_addr + (i << IO_TLB_SHIFT); |
7445 |
+- if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) |
7446 |
+- swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); |
7447 |
+- |
7448 |
++ /* |
7449 |
++ * When dir == DMA_FROM_DEVICE we could omit the copy from the orig |
7450 |
++ * to the tlb buffer, if we knew for sure the device will |
7451 |
++ * overwirte the entire current content. But we don't. Thus |
7452 |
++ * unconditional bounce may prevent leaking swiotlb content (i.e. |
7453 |
++ * kernel memory) to user-space. |
7454 |
++ */ |
7455 |
++ swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); |
7456 |
+ return tlb_addr; |
7457 |
+ } |
7458 |
+ EXPORT_SYMBOL_GPL(swiotlb_tbl_map_single); |
7459 |
+diff --git a/mm/util.c b/mm/util.c |
7460 |
+index 07f4672061867..0559a1feec029 100644 |
7461 |
+--- a/mm/util.c |
7462 |
++++ b/mm/util.c |
7463 |
+@@ -11,6 +11,7 @@ |
7464 |
+ #include <linux/mman.h> |
7465 |
+ #include <linux/hugetlb.h> |
7466 |
+ #include <linux/vmalloc.h> |
7467 |
++#include <linux/random.h> |
7468 |
+ |
7469 |
+ #include <asm/sections.h> |
7470 |
+ #include <asm/uaccess.h> |
7471 |
+@@ -261,6 +262,38 @@ int vma_is_stack_for_current(struct vm_area_struct *vma) |
7472 |
+ return (vma->vm_start <= KSTK_ESP(t) && vma->vm_end >= KSTK_ESP(t)); |
7473 |
+ } |
7474 |
+ |
7475 |
++/** |
7476 |
++ * randomize_page - Generate a random, page aligned address |
7477 |
++ * @start: The smallest acceptable address the caller will take. |
7478 |
++ * @range: The size of the area, starting at @start, within which the |
7479 |
++ * random address must fall. |
7480 |
++ * |
7481 |
++ * If @start + @range would overflow, @range is capped. |
7482 |
++ * |
7483 |
++ * NOTE: Historical use of randomize_range, which this replaces, presumed that |
7484 |
++ * @start was already page aligned. We now align it regardless. |
7485 |
++ * |
7486 |
++ * Return: A page aligned address within [start, start + range). On error, |
7487 |
++ * @start is returned. |
7488 |
++ */ |
7489 |
++unsigned long randomize_page(unsigned long start, unsigned long range) |
7490 |
++{ |
7491 |
++ if (!PAGE_ALIGNED(start)) { |
7492 |
++ range -= PAGE_ALIGN(start) - start; |
7493 |
++ start = PAGE_ALIGN(start); |
7494 |
++ } |
7495 |
++ |
7496 |
++ if (start > ULONG_MAX - range) |
7497 |
++ range = ULONG_MAX - start; |
7498 |
++ |
7499 |
++ range >>= PAGE_SHIFT; |
7500 |
++ |
7501 |
++ if (range == 0) |
7502 |
++ return start; |
7503 |
++ |
7504 |
++ return start + (get_random_long() % range << PAGE_SHIFT); |
7505 |
++} |
7506 |
++ |
7507 |
+ #if defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT) |
7508 |
+ void arch_pick_mmap_layout(struct mm_struct *mm) |
7509 |
+ { |
7510 |
+diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c |
7511 |
+index fd3ce461fbe62..ed05b8277aa40 100644 |
7512 |
+--- a/net/core/secure_seq.c |
7513 |
++++ b/net/core/secure_seq.c |
7514 |
+@@ -62,7 +62,7 @@ __u32 secure_tcpv6_sequence_number(const __be32 *saddr, const __be32 *daddr, |
7515 |
+ } |
7516 |
+ EXPORT_SYMBOL(secure_tcpv6_sequence_number); |
7517 |
+ |
7518 |
+-u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, |
7519 |
++u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, |
7520 |
+ __be16 dport) |
7521 |
+ { |
7522 |
+ u32 secret[MD5_MESSAGE_BYTES / 4]; |
7523 |
+@@ -102,7 +102,7 @@ __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr, |
7524 |
+ return seq_scale(hash[0]); |
7525 |
+ } |
7526 |
+ |
7527 |
+-u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport) |
7528 |
++u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport) |
7529 |
+ { |
7530 |
+ u32 hash[MD5_DIGEST_WORDS]; |
7531 |
+ |
7532 |
+diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c |
7533 |
+index 8876338707636..db47e1c407d9a 100644 |
7534 |
+--- a/net/ipv4/inet_hashtables.c |
7535 |
++++ b/net/ipv4/inet_hashtables.c |
7536 |
+@@ -382,7 +382,7 @@ not_unique: |
7537 |
+ return -EADDRNOTAVAIL; |
7538 |
+ } |
7539 |
+ |
7540 |
+-static u32 inet_sk_port_offset(const struct sock *sk) |
7541 |
++static u64 inet_sk_port_offset(const struct sock *sk) |
7542 |
+ { |
7543 |
+ const struct inet_sock *inet = inet_sk(sk); |
7544 |
+ |
7545 |
+@@ -537,8 +537,21 @@ void inet_unhash(struct sock *sk) |
7546 |
+ } |
7547 |
+ EXPORT_SYMBOL_GPL(inet_unhash); |
7548 |
+ |
7549 |
++/* RFC 6056 3.3.4. Algorithm 4: Double-Hash Port Selection Algorithm |
7550 |
++ * Note that we use 32bit integers (vs RFC 'short integers') |
7551 |
++ * because 2^16 is not a multiple of num_ephemeral and this |
7552 |
++ * property might be used by clever attacker. |
7553 |
++ * RFC claims using TABLE_LENGTH=10 buckets gives an improvement, though |
7554 |
++ * attacks were since demonstrated, thus we use 65536 instead to really |
7555 |
++ * give more isolation and privacy, at the expense of 256kB of kernel |
7556 |
++ * memory. |
7557 |
++ */ |
7558 |
++#define INET_TABLE_PERTURB_SHIFT 16 |
7559 |
++#define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT) |
7560 |
++static u32 *table_perturb; |
7561 |
++ |
7562 |
+ int __inet_hash_connect(struct inet_timewait_death_row *death_row, |
7563 |
+- struct sock *sk, u32 port_offset, |
7564 |
++ struct sock *sk, u64 port_offset, |
7565 |
+ int (*check_established)(struct inet_timewait_death_row *, |
7566 |
+ struct sock *, __u16, struct inet_timewait_sock **)) |
7567 |
+ { |
7568 |
+@@ -550,7 +563,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, |
7569 |
+ struct inet_bind_bucket *tb; |
7570 |
+ u32 remaining, offset; |
7571 |
+ int ret, i, low, high; |
7572 |
+- static u32 hint; |
7573 |
++ u32 index; |
7574 |
+ |
7575 |
+ if (port) { |
7576 |
+ head = &hinfo->bhash[inet_bhashfn(net, port, |
7577 |
+@@ -575,7 +588,13 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, |
7578 |
+ if (likely(remaining > 1)) |
7579 |
+ remaining &= ~1U; |
7580 |
+ |
7581 |
+- offset = (hint + port_offset) % remaining; |
7582 |
++ net_get_random_once(table_perturb, |
7583 |
++ INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb)); |
7584 |
++ index = port_offset & (INET_TABLE_PERTURB_SIZE - 1); |
7585 |
++ |
7586 |
++ offset = READ_ONCE(table_perturb[index]) + (port_offset >> 32); |
7587 |
++ offset %= remaining; |
7588 |
++ |
7589 |
+ /* In first pass we try ports of @low parity. |
7590 |
+ * inet_csk_get_port() does the opposite choice. |
7591 |
+ */ |
7592 |
+@@ -628,7 +647,13 @@ next_port: |
7593 |
+ return -EADDRNOTAVAIL; |
7594 |
+ |
7595 |
+ ok: |
7596 |
+- hint += i + 2; |
7597 |
++ /* Here we want to add a little bit of randomness to the next source |
7598 |
++ * port that will be chosen. We use a max() with a random here so that |
7599 |
++ * on low contention the randomness is maximal and on high contention |
7600 |
++ * it may be inexistent. |
7601 |
++ */ |
7602 |
++ i = max_t(int, i, (prandom_u32() & 7) * 2); |
7603 |
++ WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2); |
7604 |
+ |
7605 |
+ /* Head lock still held and bh's disabled */ |
7606 |
+ inet_bind_hash(sk, tb, port); |
7607 |
+@@ -651,7 +676,7 @@ ok: |
7608 |
+ int inet_hash_connect(struct inet_timewait_death_row *death_row, |
7609 |
+ struct sock *sk) |
7610 |
+ { |
7611 |
+- u32 port_offset = 0; |
7612 |
++ u64 port_offset = 0; |
7613 |
+ |
7614 |
+ if (!inet_sk(sk)->inet_num) |
7615 |
+ port_offset = inet_sk_port_offset(sk); |
7616 |
+@@ -669,6 +694,15 @@ void inet_hashinfo_init(struct inet_hashinfo *h) |
7617 |
+ INIT_HLIST_NULLS_HEAD(&h->listening_hash[i].nulls_head, |
7618 |
+ i + LISTENING_NULLS_BASE); |
7619 |
+ } |
7620 |
++ |
7621 |
++ if (h != &tcp_hashinfo) |
7622 |
++ return; |
7623 |
++ |
7624 |
++ /* this one is used for source ports of outgoing connections */ |
7625 |
++ table_perturb = kmalloc_array(INET_TABLE_PERTURB_SIZE, |
7626 |
++ sizeof(*table_perturb), GFP_KERNEL); |
7627 |
++ if (!table_perturb) |
7628 |
++ panic("TCP: failed to alloc table_perturb"); |
7629 |
+ } |
7630 |
+ EXPORT_SYMBOL_GPL(inet_hashinfo_init); |
7631 |
+ |
7632 |
+diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c |
7633 |
+index d47cab6d7c6de..8223ac61a9fd3 100644 |
7634 |
+--- a/net/ipv6/inet6_hashtables.c |
7635 |
++++ b/net/ipv6/inet6_hashtables.c |
7636 |
+@@ -242,7 +242,7 @@ not_unique: |
7637 |
+ return -EADDRNOTAVAIL; |
7638 |
+ } |
7639 |
+ |
7640 |
+-static u32 inet6_sk_port_offset(const struct sock *sk) |
7641 |
++static u64 inet6_sk_port_offset(const struct sock *sk) |
7642 |
+ { |
7643 |
+ const struct inet_sock *inet = inet_sk(sk); |
7644 |
+ |
7645 |
+@@ -254,7 +254,7 @@ static u32 inet6_sk_port_offset(const struct sock *sk) |
7646 |
+ int inet6_hash_connect(struct inet_timewait_death_row *death_row, |
7647 |
+ struct sock *sk) |
7648 |
+ { |
7649 |
+- u32 port_offset = 0; |
7650 |
++ u64 port_offset = 0; |
7651 |
+ |
7652 |
+ if (!inet_sk(sk)->inet_num) |
7653 |
+ port_offset = inet6_sk_port_offset(sk); |
7654 |
+diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c |
7655 |
+index 76ef758db1124..e412020029dfb 100644 |
7656 |
+--- a/net/l2tp/l2tp_ip6.c |
7657 |
++++ b/net/l2tp/l2tp_ip6.c |
7658 |
+@@ -518,14 +518,15 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) |
7659 |
+ struct ipcm6_cookie ipc6; |
7660 |
+ int addr_len = msg->msg_namelen; |
7661 |
+ int transhdrlen = 4; /* zero session-id */ |
7662 |
+- int ulen = len + transhdrlen; |
7663 |
++ int ulen; |
7664 |
+ int err; |
7665 |
+ |
7666 |
+ /* Rough check on arithmetic overflow, |
7667 |
+ better check is made in ip6_append_data(). |
7668 |
+ */ |
7669 |
+- if (len > INT_MAX) |
7670 |
++ if (len > INT_MAX - transhdrlen) |
7671 |
+ return -EMSGSIZE; |
7672 |
++ ulen = len + transhdrlen; |
7673 |
+ |
7674 |
+ /* Mirror BSD error message compatibility */ |
7675 |
+ if (msg->msg_flags & MSG_OOB) |
7676 |
+diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c |
7677 |
+index 979fa868a4f1d..4673f6f489425 100644 |
7678 |
+--- a/net/l2tp/l2tp_ppp.c |
7679 |
++++ b/net/l2tp/l2tp_ppp.c |
7680 |
+@@ -435,20 +435,28 @@ abort: |
7681 |
+ * Session (and tunnel control) socket create/destroy. |
7682 |
+ *****************************************************************************/ |
7683 |
+ |
7684 |
++static void pppol2tp_put_sk(struct rcu_head *head) |
7685 |
++{ |
7686 |
++ struct pppol2tp_session *ps; |
7687 |
++ |
7688 |
++ ps = container_of(head, typeof(*ps), rcu); |
7689 |
++ sock_put(ps->__sk); |
7690 |
++} |
7691 |
++ |
7692 |
+ /* Called by l2tp_core when a session socket is being closed. |
7693 |
+ */ |
7694 |
+ static void pppol2tp_session_close(struct l2tp_session *session) |
7695 |
+ { |
7696 |
+- struct sock *sk; |
7697 |
+- |
7698 |
+- BUG_ON(session->magic != L2TP_SESSION_MAGIC); |
7699 |
++ struct pppol2tp_session *ps; |
7700 |
+ |
7701 |
+- sk = pppol2tp_session_get_sock(session); |
7702 |
+- if (sk) { |
7703 |
+- if (sk->sk_socket) |
7704 |
+- inet_shutdown(sk->sk_socket, SEND_SHUTDOWN); |
7705 |
+- sock_put(sk); |
7706 |
+- } |
7707 |
++ ps = l2tp_session_priv(session); |
7708 |
++ mutex_lock(&ps->sk_lock); |
7709 |
++ ps->__sk = rcu_dereference_protected(ps->sk, |
7710 |
++ lockdep_is_held(&ps->sk_lock)); |
7711 |
++ RCU_INIT_POINTER(ps->sk, NULL); |
7712 |
++ if (ps->__sk) |
7713 |
++ call_rcu(&ps->rcu, pppol2tp_put_sk); |
7714 |
++ mutex_unlock(&ps->sk_lock); |
7715 |
+ } |
7716 |
+ |
7717 |
+ /* Really kill the session socket. (Called from sock_put() if |
7718 |
+@@ -468,14 +476,6 @@ static void pppol2tp_session_destruct(struct sock *sk) |
7719 |
+ } |
7720 |
+ } |
7721 |
+ |
7722 |
+-static void pppol2tp_put_sk(struct rcu_head *head) |
7723 |
+-{ |
7724 |
+- struct pppol2tp_session *ps; |
7725 |
+- |
7726 |
+- ps = container_of(head, typeof(*ps), rcu); |
7727 |
+- sock_put(ps->__sk); |
7728 |
+-} |
7729 |
+- |
7730 |
+ /* Called when the PPPoX socket (session) is closed. |
7731 |
+ */ |
7732 |
+ static int pppol2tp_release(struct socket *sock) |
7733 |
+@@ -499,26 +499,17 @@ static int pppol2tp_release(struct socket *sock) |
7734 |
+ sock_orphan(sk); |
7735 |
+ sock->sk = NULL; |
7736 |
+ |
7737 |
++ /* If the socket is associated with a session, |
7738 |
++ * l2tp_session_delete will call pppol2tp_session_close which |
7739 |
++ * will drop the session's ref on the socket. |
7740 |
++ */ |
7741 |
+ session = pppol2tp_sock_to_session(sk); |
7742 |
+- |
7743 |
+- if (session != NULL) { |
7744 |
+- struct pppol2tp_session *ps; |
7745 |
+- |
7746 |
++ if (session) { |
7747 |
+ l2tp_session_delete(session); |
7748 |
+- |
7749 |
+- ps = l2tp_session_priv(session); |
7750 |
+- mutex_lock(&ps->sk_lock); |
7751 |
+- ps->__sk = rcu_dereference_protected(ps->sk, |
7752 |
+- lockdep_is_held(&ps->sk_lock)); |
7753 |
+- RCU_INIT_POINTER(ps->sk, NULL); |
7754 |
+- mutex_unlock(&ps->sk_lock); |
7755 |
+- call_rcu(&ps->rcu, pppol2tp_put_sk); |
7756 |
+- |
7757 |
+- /* Rely on the sock_put() call at the end of the function for |
7758 |
+- * dropping the reference held by pppol2tp_sock_to_session(). |
7759 |
+- * The last reference will be dropped by pppol2tp_put_sk(). |
7760 |
+- */ |
7761 |
++ /* drop the ref obtained by pppol2tp_sock_to_session */ |
7762 |
++ sock_put(sk); |
7763 |
+ } |
7764 |
++ |
7765 |
+ release_sock(sk); |
7766 |
+ |
7767 |
+ /* This will delete the session context via |
7768 |
+@@ -827,6 +818,7 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr, |
7769 |
+ |
7770 |
+ out_no_ppp: |
7771 |
+ /* This is how we get the session context from the socket. */ |
7772 |
++ sock_hold(sk); |
7773 |
+ sk->sk_user_data = session; |
7774 |
+ rcu_assign_pointer(ps->sk, sk); |
7775 |
+ mutex_unlock(&ps->sk_lock); |
7776 |
+diff --git a/net/sunrpc/xprtrdma/rpc_rdma.c b/net/sunrpc/xprtrdma/rpc_rdma.c |
7777 |
+index 0287734f126f6..aec0113a88b08 100644 |
7778 |
+--- a/net/sunrpc/xprtrdma/rpc_rdma.c |
7779 |
++++ b/net/sunrpc/xprtrdma/rpc_rdma.c |
7780 |
+@@ -75,7 +75,7 @@ static unsigned int rpcrdma_max_call_header_size(unsigned int maxsegs) |
7781 |
+ |
7782 |
+ /* Maximum Read list size */ |
7783 |
+ maxsegs += 2; /* segment for head and tail buffers */ |
7784 |
+- size = maxsegs * sizeof(struct rpcrdma_read_chunk); |
7785 |
++ size += maxsegs * sizeof(struct rpcrdma_read_chunk); |
7786 |
+ |
7787 |
+ /* Minimal Read chunk size */ |
7788 |
+ size += sizeof(__be32); /* segment count */ |
7789 |
+@@ -101,7 +101,7 @@ static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs) |
7790 |
+ |
7791 |
+ /* Maximum Write list size */ |
7792 |
+ maxsegs += 2; /* segment for head and tail buffers */ |
7793 |
+- size = sizeof(__be32); /* segment count */ |
7794 |
++ size += sizeof(__be32); /* segment count */ |
7795 |
+ size += maxsegs * sizeof(struct rpcrdma_segment); |
7796 |
+ size += sizeof(__be32); /* list discriminator */ |
7797 |
+ |
7798 |
+diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c |
7799 |
+index 0d9c4a57301bb..47f2439fd7b08 100644 |
7800 |
+--- a/sound/soc/codecs/cs42l52.c |
7801 |
++++ b/sound/soc/codecs/cs42l52.c |
7802 |
+@@ -141,7 +141,9 @@ static DECLARE_TLV_DB_SCALE(mic_tlv, 1600, 100, 0); |
7803 |
+ |
7804 |
+ static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0); |
7805 |
+ |
7806 |
+-static DECLARE_TLV_DB_SCALE(mix_tlv, -50, 50, 0); |
7807 |
++static DECLARE_TLV_DB_SCALE(pass_tlv, -6000, 50, 0); |
7808 |
++ |
7809 |
++static DECLARE_TLV_DB_SCALE(mix_tlv, -5150, 50, 0); |
7810 |
+ |
7811 |
+ static DECLARE_TLV_DB_SCALE(beep_tlv, -56, 200, 0); |
7812 |
+ |
7813 |
+@@ -355,7 +357,7 @@ static const struct snd_kcontrol_new cs42l52_snd_controls[] = { |
7814 |
+ CS42L52_SPKB_VOL, 0, 0x40, 0xC0, hl_tlv), |
7815 |
+ |
7816 |
+ SOC_DOUBLE_R_SX_TLV("Bypass Volume", CS42L52_PASSTHRUA_VOL, |
7817 |
+- CS42L52_PASSTHRUB_VOL, 0, 0x88, 0x90, pga_tlv), |
7818 |
++ CS42L52_PASSTHRUB_VOL, 0, 0x88, 0x90, pass_tlv), |
7819 |
+ |
7820 |
+ SOC_DOUBLE("Bypass Mute", CS42L52_MISC_CTL, 4, 5, 1, 0), |
7821 |
+ |
7822 |
+@@ -368,7 +370,7 @@ static const struct snd_kcontrol_new cs42l52_snd_controls[] = { |
7823 |
+ CS42L52_ADCB_VOL, 0, 0xA0, 0x78, ipd_tlv), |
7824 |
+ SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", |
7825 |
+ CS42L52_ADCA_MIXER_VOL, CS42L52_ADCB_MIXER_VOL, |
7826 |
+- 0, 0x19, 0x7F, ipd_tlv), |
7827 |
++ 0, 0x19, 0x7F, mix_tlv), |
7828 |
+ |
7829 |
+ SOC_DOUBLE("ADC Switch", CS42L52_ADC_MISC_CTL, 0, 1, 1, 0), |
7830 |
+ |
7831 |
+diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c |
7832 |
+index a2535a7eb4bbd..f9f8a9112ff8d 100644 |
7833 |
+--- a/sound/soc/codecs/cs42l56.c |
7834 |
++++ b/sound/soc/codecs/cs42l56.c |
7835 |
+@@ -405,9 +405,9 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { |
7836 |
+ SOC_DOUBLE("ADC Boost Switch", CS42L56_GAIN_BIAS_CTL, 3, 2, 1, 1), |
7837 |
+ |
7838 |
+ SOC_DOUBLE_R_SX_TLV("Headphone Volume", CS42L56_HPA_VOLUME, |
7839 |
+- CS42L56_HPB_VOLUME, 0, 0x84, 0x48, hl_tlv), |
7840 |
++ CS42L56_HPB_VOLUME, 0, 0x44, 0x48, hl_tlv), |
7841 |
+ SOC_DOUBLE_R_SX_TLV("LineOut Volume", CS42L56_LOA_VOLUME, |
7842 |
+- CS42L56_LOB_VOLUME, 0, 0x84, 0x48, hl_tlv), |
7843 |
++ CS42L56_LOB_VOLUME, 0, 0x44, 0x48, hl_tlv), |
7844 |
+ |
7845 |
+ SOC_SINGLE_TLV("Bass Shelving Volume", CS42L56_TONE_CTL, |
7846 |
+ 0, 0x00, 1, tone_tlv), |
7847 |
+diff --git a/sound/soc/codecs/cs53l30.c b/sound/soc/codecs/cs53l30.c |
7848 |
+index cb47fb595ff41..5a16020423fe0 100644 |
7849 |
+--- a/sound/soc/codecs/cs53l30.c |
7850 |
++++ b/sound/soc/codecs/cs53l30.c |
7851 |
+@@ -351,22 +351,22 @@ static const struct snd_kcontrol_new cs53l30_snd_controls[] = { |
7852 |
+ SOC_ENUM("ADC2 NG Delay", adc2_ng_delay_enum), |
7853 |
+ |
7854 |
+ SOC_SINGLE_SX_TLV("ADC1A PGA Volume", |
7855 |
+- CS53L30_ADC1A_AFE_CTL, 0, 0x34, 0x18, pga_tlv), |
7856 |
++ CS53L30_ADC1A_AFE_CTL, 0, 0x34, 0x24, pga_tlv), |
7857 |
+ SOC_SINGLE_SX_TLV("ADC1B PGA Volume", |
7858 |
+- CS53L30_ADC1B_AFE_CTL, 0, 0x34, 0x18, pga_tlv), |
7859 |
++ CS53L30_ADC1B_AFE_CTL, 0, 0x34, 0x24, pga_tlv), |
7860 |
+ SOC_SINGLE_SX_TLV("ADC2A PGA Volume", |
7861 |
+- CS53L30_ADC2A_AFE_CTL, 0, 0x34, 0x18, pga_tlv), |
7862 |
++ CS53L30_ADC2A_AFE_CTL, 0, 0x34, 0x24, pga_tlv), |
7863 |
+ SOC_SINGLE_SX_TLV("ADC2B PGA Volume", |
7864 |
+- CS53L30_ADC2B_AFE_CTL, 0, 0x34, 0x18, pga_tlv), |
7865 |
++ CS53L30_ADC2B_AFE_CTL, 0, 0x34, 0x24, pga_tlv), |
7866 |
+ |
7867 |
+ SOC_SINGLE_SX_TLV("ADC1A Digital Volume", |
7868 |
+- CS53L30_ADC1A_DIG_VOL, 0, 0xA0, 0x0C, dig_tlv), |
7869 |
++ CS53L30_ADC1A_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv), |
7870 |
+ SOC_SINGLE_SX_TLV("ADC1B Digital Volume", |
7871 |
+- CS53L30_ADC1B_DIG_VOL, 0, 0xA0, 0x0C, dig_tlv), |
7872 |
++ CS53L30_ADC1B_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv), |
7873 |
+ SOC_SINGLE_SX_TLV("ADC2A Digital Volume", |
7874 |
+- CS53L30_ADC2A_DIG_VOL, 0, 0xA0, 0x0C, dig_tlv), |
7875 |
++ CS53L30_ADC2A_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv), |
7876 |
+ SOC_SINGLE_SX_TLV("ADC2B Digital Volume", |
7877 |
+- CS53L30_ADC2B_DIG_VOL, 0, 0xA0, 0x0C, dig_tlv), |
7878 |
++ CS53L30_ADC2B_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv), |
7879 |
+ }; |
7880 |
+ |
7881 |
+ static const struct snd_soc_dapm_widget cs53l30_dapm_widgets[] = { |
7882 |
+diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c |
7883 |
+index 0e8008d381619..d46881f96c164 100644 |
7884 |
+--- a/sound/soc/codecs/wm8962.c |
7885 |
++++ b/sound/soc/codecs/wm8962.c |
7886 |
+@@ -3861,6 +3861,7 @@ static int wm8962_runtime_suspend(struct device *dev) |
7887 |
+ #endif |
7888 |
+ |
7889 |
+ static const struct dev_pm_ops wm8962_pm = { |
7890 |
++ SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) |
7891 |
+ SET_RUNTIME_PM_OPS(wm8962_runtime_suspend, wm8962_runtime_resume, NULL) |
7892 |
+ }; |
7893 |
+ |