[PATCH 0/2] um: improve UML page fault handling

Petr Tesarik posted 2 patches 2 years ago
arch/um/kernel/trap.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
[PATCH 0/2] um: improve UML page fault handling
Posted by Petr Tesarik 2 years ago
From: Petr Tesarik <petr.tesarik1@huawei-partners.com>

Improve UML handling of segmentation faults in kernel mode. Although
such page faults are generally caused by a kernel bug, it is annoying
if they cause an infinite loop, or panic the kernel. More importantly,
a robust implementation allows to write KUnit tests for various guard
pages, preventing potential kernel self-protection regressions.

Petr Tesarik (2):
  um: do not panic on kernel mode faults
  um: oops on accessing an non-present page in the vmalloc area

 arch/um/kernel/trap.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

-- 
2.34.1
Re: [PATCH 0/2] um: improve UML page fault handling
Posted by Richard Weinberger 1 year, 11 months ago
----- Ursprüngliche Mail -----
> Von: "Petr Tesarik" <petrtesarik@huaweicloud.com>
> An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> <johannes@sipsolutions.net>, "linux-um" <linux-um@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>
> CC: "Roberto Sassu" <roberto.sassu@huaweicloud.com>, petr@tesarici.cz, "Petr Tesarik"
> <petr.tesarik1@huawei-partners.com>
> Gesendet: Freitag, 15. Dezember 2023 13:14:29
> Betreff: [PATCH 0/2] um: improve UML page fault handling

> From: Petr Tesarik <petr.tesarik1@huawei-partners.com>
> 
> Improve UML handling of segmentation faults in kernel mode. Although
> such page faults are generally caused by a kernel bug, it is annoying
> if they cause an infinite loop, or panic the kernel. More importantly,
> a robust implementation allows to write KUnit tests for various guard
> pages, preventing potential kernel self-protection regressions.
> 
> Petr Tesarik (2):
>  um: do not panic on kernel mode faults
>  um: oops on accessing an non-present page in the vmalloc area

I think this is a good thing to have.
For the implementation side, this needs to use the oops_* helpers
from kernel/panic.c and taint the kernel, etc...
See arch/x86/kernel/dumpstack.c die() and friends.

Thanks,
//richard
Re: [PATCH 0/2] um: improve UML page fault handling
Posted by Petr Tesařík 1 year, 11 months ago
Helo Richard,

Am Fri, 5 Jan 2024 00:22:11 +0100 (CET)
schrieb Richard Weinberger <richard@nod.at>:

> ----- Ursprüngliche Mail -----
> > Von: "Petr Tesarik" <petrtesarik@huaweicloud.com>
> > An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> > <johannes@sipsolutions.net>, "linux-um" <linux-um@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>
> > CC: "Roberto Sassu" <roberto.sassu@huaweicloud.com>, petr@tesarici.cz, "Petr Tesarik"
> > <petr.tesarik1@huawei-partners.com>
> > Gesendet: Freitag, 15. Dezember 2023 13:14:29
> > Betreff: [PATCH 0/2] um: improve UML page fault handling  
> 
> > From: Petr Tesarik <petr.tesarik1@huawei-partners.com>
> > 
> > Improve UML handling of segmentation faults in kernel mode. Although
> > such page faults are generally caused by a kernel bug, it is annoying
> > if they cause an infinite loop, or panic the kernel. More importantly,
> > a robust implementation allows to write KUnit tests for various guard
> > pages, preventing potential kernel self-protection regressions.
> > 
> > Petr Tesarik (2):
> >  um: do not panic on kernel mode faults
> >  um: oops on accessing an non-present page in the vmalloc area  
> 
> I think this is a good thing to have.

Thanks for the feedback.

> For the implementation side, this needs to use the oops_* helpers
> from kernel/panic.c and taint the kernel, etc...

Yes, I did see that coming but wanted to get some confirmation that
it's worth the effort.

> See arch/x86/kernel/dumpstack.c die() and friends.

This implementation also calls die notifiers, but AFAICS different
architectures are not very consistent in their use. Do you also
require die notifiers for the UML implementation?

Petr T
Re: [PATCH 0/2] um: improve UML page fault handling
Posted by Petr Tesařík 1 year, 10 months ago
On Fri, 5 Jan 2024 07:51:09 +0100
Petr Tesařík <petr@tesarici.cz> wrote:

> Helo Richard,
> 
> Am Fri, 5 Jan 2024 00:22:11 +0100 (CET)
> schrieb Richard Weinberger <richard@nod.at>:
> 
> > ----- Ursprüngliche Mail -----  
> > > Von: "Petr Tesarik" <petrtesarik@huaweicloud.com>
> > > An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> > > <johannes@sipsolutions.net>, "linux-um" <linux-um@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>
> > > CC: "Roberto Sassu" <roberto.sassu@huaweicloud.com>, petr@tesarici.cz, "Petr Tesarik"
> > > <petr.tesarik1@huawei-partners.com>
> > > Gesendet: Freitag, 15. Dezember 2023 13:14:29
> > > Betreff: [PATCH 0/2] um: improve UML page fault handling    
> >   
> > > From: Petr Tesarik <petr.tesarik1@huawei-partners.com>
> > > 
> > > Improve UML handling of segmentation faults in kernel mode. Although
> > > such page faults are generally caused by a kernel bug, it is annoying
> > > if they cause an infinite loop, or panic the kernel. More importantly,
> > > a robust implementation allows to write KUnit tests for various guard
> > > pages, preventing potential kernel self-protection regressions.
> > > 
> > > Petr Tesarik (2):
> > >  um: do not panic on kernel mode faults
> > >  um: oops on accessing an non-present page in the vmalloc area    
> > 
> > I think this is a good thing to have.  
> 
> Thanks for the feedback.
> 
> > For the implementation side, this needs to use the oops_* helpers
> > from kernel/panic.c and taint the kernel, etc...  
> 
> Yes, I did see that coming but wanted to get some confirmation that
> it's worth the effort.
> 
> > See arch/x86/kernel/dumpstack.c die() and friends.  
> 
> This implementation also calls die notifiers, but AFAICS different
> architectures are not very consistent in their use. Do you also
> require die notifiers for the UML implementation?

It seems I won't have time for this in the near future... Can I start
by sending a trivial patch that panics the kernel if kernel mode tries
to access a vmalloc guard page? That's something I can do immediately,
and it's still better than getting page faults in an infinite loop...

Petr T
Re: [PATCH 0/2] um: improve UML page fault handling
Posted by Petr Tesařík 1 year, 11 months ago
Happy New Year, everyone!

I can fully understand that you all have had other priorities around
the year end; it was no different with me. ;-)

However, may I kindly ask for some feedback on my proposed fixes?

Petr T

On Fri, 15 Dec 2023 13:14:29 +0100
Petr Tesarik <petrtesarik@huaweicloud.com> wrote:

> From: Petr Tesarik <petr.tesarik1@huawei-partners.com>
> 
> Improve UML handling of segmentation faults in kernel mode. Although
> such page faults are generally caused by a kernel bug, it is annoying
> if they cause an infinite loop, or panic the kernel. More importantly,
> a robust implementation allows to write KUnit tests for various guard
> pages, preventing potential kernel self-protection regressions.
> 
> Petr Tesarik (2):
>   um: do not panic on kernel mode faults
>   um: oops on accessing an non-present page in the vmalloc area
> 
>  arch/um/kernel/trap.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
>