* [PATCH] mmc: dw_mmc: Fix potential null pointer risk
@ 2024-03-07 8:51 Aleksandr Mishin
2024-03-07 10:57 ` Ulf Hansson
0 siblings, 1 reply; 7+ messages in thread
From: Aleksandr Mishin @ 2024-03-07 8:51 UTC (permalink / raw)
To: Jaehoon Chung
Cc: Aleksandr Mishin, Ulf Hansson, Wen Zhiwei, linux-mmc,
linux-kernel, lvc-project
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(-)
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk
2024-03-07 8:51 [PATCH] mmc: dw_mmc: Fix potential null pointer risk Aleksandr Mishin
@ 2024-03-07 10:57 ` Ulf Hansson
2024-03-07 19:02 ` Aleksandr Mishin
0 siblings, 1 reply; 7+ messages in thread
From: Ulf Hansson @ 2024-03-07 10:57 UTC (permalink / raw)
To: Aleksandr Mishin
Cc: Jaehoon Chung, Wen Zhiwei, linux-mmc, linux-kernel, lvc-project
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
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk
2024-03-07 10:57 ` Ulf Hansson
@ 2024-03-07 19:02 ` Aleksandr Mishin
2024-03-12 11:29 ` Ulf Hansson
0 siblings, 1 reply; 7+ messages in thread
From: Aleksandr Mishin @ 2024-03-07 19:02 UTC (permalink / raw)
To: Ulf Hansson
Cc: Jaehoon Chung, Wen Zhiwei, linux-mmc, linux-kernel, lvc-project
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?
--
Kind regadrds
Aleksandr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk
2024-03-07 19:02 ` Aleksandr Mishin
@ 2024-03-12 11:29 ` Ulf Hansson
0 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2024-03-12 11:29 UTC (permalink / raw)
To: Aleksandr Mishin
Cc: Jaehoon Chung, Wen Zhiwei, linux-mmc, linux-kernel, lvc-project
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
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CGME20211229023827epcas1p1c62596be323776d0abad266224c299e0@epcas1p1.samsung.com>]
* [PATCH] mmc: dw_mmc: Fix potential null pointer risk
@ 2021-12-29 2:38 ` Wen Zhiwei
2021-12-30 8:35 ` Jaehoon Chung
2022-01-24 14:40 ` Ulf Hansson
0 siblings, 2 replies; 7+ messages in thread
From: Wen Zhiwei @ 2021-12-29 2:38 UTC (permalink / raw)
To: jh80.chung, ulf.hansson, p.zabel, wenzhiwei; +Cc: linux-mmc, linux-kernel
we previously assumed 'host->slot' could be null,
null pointer judgment should be added
Signed-off-by: Wen Zhiwei <wenzhiwei@kylinos.cn>
---
drivers/mmc/host/dw_mmc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index d977f34f6b55..c9dc8c168efb 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -3518,7 +3518,7 @@ int dw_mci_runtime_resume(struct device *dev)
mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
- if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
+ if (host->slot && 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.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk
2021-12-29 2:38 ` Wen Zhiwei
@ 2021-12-30 8:35 ` Jaehoon Chung
2022-01-24 14:40 ` Ulf Hansson
1 sibling, 0 replies; 7+ messages in thread
From: Jaehoon Chung @ 2021-12-30 8:35 UTC (permalink / raw)
To: Wen Zhiwei, ulf.hansson, p.zabel; +Cc: linux-mmc, linux-kernel
On 12/29/21 11:38 AM, Wen Zhiwei wrote:
> we previously assumed 'host->slot' could be null,
> null pointer judgment should be added
>
> Signed-off-by: Wen Zhiwei <wenzhiwei@kylinos.cn>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Beset Regards,
Jaehoon Chung
> ---
> drivers/mmc/host/dw_mmc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index d977f34f6b55..c9dc8c168efb 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -3518,7 +3518,7 @@ int dw_mci_runtime_resume(struct device *dev)
> mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
>
>
> - if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
> + if (host->slot && 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 */
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk
2021-12-29 2:38 ` Wen Zhiwei
2021-12-30 8:35 ` Jaehoon Chung
@ 2022-01-24 14:40 ` Ulf Hansson
1 sibling, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2022-01-24 14:40 UTC (permalink / raw)
To: Wen Zhiwei; +Cc: jh80.chung, p.zabel, linux-mmc, linux-kernel
On Wed, 29 Dec 2021 at 03:38, Wen Zhiwei <wenzhiwei@kylinos.cn> wrote:
>
> we previously assumed 'host->slot' could be null,
> null pointer judgment should be added
>
> Signed-off-by: Wen Zhiwei <wenzhiwei@kylinos.cn>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/dw_mmc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index d977f34f6b55..c9dc8c168efb 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -3518,7 +3518,7 @@ int dw_mci_runtime_resume(struct device *dev)
> mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
>
>
> - if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
> + if (host->slot && 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.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-12 11:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 8:51 [PATCH] mmc: dw_mmc: Fix potential null pointer risk Aleksandr Mishin
2024-03-07 10:57 ` Ulf Hansson
2024-03-07 19:02 ` Aleksandr Mishin
2024-03-12 11:29 ` Ulf Hansson
[not found] <CGME20211229023827epcas1p1c62596be323776d0abad266224c299e0@epcas1p1.samsung.com>
2021-12-29 2:38 ` Wen Zhiwei
2021-12-30 8:35 ` Jaehoon Chung
2022-01-24 14:40 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®