treewide: use get_random_bytes() when possible
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 5 Oct 2022 15:49:46 +0000 (17:49 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 11 Oct 2022 23:42:58 +0000 (17:42 -0600)
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 <gregkh@linuxfoundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> # powerpc
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
19 files changed:
arch/powerpc/crypto/crc-vpmsum_test.c
block/blk-crypto-fallback.c
crypto/async_tx/raid6test.c
drivers/dma/dmatest.c
drivers/mtd/nand/raw/nandsim.c
drivers/mtd/tests/mtd_nandecctest.c
drivers/mtd/tests/speedtest.c
drivers/mtd/tests/stresstest.c
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/rocker/rocker_main.c
drivers/net/wireguard/selftest/allowedips.c
fs/ubifs/debug.c
kernel/kcsan/selftest.c
lib/random32.c
lib/test_objagg.c
lib/uuid.c
net/ipv4/route.c
net/mac80211/rc80211_minstrel_ht.c
net/sched/sch_pie.c

index c1c1ef9457fb494279873799c373b68b9485e09d..273c527868db2e6dd5f81a18d71373d6df616250 100644 (file)
@@ -82,7 +82,7 @@ static int __init crc_test_init(void)
 
                        if (len <= offset)
                                continue;
-                       prandom_bytes(data, len);
+                       get_random_bytes(data, len);
                        len -= offset;
 
                        crypto_shash_update(crct10dif_shash, data+offset, len);
index 621abd1b0e4d329655b2ea276bed7005e93522ef..ad9844c5b40cb8f491ff9f6647d1f67af007a39e 100644 (file)
@@ -539,7 +539,7 @@ static int blk_crypto_fallback_init(void)
        if (blk_crypto_fallback_inited)
                return 0;
 
-       prandom_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
+       get_random_bytes(blank_key, BLK_CRYPTO_MAX_KEY_SIZE);
 
        err = bioset_init(&crypto_bio_split, 64, 0, 0);
        if (err)
index 9719c75206618d989dd8421a5ad586c272900822..d3fbee1e03e55f1132202022366798342e044922 100644 (file)
@@ -37,7 +37,7 @@ static void makedata(int disks)
        int i;
 
        for (i = 0; i < disks; i++) {
-               prandom_bytes(page_address(data[i]), PAGE_SIZE);
+               get_random_bytes(page_address(data[i]), PAGE_SIZE);
                dataptrs[i] = data[i];
                dataoffs[i] = 0;
        }
index 9fe2ae794316967caf8c36a3d38d0cb2a0bf6ba2..ffe621695e472b6b6d96e2a06a85ff514ee65651 100644 (file)
@@ -312,7 +312,7 @@ static unsigned long dmatest_random(void)
 {
        unsigned long buf;
 
-       prandom_bytes(&buf, sizeof(buf));
+       get_random_bytes(&buf, sizeof(buf));
        return buf;
 }
 
index d211939c8bdd518ad1808d6708cffb97c614485d..672719023241b7e2f1ed0c3b36252334f9ee10d2 100644 (file)
@@ -1393,7 +1393,7 @@ static int ns_do_read_error(struct nandsim *ns, int num)
        unsigned int page_no = ns->regs.row;
 
        if (ns_read_error(page_no)) {
-               prandom_bytes(ns->buf.byte, num);
+               get_random_bytes(ns->buf.byte, num);
                NS_WARN("simulating read error in page %u\n", page_no);
                return 1;
        }
index 1c7201b0f372dfeb45ac107783b83d36f3f4de53..440988562cfdcb0340fee9fed2cfa471463cdeba 100644 (file)
@@ -266,7 +266,7 @@ static int nand_ecc_test_run(const size_t size)
                goto error;
        }
 
