* [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
@ 2019-12-11 10:42 Jan Kara
2019-12-20 5:06 ` Alexey Kardashevskiy
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2019-12-11 10:42 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Jan Kara, Paul Mackerras
The last jump to free_exit in mm_iommu_do_alloc() happens after page
pointers in struct mm_iommu_table_group_mem_t were already converted to
physical addresses. Thus calling put_page() on these physical addresses
will likely crash. Convert physical addresses back to page pointers
during the error cleanup.
Signed-off-by: Jan Kara <jack@suse.cz>
---
arch/powerpc/mm/book3s64/iommu_api.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Beware, this is completely untested, spotted just by code audit.
diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
index 56cc84520577..06c403381c9c 100644
--- a/arch/powerpc/mm/book3s64/iommu_api.c
+++ b/arch/powerpc/mm/book3s64/iommu_api.c
@@ -154,7 +154,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
(mem2->entries << PAGE_SHIFT)))) {
ret = -EINVAL;
mutex_unlock(&mem_list_mutex);
- goto free_exit;
+ goto convert_exit;
}
}
@@ -166,6 +166,9 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
return 0;
+convert_exit:
+ for (i = 0; i < pinned; i++)
+ mem->hpages[i] = pfn_to_page(mem->hpas[i] >> PAGE_SHIFT);
free_exit:
/* free the reference taken */
for (i = 0; i < pinned; i++)
--
2.16.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
2019-12-11 10:42 [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc() Jan Kara
@ 2019-12-20 5:06 ` Alexey Kardashevskiy
2019-12-20 9:57 ` Jan Kara
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Kardashevskiy @ 2019-12-20 5:06 UTC (permalink / raw)
To: Jan Kara, linuxppc-dev; +Cc: Paul Mackerras
On 11/12/2019 21:42, Jan Kara wrote:
> The last jump to free_exit in mm_iommu_do_alloc() happens after page
> pointers in struct mm_iommu_table_group_mem_t were already converted to
> physical addresses. Thus calling put_page() on these physical addresses
> will likely crash. Convert physical addresses back to page pointers
> during the error cleanup.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> arch/powerpc/mm/book3s64/iommu_api.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> Beware, this is completely untested, spotted just by code audit.
>
> diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
> index 56cc84520577..06c403381c9c 100644
> --- a/arch/powerpc/mm/book3s64/iommu_api.c
> +++ b/arch/powerpc/mm/book3s64/iommu_api.c
> @@ -154,7 +154,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
> (mem2->entries << PAGE_SHIFT)))) {
> ret = -EINVAL;
> mutex_unlock(&mem_list_mutex);
> - goto free_exit;
> + goto convert_exit;
> }
> }
>
> @@ -166,6 +166,9 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
>
> return 0;
>
> +convert_exit:
> + for (i = 0; i < pinned; i++)
> + mem->hpages[i] = pfn_to_page(mem->hpas[i] >> PAGE_SHIFT);
Good find. Although doing it where you added "goto convert_exit" seems
cleaner imho. Thanks,
> free_exit:
> /* free the reference taken */
> for (i = 0; i < pinned; i++)
>
--
Alexey
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
2019-12-20 5:06 ` Alexey Kardashevskiy
@ 2019-12-20 9:57 ` Jan Kara
2019-12-23 0:57 ` Alexey Kardashevskiy
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2019-12-20 9:57 UTC (permalink / raw)
To: Alexey Kardashevskiy; +Cc: linuxppc-dev, Jan Kara, Paul Mackerras
[-- Attachment #1: Type: text/plain, Size: 1618 bytes --]
On Fri 20-12-19 16:06:05, Alexey Kardashevskiy wrote:
>
>
> On 11/12/2019 21:42, Jan Kara wrote:
> > The last jump to free_exit in mm_iommu_do_alloc() happens after page
> > pointers in struct mm_iommu_table_group_mem_t were already converted to
> > physical addresses. Thus calling put_page() on these physical addresses
> > will likely crash. Convert physical addresses back to page pointers
> > during the error cleanup.
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> > arch/powerpc/mm/book3s64/iommu_api.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > Beware, this is completely untested, spotted just by code audit.
> >
> > diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
> > index 56cc84520577..06c403381c9c 100644
> > --- a/arch/powerpc/mm/book3s64/iommu_api.c
> > +++ b/arch/powerpc/mm/book3s64/iommu_api.c
> > @@ -154,7 +154,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
> > (mem2->entries << PAGE_SHIFT)))) {
> > ret = -EINVAL;
> > mutex_unlock(&mem_list_mutex);
> > - goto free_exit;
> > + goto convert_exit;
> > }
> > }
> >
> > @@ -166,6 +166,9 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
> >
> > return 0;
> >
> > +convert_exit:
> > + for (i = 0; i < pinned; i++)
> > + mem->hpages[i] = pfn_to_page(mem->hpas[i] >> PAGE_SHIFT);
>
>
> Good find. Although doing it where you added "goto convert_exit" seems
> cleaner imho. Thanks,
I don't really care :). V2 attached.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
[-- Attachment #2: 0001-powerpc-book3s64-Fix-error-handling-in-mm_iommu_do_a.patch --]
[-- Type: text/x-patch, Size: 1251 bytes --]
From 947c7a893c282b829a8623da73276a2fe56fdcd3 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Wed, 11 Dec 2019 11:36:54 +0100
Subject: [PATCH v2] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
The last jump to free_exit in mm_iommu_do_alloc() happens after page
pointers in struct mm_iommu_table_group_mem_t were already converted to
physical addresses. Thus calling put_page() on these physical addresses
will likely crash. Convert physical addresses back to page pointers
during the error cleanup.
Signed-off-by: Jan Kara <jack@suse.cz>
---
arch/powerpc/mm/book3s64/iommu_api.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
index 56cc84520577..1aa06584d783 100644
--- a/arch/powerpc/mm/book3s64/iommu_api.c
+++ b/arch/powerpc/mm/book3s64/iommu_api.c
@@ -154,6 +154,11 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
(mem2->entries << PAGE_SHIFT)))) {
ret = -EINVAL;
mutex_unlock(&mem_list_mutex);
+ /* Convert back to page pointers */
+ for (i = 0; i < pinned; i++) {
+ mem->hpages[i] =
+ pfn_to_page(mem->hpas[i] >> PAGE_SHIFT);
+ }
goto free_exit;
}
}
--
2.16.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
2019-12-20 9:57 ` Jan Kara
@ 2019-12-23 0:57 ` Alexey Kardashevskiy
0 siblings, 0 replies; 4+ messages in thread
From: Alexey Kardashevskiy @ 2019-12-23 0:57 UTC (permalink / raw)
To: Jan Kara; +Cc: Paul Mackerras, linuxppc-dev
On 20/12/2019 20:57, Jan Kara wrote:
> On Fri 20-12-19 16:06:05, Alexey Kardashevskiy wrote:
>>
>>
>> On 11/12/2019 21:42, Jan Kara wrote:
>>> The last jump to free_exit in mm_iommu_do_alloc() happens after page
>>> pointers in struct mm_iommu_table_group_mem_t were already converted to
>>> physical addresses. Thus calling put_page() on these physical addresses
>>> will likely crash. Convert physical addresses back to page pointers
>>> during the error cleanup.
>>>
>>> Signed-off-by: Jan Kara <jack@suse.cz>
>>> ---
>>> arch/powerpc/mm/book3s64/iommu_api.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> Beware, this is completely untested, spotted just by code audit.
>>>
>>> diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c
>>> index 56cc84520577..06c403381c9c 100644
>>> --- a/arch/powerpc/mm/book3s64/iommu_api.c
>>> +++ b/arch/powerpc/mm/book3s64/iommu_api.c
>>> @@ -154,7 +154,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
>>> (mem2->entries << PAGE_SHIFT)))) {
>>> ret = -EINVAL;
>>> mutex_unlock(&mem_list_mutex);
>>> - goto free_exit;
>>> + goto convert_exit;
>>> }
>>> }
>>>
>>> @@ -166,6 +166,9 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua,
>>>
>>> return 0;
>>>
>>> +convert_exit:
>>> + for (i = 0; i < pinned; i++)
>>> + mem->hpages[i] = pfn_to_page(mem->hpas[i] >> PAGE_SHIFT);
>>
>>
>> Good find. Although doing it where you added "goto convert_exit" seems
>> cleaner imho. Thanks,
>
> I don't really care :). V2 attached.
Usually patches are posted using git send-mail, not as attachment. A
nit: v2 has now curly braces which v1 did not.
Either way, v2 is correct.
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
--
Alexey
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-23 0:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 10:42 [PATCH] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc() Jan Kara
2019-12-20 5:06 ` Alexey Kardashevskiy
2019-12-20 9:57 ` Jan Kara
2019-12-23 0:57 ` Alexey Kardashevskiy
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).