120-hwrng-geode-fix-accessing-registers.patch 1.8 KB

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