2022-09-27 02:52:53

by Weizhao Ouyang

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

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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
Signed-off-by: Matthew Ma <[email protected]>
Reviewed-by: Weizhao Ouyang <[email protected]>
Reviewed-by: John Wang <[email protected]>
---
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-11 15:23:35

by Ulf Hansson

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

On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang <[email protected]> wrote:
>
> 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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> Signed-off-by: Matthew Ma <[email protected]>
> Reviewed-by: Weizhao Ouyang <[email protected]>
> Reviewed-by: John Wang <[email protected]>

Apologize for the delay!

Wow, that's a very old bug you fixed! However, it looks like the fixed
commit should be changed to 6f51be3d37df ("sdio: allow non-standard
SDIO cards").

I tried to apply the patch, but the patch format seems to be corrupt.
Did you use git format-patch and did run ./scripts/checkpatch.pl on
it?

Kind regards
Uffe

> ---
> 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-12 02:11:47

by Weizhao Ouyang

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

2022年10月11日 22:41, Ulf Hansson <[email protected]> wrote:
>
> On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang <[email protected]>
> wrote:
> >
> > 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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> > Signed-off-by: Matthew Ma <[email protected]>
> > Reviewed-by: Weizhao Ouyang <[email protected]>
> > Reviewed-by: John Wang <[email protected]>
>
> Apologize for the delay!
>
> Wow, that's a very old bug you fixed! However, it looks like the fixed
> commit should be changed to 6f51be3d37df ("sdio: allow non-standard
> SDIO cards").

Thanks, I messed the tag.

>
> I tried to apply the patch, but the patch format seems to be corrupt.
> Did you use git format-patch and did run ./scripts/checkpatch.pl on
> it?
>

Yeah I used checkpatch.pl with strict mode to check this patch, and it
has no obvious style problems. What's the format error you got?

Thanks,
Weizhao

2022-10-12 10:13:46

by Ulf Hansson

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

On Wed, 12 Oct 2022 at 03:50, 欧阳炜钊(Weizhao Ouyang)
<[email protected]> wrote:
>
> 2022年10月11日 22:41, Ulf Hansson <[email protected]> wrote:
> >
> > On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang <[email protected]>
> > wrote:
> > >
> > > 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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> > > Signed-off-by: Matthew Ma <[email protected]>
> > > Reviewed-by: Weizhao Ouyang <[email protected]>
> > > Reviewed-by: John Wang <[email protected]>
> >
> > Apologize for the delay!
> >
> > Wow, that's a very old bug you fixed! However, it looks like the fixed
> > commit should be changed to 6f51be3d37df ("sdio: allow non-standard
> > SDIO cards").
>
> Thanks, I messed the tag.
>
> >
> > I tried to apply the patch, but the patch format seems to be corrupt.
> > Did you use git format-patch and did run ./scripts/checkpatch.pl on
> > it?
> >
>
> Yeah I used checkpatch.pl with strict mode to check this patch, and it
> has no obvious style problems. What's the format error you got?

ERROR: patch seems to be corrupt (line wrapped?)
#130: FILE: drivers/mmc/core/sdio_bus.c:291:
struct sdio_func *func = dev_to_sdio_func(dev);

total: 1 errors, 0 warnings, 9 lines checked

If you haven't read the submitting-patches guidelines [1], I strongly
recommend you to have a look.
For example, it explains why you should use git send-email, if you
aren't doing that already.

Kind regards
Uffe

[1]
https://www.kernel.org/doc/html/v6.0/process/submitting-patches.html

2022-10-14 02:43:40

by Weizhao Ouyang

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

2022年10月12日 18:09, Ulf Hansson <[email protected]> wrote:
>
> On Wed, 12 Oct 2022 at 03:50, 欧阳炜钊(Weizhao Ouyang)
> <[email protected]> wrote:
> >
> > 2022年10月11日 22:41, Ulf Hansson <[email protected]> wrote:
> > >
> > > On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang
> <[email protected]>
> > > wrote:
> > > >
> > > > 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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> > > > Signed-off-by: Matthew Ma <[email protected]>
> > > > Reviewed-by: Weizhao Ouyang <[email protected]>
> > > > Reviewed-by: John Wang <[email protected]>
> > >
> > > Apologize for the delay!
> > >
> > > Wow, that's a very old bug you fixed! However, it looks like the fixed
> > > commit should be changed to 6f51be3d37df ("sdio: allow non-standard
> > > SDIO cards").
> >
> > Thanks, I messed the tag.
> >
> > >
> > > I tried to apply the patch, but the patch format seems to be corrupt.
> > > Did you use git format-patch and did run ./scripts/checkpatch.pl on
> > > it?
> > >
> >
> > Yeah I used checkpatch.pl with strict mode to check this patch, and it
> > has no obvious style problems. What's the format error you got?
>
> ERROR: patch seems to be corrupt (line wrapped?)
> #130: FILE: drivers/mmc/core/sdio_bus.c:291:
> struct sdio_func *func = dev_to_sdio_func(dev);
>
> total: 1 errors, 0 warnings, 9 lines checked
>

Sorry our email hosting service made some issue on formatting, I will
send an updated patch ASAP.

Thanks,
Weizhao

2022-10-14 03:02:30

by Weizhao Ouyang

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

Wednesday, October 12, 2022 6:09 PM, Ulf Hansson <[email protected]> wrote:
>
> On Wed, 12 Oct 2022 at 03:50, 欧阳炜钊(Weizhao Ouyang)
> <[email protected]> wrote:
> >
> > 2022年10月11日 22:41, Ulf Hansson <[email protected]> wrote:
> > >
> > > On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang
> <[email protected]>
> > > wrote:
> > > >
> > > > 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: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> > > > Signed-off-by: Matthew Ma <[email protected]>
> > > > Reviewed-by: Weizhao Ouyang <[email protected]>
> > > > Reviewed-by: John Wang <[email protected]>
> > >
> > > Apologize for the delay!
> > >
> > > Wow, that's a very old bug you fixed! However, it looks like the fixed
> > > commit should be changed to 6f51be3d37df ("sdio: allow non-standard
> > > SDIO cards").
> >
> > Thanks, I messed the tag.
> >
> > >
> > > I tried to apply the patch, but the patch format seems to be corrupt.
> > > Did you use git format-patch and did run ./scripts/checkpatch.pl on
> > > it?
> > >
> >
> > Yeah I used checkpatch.pl with strict mode to check this patch, and it
> > has no obvious style problems. What's the format error you got?
>
> ERROR: patch seems to be corrupt (line wrapped?)
> #130: FILE: drivers/mmc/core/sdio_bus.c:291:
> struct sdio_func *func = dev_to_sdio_func(dev);
>
> total: 1 errors, 0 warnings, 9 lines checked
>

Sorry our email hosting service made some issue on formatting, I will
send an updated patch ASAP.

Thanks,
Weizhao