Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Sep 2022 19:00:09 +0200
From:      =?UTF-8?B?VMSzbA==?= Coosemans <tijl@FreeBSD.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
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:  <20220908190009.6377b71a@FreeBSD.org>
In-Reply-To: <20220908144909.7e6a0d6b@FreeBSD.org>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 8 Sep 2022 14:49:09 +0200 T=C4=B3l Coosemans <tijl@FreeBSD.org> wro=
te:
> 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, T=C4=B3l Coosemans wrote: =20
> >> So interrupts must have been reenabled somehow, probably by the page
> >> fault handler, and this allows context switches and then another proce=
ss
> >> can call copyout or copyin and corrupt the trampoline stack and
> >> copyout_buf.   =20
> > I do not see where the interrupts could be reenabled in copyout_fast pa=
th,
> > without or with page fault on the userspace access. =20
>=20
> 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.
>=20
> 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=
=20
> 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 =3D=3D 0 &&
	    frame->tf_eip !=3D (int)cpu_switch_load_gs)
		enable_intr();

Where trap_enable_intr(T_PAGEFLT) returns true and enable_intr() is sti.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220908190009.6377b71a>