mmc: core: Fix struct mmc_gpio corruption
PATCH 1/1 mmc: core: Fix struct mmc_gpio corruption
I recently realised that something was amiss with /proc/interrupts on my cubietruck:
51: 0 0 GICv2 41 Level mv64xxx_i2c 59: 1047 0 GICv2 117 Level eth0 66: 2 0 sunxi_pio_edge 1 Edge XXXXX
where XXXXX has some non-ASCII characters, while I was expecting:
66: 0 0 sunxi_pio_edge 1 Edge 1c0f000.mmc cd
It turns out that the cd_debounce_delay_ms field was recently to struct mmc_gpio, and carefully placed at the one spot where it could cause damage: right *after* the zero-sized array that contains the associated label. This label ends up being passed to the IRQ subsystem, and then overwritten by the cd_debounce_delay_ms field.
Funky!
Let's move that field to a less crowded location.
--- drivers/mmc/core/slot-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/slot-gpio.c +1 -1
@@ -27,8 +27,8 @@ struct mmc_gpio {bool override_cd_active_level;irqreturn_t (*cd_gpio_isr)(int irq,void *dev_id);char *ro_label; -char cd_label[0 ];u32 cd_debounce_delay_ms; +char cd_label[0 ]; };static irqreturn_t mmc_gpio_cd_irqt (int irq,void *dev_id)
Signature · 1 line
2.17.1
Hi Marc,
Quoted 35 lines · Marc Zyngier
I recently realised that something was amiss with
/proc/interruptson my cubietruck:51: 0 0 GICv2 41 Level mv64xxx_i2c 59: 1047 0 GICv2 117 Level eth0 66: 2 0 sunxi_pio_edge 1 Edge XXXXXwhere XXXXX has some non-ASCII characters, while I was expecting:
66: 0 0
sunxi_pio_edge1 Edge 1c0f000.mmc cdIt turns out that the
cd_debounce_delay_msfield was recently to structmmc_gpio, and carefully placed at the one spot where it could cause damage: right *after* the zero-sized array that contains the associated label. This label ends up being passed to the IRQ subsystem, and then overwritten by thecd_debounce_delay_msfield.Funky!
Let's move that field to a less crowded location.
Fixes bfd694d5e21c ("mmc: core: Add tunable delay before detecting card after card is inserted")Cc Shawn Lin <[email protected]>Cc Linus Walleij <[email protected]>Cc Ulf Hansson <[email protected]>Signed-off-by Marc Zyngier <[email protected]>--- drivers/mmc/core/slot-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mmc/core/slot-gpio.c +0
-0
drivers/mmc/core/slot-gpio.c struct mmc_gpio { · line 31
Quoted 6 lines
drivers/mmc/core/slot-gpio.c +1
-1@@ -27,8 +27,8 @@ struct mmc_gpio {bool override_cd_active_level;irqreturn_t (*cd_gpio_isr)(int irq,void *dev_id);char *ro_label; -char cd_label[0 ];u32 cd_debounce_delay_ms; +char cd_label[0 ];
Ulf has already applied a fix for this:
https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/commit/?h=fixes&id=60feca8f59a0bbdee9545ab52775cad0171151ff
which is more robust as it will give a gcc error when cd_label gets moved in the future.
Quoted 48 lines · Fabio Estevam
Hi Marc,
Quoted 35 lines · Marc Zyngier
I recently realised that something was amiss with
/proc/interruptson my cubietruck:51: 0 0 GICv2 41 Level mv64xxx_i2c 59: 1047 0 GICv2 117 Level eth0 66: 2 0 sunxi_pio_edge 1 Edge XXXXXwhere XXXXX has some non-ASCII characters, while I was expecting:
66: 0 0
sunxi_pio_edge1 Edge 1c0f000.mmc cdIt turns out that the
cd_debounce_delay_msfield was recently to structmmc_gpio, and carefully placed at the one spot where it could cause damage: right *after* the zero-sized array that contains the associated label. This label ends up being passed to the IRQ subsystem, and then overwritten by thecd_debounce_delay_msfield.Funky!
Let's move that field to a less crowded location.
Fixes bfd694d5e21c ("mmc: core: Add tunable delay before detecting card after card is inserted")Cc Shawn Lin <[email protected]>Cc Linus Walleij <[email protected]>Cc Ulf Hansson <[email protected]>Signed-off-by Marc Zyngier <[email protected]>--- drivers/mmc/core/slot-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mmc/core/slot-gpio.c +0
-0drivers/mmc/core/slot-gpio.c struct mmc_gpio { · line 31
Quoted 6 lines
drivers/mmc/core/slot-gpio.c +1
-1@@ -27,8 +27,8 @@ struct mmc_gpio {bool override_cd_active_level;irqreturn_t (*cd_gpio_isr)(int irq,void *dev_id);char *ro_label; -char cd_label[0 ];u32 cd_debounce_delay_ms; +char cd_label[0 ];Ulf has already applied a fix for this:
https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/commit/?h=fixes&id=60feca8f59a0bbdee9545ab52775cad0171151ff
Quoted 2 lines
which is more robust as it will give a gcc error when
cd_labelgets moved in the future.
Ah, good. Thanks for the heads-up.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...