linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: warn for invalid SDIO data buffers
@ 2021-06-30 12:20 Arnd Bergmann
  2021-06-30 23:02 ` kernel test robot
  2021-07-02  1:02 ` [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由linux-mmc-owner@vger.kernel.org代发】 Shawn Lin
  0 siblings, 2 replies; 7+ messages in thread
From: Arnd Bergmann @ 2021-06-30 12:20 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Arnd Bergmann, Jernej Skrabec, Adrian Hunter, linux-mmc, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

Jernej Skrabec reported a problem with the cw1200 driver failing on
arm64 systems with CONFIG_VMAP_STACK=y.

The driver in this case passes a pointer to a stack variable (in vmalloc
space) into the sdio layer, which gets translated into an invalid DMA
address.

Even without CONFIG_VMAP_STACK, the driver is still unreliable, as
cache invalidations on the DMA buffer may cause random data corruption
in adjacent stack slots.

This could be worked around in the SDIO core, but in the discussion we
decided that passing a stack variable into SDIO should always be considered
a bug, as it is for USB drivers.

Change the sdio core to produce a one-time warning for any on-stack
(both with and without CONFIG_VMAP_STACK) as well as any vmalloc
or module-local address that would have the same translation problem.

Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Link: https://lore.kernel.org/lkml/20210622202345.795578-1-jernej.skrabec@gmail.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/mmc/core/sdio_ops.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
index 4c229dd2b6e5..14e983faf223 100644
--- a/drivers/mmc/core/sdio_ops.c
+++ b/drivers/mmc/core/sdio_ops.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/scatterlist.h>
+#include <linux/sched/task_stack.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -124,6 +125,7 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
 	int err;
 
 	WARN_ON(blksz == 0);
+	WARN_ON_ONCE(is_vmalloc_or_module_addr(buf) || object_is_on_stack(buf));
 
 	/* sanity check */
 	if (addr & ~0x1FFFF)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-02  8:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 12:20 [PATCH] mmc: warn for invalid SDIO data buffers Arnd Bergmann
2021-06-30 23:02 ` kernel test robot
2021-07-01  9:06   ` Arnd Bergmann
2021-07-02  1:02 ` [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由linux-mmc-owner@vger.kernel.org代发】 Shawn Lin
2021-07-02  7:03   ` Arnd Bergmann
2021-07-02  8:15     ` Shawn Lin
2021-07-02  8:19     ` Ulf Hansson

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).