From nobody Thu Sep 08 20:16:56 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MNr4x47v4z4bf9Y; Thu, 8 Sep 2022 20:17:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MNr4w5Nmyz3lts; Thu, 8 Sep 2022 20:17:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 288KGuxa076561 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 8 Sep 2022 23:16:59 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 288KGura076560; Thu, 8 Sep 2022 23:16:56 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 8 Sep 2022 23:16:56 +0300 From: Konstantin Belousov To: =?utf-8?Q?T=C4=B3l?= Coosemans 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: References: <202208241925.27OJP9Fh069091@gitrepo.freebsd.org> <20220906171826.1629cfcf@FreeBSD.org> <20220906231745.1a0f3c15@FreeBSD.org> <20220907183804.29829b14@FreeBSD.org> <20220908144909.7e6a0d6b@FreeBSD.org> <20220908190009.6377b71a@FreeBSD.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on tom.home X-Rspamd-Queue-Id: 4MNr4w5Nmyz3lts X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-2.91 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.91)[-0.907]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_FIVE(0.00)[5]; R_SPF_SOFTFAIL(0.00)[~all:c]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FREEMAIL_FROM(0.00)[gmail.com]; HAS_XAW(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[] X-ThisMailContainsUnwantedMimeParts: N 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 wrote: > > > On Wed, 7 Sep 2022 23:18:32 +0300 Konstantin Belousov > > > 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.