-       prandom_bytes(correct_data, size);
+       get_random_bytes(correct_data, size);
        ecc_sw_hamming_calculate(correct_data, size, correct_ecc, sm_order);
        for (i = 0; i < ARRAY_SIZE(nand_ecc_test); i++) {
                nand_ecc_test[i].prepare(error_data, error_ecc,
index c9ec7086bfa1deba599e9db274cfcf01d9e27cfa..075bce32caa51beda6754c1616def1246ed7fb94 100644 (file)
@@ -223,7 +223,7 @@ static int __init mtd_speedtest_init(void)
        if (!iobuf)
                goto out;
 
-       prandom_bytes(iobuf, mtd->erasesize);
+       get_random_bytes(iobuf, mtd->erasesize);
 
        bbt = kzalloc(ebcnt, GFP_KERNEL);
        if (!bbt)
index d2faaca7f19d79f3727012f4bd51b4b4798d21c5..75b6ddc5dc4dae2202e33b65a79e2a4ac5c0958c 100644 (file)
@@ -183,7 +183,7 @@ static int __init mtd_stresstest_init(void)
                goto out;
        for (i = 0; i < ebcnt; i++)
                offsets[i] = mtd->erasesize;
-       prandom_bytes(writebuf, bufsize);
+       get_random_bytes(writebuf, bufsize);
 
        bbt = kzalloc(ebcnt, GFP_KERNEL);
        if (!bbt)
index eed98c10ca9d6e422c926e9e72cdf10fd312ea03..04cf7684f1b0c2630c5984b1f7e9f4d78110aa8e 100644 (file)
@@ -3874,7 +3874,7 @@ static void bnxt_init_vnics(struct bnxt *bp)
 
                if (bp->vnic_info[i].rss_hash_key) {
                        if (i == 0)
-                               prandom_bytes(vnic->rss_hash_key,
+                               get_random_bytes(vnic->rss_hash_key,
                                              HW_HASH_KEY_SIZE);
                        else
                                memcpy(vnic->rss_hash_key,
index 5672d952452fd792de4651631e712aa3d48ffff0..9e59669a93dd3988ca6c8198995f95a9886d8cf7 100644 (file)
@@ -224,7 +224,7 @@ static int rocker_dma_test_offset(const struct rocker *rocker,
        if (err)
                goto unmap;
 
-       prandom_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
+       get_random_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
        for (i = 0; i < ROCKER_TEST_DMA_BUF_SIZE; i++)
                expect[i] = ~buf[i];
        err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_INVERT,
index dd897c0740a2814012119bb689e56156411b55a5..19eac00b2381446763f306398399528026a8df23 100644 (file)
@@ -284,7 +284,7 @@ static __init bool randomized_test(void)
        mutex_lock(&mutex);
 
        for (i = 0; i < NUM_RAND_ROUTES; ++i) {
-               prandom_bytes(ip, 4);
+               get_random_bytes(ip, 4);
                cidr = prandom_u32_max(32) + 1;
                peer = peers[prandom_u32_max(NUM_PEERS)];
                if (wg_allowedips_insert_v4(&t, (struct in_addr *)ip, cidr,
@@ -299,7 +299,7 @@ static __init bool randomized_test(void)
                }
                for (j = 0; j < NUM_MUTATED_ROUTES; ++j) {
                        memcpy(mutated, ip, 4);
-                       prandom_bytes(mutate_mask, 4);
+                       get_random_bytes(mutate_mask, 4);
                        mutate_amount = prandom_u32_max(32);
                        for (k = 0; k < mutate_amount / 8; ++k)
                                mutate_mask[k] = 0xff;
@@ -328,7 +328,7 @@ static __init bool randomized_test(void)
        }
 
        for (i = 0; i < NUM_RAND_ROUTES; ++i) {
-               prandom_bytes(ip, 16);
+               get_random_bytes(ip, 16);
                cidr = prandom_u32_max(128) + 1;
                peer = peers[prandom_u32_max(NUM_PEERS)];
                if (wg_allowedips_insert_v6(&t, (struct in6_addr *)ip, cidr,
@@ -343,7 +343,7 @@ static __init bool randomized_test(void)
                }
                for (j = 0; j < NUM_MUTATED_ROUTES; ++j) {
                        memcpy(mutated, ip, 16);
-                       prandom_bytes(mutate_mask, 16);
+                       get_random_bytes(mutate_mask, 16);
                        mutate_amount = prandom_u32_max(128);
                        for (k = 0; k < mutate_amount / 8; ++k)
                                mutate_mask[k] = 0xff;
@@ -381,13 +381,13 @@ static __init bool randomized_test(void)
 
        for (j = 0;; ++j) {
                for (i = 0; i < NUM_QUERIES; ++i) {
-                       prandom_bytes(ip, 4);
+                       get_random_bytes(ip, 4);
                        if (lookup(t.root4, 32, ip) != horrible_allowedips_lookup_v4(&h, (struct in_addr *)ip)) {
                                horrible_allowedips_lookup_v4(&h, (struct in_addr *)ip);
                                pr_err("allowedips random v4 self-test: FAIL\n");
                                goto free;
                        }
-                       prandom_bytes(ip, 16);
+                       get_random_bytes(ip, 16);
                        if (lookup(t.root6, 128, ip) != horrible_allowedips_lookup_v6(&h, (struct in6_addr *)ip)) {
                                pr_err("allowedips random v6 self-test: FAIL\n");
                                goto free;
index f4d3b568aa64a7e139ede904924d41de5c3b95b9..3f128b9fdfbb23bd3dd93ea37d54702c59850b0c 100644 (file)
@@ -2581,7 +2581,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
        if (ffs)
                memset(p + from, 0xFF, to - from);
        else
-               prandom_bytes(p + from, to - from);
+               get_random_bytes(p + from, to - from);
 
        return to;
 }
index 58b94deae5c0bfd9f43950aad5194050b1b15fac..00cdf8fa5693623273eb1244706ae3d5f6aeaab8 100644 (file)
@@ -46,7 +46,7 @@ static bool __init test_encode_decode(void)
                unsigned long addr;
                size_t verif_size;
 
-               prandom_bytes(&addr, sizeof(addr));
+               get_random_bytes(&addr, sizeof(addr));
                if (addr < PAGE_SIZE)
                        addr = PAGE_SIZE;
 
index d4f19e1a69d4e39b296fb22ae34a65a8f396056f..32060b8526681f069d97b1ffa1d53d3cc1e3e620 100644 (file)
@@ -69,7 +69,7 @@ EXPORT_SYMBOL(prandom_u32_state);
  *     @bytes: the requested number of bytes
  *
  *     This is used for pseudo-randomness with no outside seeding.
- *     For more random results, use prandom_bytes().
+ *     For more random results, use get_random_bytes().
  */
 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t bytes)
 {
index da137939a410072751320cd0a0c5109f656742db..c0c957c50635415b00b5ce526c2b25efc4ac370e 100644 (file)
@@ -157,7 +157,7 @@ static int test_nodelta_obj_get(struct world *world, struct objagg *objagg,
        int err;
 
        if (should_create_root)
-               prandom_bytes(world->next_root_buf,
+               get_random_bytes(world->next_root_buf,
                              sizeof(world->next_root_buf));
 
        objagg_obj = world_obj_get(world, objagg, key_id);
index 562d53977cabb99b84ad9dfb5a52440db260ed09..e309b4c5be3df0eb74861506d8cbbc3dd206c39b 100644 (file)
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(generate_random_guid);
 
 static void __uuid_gen_common(__u8 b[16])
 {
-       prandom_bytes(b, 16);
+       get_random_bytes(b, 16);
        /* reversion 0b10 */
        b[8] = (b[8] & 0x3F) | 0x80;
 }
index 1a37a07c7163c327c9a41bfa652da363daf362a8..cd1fa9f70f1a17276648f1ec693c3b40cb6e11b4 100644 (file)
@@ -3719,7 +3719,7 @@ int __init ip_rt_init(void)
 
        ip_idents = idents_hash;
 
-       prandom_bytes(ip_idents, (ip_idents_mask + 1) * sizeof(*ip_idents));
+       get_random_bytes(ip_idents, (ip_idents_mask + 1) * sizeof(*ip_idents));
 
        ip_tstamps = idents_hash + (ip_idents_mask + 1) * sizeof(*ip_idents);
 
index 7f3f5f51081d55b3958d81cf42cf97d930f631db..3d91b98db0996a2e1ec6d57fb035fc2988a94b09 100644 (file)
@@ -2036,7 +2036,7 @@ static void __init init_sample_table(void)
 
        memset(sample_table, 0xff, sizeof(sample_table));
        for (col = 0; col < SAMPLE_COLUMNS; col++) {
-               prandom_bytes(rnd, sizeof(rnd));
+               get_random_bytes(rnd, sizeof(rnd));
                for (i = 0; i < MCS_GROUP_RATES; i++) {
                        new_idx = (i + rnd[i]) % MCS_GROUP_RATES;
                        while (sample_table[col][new_idx] != 0xff)
index 974038ba6c7b879d0b550178e210a12a41320763..265c238047a42f47ca18d976873857e20bebcf30 100644 (file)
@@ -72,7 +72,7 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
        if (vars->accu_prob >= (MAX_PROB / 2) * 17)
                return true;
 
-       prandom_bytes(&rnd, 8);
+       get_random_bytes(&rnd, 8);
        if ((rnd >> BITS_PER_BYTE) < local_prob) {
                vars->accu_prob = 0;
                return true;