linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
@ 2016-05-25 19:09 Hoan Tran
  2016-05-27 16:10 ` Ashwin Chaugule
  0 siblings, 1 reply; 7+ messages in thread
From: Hoan Tran @ 2016-05-25 19:09 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Ashwin Chaugule
  Cc: linux-acpi, linux-kernel, Duc Dang, lho, Hoan Tran

When CPPC fails to request PCC channel, the CPC data is freed
and cpc_desc_ptr points to the invalid data. This change prevents
this issue by moving cpc_desc_ptr assignment after PCC channel
request.

Signed-off-by: Hoan Tran <hotran@apm.com>
---
 drivers/acpi/cppc_acpi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 8adac69..85fd8f7 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 	/* Store CPU Logical ID */
 	cpc_ptr->cpu_id = pr->id;
 
-	/* Plug it into this CPUs CPC descriptor. */
-	per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
-
 	/* Parse PSD data for this CPU */
 	ret = acpi_get_psd(cpc_ptr, handle);
 	if (ret)
@@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 			goto out_free;
 	}
 
+	/* Plug PSD data into this CPUs CPC descriptor. */
+	per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
+
 	/* Everything looks okay */
 	pr_debug("Parsed CPC struct for CPU: %d\n", pr->id);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-05-25 19:09 [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data Hoan Tran
@ 2016-05-27 16:10 ` Ashwin Chaugule
  2016-05-27 16:41   ` Hoan Tran
  0 siblings, 1 reply; 7+ messages in thread
From: Ashwin Chaugule @ 2016-05-27 16:10 UTC (permalink / raw)
  To: Hoan Tran
  Cc: Rafael J. Wysocki, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
> When CPPC fails to request PCC channel, the CPC data is freed
> and cpc_desc_ptr points to the invalid data. This change prevents
> this issue by moving cpc_desc_ptr assignment after PCC channel
> request.
>
> Signed-off-by: Hoan Tran <hotran@apm.com>
> ---
>  drivers/acpi/cppc_acpi.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index 8adac69..85fd8f7 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>         /* Store CPU Logical ID */
>         cpc_ptr->cpu_id = pr->id;
>
> -       /* Plug it into this CPUs CPC descriptor. */
> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> -
>         /* Parse PSD data for this CPU */
>         ret = acpi_get_psd(cpc_ptr, handle);
>         if (ret)
> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>                         goto out_free;
>         }
>
> +       /* Plug PSD data into this CPUs CPC descriptor. */
> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> +

Are you seeing a real problem without this change? I'm missing where
this pointer is dereferenced if the PCC channel request fails.

Thanks,
Ashwin.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-05-27 16:10 ` Ashwin Chaugule
@ 2016-05-27 16:41   ` Hoan Tran
  2016-05-31 19:29     ` Ashwin Chaugule
  0 siblings, 1 reply; 7+ messages in thread
From: Hoan Tran @ 2016-05-27 16:41 UTC (permalink / raw)
  To: Ashwin Chaugule
  Cc: Rafael J. Wysocki, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

Hi Ashwin,

Yes, I saw kernel crash.
As cpc_desc_ptr is not NULL, cppc_cpufreq_init() still can pass then
crash during cppc_get_perf_caps() access CPPC shared memory.

It's not only "PCC channel request fail" can create this issue but
"acpi_get_psd() fail" also creates it

Thanks
Hoan

On Fri, May 27, 2016 at 9:10 AM, Ashwin Chaugule
<ashwin.chaugule@linaro.org> wrote:
> On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
>> When CPPC fails to request PCC channel, the CPC data is freed
>> and cpc_desc_ptr points to the invalid data. This change prevents
>> this issue by moving cpc_desc_ptr assignment after PCC channel
>> request.
>>
>> Signed-off-by: Hoan Tran <hotran@apm.com>
>> ---
>>  drivers/acpi/cppc_acpi.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>> index 8adac69..85fd8f7 100644
>> --- a/drivers/acpi/cppc_acpi.c
>> +++ b/drivers/acpi/cppc_acpi.c
>> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>         /* Store CPU Logical ID */
>>         cpc_ptr->cpu_id = pr->id;
>>
>> -       /* Plug it into this CPUs CPC descriptor. */
>> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>> -
>>         /* Parse PSD data for this CPU */
>>         ret = acpi_get_psd(cpc_ptr, handle);
>>         if (ret)
>> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>                         goto out_free;
>>         }
>>
>> +       /* Plug PSD data into this CPUs CPC descriptor. */
>> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>> +
>
> Are you seeing a real problem without this change? I'm missing where
> this pointer is dereferenced if the PCC channel request fails.
>
> Thanks,
> Ashwin.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-05-27 16:41   ` Hoan Tran
@ 2016-05-31 19:29     ` Ashwin Chaugule
  2016-05-31 19:38       ` Hoan Tran
  2016-06-24 16:35       ` Hoan Tran
  0 siblings, 2 replies; 7+ messages in thread
