Skip to content

Commit

Permalink
treewide: use get_random_u32_below() instead of deprecated function
Browse files Browse the repository at this point in the history
This is a simple mechanical transformation done by:

@@
expression E;
@@
- prandom_u32_max
+ get_random_u32_below
  (E)

Reviewed-by: Kees Cook <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Acked-by: Darrick J. Wong <[email protected]> # for xfs
Reviewed-by: SeongJae Park <[email protected]> # for damon
Reviewed-by: Jason Gunthorpe <[email protected]> # for infiniband
Reviewed-by: Russell King (Oracle) <[email protected]> # for arm
Acked-by: Ulf Hansson <[email protected]> # for mmc
Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Nov 18, 2022
1 parent 7f576b2 commit 8032bf1
Show file tree
Hide file tree
Showing 132 changed files with 280 additions and 280 deletions.
2 changes: 1 addition & 1 deletion arch/arm/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static unsigned long sigpage_addr(const struct mm_struct *mm,

slots = ((last - first) >> PAGE_SHIFT) + 1;

offset = prandom_u32_max(slots);
offset = get_random_u32_below(slots);

addr = first + (offset << PAGE_SHIFT);

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ unsigned long __get_wchan(struct task_struct *p)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(PAGE_SIZE);
sp -= get_random_u32_below(PAGE_SIZE);
return sp & ~0xf;
}

Expand Down
2 changes: 1 addition & 1 deletion arch/loongarch/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ unsigned long stack_top(void)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(PAGE_SIZE);
sp -= get_random_u32_below(PAGE_SIZE);

return sp & STACK_ALIGN;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/loongarch/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static unsigned long vdso_base(void)
unsigned long base = STACK_TOP;

if (current->flags & PF_RANDOMIZE) {
base += prandom_u32_max(VDSO_RANDOMIZE_SIZE);
base += get_random_u32_below(VDSO_RANDOMIZE_SIZE);
base = PAGE_ALIGN(base);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ unsigned long mips_stack_top(void)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(PAGE_SIZE);
sp -= get_random_u32_below(PAGE_SIZE);

return sp & ALMASK;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static unsigned long vdso_base(void)
}

if (current->flags & PF_RANDOMIZE) {
base += prandom_u32_max(VDSO_RANDOMIZE_SIZE);
base += get_random_u32_below(VDSO_RANDOMIZE_SIZE);
base = PAGE_ALIGN(base);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/parisc/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,

map_base = mm->mmap_base;
if (current->flags & PF_RANDOMIZE)
map_base -= prandom_u32_max(0x20) * PAGE_SIZE;
map_base -= get_random_u32_below(0x20) * PAGE_SIZE;

vdso_text_start = get_unmapped_area(NULL, map_base, vdso_text_len, 0, 0);

Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/crypto/crc-vpmsum_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static int __init crc_test_init(void)

pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
for (i=0; i<iterations; i++) {
size_t offset = prandom_u32_max(16);
size_t len = prandom_u32_max(MAX_CRC_LENGTH);
size_t offset = get_random_u32_below(16);
size_t len = get_random_u32_below(MAX_CRC_LENGTH);

if (len <= offset)
continue;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,6 @@ void notrace __ppc64_runlatch_off(void)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(PAGE_SIZE);
sp -= get_random_u32_below(PAGE_SIZE);
return sp & ~0xf;
}
2 changes: 1 addition & 1 deletion arch/s390/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ unsigned long __get_wchan(struct task_struct *p)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(PAGE_SIZE);
sp -= get_random_u32_below(PAGE_SIZE);
return sp & ~0xf;
}

Expand Down
2 changes: 1 addition & 1 deletion arch/s390/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static unsigned long vdso_addr(unsigned long start, unsigned long len)
end -= len;

if (end > start) {
offset = prandom_u32_max(((end - start) >> PAGE_SHIFT) + 1);
offset = get_random_u32_below(((end - start) >> PAGE_SHIFT) + 1);
addr = start + (offset << PAGE_SHIFT);
} else {
addr = start;
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/vdso/vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static unsigned long vdso_addr(unsigned long start, unsigned int len)
unsigned int offset;

/* This loses some more bits than a modulo, but is cheaper */
offset = prandom_u32_max(PTRS_PER_PTE);
offset = get_random_u32_below(PTRS_PER_PTE);
return start + (offset << PAGE_SHIFT);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/um/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ int singlestepping(void * t)
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(8192);
sp -= get_random_u32_below(8192);
return sp & ~0xf;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/entry/vdso/vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
end -= len;

if (end > start) {
offset = prandom_u32_max(((end - start) >> PAGE_SHIFT) + 1);
offset = get_random_u32_below(((end - start) >> PAGE_SHIFT) + 1);
addr = start + (offset << PAGE_SHIFT);
} else {
addr = start;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static unsigned long int get_module_load_offset(void)
*/
if (module_load_offset == 0)
module_load_offset =
(prandom_u32_max(1024) + 1) * PAGE_SIZE;
(get_random_u32_below(1024) + 1) * PAGE_SIZE;
mutex_unlock(&module_kaslr_mutex);
}
return module_load_offset;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ early_param("idle", idle_setup);
unsigned long arch_align_stack(unsigned long sp)
{
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
sp -= prandom_u32_max(8192);
sp -= get_random_u32_below(8192);
return sp & ~0xf;
}

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/mm/pat/cpa-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ static int pageattr_test(void)
failed += print_split(&sa);

for (i = 0; i < NTEST; i++) {
unsigned long pfn = prandom_u32_max(max_pfn_mapped);
unsigned long pfn = get_random_u32_below(max_pfn_mapped);

addr[i] = (unsigned long)__va(pfn << PAGE_SHIFT);
len[i] = prandom_u32_max(NPAGES);
len[i] = get_random_u32_below(NPAGES);
len[i] = min_t(unsigned long, len[i], max_pfn_mapped - pfn - 1);

if (len[i] == 0)
Expand Down
2 changes: 1 addition & 1 deletion crypto/rsa-pkcs1pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static int pkcs1pad_encrypt(struct akcipher_request *req)
ps_end = ctx->key_size - req->src_len - 2;
req_ctx->in_buf[0] = 0x02;
for (i = 1; i < ps_end; i++)
req_ctx->in_buf[i] = 1 + prandom_u32_max(255);
req_ctx->in_buf[i] = 1 + get_random_u32_below(255);
req_ctx->in_buf[ps_end] = 0x00;

pkcs1pad_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf,
Expand Down
Loading

0 comments on commit 8032bf1

Please sign in to comment.