Re: [PATCH v2 1/2] MIPS: ptrace: disallow setting watchpoints in kernel address space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Maciej,

On Tue, Jan 24, 2017 at 05:09:32PM +0000, Maciej W. Rozycki wrote:
> On Mon, 23 Jan 2017, Marcin Nowakowski wrote:
> 
> > With certain EVA configurations it is possible for the kernel address
> > space to overlap user address space, which allows the user to set
> > watchpoints on kernel addresses via ptrace.
> > 
> > If a watchpoint is set in the watch exception handling code (after
> > exception level has been cleared) then the system will hang in an
> > infinite loop when hitting a watchpoint while trying to process it.
> > 
> > To prevent that simply disallow placing any watchpoints at addresses
> > above start of kernel that overlap userspace.
> 
>  This can be severely crippling for user debugging.  Is there no better 
> way?

See the v1 patches, but as you say below, an architectural fix is vastly
preferable. Other proposed solutions have so far added complexity and
fragility, while struggling to completely plug the original problem.

> 
>  Can't for example the low-level exception handling entry/exit code be 
> moved out of the way of the EVA overlap range and then all watchpoints 
> masked for the duration of kernel mode execution?  This would be quite 
> expensive, however it could only be executed if a task flag indicates 
> watchpoints are being used.

That doesn't cover data watches. RAM would still need accessing, e.g. to
save/restore the watch state from the thread context, or even to read
the task flag, and stack accesses in C code. The only safe way for it to
work would be to somehow disable or inhibit watchpoints before clearing
EXL, and re-enable them after setting EXL, though you'd still get a loop
of deferred watchpoints if it hit on the way out to user mode unless
cleared at the last moment before ERET.

> Alternatively perhaps we could clobber 
> CP0.EntryHi.ASID, at least temporarily; that would be cheaper.

Kernel mode still needs to access the user address space.

Alternatively we could set WatchHi.ASID to a reserved one, and only
clear/set the WatchHi.G bit (to bypass the ASID match) at the first/last
moment while EXL=1. It still wouldn't protect against code watches
around there exposing the kernel address of that code by the resulting
hang though, so would need to move the ebase out of the overlap range
too (which would have to be platform specific).

Cheers
James

> 
>  Overall I think this situation is asking for a watchpoint flag to be 
> added to inhibit hits in the kernel mode in hardware; for completeness 
> this probably actually ought to be a field to cover the kernel, supervisor 
> and user modes separately -- either a plain bitmask for arbitrary control 
> or an encoded value similar to CP0.Status.KSU which would indicate the 
> most privileged mode to accept a watchpoint in.
> 
>  I had a recollection of such a facility already being available for JTAG 
> debugging, but I can't track it down in the specification, so perhaps it 
> was for another architecture and it would be completely new for ours.
> 
>   Maciej

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux