Skip to content

Commit 197173d

Browse files
committed
treewide: use get_random_bytes() when possible
The prandom_bytes() function has been a deprecated inline wrapper around get_random_bytes() for several releases now, and compiles down to the exact same code. Replace the deprecated wrapper with a direct call to the real function. This was done as a basic find and replace. Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Yury Norov <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> # powerpc Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent a251c17 commit 197173d

File tree

19 files changed

+24
-24
lines changed

19 files changed

+24
-24
lines changed

arch/powerpc/crypto/crc-vpmsum_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int __init crc_test_init(void)
8282

8383
if (len <= offset)
8484
continue;
85-
prandom_bytes(data, len);
85+
get_random_bytes(data, len);
8686
len -= offset;
8787

8888
crypto_shash_update(crct10dif_shash, data+offset, len);

block/blk-crypto-fallback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static int blk_crypto_fallback_init(void)
539539
if (blk_crypto_fallback_inited)
540540
return 0;
541541

542-
prandom_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
542+
get_random_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
543543

544544
err = bioset_init(&crypto_bio_split, 64, 0, 0);
545545
if (err)

crypto/async_tx/raid6test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void makedata(int disks)
3737
int i;
3838

3939
for (i = 0; i < disks; i++) {
40-
prandom_bytes(page_address(data[i]), PAGE_SIZE);
40+
get_random_bytes(page_address(data[i]), PAGE_SIZE);
4141
dataptrs[i] = data[i];
4242
dataoffs[i] = 0;
4343
}

drivers/dma/dmatest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static unsigned long dmatest_random(void)
312312
{
313313
unsigned long buf;
314314

315-
prandom_bytes(&buf, sizeof(buf));
315+
get_random_bytes(&buf, sizeof(buf));
316316
return buf;
317317
}
318318

drivers/mtd/nand/raw/nandsim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ static int ns_do_read_error(struct nandsim *ns, int num)
13931393
unsigned int page_no = ns->regs.row;
13941394

13951395
if (ns_read_error(page_no)) {
1396-
prandom_bytes(ns->buf.byte, num);
1396+
get_random_bytes(ns->buf.byte, num);
13971397
NS_WARN("simulating read error in page %u\n", page_no);
13981398
return 1;
13991399
}

drivers/mtd/tests/mtd_nandecctest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int nand_ecc_test_run(const size_t size)
266266
goto error;
267267
}
268268

