Message ID | 20240307085135.16245-1-amishin@t-argos.ru (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mmc: dw_mmc: Fix potential null pointer risk | expand |
On Thu, 7 Mar 2024 at 09:53, Aleksandr Mishin <amishin@t-argos.ru> wrote: > > In dw_mci_runtime_resume() 'host->slot' could be null, but check is not cover all corresponding code. > Fix this bug by changing check place. In fact host->slot can never be NULL in dw_mci_runtime_resume() or in dw_mci_runtime_suspend(). A better fix would thus be to remove the redundant checks. Kind regards Uffe > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: 4a835afd808a (mmc: dw_mmc: Fix potential null pointer risk) > Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru> > --- > drivers/mmc/host/dw_mmc.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c > index 829af2c98a44..a4f124452abc 100644 > --- a/drivers/mmc/host/dw_mmc.c > +++ b/drivers/mmc/host/dw_mmc.c > @@ -3570,8 +3570,10 @@ int dw_mci_runtime_resume(struct device *dev) > DW_MCI_ERROR_FLAGS); > mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); > > + if (!host->slot) > + goto err; > > - if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > + if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); > > /* Force setup bus to guarantee available clock output */ > -- > 2.30.2 > >
07.03.2024 13:57, Ulf Hansson wrote: > On Thu, 7 Mar 2024 at 09:53, Aleksandr Mishin <amishin@t-argos.ru> wrote: >> >> In dw_mci_runtime_resume() 'host->slot' could be null, but check is not cover all corresponding code. >> Fix this bug by changing check place. > > In fact host->slot can never be NULL in dw_mci_runtime_resume() or in > dw_mci_runtime_suspend(). > > A better fix would thus be to remove the redundant checks. > > Kind regards > Uffe > >> >> Found by Linux Verification Center (linuxtesting.org) with SVACE. >> >> Fixes: 4a835afd808a (mmc: dw_mmc: Fix potential null pointer risk) >> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru> >> --- >> drivers/mmc/host/dw_mmc.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c >> index 829af2c98a44..a4f124452abc 100644 >> --- a/drivers/mmc/host/dw_mmc.c >> +++ b/drivers/mmc/host/dw_mmc.c >> @@ -3570,8 +3570,10 @@ int dw_mci_runtime_resume(struct device *dev) >> DW_MCI_ERROR_FLAGS); >> mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); >> >> + if (!host->slot) >> + goto err; >> >> - if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) >> + if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) >> dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); >> >> /* Force setup bus to guarantee available clock output */ >> -- >> 2.30.2 >> >> > At the same time there are few checks such as "if (host->slot)" in dw_mci_runtime_resume() and commit 4a835afd808a3dbbac44bb399a902b822dc7445c message contains: "we previously assumed 'host->slot' could be null, null pointer judgment should be added" and replaces "if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)" with "if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)" So where is the truth?
On Thu, 7 Mar 2024 at 20:07, Aleksandr Mishin <amishin@t-argos.ru> wrote: > > > > 07.03.2024 13:57, Ulf Hansson wrote: > > On Thu, 7 Mar 2024 at 09:53, Aleksandr Mishin <amishin@t-argos.ru> wrote: > >> > >> In dw_mci_runtime_resume() 'host->slot' could be null, but check is not cover all corresponding code. > >> Fix this bug by changing check place. > > > > In fact host->slot can never be NULL in dw_mci_runtime_resume() or in > > dw_mci_runtime_suspend(). > > > > A better fix would thus be to remove the redundant checks. > > > > Kind regards > > Uffe > > > >> > >> Found by Linux Verification Center (linuxtesting.org) with SVACE. > >> > >> Fixes: 4a835afd808a (mmc: dw_mmc: Fix potential null pointer risk) > >> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru> > >> --- > >> drivers/mmc/host/dw_mmc.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c > >> index 829af2c98a44..a4f124452abc 100644 > >> --- a/drivers/mmc/host/dw_mmc.c > >> +++ b/drivers/mmc/host/dw_mmc.c > >> @@ -3570,8 +3570,10 @@ int dw_mci_runtime_resume(struct device *dev) > >> DW_MCI_ERROR_FLAGS); > >> mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); > >> > >> + if (!host->slot) > >> + goto err; > >> > >> - if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > >> + if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > >> dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); > >> > >> /* Force setup bus to guarantee available clock output */ > >> -- > >> 2.30.2 > >> > >> > > > > At the same time there are few checks such as "if (host->slot)" in > dw_mci_runtime_resume() and commit > 4a835afd808a3dbbac44bb399a902b822dc7445c message contains: "we > previously assumed 'host->slot' could be null, null pointer judgment > should be added" and replaces "if (host->slot->mmc->pm_flags & > MMC_PM_KEEP_POWER)" with "if (host->slot && host->slot->mmc->pm_flags & > MMC_PM_KEEP_POWER)" > So where is the truth? It looks to me that the runtime PM callbacks are prevented from being called, unless we have a host->slot assigned. Just adding checks because it looks like the code could need it, isn't always the correct thing to do. I would rather try to remove the checks altogether and give it some tests to see how it plays. Kind regards Uffe
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 829af2c98a44..a4f124452abc 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -3570,8 +3570,10 @@ int dw_mci_runtime_resume(struct device *dev) DW_MCI_ERROR_FLAGS); mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); + if (!host->slot) + goto err; - if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) + if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); /* Force setup bus to guarantee available clock output */
In dw_mci_runtime_resume() 'host->slot' could be null, but check is not cover all corresponding code. Fix this bug by changing check place. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 4a835afd808a (mmc: dw_mmc: Fix potential null pointer risk) Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru> --- drivers/mmc/host/dw_mmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)