From patchwork Tue Apr 19 13:52:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 12818553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EE84C4332F for ; Tue, 19 Apr 2022 13:53:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.308146.523705 (Exim 4.92) (envelope-from ) id 1ngoHs-0003nb-EP; Tue, 19 Apr 2022 13:53:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 308146.523705; Tue, 19 Apr 2022 13:53:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHs-0003nU-BS; Tue, 19 Apr 2022 13:53:00 +0000 Received: by outflank-mailman (input) for mailman id 308146; Tue, 19 Apr 2022 13:52:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHr-0003n8-7U for xen-devel@lists.xenproject.org; Tue, 19 Apr 2022 13:52:59 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04ee214f-bfe8-11ec-a405-831a346695d4; Tue, 19 Apr 2022 15:52:58 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 99CC12112B; Tue, 19 Apr 2022 13:52:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 52884139F6; Tue, 19 Apr 2022 13:52:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qIzvErm+XmL/EgAAMHmgww (envelope-from ); Tue, 19 Apr 2022 13:52:57 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 04ee214f-bfe8-11ec-a405-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1650376377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U4wJ7ITwhPEI/c6FS563E3yxL+vilAPqU1YHXYgdh9M=; b=Hf6Slkfb596jSsL3JpkD7yHvevxLV4Qye9KDHHZ/dDIveP3Ydu2S3uG2BMPWYjShF7hr// b2WPKajFuirm/rkkY0+WSALlMYvz2yySc2cxBP1+6Jl8nmLjgaJT+D1J6aDCC8ZmF3EAZ9 Pc/xwSB3toL7eopkTTrpsWGYanuwNlQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Cheyenne Wills Subject: [PATCH v3 1/3] xen: fix XEN_DOMCTL_gdbsx_guestmemio crash Date: Tue, 19 Apr 2022 15:52:52 +0200 Message-Id: <20220419135254.21729-2-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419135254.21729-1-jgross@suse.com> References: <20220419135254.21729-1-jgross@suse.com> MIME-Version: 1.0 A hypervisor built without CONFIG_GDBSX will crash in case the XEN_DOMCTL_gdbsx_guestmemio domctl is being called, as the call will end up in iommu_do_domctl() with d == NULL: (XEN) CPU: 6 (XEN) RIP: e008:[] iommu_do_domctl+0x4/0x30 (XEN) RFLAGS: 0000000000010202 CONTEXT: hypervisor (d0v0) (XEN) rax: 00000000000003e8 rbx: ffff830856277ef8 rcx: ffff830856277fff ... (XEN) Xen call trace: (XEN) [] R iommu_do_domctl+0x4/0x30 (XEN) [] S arch_do_domctl+0x7f/0x2330 (XEN) [] S do_domctl+0xe56/0x1930 (XEN) [] S do_domctl+0/0x1930 (XEN) [] S pv_hypercall+0x99/0x110 (XEN) [] S arch/x86/pv/domain.c#_toggle_guest_pt+0x11/0x90 (XEN) [] S lstar_enter+0x128/0x130 (XEN) (XEN) Pagetable walk from 0000000000000144: (XEN) L4[0x000] = 0000000000000000 ffffffffffffffff (XEN) (XEN) **************************************** (XEN) Panic on CPU 6: (XEN) FATAL PAGE FAULT (XEN) [error_code=0000] (XEN) Faulting linear address: 0000000000000144 Fix this issue by making sure the domain pointer has a sane value. Reported-by: Cheyenne Wills Fixes: e726a82ca0dc ("xen: make gdbsx support configurable") Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - use gdbsx_guest_mem_io() interface modification (Jan Beulich) V3: - avoid d being NULL (Andrew Cooper) --- xen/common/domctl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 57135d4478..5879117580 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -308,7 +308,6 @@ long cf_check do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) if ( op->domain == DOMID_INVALID ) { case XEN_DOMCTL_createdomain: - case XEN_DOMCTL_gdbsx_guestmemio: d = NULL; break; } From patchwork Tue Apr 19 13:52:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 12818554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47E84C4321E for ; Tue, 19 Apr 2022 13:53:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.308147.523710 (Exim 4.92) (envelope-from ) id 1ngoHs-0003qn-Mb; Tue, 19 Apr 2022 13:53:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 308147.523710; Tue, 19 Apr 2022 13:53:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHs-0003q8-Ir; Tue, 19 Apr 2022 13:53:00 +0000 Received: by outflank-mailman (input) for mailman id 308147; Tue, 19 Apr 2022 13:52:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHr-0003n9-94 for xen-devel@lists.xenproject.org; Tue, 19 Apr 2022 13:52:59 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0515609d-bfe8-11ec-8fbe-03012f2f19d4; Tue, 19 Apr 2022 15:52:58 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DA6AA1F74E; Tue, 19 Apr 2022 13:52:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A1228132E7; Tue, 19 Apr 2022 13:52:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ANwbJrm+XmL/EgAAMHmgww (envelope-from ); Tue, 19 Apr 2022 13:52:57 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0515609d-bfe8-11ec-8fbe-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1650376377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L4AQsF0qS2f7XQ0Ro2SIxitX/SjtNc2JqVh6FUtqIEw=; b=Sn0cIqdU25k6LU5Xq0tjR2hNggQ5idFBTMTSHFb+cdV+iAVHw9HqsRzQXjwQOgTo/IjHp2 mKKdgfoqSLEkghtzRl8Ofx1m0E1oyO37SLK9kQl0v+reN9mAZuDMSW0MAW6inV0DGa0pZ1 5IlCxWRRiDk3vcreY8Oq7bfA9rG1yk8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Elena Ufimtseva , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 2/3] xen: cleanup gdbsx_guest_mem_io() call Date: Tue, 19 Apr 2022 15:52:53 +0200 Message-Id: <20220419135254.21729-3-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419135254.21729-1-jgross@suse.com> References: <20220419135254.21729-1-jgross@suse.com> MIME-Version: 1.0 Modify the gdbsx_guest_mem_io() interface to take the already known domain pointer as parameter instead of the domid. This enables to remove some more code further down the call tree. Suggested-by: Jan Beulich Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Reviewed-by: Andrew Cooper --- V2: - split off from previous patch (Andrew Cooper) --- xen/arch/x86/debug.c | 12 +++--------- xen/arch/x86/domctl.c | 6 +++--- xen/arch/x86/include/asm/debugger.h | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/debug.c b/xen/arch/x86/debug.c index d90dc93056..62fbabb084 100644 --- a/xen/arch/x86/debug.c +++ b/xen/arch/x86/debug.c @@ -159,17 +159,11 @@ static unsigned int dbg_rw_guest_mem(struct domain *dp, unsigned long addr, * Returns: number of bytes remaining to be copied. */ unsigned int dbg_rw_mem(unsigned long gva, XEN_GUEST_HANDLE_PARAM(void) buf, - unsigned int len, domid_t domid, bool toaddr, + unsigned int len, struct domain *d, bool toaddr, uint64_t pgd3) { - struct domain *d = rcu_lock_domain_by_id(domid); - - if ( d ) - { - if ( !d->is_dying ) - len = dbg_rw_guest_mem(d, gva, buf, len, toaddr, pgd3); - rcu_unlock_domain(d); - } + if ( d && !d->is_dying ) + len = dbg_rw_guest_mem(d, gva, buf, len, toaddr, pgd3); return len; } diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index e49f9e91b9..a6aae500a3 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -38,10 +38,10 @@ #include #ifdef CONFIG_GDBSX -static int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio *iop) +static int gdbsx_guest_mem_io(struct domain *d, struct xen_domctl_gdbsx_memio *iop) { iop->remain = dbg_rw_mem(iop->gva, guest_handle_from_ptr(iop->uva, void), - iop->len, domid, iop->gwr, iop->pgd3val); + iop->len, d, iop->gwr, iop->pgd3val); return iop->remain ? -EFAULT : 0; } @@ -828,7 +828,7 @@ long arch_do_domctl( #ifdef CONFIG_GDBSX case XEN_DOMCTL_gdbsx_guestmemio: domctl->u.gdbsx_guest_memio.remain = domctl->u.gdbsx_guest_memio.len; - ret = gdbsx_guest_mem_io(domctl->domain, &domctl->u.gdbsx_guest_memio); + ret = gdbsx_guest_mem_io(d, &domctl->u.gdbsx_guest_memio); if ( !ret ) copyback = true; break; diff --git a/xen/arch/x86/include/asm/debugger.h b/xen/arch/x86/include/asm/debugger.h index 99803bfd0c..221bcde137 100644 --- a/xen/arch/x86/include/asm/debugger.h +++ b/xen/arch/x86/include/asm/debugger.h @@ -94,7 +94,7 @@ static inline bool debugger_trap_entry( #ifdef CONFIG_GDBSX unsigned int dbg_rw_mem(unsigned long gva, XEN_GUEST_HANDLE_PARAM(void) buf, - unsigned int len, domid_t domid, bool toaddr, + unsigned int len, struct domain *d, bool toaddr, uint64_t pgd3); #endif From patchwork Tue Apr 19 13:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 12818555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55791C4167D for ; Tue, 19 Apr 2022 13:53:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.308149.523739 (Exim 4.92) (envelope-from ) id 1ngoHu-0004VP-9C; Tue, 19 Apr 2022 13:53:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 308149.523739; Tue, 19 Apr 2022 13:53:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHu-0004V8-5Q; Tue, 19 Apr 2022 13:53:02 +0000 Received: by outflank-mailman (input) for mailman id 308149; Tue, 19 Apr 2022 13:53:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngoHs-0003n9-1V for xen-devel@lists.xenproject.org; Tue, 19 Apr 2022 13:53:00 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 053ec57a-bfe8-11ec-8fbe-03012f2f19d4; Tue, 19 Apr 2022 15:52:58 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3886C1F750; Tue, 19 Apr 2022 13:52:58 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DF56D132E7; Tue, 19 Apr 2022 13:52:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qB5ZNbm+XmL/EgAAMHmgww (envelope-from ); Tue, 19 Apr 2022 13:52:57 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 053ec57a-bfe8-11ec-8fbe-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1650376378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6/VWhQSdoCzBqVa8x/quqgeEjSXetNd8IJxjXUoErU4=; b=M3cz+pB2CCUNe8C1A95O1lap4xXxEgJXnIhJva5g0Czvy8QIjRm4AVBN2V41i/jHVYaKQM qff3o6VRyCjFgOJDEMedddRdAIswQXmsyxyo7kbXiAijOsMh8Njq8WBQxfkQvum2Y6UoNa p0R2TGqhEdgPeYfl34L9V1G5S/jg1yQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 3/3] xen/iommu: cleanup iommu related domctl handling Date: Tue, 19 Apr 2022 15:52:54 +0200 Message-Id: <20220419135254.21729-4-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220419135254.21729-1-jgross@suse.com> References: <20220419135254.21729-1-jgross@suse.com> MIME-Version: 1.0 Today iommu_do_domctl() is being called from arch_do_domctl() in the "default:" case of a switch statement. This has led already to crashes due to unvalidated parameters. Fix that by moving the call of iommu_do_domctl() to the main switch statement of do_domctl(). Signed-off-by: Juergen Gross --- Another possibility would even be to merge iommu_do_domctl() completely into do_domctl(), but I wanted to start with a less intrusive variant. V3: - new patch --- xen/arch/arm/domctl.c | 11 +---------- xen/arch/x86/domctl.c | 2 +- xen/common/domctl.c | 7 +++++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 6245af6d0b..1baf25c3d9 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -176,16 +176,7 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return rc; } default: - { - int rc; - - rc = subarch_do_domctl(domctl, d, u_domctl); - - if ( rc == -ENOSYS ) - rc = iommu_do_domctl(domctl, d, u_domctl); - - return rc; - } + return subarch_do_domctl(domctl, d, u_domctl); } } diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index a6aae500a3..c9699bb868 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1380,7 +1380,7 @@ long arch_do_domctl( break; default: - ret = iommu_do_domctl(domctl, d, u_domctl); + ret = -ENOSYS; break; } diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 5879117580..0a866e3132 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -871,6 +871,13 @@ long cf_check do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) copyback = 1; break; + case XEN_DOMCTL_assign_device: + case XEN_DOMCTL_test_assign_device: + case XEN_DOMCTL_deassign_device: + case XEN_DOMCTL_get_device_group: + ret = iommu_do_domctl(op, d, u_domctl); + break; + default: ret = arch_do_domctl(op, d, u_domctl); break;