Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwrng: geode - fix accessing registers

When the membase and pci_dev pointer were moved to a new struct in priv,
the actual membase users were left untouched, and they started reading
out arbitrary memory behind the struct instead of registers. This
unfortunately turned the RNG into a constant number generator, depending
on the content of what was at that offset.

To fix this, update geode_rng_data_{read,present}() to also get the
membase via amd_geode_priv, and properly read from the right addresses
again.

Fixes: 9f6ec8dc574e ("hwrng: geode - Fix PCI device refcount leak")
Reported-by: Timur I. Davletshin <timur.davletshin@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217882
Tested-by: Timur I. Davletshin <timur.davletshin@gmail.com>
Suggested-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Jonas Gorski and committed by
Herbert Xu
464bd8ec 453b3d02

+4 -2
+4 -2
drivers/char/hw_random/geode-rng.c
··· 58 58 59 59 static int geode_rng_data_read(struct hwrng *rng, u32 *data) 60 60 { 61 - void __iomem *mem = (void __iomem *)rng->priv; 61 + struct amd_geode_priv *priv = (struct amd_geode_priv *)rng->priv; 62 + void __iomem *mem = priv->membase; 62 63 63 64 *data = readl(mem + GEODE_RNG_DATA_REG); 64 65 ··· 68 67 69 68 static int geode_rng_data_present(struct hwrng *rng, int wait) 70 69 { 71 - void __iomem *mem = (void __iomem *)rng->priv; 70 + struct amd_geode_priv *priv = (struct amd_geode_priv *)rng->priv; 71 + void __iomem *mem = priv->membase; 72 72 int data, i; 73 73 74 74 for (i = 0; i < 20; i++) {