From: Ashwin Chaugule @ 2016-05-31 19:29 UTC (permalink / raw)
  To: Hoan Tran
  Cc: Rafael J. Wysocki, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

On 27 May 2016 at 12:41, Hoan Tran <hotran@apm.com> wrote:
> Hi Ashwin,

Hi,

>
> Yes, I saw kernel crash.
> As cpc_desc_ptr is not NULL, cppc_cpufreq_init() still can pass then
> crash during cppc_get_perf_caps() access CPPC shared memory.
>
> It's not only "PCC channel request fail" can create this issue but
> "acpi_get_psd() fail" also creates it
>
> Thanks
> Hoan


Just for future reference. :)

https://web.archive.org/web/20080722025748/http://www.zip.com.au/~akpm/linux/patches/stuff/top-posting.txt


>
> On Fri, May 27, 2016 at 9:10 AM, Ashwin Chaugule
> <ashwin.chaugule@linaro.org> wrote:
>> On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
>>> When CPPC fails to request PCC channel, the CPC data is freed
>>> and cpc_desc_ptr points to the invalid data. This change prevents
>>> this issue by moving cpc_desc_ptr assignment after PCC channel
>>> request.
>>>
>>> Signed-off-by: Hoan Tran <hotran@apm.com>
>>> ---
>>>  drivers/acpi/cppc_acpi.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>>> index 8adac69..85fd8f7 100644
>>> --- a/drivers/acpi/cppc_acpi.c
>>> +++ b/drivers/acpi/cppc_acpi.c
>>> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>>         /* Store CPU Logical ID */
>>>         cpc_ptr->cpu_id = pr->id;
>>>
>>> -       /* Plug it into this CPUs CPC descriptor. */
>>> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>>> -
>>>         /* Parse PSD data for this CPU */
>>>         ret = acpi_get_psd(cpc_ptr, handle);
>>>         if (ret)
>>> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>>                         goto out_free;
>>>         }
>>>
>>> +       /* Plug PSD data into this CPUs CPC descriptor. */
>>> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>>> +
>>
>> Are you seeing a real problem without this change? I'm missing where
>> this pointer is dereferenced if the PCC channel request fails.
>>

So, after freeing the cpc_ptr, we need to NULL the per-cpu pointer as
well. Alternately, not assign it until everything passes and rely on
the static declaration, which is the path you've taken here.

