4c8015013bc8a5bcd3dd826cfc34e77c7180ab5a
[openwrt/staging/jow.git] / target / linux / x86 / patches-5.15 / 120-hwrng-geode-fix-accessing-registers.patch
1 From 859bd2e0c0052967536f3f902716f204d5a978b1 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Fri, 8 Sep 2023 22:48:33 +0200
4 Subject: [PATCH] hwrng: geode: fix accessing registers
5
6 When the membase and pci_dev pointer were moved to a new struct in priv,
7 the actual membase users were left untouched, and they started reading
8 out arbitrary memory behind the struct instead of registers. This
9 unfortunately turned the RNG into a constant number generator, depending
10 on the content of what was at that offset.
11
12 To fix this, update geode_rng_data_{read,present}() to also get the
13 membase via amd_geode_priv, and properly read from the right addresses
14 again.
15
16 Fixes: 9f6ec8dc574e ("hwrng: geode - Fix PCI device refcount leak")
17 Reported-by: Timur I. Davletshin <timur.davletshin@gmail.com>
18 Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217882
19 Tested-by: Timur I. Davletshin <timur.davletshin@gmail.com>
20 Suggested-by: Jo-Philipp Wich <jo@mein.io>
21 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
22 ---
23 drivers/char/hw_random/geode-rng.c | 6 ++++--
24 1 file changed, 4 insertions(+), 2 deletions(-)
25
26 --- a/drivers/char/hw_random/geode-rng.c
27 +++ b/drivers/char/hw_random/geode-rng.c
28 @@ -58,7 +58,8 @@ struct amd_geode_priv {
29
30 static int geode_rng_data_read(struct hwrng *rng, u32 *data)
31 {
32 - void __iomem *mem = (void __iomem *)rng->priv;
33 + struct amd_geode_priv *priv = (struct amd_geode_priv *)rng->priv;
34 + void __iomem *mem = priv->membase;
35
36 *data = readl(mem + GEODE_RNG_DATA_REG);
37
38 @@ -67,7 +68,8 @@ static int geode_rng_data_read(struct hw
39
40 static int geode_rng_data_present(struct hwrng *rng, int wait)
41 {
42 - void __iomem *mem = (void __iomem *)rng->priv;
43 + struct amd_geode_priv *priv = (struct amd_geode_priv *)rng->priv;
44 + void __iomem *mem = priv->membase;
45 int data, i;
46
47 for (i = 0; i < 20; i++) {