Date: Thu, 8 Sep 2022 23:16:56 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: =?utf-8?Q?T=C4=B3l?= Coosemans <tijl@freebsd.org> Cc: pho@freebsd.org, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 95f773e59482 - main - i386 copyout_fast: improve detection of a fault on accessing userspace Message-ID: <YxpNuFQbCs7ni%2Bks@kib.kiev.ua> In-Reply-To: <YxoksPNqF0EZszDm@kib.kiev.ua> References: <202208241925.27OJP9Fh069091@gitrepo.freebsd.org> <20220906171826.1629cfcf@FreeBSD.org> <YxdneZXqyaAPmVL0@kib.kiev.ua> <20220906231745.1a0f3c15@FreeBSD.org> <20220907183804.29829b14@FreeBSD.org> <Yxj8mG/lQNIH3fSC@kib.kiev.ua> <20220908144909.7e6a0d6b@FreeBSD.org> <20220908190009.6377b71a@FreeBSD.org> <YxoksPNqF0EZszDm@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YxpNuFQbCs7ni%2Bks>