269-
prandom_bytes(correct_data, size);
269+
get_random_bytes(correct_data, size);
270270
ecc_sw_hamming_calculate(correct_data, size, correct_ecc, sm_order);
271271
for (i = 0; i < ARRAY_SIZE(nand_ecc_test); i++) {
272272
nand_ecc_test[i].prepare(error_data, error_ecc,

drivers/mtd/tests/speedtest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int __init mtd_speedtest_init(void)
223223
if (!iobuf)
224224
goto out;
225225

226-
prandom_bytes(iobuf, mtd->erasesize);
226+
get_random_bytes(iobuf, mtd->erasesize);
227227

228228
bbt = kzalloc(ebcnt, GFP_KERNEL);
229229
if (!bbt)

drivers/mtd/tests/stresstest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static int __init mtd_stresstest_init(void)
183183
goto out;
184184
for (i = 0; i < ebcnt; i++)
185185
offsets[i] = mtd->erasesize;
186-
prandom_bytes(writebuf, bufsize);
186+
get_random_bytes(writebuf, bufsize);
187187

188188
bbt = kzalloc(ebcnt, GFP_KERNEL);
189189
if (!bbt)

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3874,7 +3874,7 @@ static void bnxt_init_vnics(struct bnxt *bp)
38743874

38753875
if (bp->vnic_info[i].rss_hash_key) {
38763876
if (i == 0)
3877-
prandom_bytes(vnic->rss_hash_key,
3877+
get_random_bytes(vnic->rss_hash_key,
38783878
HW_HASH_KEY_SIZE);
38793879
else
38803880
memcpy(vnic->rss_hash_key,

drivers/net/ethernet/rocker/rocker_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static int rocker_dma_test_offset(const struct rocker *rocker,
224224
if (err)
225225
goto unmap;
226226

227-
prandom_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
227+
get_random_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
228228
for (i = 0; i < ROCKER_TEST_DMA_BUF_SIZE; i++)
229229
expect[i] = ~buf[i];
230230
err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_INVERT,

drivers/net/wireguard/selftest/allowedips.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static __init bool randomized_test(void)
284284
mutex_lock(&mutex);
285285

286286
for (i = 0; i < NUM_RAND_ROUTES; ++i) {
287-
prandom_bytes(ip, 4);
287+
get_random_bytes(ip, 4);
288288
cidr = prandom_u32_max(32) + 1;
289289
peer = peers[prandom_u32_max(NUM_PEERS)];
290290
if (wg_allowedips_insert_v4(&t, (struct in_addr *)ip, cidr,
@@ -299,7 +299,7 @@ static __init bool randomized_test(void)
299299
}
300300
for (j = 0; j < NUM_MUTATED_ROUTES; ++j) {
301301
memcpy(mutated, ip, 4);
302-
prandom_bytes(mutate_mask, 4);
302+
get_random_bytes(mutate_mask, 4);
303303
mutate_amount = prandom_u32_max(32);
304304
for (k = 0; k < mutate_amount / 8; ++k)
305305
mutate_mask[k] = 0xff;
@@ -328,7 +328,7 @@ static __init bool randomized_test(void)
328328
}
329329

330330
for (i = 0; i < NUM_RAND_ROUTES; ++i) {
331-
prandom_bytes(ip, 16);
331+
get_random_bytes(ip, 16);
332332
cidr = prandom_u32_max(128) + 1;
333333
peer = peers[prandom_u32_max(NUM_PEERS)];
334334
if (wg_allowedips_insert_v6(&t, (struct in6_addr *)ip, cidr,
@@ -343,7 +343,7 @@ static __init bool randomized_test(void)
343343
}
344344
for (j = 0; j < NUM_MUTATED_ROUTES; ++j) {
345345
memcpy(mutated, ip, 16);
346-
prandom_bytes(mutate_mask, 16);
346+
get_random_bytes(mutate_mask, 16);
347347
mutate_amount = prandom_u32_max(128);
348348
for (k = 0; k < mutate_amount / 8; ++k)
349349
mutate_mask[k] = 0xff;
@@ -381,13 +381,13 @@ static __init bool randomized_test(void)
381381

382382
for (j = 0;; ++j) {
383383
for (i = 0; i < NUM_QUERIES; ++i) {
384-
prandom_bytes(ip, 4);
384+
get_random_bytes(ip, 4);
385385
if (lookup(t.root4, 32, ip) != horrible_allowedips_lookup_v4(&h, (struct in_addr *)ip)) {
386386
horrible_allowedips_lookup_v4(&h, (struct in_addr *)ip);
387387
pr_err("allowedips random v4 self-test: FAIL\n");
388388
goto free;
389389
}
390-
prandom_bytes(ip, 16);
390+
get_random_bytes(ip, 16);
391391
if (lookup(t.root6, 128, ip) != horrible_allowedips_lookup_v6(&h, (struct in6_addr *)ip)) {
392392
pr_err("allowedips random v6 self-test: FAIL\n");
393393
goto free;

fs/ubifs/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
25812581
if (ffs)
25822582
memset(p + from, 0xFF, to - from);
25832583
else
2584-
prandom_bytes(p + from, to - from);
2584+
get_random_bytes(p + from, to - from);
25852585

25862586
return to;
25872587
}

kernel/kcsan/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static bool __init test_encode_decode(void)
4646
unsigned long addr;
4747
size_t verif_size;
4848

49-
prandom_bytes(&addr, sizeof(addr));
49+
get_random_bytes(&addr, sizeof(addr));
5050
if (addr < PAGE_SIZE)
5151
addr = PAGE_SIZE;
5252

lib/random32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ EXPORT_SYMBOL(prandom_u32_state);
6969
* @bytes: the requested number of bytes
7070
*
7171
* This is used for pseudo-randomness with no outside seeding.
72-
* For more random results, use prandom_bytes().
72+
* For more random results, use get_random_bytes().
7373
*/
7474
void prandom_bytes_state(struct rnd_state *state, void *buf, size_t bytes)
7575
{

lib/test_objagg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int test_nodelta_obj_get(struct world *world, struct objagg *objagg,
157157
int err;
158158

159159
if (should_create_root)
160-
prandom_bytes(world->next_root_buf,
160+
get_random_bytes(world->next_root_buf,
161161
sizeof(world->next_root_buf));
162162

163163
objagg_obj = world_obj_get(world, objagg, key_id);

lib/uuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(generate_random_guid);
5252

5353
static void __uuid_gen_common(__u8 b[16])
5454
{
55-
prandom_bytes(b, 16);
55+
get_random_bytes(b, 16);
5656
/* reversion 0b10 */
5757
b[8] = (b[8] & 0x3F) | 0x80;
5858
}

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3719,7 +3719,7 @@ int __init ip_rt_init(void)
37193719

37203720
ip_idents = idents_hash;
37213721

3722-
prandom_bytes(ip_idents, (ip_idents_mask + 1) * sizeof(*ip_idents));
3722+
get_random_bytes(ip_idents, (ip_idents_mask + 1) * sizeof(*ip_idents));
37233723

37243724
ip_tstamps = idents_hash + (ip_idents_mask + 1) * sizeof(*ip_idents);
37253725

net/mac80211/rc80211_minstrel_ht.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ static void __init init_sample_table(void)
20362036

20372037
memset(sample_table, 0xff, sizeof(sample_table));
20382038
for (col = 0; col < SAMPLE_COLUMNS; col++) {
2039-
prandom_bytes(rnd, sizeof(rnd));
2039+
get_random_bytes(rnd, sizeof(rnd));
20402040
for (i = 0; i < MCS_GROUP_RATES; i++) {
20412041
new_idx = (i + rnd[i]) % MCS_GROUP_RATES;
20422042
while (sample_table[col][new_idx] != 0xff)

net/sched/sch_pie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
7272
if (vars->accu_prob >= (MAX_PROB / 2) * 17)
7373
return true;
7474

75-
prandom_bytes(&rnd, 8);
75+
get_random_bytes(&rnd, 8);
7676
if ((rnd >> BITS_PER_BYTE) < local_prob) {
7777
vars->accu_prob = 0;
7878
return true;

0 commit comments

Comments
 (0)