-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fox Snowpatch
committed
Aug 22, 2024
1 parent
ddf9a4c
commit 8d485b4
Showing
35 changed files
with
628 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (C) 2024 Christophe Leroy <christophe.leroy@csgroup.eu>, CS GROUP France | ||
*/ | ||
#ifndef _ASM_POWERPC_VDSO_GETRANDOM_H | ||
#define _ASM_POWERPC_VDSO_GETRANDOM_H | ||
|
||
#ifndef __ASSEMBLY__ | ||
|
||
static __always_inline int do_syscall_3(const unsigned long _r0, const unsigned long _r3, | ||
const unsigned long _r4, const unsigned long _r5) | ||
{ | ||
register long r0 asm("r0") = _r0; | ||
register unsigned long r3 asm("r3") = _r3; | ||
register unsigned long r4 asm("r4") = _r4; | ||
register unsigned long r5 asm("r5") = _r5; | ||
register int ret asm ("r3"); | ||
|
||
asm volatile( | ||
" sc\n" | ||
" bns+ 1f\n" | ||
" neg %0, %0\n" | ||
"1:\n" | ||
: "=r" (ret), "+r" (r4), "+r" (r5), "+r" (r0) | ||
: "r" (r3) | ||
: "memory", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr"); | ||
|
||
return ret; | ||
} | ||
|
||
/** | ||
* getrandom_syscall - Invoke the getrandom() syscall. | ||
* @buffer: Destination buffer to fill with random bytes. | ||
* @len: Size of @buffer in bytes. | ||
* @flags: Zero or more GRND_* flags. | ||
* Returns: The number of bytes written to @buffer, or a negative value indicating an error. | ||
*/ | ||
static __always_inline ssize_t getrandom_syscall(void *buffer, size_t len, unsigned int flags) | ||
{ | ||
return do_syscall_3(__NR_getrandom, (unsigned long)buffer, | ||
(unsigned long)len, (unsigned long)flags); | ||
} | ||
|
||
static __always_inline struct vdso_rng_data *__arch_get_vdso_rng_data(void) | ||
{ | ||
BUILD_BUG(); | ||
} | ||
|
||
ssize_t __c_kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, | ||
size_t opaque_len, const struct vdso_rng_data *vd); | ||
|
||
/** | ||
* __arch_chacha20_blocks_nostack - Generate ChaCha20 stream without using the stack. | ||
* @dst_bytes: Destination buffer to hold @nblocks * 64 bytes of output. | ||
* @key: 32-byte input key. | ||
* @counter: 8-byte counter, read on input and updated on return. | ||
* @nblocks: Number of blocks to generate. | ||
* | ||
* Generates a given positive number of blocks of ChaCha20 output with nonce=0, and does not write | ||
* to any stack or memory outside of the parameters passed to it, in order to mitigate stack data | ||
* leaking into forked child processes. | ||
*/ | ||
void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *counter, size_t nblocks); | ||
|
||
#endif /* !__ASSEMBLY__ */ | ||
|
||
#endif /* _ASM_POWERPC_VDSO_GETRANDOM_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Userland implementation of getrandom() for processes | ||
* for use in the vDSO | ||
* | ||
* Copyright (C) 2024 Christophe Leroy <christophe.leroy@csgroup.eu>, CS GROUP France | ||
*/ | ||
#include <asm/processor.h> | ||
#include <asm/ppc_asm.h> | ||
#include <asm/vdso.h> | ||
#include <asm/vdso_datapage.h> | ||
#include <asm/asm-offsets.h> | ||
#include <asm/unistd.h> | ||
|
||
/* | ||
* The macro sets two stack frames, one for the caller and one for the callee | ||
* because there are no requirement for the caller to set a stack frame when | ||
* calling VDSO so it may have omitted to set one, especially on PPC64 | ||
*/ | ||
|
||
.macro cvdso_call funct | ||
.cfi_startproc | ||
PPC_STLU r1, -PPC_MIN_STKFRM(r1) | ||
.cfi_adjust_cfa_offset PPC_MIN_STKFRM | ||
mflr r0 | ||
PPC_STLU r1, -PPC_MIN_STKFRM(r1) | ||
.cfi_adjust_cfa_offset PPC_MIN_STKFRM | ||
PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) | ||
.cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF | ||
#ifdef __powerpc64__ | ||
PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) | ||
.cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT | ||
#endif | ||
get_datapage r8 | ||
addi r8, r8, VDSO_RNG_DATA_OFFSET | ||
bl CFUNC(DOTSYM(\funct)) | ||
PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) | ||
#ifdef __powerpc64__ | ||
PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1) | ||
.cfi_restore r2 | ||
#endif | ||
cmpwi r3, 0 | ||
mtlr r0 | ||
addi r1, r1, 2 * PPC_MIN_STKFRM | ||
.cfi_restore lr | ||
.cfi_def_cfa_offset 0 | ||
crclr so | ||
bgelr+ | ||
crset so | ||
neg r3, r3 | ||
blr | ||
.cfi_endproc | ||
.endm | ||
|
||
.text | ||
V_FUNCTION_BEGIN(__kernel_getrandom) | ||
cvdso_call __c_kernel_getrandom | ||
V_FUNCTION_END(__kernel_getrandom) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ VERSION | |
__kernel_sigtramp_rt64; | ||
__kernel_getcpu; | ||
__kernel_time; | ||
__kernel_getrandom; | ||
|
||
local: *; | ||
}; | ||
|
Oops, something went wrong.