From nobody Fri May 17 03:54:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1662728054; cv=none; d=zohomail.com; s=zohoarc; b=Q+oKKMZxAKshasiRsDRtOpQCrzM5o+jWEDl+O6g+btlFcR/nNAFiq9LYB5Oj+/KFTgISZp15VHy5OvzQaTgg8gQrI1LExgqS+ddZ2HFMUGLnL2DS+X6/xX6mM+ellsbAbV4d+gwn2H4qIuxdLFHZlDhzfhiujh2EBUu3g1CGyhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662728054; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Ywj87vOwTKhT5iZ677cNQ2Fr/sHl0+j5C9vmNgewlYk=; b=WTB27WaBUVHrNfaGIKHdFYfYXP62vwxP37PcDVzZsTfnRtkRTQ4nZhmec5nyyvaTDU5VsF3mlEsi3TJRDA1lgdhJewdfimstjxKf+EkFjTtxzJLtHhGfMQx+8p99vBs47dZdXlGK+TRjZMmGUTnVdA8Vb8wYLhnKL1zLyQKdgUY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1662728054434649.6407184248384; Fri, 9 Sep 2022 05:54:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.404308.646736 (Exim 4.92) (envelope-from ) id 1oWdW4-0006ve-7M; Fri, 09 Sep 2022 12:53:52 +0000 Received: by outflank-mailman (output) from mailman id 404308.646736; Fri, 09 Sep 2022 12:53:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWdW4-0006vX-4W; Fri, 09 Sep 2022 12:53:52 +0000 Received: by outflank-mailman (input) for mailman id 404308; Fri, 09 Sep 2022 12:53:50 +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 1oWdW2-0006vQ-HY for xen-devel@lists.xenproject.org; Fri, 09 Sep 2022 12:53:50 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 72c9561b-303e-11ed-a31c-8f8a9ae3403f; Fri, 09 Sep 2022 14:53:49 +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 AE5EA1F8DA; Fri, 9 Sep 2022 12:53:48 +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 670FA139D5; Fri, 9 Sep 2022 12:53:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id D6rjF1w3G2PVNQAAMHmgww (envelope-from ); Fri, 09 Sep 2022 12:53:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 72c9561b-303e-11ed-a31c-8f8a9ae3403f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1662728028; 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; bh=Ywj87vOwTKhT5iZ677cNQ2Fr/sHl0+j5C9vmNgewlYk=; b=VUeiWhP8lEn+qG5qfDVDxma3RCTLiKgJ46VzrYNT1RczaXbLHtPRwlcsvPFML7xYKeUUWd T/fGb42kZC5pMy9LRB3x6+q8J0CbWwvmEHaTMqLYdS1lU+96UEeIntlXfd94lm70UIiPux DEhPe+23x6CMjXxu4W6xp0WFUKNXSQ4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Henry.Wang@arm.com, Juergen Gross , Wei Liu , Anthony PERARD , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3] xen/gnttab: fix gnttab_acquire_resource() Date: Fri, 9 Sep 2022 14:53:47 +0200 Message-Id: <20220909125347.25734-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1662728055929100001 Content-Type: text/plain; charset="utf-8" Commit 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddrs can legitimately be NULL in case XENMEM_resource_grant_table_id_status was specified for a grant table v1. This would result in crashes in debug builds due to ASSERT_UNREACHABLE() triggering. Check vaddrs only to be NULL in the rc =3D=3D 0 case. Expand the tests in tools/tests/resource to verify that using XENMEM_resource_grant_table_id_status on a V1 grant table will result in EINVAL. Fixes: 9dc46386d89d ("gnttab: work around "may be used uninitialized" warni= ng") Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich # xen Release-acked-by: Henry Wang --- V2: - rework (Jan Beulich, Julien Grall) V3: - added test support (Andrew Cooper) --- tools/tests/resource/test-resource.c | 11 +++++++++++ xen/common/grant_table.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/te= st-resource.c index 189353ebcb..71a81f207e 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -106,6 +106,17 @@ static void test_gnttab(uint32_t domid, unsigned int n= r_frames, if ( rc ) return fail(" Fail: Unmap grant table %d - %s\n", errno, strerror(errno)); + + /* Verify that the attempt to map the status frames is failing for V1.= */ + res =3D xenforeignmemory_map_resource( + fh, domid, XENMEM_resource_grant_table, + XENMEM_resource_grant_table_id_status, 0, 1, + (void **)&gnttab, PROT_READ | PROT_WRITE, 0); + if ( res || errno !=3D EINVAL ) + fail(" Fail: Map status not failing with EINVAL %d - %s\n", + res ? 0 : errno, res ? "no error" : strerror(errno)); + if ( res ) + xenforeignmemory_unmap_resource(fh, res); } =20 static void test_domain_configurations(void) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index ad773a6996..fba329dcc2 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4140,7 +4140,7 @@ int gnttab_acquire_resource( * on non-error paths, and hence it needs setting to NULL at the top o= f the * function. Leave some runtime safety. */ - if ( !vaddrs ) + if ( !rc && !vaddrs ) { ASSERT_UNREACHABLE(); rc =3D -ENODATA; --=20 2.35.3