Skip to contentSkip to conversation

mmc: warn for invalid SDIO data buffers

PATCH In review Arnd Bergmann 4 participants 7 messages Jun 30, 2021 – Jul 2, 2021 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: warn for invalid SDIO data buffers

From: Arnd Bergmann <[email protected]>

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.

---
 drivers/mmc/core/sdio_ops.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/core/sdio_ops.c +2 -0
index 4c229dd2b6e5..14e983faf223 100644
@@ -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)
Signature · 1 line
2.29.2
#1 lore raw
I love your patch! Yet something to improve:

Hi Arnd,

I love your patch! Yet something to improve:

[auto build test ERROR on soc/for-next]
[also build test ERROR on linus/master v5.13 next-20210630] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Arnd-Bergmann/mmc-warn-for-invalid-SDIO-data-buffers/20210630-202237
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
config: i386-randconfig-c001-20210630 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/256b826ee105fe46723b99c3f128ea01aa3e7adf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Arnd-Bergmann/mmc-warn-for-invalid-SDIO-data-buffers/20210630-202237
        git checkout 256b826ee105fe46723b99c3f128ea01aa3e7adf
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "is_vmalloc_or_module_addr" [drivers/mmc/core/mmc_core.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
Quoted 23 lines · kernel test robot

Hi Arnd,

I love your patch! Yet something to improve:

[auto build test ERROR on soc/for-next]
[also build test ERROR on linus/master v5.13 next-20210630] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Arnd-Bergmann/mmc-warn-for-invalid-SDIO-data-buffers/20210630-202237
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
config: i386-randconfig-c001-20210630 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/256b826ee105fe46723b99c3f128ea01aa3e7adf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Arnd-Bergmann/mmc-warn-for-invalid-SDIO-data-buffers/20210630-202237
        git checkout 256b826ee105fe46723b99c3f128ea01aa3e7adf
        # save the attached .config to linux build tree
        make W=1 ARCH=i386
Quoted 6 lines

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

Quoted 1 line
Quoted 1 line

ERROR: modpost: "is_vmalloc_or_module_addr" [drivers/mmc/core/mmc_core.ko] undefined!

Ah, I see that is_vmalloc_addr() is exported, but is_vmalloc_or_module_addr() is not. I assume it's ok to add a corresponding EXPORT_SYMBOL_GPL() for it as well. I'll wait for other comments before resending with that change.

Arnd

#3 lore raw

Re: [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由[email protected]代发】

In reply to Arnd Bergmann

Hi Arnd

Quoted 13 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 7 lines

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.

This was the previous comment about the same topic. Should we check for mmc_io_rw_direct?

https://www.spinics.net/lists/linux-mmc/msg41794.html

Quoted 29 lines
---
  drivers/mmc/core/sdio_ops.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/mmc/core/sdio_ops.c +2 -0
index 4c229dd2b6e5..14e983faf223 100644
@@ -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)
#4 lore raw

Re: [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由[email protected]代发】

Quoted 18 lines · Shawn Lin
Quoted 17 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 8 lines
Quoted 3 lines

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.

This was the previous comment about the same topic. Should we check for mmc_io_rw_direct?

https://www.spinics.net/lists/linux-mmc/msg41794.html

Hi Shawn,

thank you for remembering that previous discussion, that is a good question. Looking at the code though, I don't actually see any part of mmc_io_rw_direct() doing DMA on a caller-provided buffer. The only thing I see in the code is a 'u8 *out' argument, but that is just a pointer to a single byte that is set by this function.

Do you see any other issue with that function, or does that mean we don't have to change it?

Arnd

#5 lore raw

Re: [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由[email protected]代发】

Quoted 28 lines · Arnd Bergmann
Quoted 18 lines · Shawn Lin
Quoted 17 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 8 lines
Quoted 3 lines

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.

This was the previous comment about the same topic. Should we check for mmc_io_rw_direct?

https://www.spinics.net/lists/linux-mmc/msg41794.html

Quoted 8 lines

Hi Shawn,

thank you for remembering that previous discussion, that is a good question. Looking at the code though, I don't actually see any part of mmc_io_rw_direct() doing DMA on a caller-provided buffer. The only thing I see in the code is a 'u8 *out' argument, but that is just a pointer to a single byte that is set by this function.

I didn't quite get the point we need check out for mmc_io_rw_direct() either. As I thought what Ulf was suggesting was some controllers might use data fifo to get cmd response and get DMA involved? But I don't see a explicit one.

Quoted 7 lines

Do you see any other issue with that function, or does that mean we don't have to change it?

Arnd

#6 lore raw

Re: [PATCH] mmc: warn for invalid SDIO data buffers【请注意,邮件由[email protected]代发】

In reply to Arnd Bergmann
Quoted 31 lines · Arnd Bergmann
Quoted 18 lines · Shawn Lin
Quoted 17 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 8 lines
Quoted 3 lines

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.

This was the previous comment about the same topic. Should we check for mmc_io_rw_direct?

https://www.spinics.net/lists/linux-mmc/msg41794.html

Hi Shawn,

Quoted 8 lines

thank you for remembering that previous discussion, that is a good question. Looking at the code though, I don't actually see any part of mmc_io_rw_direct() doing DMA on a caller-provided buffer. The only thing I see in the code is a 'u8 *out' argument, but that is just a pointer to a single byte that is set by this function.

Do you see any other issue with that function, or does that mean we don't have to change it?

I was wrong when I earlier said that we needed to care about mmc_io_rw_direct(). mmc_io_rw_direct() transfer "data" over the CMD line. MMC host drivers can't do DMA on that.

I think the $subject patch looks reasonable to me.

Kind regards
Uffe