Skip to content

Commit b7552e1

Browse files
borkmanndavem330
authored andcommitted
bpf: rather use get_random_int for randomizations
Start address randomization and blinding in BPF currently use prandom_u32(). prandom_u32() values are not exposed to unpriviledged user space to my knowledge, but given other kernel facilities such as ASLR, stack canaries, etc make use of stronger get_random_int(), we better make use of it here as well given blinding requests successively new random values. get_random_int() has minimal entropy pool depletion, is not cryptographically secure, but doesn't need to be for our use cases here. Suggested-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 09ec8e7 commit b7552e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/bpf/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
231231
hdr->pages = size / PAGE_SIZE;
232232
hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
233233
PAGE_SIZE - sizeof(*hdr));
234-
start = (prandom_u32() % hole) & ~(alignment - 1);
234+
start = (get_random_int() % hole) & ~(alignment - 1);
235235

236236
/* Leave a random number of instructions before BPF code. */
237237
*image_ptr = &hdr->image[start];
@@ -251,7 +251,7 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
251251
struct bpf_insn *to_buff)
252252
{
253253
struct bpf_insn *to = to_buff;
254-
u32 imm_rnd = prandom_u32();
254+
u32 imm_rnd = get_random_int();
255255
s16 off;
256256

257257
BUILD_BUG_ON(BPF_REG_AX + 1 != MAX_BPF_JIT_REG);

0 commit comments

Comments
 (0)