Acked-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-05-31 19:29     ` Ashwin Chaugule
@ 2016-05-31 19:38       ` Hoan Tran
  2016-06-24 16:35       ` Hoan Tran
  1 sibling, 0 replies; 7+ messages in thread
From: Hoan Tran @ 2016-05-31 19:38 UTC (permalink / raw)
  To: Ashwin Chaugule
  Cc: Rafael J. Wysocki, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

Hi Ashwin,


On Tue, May 31, 2016 at 12:29 PM, Ashwin Chaugule
<ashwin.chaugule@linaro.org> wrote:
> On 27 May 2016 at 12:41, Hoan Tran <hotran@apm.com> wrote:
>> Hi Ashwin,
>
> Hi,
>
>>
>> Yes, I saw kernel crash.
>> As cpc_desc_ptr is not NULL, cppc_cpufreq_init() still can pass then
>> crash during cppc_get_perf_caps() access CPPC shared memory.
>>
>> It's not only "PCC channel request fail" can create this issue but
>> "acpi_get_psd() fail" also creates it
>>
>> Thanks
>> Hoan
>
>
> Just for future reference. :)
>
> https://web.archive.org/web/20080722025748/http://www.zip.com.au/~akpm/linux/patches/stuff/top-posting.txt

My mistake and will fix in future :)

>
>
>>
>> On Fri, May 27, 2016 at 9:10 AM, Ashwin Chaugule
>> <ashwin.chaugule@linaro.org> wrote:
>>> On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
>>>> When CPPC fails to request PCC channel, the CPC data is freed
>>>> and cpc_desc_ptr points to the invalid data. This change prevents
>>>> this issue by moving cpc_desc_ptr assignment after PCC channel
>>>> request.
>>>>
>>>> Signed-off-by: Hoan Tran <hotran@apm.com>
>>>> ---
>>>>  drivers/acpi/cppc_acpi.c | 6 +++---
>>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>>>> index 8adac69..85fd8f7 100644
>>>> --- a/drivers/acpi/cppc_acpi.c
>>>> +++ b/drivers/acpi/cppc_acpi.c
>>>> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>>>         /* Store CPU Logical ID */
>>>>         cpc_ptr->cpu_id = pr->id;
>>>>
>>>> -       /* Plug it into this CPUs CPC descriptor. */
>>>> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>>>> -
>>>>         /* Parse PSD data for this CPU */
>>>>         ret = acpi_get_psd(cpc_ptr, handle);
>>>>         if (ret)
>>>> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
>>>>                         goto out_free;
>>>>         }
>>>>
>>>> +       /* Plug PSD data into this CPUs CPC descriptor. */
>>>> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
>>>> +
>>>
>>> Are you seeing a real problem without this change? I'm missing where
>>> this pointer is dereferenced if the PCC channel request fails.
>>>
>
> So, after freeing the cpc_ptr, we need to NULL the per-cpu pointer as
> well. Alternately, not assign it until everything passes and rely on
> the static declaration, which is the path you've taken here.
>
> Acked-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>

Thanks
Hoan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-05-31 19:29     ` Ashwin Chaugule
  2016-05-31 19:38       ` Hoan Tran
@ 2016-06-24 16:35       ` Hoan Tran
  2016-06-24 23:05         ` Rafael J. Wysocki
  1 sibling, 1 reply; 7+ messages in thread
From: Hoan Tran @ 2016-06-24 16:35 UTC (permalink / raw)
  To: Ashwin Chaugule
  Cc: Rafael J. Wysocki, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

On Tue, May 31, 2016 at 12:29 PM, Ashwin Chaugule
<ashwin.chaugule@linaro.org> wrote:
>
> On 27 May 2016 at 12:41, Hoan Tran <hotran@apm.com> wrote:
> > Hi Ashwin,
>
> Hi,
>
> >
> > Yes, I saw kernel crash.
> > As cpc_desc_ptr is not NULL, cppc_cpufreq_init() still can pass then
> > crash during cppc_get_perf_caps() access CPPC shared memory.
> >
> > It's not only "PCC channel request fail" can create this issue but
> > "acpi_get_psd() fail" also creates it
> >
> > Thanks
> > Hoan
>
>
> Just for future reference. :)
>
> https://web.archive.org/web/20080722025748/http://www.zip.com.au/~akpm/linux/patches/stuff/top-posting.txt
>
>
> >
> > On Fri, May 27, 2016 at 9:10 AM, Ashwin Chaugule
> > <ashwin.chaugule@linaro.org> wrote:
> >> On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
> >>> When CPPC fails to request PCC channel, the CPC data is freed
> >>> and cpc_desc_ptr points to the invalid data. This change prevents
> >>> this issue by moving cpc_desc_ptr assignment after PCC channel
> >>> request.
> >>>
> >>> Signed-off-by: Hoan Tran <hotran@apm.com>
> >>> ---
> >>>  drivers/acpi/cppc_acpi.c | 6 +++---
> >>>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> >>> index 8adac69..85fd8f7 100644
> >>> --- a/drivers/acpi/cppc_acpi.c
> >>> +++ b/drivers/acpi/cppc_acpi.c
> >>> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
> >>>         /* Store CPU Logical ID */
> >>>         cpc_ptr->cpu_id = pr->id;
> >>>
> >>> -       /* Plug it into this CPUs CPC descriptor. */
> >>> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> >>> -
> >>>         /* Parse PSD data for this CPU */
> >>>         ret = acpi_get_psd(cpc_ptr, handle);
> >>>         if (ret)
> >>> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
> >>>                         goto out_free;
> >>>         }
> >>>
> >>> +       /* Plug PSD data into this CPUs CPC descriptor. */
> >>> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> >>> +
> >>
> >> Are you seeing a real problem without this change? I'm missing where
> >> this pointer is dereferenced if the PCC channel request fails.
> >>
>
> So, after freeing the cpc_ptr, we need to NULL the per-cpu pointer as
> well. Alternately, not assign it until everything passes and rely on
> the static declaration, which is the path you've taken here.
>
> Acked-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>

Hi Rafael,

Do you have plan to apply this patch ?

Thanks
Hoan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data
  2016-06-24 16:35       ` Hoan Tran
