Re: [PATCH 2/2] kfence: only handle kernel mode faults

From: Marco Elver
Date: Fri May 14 2021 - 06:59:44 EST


On Fri, 14 May 2021 at 12:55, Sven Schnelle <svens@xxxxxxxxxxxxx> wrote:
>
> Marco Elver <elver@xxxxxxxxxx> writes:
>
> > On Fri, 14 May 2021 at 11:22, Sven Schnelle <svens@xxxxxxxxxxxxx> wrote:
> >>
> >> Signed-off-by: Sven Schnelle <svens@xxxxxxxxxxxxx>
> >> ---
> >> mm/kfence/core.c | 3 +++
> >> 1 file changed, 3 insertions(+)
> >>
> >> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> >> index bc15e3cb71d5..161df492750c 100644
> >> --- a/mm/kfence/core.c
> >> +++ b/mm/kfence/core.c
> >> @@ -813,6 +813,9 @@ bool kfence_handle_page_fault(unsigned long addr, bool is_write, struct pt_regs
> >> enum kfence_error_type error_type;
> >> unsigned long flags;
> >>
> >> + if (user_mode(regs))
> >> + return false;
> >> +
> >
> > I don't think it's required on all architectures, correct? If so, I
> > think this should be part of the arch-specific code, i.e. just do "if
> > (user_mode(regs) && kfence_handle_page_fault(...))" or similar.

Ah, this should have obviously been "if (!user_mode(regs) &&
kfence_handle_page_fault(...))", but I think you would have caught
that anyway. ;-)

> > Because otherwise we'll wonder in future why we ever needed this, and
> > e.g. determine it's useless and remove it again. ;-) Either that, or a
> > comment. But I'd prefer to just keep it in the arch-specific code if
> > required, because it seems to be the exception rather than the norm.
>
> Ok, that's fine, i add it to our code then.

Sounds good.

Thanks,
-- Marco

> Thanks
> Sven