2022-10-14 03:59:04

by Weizhao Ouyang

[permalink] [raw]
Subject: [PATCH v2] mmc: sdio: fix kernel panic when remove non-standard SDIO card

From: Weizhao Ouyang <[email protected]>

From: Matthew Ma <[email protected]>

SDIO tuple is only allocated for standard SDIO card, especially it
causes memory corruption issues when the non-standard SDIO card has
removed since the card device's reference counter does not increase for
it at sdio_init_func(), but all SDIO card device reference counter has
decreased at sdio_release_func().

Fixes: 6f51be3d37df ("sdio: allow non-standard SDIO cards")
Signed-off-by: Matthew Ma <[email protected]>
Reviewed-by: Weizhao Ouyang <[email protected]>
Reviewed-by: John Wang <[email protected]>
---
Changes in v2:
-- update Fixes tag

drivers/mmc/core/sdio_bus.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index c6268c38c69e..babf21a0adeb 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -291,7 +291,8 @@ static void sdio_release_func(struct device *dev)
{
struct sdio_func *func = dev_to_sdio_func(dev);

- sdio_free_func_cis(func);
+ if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
+ sdio_free_func_cis(func);

kfree(func->info);
kfree(func->tmpbuf);
--
2.25.1


2022-10-14 14:47:45

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2] mmc: sdio: fix kernel panic when remove non-standard SDIO card

On Fri, 14 Oct 2022 at 05:50, Weizhao Ouyang <[email protected]> wrote:
>
> From: Weizhao Ouyang <[email protected]>
>
> From: Matthew Ma <[email protected]>
>
> SDIO tuple is only allocated for standard SDIO card, especially it
> causes memory corruption issues when the non-standard SDIO card has
> removed since the card device's reference counter does not increase for
> it at sdio_init_func(), but all SDIO card device reference counter has
> decreased at sdio_release_func().
>
> Fixes: 6f51be3d37df ("sdio: allow non-standard SDIO cards")
> Signed-off-by: Matthew Ma <[email protected]>
> Reviewed-by: Weizhao Ouyang <[email protected]>
> Reviewed-by: John Wang <[email protected]>

If I understand correctly, Matthew Ma <[email protected]> should be
the author of the patch?

Assuming I am correct, I have amended the patch and changed that,
please tell me if I should change that.

So, I applied this for fixes and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
> Changes in v2:
> -- update Fixes tag
>
> drivers/mmc/core/sdio_bus.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
> index c6268c38c69e..babf21a0adeb 100644
> --- a/drivers/mmc/core/sdio_bus.c
> +++ b/drivers/mmc/core/sdio_bus.c
> @@ -291,7 +291,8 @@ static void sdio_release_func(struct device *dev)
> {
> struct sdio_func *func = dev_to_sdio_func(dev);
>
> - sdio_free_func_cis(func);
> + if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
> + sdio_free_func_cis(func);
>
> kfree(func->info);
> kfree(func->tmpbuf);
> --
> 2.25.1
>

2022-10-14 16:49:56

by Weizhao Ouyang

[permalink] [raw]
Subject: Re: [PATCH v2] mmc: sdio: fix kernel panic when remove non-standard SDIO card


On 10/14/22 22:07, Ulf Hansson wrote:
> On Fri, 14 Oct 2022 at 05:50, Weizhao Ouyang <[email protected]> wrote:
>> From: Weizhao Ouyang <[email protected]>
>>
>> From: Matthew Ma <[email protected]>
>>
>> SDIO tuple is only allocated for standard SDIO card, especially it
>> causes memory corruption issues when the non-standard SDIO card has
>> removed since the card device's reference counter does not increase for
>> it at sdio_init_func(), but all SDIO card device reference counter has
>> decreased at sdio_release_func().
>>
>> Fixes: 6f51be3d37df ("sdio: allow non-standard SDIO cards")
>> Signed-off-by: Matthew Ma <[email protected]>
>> Reviewed-by: Weizhao Ouyang <[email protected]>
>> Reviewed-by: John Wang <[email protected]>
> If I understand correctly, Matthew Ma <[email protected]> should be
> the author of the patch?
>
> Assuming I am correct, I have amended the patch and changed that,
> please tell me if I should change that.

Yeah you are correct, thanks for the reply!

> So, I applied this for fixes and by adding a stable tag, thanks!
>
> Kind regards
> Uffe
>
>
>> ---
>> Changes in v2:
>> -- update Fixes tag
>>
>> drivers/mmc/core/sdio_bus.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
>> index c6268c38c69e..babf21a0adeb 100644
>> --- a/drivers/mmc/core/sdio_bus.c
>> +++ b/drivers/mmc/core/sdio_bus.c
>> @@ -291,7 +291,8 @@ static void sdio_release_func(struct device *dev)
>> {
>> struct sdio_func *func = dev_to_sdio_func(dev);
>>
>> - sdio_free_func_cis(func);
>> + if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
>> + sdio_free_func_cis(func);
>>
>> kfree(func->info);
>> kfree(func->tmpbuf);
>> --
>> 2.25.1
>>