@ 2016-06-24 23:05         ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2016-06-24 23:05 UTC (permalink / raw)
  To: Hoan Tran; +Cc: Ashwin Chaugule, Len Brown, linux acpi, lkml, Duc Dang, Loc Ho

On Friday, June 24, 2016 09:35:32 AM Hoan Tran wrote:
> On Tue, May 31, 2016 at 12:29 PM, Ashwin Chaugule
> <ashwin.chaugule@linaro.org> wrote:
> >
> > On 27 May 2016 at 12:41, Hoan Tran <hotran@apm.com> wrote:
> > > Hi Ashwin,
> >
> > Hi,
> >
> > >
> > > Yes, I saw kernel crash.
> > > As cpc_desc_ptr is not NULL, cppc_cpufreq_init() still can pass then
> > > crash during cppc_get_perf_caps() access CPPC shared memory.
> > >
> > > It's not only "PCC channel request fail" can create this issue but
> > > "acpi_get_psd() fail" also creates it
> > >
> > > Thanks
> > > Hoan
> >
> >
> > Just for future reference. :)
> >
> > https://web.archive.org/web/20080722025748/http://www.zip.com.au/~akpm/linux/patches/stuff/top-posting.txt
> >
> >
> > >
> > > On Fri, May 27, 2016 at 9:10 AM, Ashwin Chaugule
> > > <ashwin.chaugule@linaro.org> wrote:
> > >> On 25 May 2016 at 15:09, Hoan Tran <hotran@apm.com> wrote:
> > >>> When CPPC fails to request PCC channel, the CPC data is freed
> > >>> and cpc_desc_ptr points to the invalid data. This change prevents
> > >>> this issue by moving cpc_desc_ptr assignment after PCC channel
> > >>> request.
> > >>>
> > >>> Signed-off-by: Hoan Tran <hotran@apm.com>
> > >>> ---
> > >>>  drivers/acpi/cppc_acpi.c | 6 +++---
> > >>>  1 file changed, 3 insertions(+), 3 deletions(-)
> > >>>
> > >>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> > >>> index 8adac69..85fd8f7 100644
> > >>> --- a/drivers/acpi/cppc_acpi.c
> > >>> +++ b/drivers/acpi/cppc_acpi.c
> > >>> @@ -595,9 +595,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
> > >>>         /* Store CPU Logical ID */
> > >>>         cpc_ptr->cpu_id = pr->id;
> > >>>
> > >>> -       /* Plug it into this CPUs CPC descriptor. */
> > >>> -       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> > >>> -
> > >>>         /* Parse PSD data for this CPU */
> > >>>         ret = acpi_get_psd(cpc_ptr, handle);
> > >>>         if (ret)
> > >>> @@ -610,6 +607,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
> > >>>                         goto out_free;
> > >>>         }
> > >>>
> > >>> +       /* Plug PSD data into this CPUs CPC descriptor. */
> > >>> +       per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
> > >>> +
> > >>
> > >> Are you seeing a real problem without this change? I'm missing where
> > >> this pointer is dereferenced if the PCC channel request fails.
> > >>
> >
> > So, after freeing the cpc_ptr, we need to NULL the per-cpu pointer as
> > well. Alternately, not assign it until everything passes and rely on
> > the static declaration, which is the path you've taken here.
> >
> > Acked-by: Ashwin Chaugule <ashwin.chaugule@linaro.org>
> 
> Hi Rafael,
> 
> Do you have plan to apply this patch ?

I do now. :-)

I've overlooked the Ashwin's ACK, so thanks for the reminder.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-06-24 23:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-25 19:09 [PATCH] acpi: cppc: Prevent cpc_desc_ptr points to the invalid data Hoan Tran
2016-05-27 16:10 ` Ashwin Chaugule
2016-05-27 16:41   ` Hoan Tran
2016-05-31 19:29     ` Ashwin Chaugule
2016-05-31 19:38       ` Hoan Tran
2016-06-24 16:35       ` Hoan Tran
2016-06-24 23:05         ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).