Re: [BUGFIX][PATCH -rc/-mm] prevent kprobes from catching spuriouspage faults

From: Masami Hiramatsu
Date: Fri Feb 06 2009 - 10:57:40 EST


Ingo Molnar wrote:
> * Masami Hiramatsu <mhiramat@xxxxxxxxxx> wrote:
>
>> - if (notify_page_fault(regs))
>> - return;
>> if (unlikely(kmmio_fault(regs, address)))
>> return;
>>
>> @@ -634,6 +632,9 @@ void __kprobes do_page_fault(struct pt_r
>> if (spurious_fault(address, error_code))
>> return;
>>
>> + /* kprobes don't want to hook the spurious faults. */
>> + if (notify_page_fault(regs))
>> + return;
>> /*
>> * Don't take the mm semaphore here. If we fixup a prefetch
>> * fault we could otherwise deadlock.
>> @@ -641,6 +642,9 @@ void __kprobes do_page_fault(struct pt_r
>> goto bad_area_nosemaphore;
>> }
>>
>> + /* kprobes don't want to hook the spurious faults. */
>> + if (notify_page_fault(regs))
>> + return;
>
> I dont know - this spreads that callback to two places now. Any
> reason why kprobes cannot call spurious_fault(), if there's a
> probe active?

Hmm, because I think how the spurious faults are treated depends on
do_page_fault(). Calling spurious_fault() and vmalloc_fault() in
kprobe_fault_handler() is just spreading another code different way...

> Also, moving that would remove the planned cleanup of merging these
> two into one call:
>
> if (notify_page_fault(regs))
> return;
> if (unlikely(kmmio_fault(regs, address)))
> return;

Sure, that is reasonable, if kmmio also want not catch spurious fault too.

> We should reduce the probing cross section, not increase it,
> especially in such a critical codepath as the pagefault handler.

I think my patch doesn't increase it, the first path jumps to
bad_area_nosemaphore right after calling notify_page_fault().

>
> Btw., why cannot kprobes install a dynamic probe to the fault
> handler itself? That way the default path would have no such
> callbacks and checks at all.

because kprobe_fault_handler() is implemented not only for the
user fault handler but also for fixup page-fault ip during
single step out-of-line. It's an elemental part of kprobes.

Thank you,

--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@xxxxxxxxxx

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/