Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

random: vDSO: move prototype of arch chacha function to vdso/getrandom.h

Having the prototype for __arch_chacha20_blocks_nostack in
arch/x86/include/asm/vdso/getrandom.h meant that the prototype and large
doc comment were cloned by every architecture, which has been causing
unnecessary churn. Instead move it into include/vdso/getrandom.h, where
it can be shared by all archs implementing it.

As a side bonus, this then lets us use that prototype in the
vdso_test_chacha self test, to ensure that it matches the source, and
indeed doing so turned up some inconsistencies, which are rectified
here.

Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

+20 -16
-13
arch/x86/include/asm/vdso/getrandom.h
··· 37 37 return &__vdso_rng_data; 38 38 } 39 39 40 - /** 41 - * __arch_chacha20_blocks_nostack - Generate ChaCha20 stream without using the stack. 42 - * @dst_bytes: Destination buffer to hold @nblocks * 64 bytes of output. 43 - * @key: 32-byte input key. 44 - * @counter: 8-byte counter, read on input and updated on return. 45 - * @nblocks: Number of blocks to generate. 46 - * 47 - * Generates a given positive number of blocks of ChaCha20 output with nonce=0, and does not write 48 - * to any stack or memory outside of the parameters passed to it, in order to mitigate stack data 49 - * leaking into forked child processes. 50 - */ 51 - extern void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *counter, size_t nblocks); 52 - 53 40 #endif /* !__ASSEMBLY__ */ 54 41 55 42 #endif /* __ASM_VDSO_GETRANDOM_H */
+13
include/vdso/getrandom.h
··· 43 43 bool in_use; 44 44 }; 45 45 46 + /** 47 + * __arch_chacha20_blocks_nostack - Generate ChaCha20 stream without using the stack. 48 + * @dst_bytes: Destination buffer to hold @nblocks * 64 bytes of output. 49 + * @key: 32-byte input key. 50 + * @counter: 8-byte counter, read on input and updated on return. 51 + * @nblocks: Number of blocks to generate. 52 + * 53 + * Generates a given positive number of blocks of ChaCha20 output with nonce=0, and does not write 54 + * to any stack or memory outside of the parameters passed to it, in order to mitigate stack data 55 + * leaking into forked child processes. 56 + */ 57 + extern void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *counter, size_t nblocks); 58 + 46 59 #endif /* _VDSO_GETRANDOM_H */
+7 -3
tools/testing/selftests/vDSO/vdso_test_chacha.c
··· 7 7 #include <sys/random.h> 8 8 #include <string.h> 9 9 #include <stdint.h> 10 + #include <stdbool.h> 10 11 #include "../kselftest.h" 11 12 12 - extern void __arch_chacha20_blocks_nostack(uint8_t *dst_bytes, const uint8_t *key, uint32_t *counter, size_t nblocks); 13 + typedef uint8_t u8; 14 + typedef uint32_t u32; 15 + typedef uint64_t u64; 16 + #include <vdso/getrandom.h> 13 17 14 18 int main(int argc, char *argv[]) 15 19 { 16 20 enum { TRIALS = 1000, BLOCKS = 128, BLOCK_SIZE = 64 }; 17 21 static const uint8_t nonce[8] = { 0 }; 18 22 uint32_t counter[2]; 19 - uint8_t key[32]; 23 + uint32_t key[8]; 20 24 uint8_t output1[BLOCK_SIZE * BLOCKS], output2[BLOCK_SIZE * BLOCKS]; 21 25 22 26 ksft_print_header(); ··· 31 27 printf("getrandom() failed!\n"); 32 28 return KSFT_SKIP; 33 29 } 34 - crypto_stream_chacha20(output1, sizeof(output1), nonce, key); 30 + crypto_stream_chacha20(output1, sizeof(output1), nonce, (uint8_t *)key); 35 31 for (unsigned int split = 0; split < BLOCKS; ++split) { 36 32 memset(output2, 'X', sizeof(output2)); 37 33 memset(counter, 0, sizeof(counter));