Re: git: 95f773e59482 - main - i386 copyout_fast: improve detection of a fault on accessing userspace
- Reply: Tijl Coosemans : "Re: git: 95f773e59482 - main - i386 copyout_fast: improve detection of a fault on accessing userspace"
- In reply to: Konstantin Belousov : "Re: git: 95f773e59482 - main - i386 copyout_fast: improve detection of a fault on accessing userspace"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 08 Sep 2022 20:16:56 UTC
On Thu, Sep 08, 2022 at 08:21:52PM +0300, Konstantin Belousov wrote: > On Thu, Sep 08, 2022 at 07:00:09PM +0200, Tijl Coosemans wrote: > > On Thu, 8 Sep 2022 14:49:09 +0200 Tijl Coosemans <tijl@FreeBSD.org> wrote: > > > On Wed, 7 Sep 2022 23:18:32 +0300 Konstantin Belousov > > > <kostikbel@gmail.com> wrote: > > > > On Wed, Sep 07, 2022 at 06:38:04PM +0200, Tijl Coosemans wrote: > > > >> So interrupts must have been reenabled somehow, probably by the page > > > >> fault handler, and this allows context switches and then another process > > > >> can call copyout or copyin and corrupt the trampoline stack and > > > >> copyout_buf. > > > > I do not see where the interrupts could be reenabled in copyout_fast path, > > > > without or with page fault on the userspace access. > > > > > > The problem is not with userspace page faults. Those are treated > > > specially by the page fault handler in exception.s causing copyout_fast > > > and copyin_fast to return immediately with EFAULT so copyout and copyin > > > fall back to doing a slow copy. > > > > > > The problem is with page faults on the kernel space accesses. Before > > > this commit they were also treated specially, and now they are not. Now > > > the page fault handler in exception.s calls trap() which calls > > > trap_pfault() etc. > > > > And trap() contains this: > > > > if (trap_enable_intr(type) && td->td_md.md_spinlock_count == 0 && > > frame->tf_eip != (int)cpu_switch_load_gs) > > enable_intr(); > > > > Where trap_enable_intr(T_PAGEFLT) returns true and enable_intr() is sti. > Yes, I understand what is going on, it is faulting in the _other_ > movsb, not in the movsb that accessed the userspace. This is because > pipe buffers are pageable. > > I will produce the patch shortly. I updated my ast branch to the commit 6bf5c0aad02323a, which hopefully would fix the issue.