From: Rolf Eike Beer <eike-kernel@sf-tec.de>
To: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
Andrew Morton <akpm@linux-foundation.org>,
Florian Westphal <fw@strlen.de>,
Herbert Xu <herbert@gondor.apana.org.au>,
Thomas Graf <tgraf@suug.ch>,
kasan-dev@googlegroups.com
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
kernel-janitors@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-block@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-media@vger.kernel.org, linux-mips@vger.kernel.org,
linux-mm@kvack.org, linux-mmc@vger.kernel.org,
linux-mtd@lists.infradead.org, linux-nvme@lists.infradead.org,
linux-parisc@vger.kernel.org, linux-rdma@vger.kernel.org,
linux-s390@vger.kernel.org, linux-um@lists.infradead.org,
linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev,
netdev@vger.kernel.org, sparclinux@vger.kernel.org,
x86@kernel.org
Subject: Re: [PATCH v6 5/7] treewide: use get_random_u32() when possible
Date: Thu, 13 Oct 2022 11:25:11 +0200 [thread overview]
Message-ID: <3026360.ZldQQBzMgz@eto.sf-tec.de> (raw)
In-Reply-To: <20221010230613.1076905-6-Jason@zx2c4.com>
[-- Attachment #1: Type: text/plain, Size: 7737 bytes --]
Am Dienstag, 11. Oktober 2022, 01:06:11 CEST schrieb Jason A. Donenfeld:
> The prandom_u32() function has been a deprecated inline wrapper around
> get_random_u32() for several releases now, and compiles down to the
> exact same code. Replace the deprecated wrapper with a direct call to
> the real function. The same also applies to get_random_int(), which is
> just a wrapper around get_random_u32(). 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>
> Acked-by: Toke Høiland-Jørgensen <toke@toke.dk> # for sch_cake
> Acked-by: Chuck Lever <chuck.lever@oracle.com> # for nfsd
> Reviewed-by: Jan Kara <jack@suse.cz> # for ext4
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> # for
> thunderbolt Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> Documentation/networking/filter.rst | 2 +-
> arch/parisc/kernel/process.c | 2 +-
> arch/parisc/kernel/sys_parisc.c | 4 ++--
> arch/s390/mm/mmap.c | 2 +-
> arch/x86/kernel/cpu/amd.c | 2 +-
> drivers/gpu/drm/i915/i915_gem_gtt.c | 6 +++---
> drivers/gpu/drm/i915/selftests/i915_selftest.c | 2 +-
> drivers/gpu/drm/tests/drm_buddy_test.c | 2 +-
> drivers/gpu/drm/tests/drm_mm_test.c | 2 +-
> drivers/infiniband/hw/cxgb4/cm.c | 4 ++--
> drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +-
> drivers/infiniband/hw/mlx4/mad.c | 2 +-
> drivers/infiniband/ulp/ipoib/ipoib_cm.c | 2 +-
> drivers/md/raid5-cache.c | 2 +-
> .../media/test-drivers/vivid/vivid-touch-cap.c | 4 ++--
> drivers/misc/habanalabs/gaudi2/gaudi2.c | 2 +-
> drivers/net/bonding/bond_main.c | 2 +-
> drivers/net/ethernet/broadcom/cnic.c | 2 +-
> .../chelsio/inline_crypto/chtls/chtls_cm.c | 2 +-
> drivers/net/ethernet/rocker/rocker_main.c | 6 +++---
> .../wireless/broadcom/brcm80211/brcmfmac/pno.c | 2 +-
> .../net/wireless/marvell/mwifiex/cfg80211.c | 4 ++--
> .../net/wireless/microchip/wilc1000/cfg80211.c | 2 +-
> .../net/wireless/quantenna/qtnfmac/cfg80211.c | 2 +-
> drivers/net/wireless/ti/wlcore/main.c | 2 +-
> drivers/nvme/common/auth.c | 2 +-
> drivers/scsi/cxgbi/cxgb4i/cxgb4i.c | 4 ++--
> drivers/target/iscsi/cxgbit/cxgbit_cm.c | 2 +-
> drivers/thunderbolt/xdomain.c | 2 +-
> drivers/video/fbdev/uvesafb.c | 2 +-
> fs/exfat/inode.c | 2 +-
> fs/ext4/ialloc.c | 2 +-
> fs/ext4/ioctl.c | 4 ++--
> fs/ext4/mmp.c | 2 +-
> fs/f2fs/namei.c | 2 +-
> fs/fat/inode.c | 2 +-
> fs/nfsd/nfs4state.c | 4 ++--
> fs/ntfs3/fslog.c | 6 +++---
> fs/ubifs/journal.c | 2 +-
> fs/xfs/libxfs/xfs_ialloc.c | 2 +-
> fs/xfs/xfs_icache.c | 2 +-
> fs/xfs/xfs_log.c | 2 +-
> include/net/netfilter/nf_queue.h | 2 +-
> include/net/red.h | 2 +-
> include/net/sock.h | 2 +-
> kernel/bpf/bloom_filter.c | 2 +-
> kernel/bpf/core.c | 2 +-
> kernel/bpf/hashtab.c | 2 +-
> kernel/bpf/verifier.c | 2 +-
> kernel/kcsan/selftest.c | 2 +-
> lib/random32.c | 2 +-
> lib/reed_solomon/test_rslib.c | 6 +++---
> lib/test_fprobe.c | 2 +-
> lib/test_kprobes.c | 2 +-
> lib/test_min_heap.c | 6 +++---
> lib/test_rhashtable.c | 6 +++---
> mm/shmem.c | 2 +-
> mm/slab.c | 2 +-
> net/core/pktgen.c | 4 ++--
> net/ipv4/route.c | 2 +-
> net/ipv4/tcp_cdg.c | 2 +-
> net/ipv4/udp.c | 2 +-
> net/ipv6/ip6_flowlabel.c | 2 +-
> net/ipv6/output_core.c | 2 +-
> net/netfilter/ipvs/ip_vs_conn.c | 2 +-
> net/netfilter/xt_statistic.c | 2 +-
> net/openvswitch/actions.c | 2 +-
> net/sched/sch_cake.c | 2 +-
> net/sched/sch_netem.c | 18 +++++++++---------
> net/sunrpc/auth_gss/gss_krb5_wrap.c | 4 ++--
> net/sunrpc/xprt.c | 2 +-
> net/unix/af_unix.c | 2 +-
> 72 files changed, 101 insertions(+), 101 deletions(-)
>
> diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
> index 5a1dd4736b56..b358a74ed7ed 100644
> --- a/lib/test_rhashtable.c
> +++ b/lib/test_rhashtable.c
> @@ -291,7 +291,7 @@ static int __init test_rhltable(unsigned int entries)
> if (WARN_ON(err))
> goto out_free;
>
> - k = prandom_u32();
> + k = get_random_u32();
> ret = 0;
> for (i = 0; i < entries; i++) {
> rhl_test_objects[i].value.id = k;
This one looks ok.
> @@ -369,12 +369,12 @@ static int __init test_rhltable(unsigned int entries)
> pr_info("test %d random rhlist add/delete operations\n", entries);
> for (j = 0; j < entries; j++) {
> u32 i = prandom_u32_max(entries);
> - u32 prand = prandom_u32();
> + u32 prand = get_random_u32();
>
> cond_resched();
>
> if (prand == 0)
> - prand = prandom_u32();
> + prand = get_random_u32();
>
> if (prand & 1) {
> prand >>= 1;
But this doesn't make any sense to me. It needs a bit more context:
> continue;
> }
Why would one change prand wen it will be overwritten in the next loop anyway?
> err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
> if (test_bit(i, obj_in_table)) {
> clear_bit(i, obj_in_table);
> if (WARN(err, "cannot remove element at slot %d", i))
> continue;
> } else {
> if (WARN(err != -ENOENT, "removed non-existent element %d, error %d not %d",
> i, err, -ENOENT))
> continue;
> }
>
> if (prand & 1) {
> prand >>= 1;
> continue;
> }
The same code again, and in this case it is impossible to reach, as the check
already returned false before.
Should these have been something like this in the first place:
if (prand & 1)
prand >>=1;
else
continue;
At least as the code looks now this only ever needs a single bit of randomness,
and the later checks and the shift can go away, but I suspect that something
else was meant with that code.
Florian, can you comment and maybe fix it? When possible use prandom_u8() as
it seems to me that you only need 3 bytes of randomness here anyway.
Or you wanted to move the variable before the loop and keep the random state
between the loops and only reseed when all '1' bits have been consumed. But
even in this case the later checks seem wrong as the value has not changed in
between.
Eike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2022-10-13 9:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 23:06 [PATCH v6 0/7] treewide cleanup of random integer usage Jason A. Donenfeld
2022-10-10 23:06 ` [PATCH v6 1/7] treewide: use prandom_u32_max() when possible, part 1 Jason A. Donenfeld
2022-10-11 9:58 ` Heiko Carstens
2022-10-10 23:06 ` [PATCH v6 2/7] treewide: use prandom_u32_max() when possible, part 2 Jason A. Donenfeld
2022-10-10 23:06 ` [PATCH v6 3/7] treewide: use get_random_{u8,u16}() when possible, part 1 Jason A. Donenfeld
2022-10-11 1:18 ` Elliott, Robert (Servers)
2022-10-11 3:00 ` Jason A. Donenfeld
2022-10-10 23:06 ` [PATCH v6 4/7] treewide: use get_random_{u8,u16}() when possible, part 2 Jason A. Donenfeld
2022-10-11 9:59 ` Heiko Carstens
2022-10-10 23:06 ` [PATCH v6 5/7] treewide: use get_random_u32() when possible Jason A. Donenfeld
2022-10-11 10:00 ` Heiko Carstens
2022-10-13 9:25 ` Rolf Eike Beer [this message]
2022-10-13 10:16 ` Florian Westphal
2022-10-13 11:40 ` Rolf Eike Beer
2022-10-13 16:21 ` Jason A. Donenfeld
2022-10-10 23:06 ` [PATCH v6 6/7] treewide: use get_random_bytes() " Jason A. Donenfeld
2022-10-10 23:06 ` [PATCH v6 7/7] prandom: remove unused functions Jason A. Donenfeld
2022-10-11 23:01 ` [PATCH v6 0/7] treewide cleanup of random integer usage Jakub Kicinski
2022-10-17 11:59 ` liulongfang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3026360.ZldQQBzMgz@eto.sf-tec.de \
--to=eike-kernel@sf-tec.de \
--cc=Jason@zx2c4.com \
--cc=akpm@linux-foundation.org \
--cc=fw@strlen.de \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=kasan-dev@googlegroups.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=sparclinux@vger.kernel.org \
--cc=tgraf@suug.ch \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).