From patchwork Tue Mar 14 20:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13175003 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 D4487C7618D for ; Tue, 14 Mar 2023 20:57:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.509830.786392 (Exim 4.92) (envelope-from ) id 1pcBhJ-0001PU-5E; Tue, 14 Mar 2023 20:56:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 509830.786392; Tue, 14 Mar 2023 20:56:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pcBhJ-0001PM-2K; Tue, 14 Mar 2023 20:56:41 +0000 Received: by outflank-mailman (input) for mailman id 509830; Tue, 14 Mar 2023 20:56:39 +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 1pcBhH-0001PG-JM for xen-devel@lists.xenproject.org; Tue, 14 Mar 2023 20:56:39 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b562f4ea-c2aa-11ed-87f5-c1b5be75604c; Tue, 14 Mar 2023 21:56:37 +0100 (CET) Received: from pps.filterd (m0174680.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32EKchDn017378; Tue, 14 Mar 2023 20:56:34 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3pb0520156-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Mar 2023 20:56:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by PAXPR03MB7967.eurprd03.prod.outlook.com (2603:10a6:102:21a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Tue, 14 Mar 2023 20:56:31 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::967e:573a:15a9:176e]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::967e:573a:15a9:176e%4]) with mapi id 15.20.6178.026; Tue, 14 Mar 2023 20:56:31 +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: b562f4ea-c2aa-11ed-87f5-c1b5be75604c ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IUk7j6c2OI3hgPhgnXSR0ytuaFnhExLrKuxPX0pyr6GLtxm//1XFkITbunUKMrghmNd/x0sMYMwg5vG/U2Ab5uV1KepFA9syX4KXNPHN6XOidsVDtoJlPUESNEIn2c7e60AIRlFuqwoXil59+xXotWKjiHfAi/ZS9P9pPZvgSqUe13Nv97Tnj0LkCIXVORB/7M1ab+psB0rvr3tzd3eP+ZT8kPLzh4NGcqzRBXnpkL5ucewt7eCbIqJKeGdfkm5I8X7FsAzWu4bZQiWp53c2KpoEm5e2rwGLGETI4gAyjzVK41ierqWIHvHAjPuwiXIRmN/ibtcjtDkDz43NsFOnHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Qbz49nUoSSct90DRuc5faIaPrcHn0RvfZzcOrFLGObg=; b=CO6abEhEfnvaEBoIH2hOrG9qsGF/TW+utOQvrpg4iBaeVRVFPvtBW/s2OX9J9EBdmeNEgWj8NC2EChtJPomFW8BSEoyT9egN5L/Ia7TtdCh6oUKlA2+l9qtRrwaaHRnEjquti8UJ7vkXVuq4uKq7/iL7vWqfbnrmdwVC0B+JGePbo1pICp/zTkOK83hHNJCDxbqITbwhYqfI29sxMKHcT1dRnvS11+ywK9hwQ+Ce4+eL+bTlaak0UBNyPF8ly1xpulEol4CYGVNeHVyW8TBAEMc8o/UmJHUqyKr3cbkrq4zef/G5FEp0yLM+ZNaUYeqEvbPLOtoq3BdtePri7rb8xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qbz49nUoSSct90DRuc5faIaPrcHn0RvfZzcOrFLGObg=; b=HOz9K0KP5kKC+l5/OL8LaS6lvVvP1CQ8eYfbCNvwB3xkTZPzS/k4DEAPhppjrYdO8SNGhpOVBfPKTux44kcYtdr29KPN/NPDXyGth00WM5XUT/avZE2kvOSlRbfkgIeccgsl39nG4qe+P8U/T1MRUItMt2PQFSiIyYZeamWGXW+3D480x98CjNLyYo6UINmu2JHr8fS3e0A7WAbUJTFBARF0a5abOW9Jgw2iS3rgi2K5kAGyV4PtAlc2YChy+4sA5TaYUTD35tofL+GfDIBHuGSLJnpWApWMYtb1CN6Wq5CEiCtLvlJjB3Ob1EdQhA1hCEhgL65G5MRopFBNJfiT7Q== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?utf-8?q?Ro?= =?utf-8?q?ger_Pau_Monn=C3=A9?= Subject: [PATCH v3 4/6] vpci: restrict unhandled read/write operations for guests Thread-Topic: [PATCH v3 4/6] vpci: restrict unhandled read/write operations for guests Thread-Index: AQHZVrdz9O2stZ5aY0OrZqeMa7i3ng== Date: Tue, 14 Mar 2023 20:56:30 +0000 Message-ID: <20230314205612.3703668-5-volodymyr_babchuk@epam.com> References: <20230314205612.3703668-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230314205612.3703668-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.39.2 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|PAXPR03MB7967:EE_ x-ms-office365-filtering-correlation-id: c2c75151-9880-435d-73ee-08db24ce96c8 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wa4gmeoamBJ7kZQJtyqzNdldYAYGXkuFnGB0JtMBdWWknGT18z9mZxt/TvA/wCc4+pOtaRExJnIkofE/uYoo+12Lp2R9nYGV0ZEVIYsLFCCVI7b15GpjOpExw1BX11sJSEatn2SudglpRb39ZOteCkhu2VCidDaMI/Yz/a9/FicfCOZP6WY5KiF4gBf3+chtS4gIuBjx8Fd8d0IgP/mVX0XVCOYuw9UbR76YCvz6I5eBPAL57zpUduQbNDg3CCvTIsGHRKK2UUYlRSa9WqMj15kB9VXJ3C1uzQjo/gMkRnq5CyAanMmRO8+CfTkcI3DwcyOpfgv57JIiWQOzgTRo7FzzJndd2JJM5okxrn0tA3ECsmo2XKAGYphhTvoO907IAkv9BUvqfanlC3Zuc2q/eukHhDbUDXgCgKcBNtjm7aeCf5udh/qkmcQsb1ZlM9r1rez9j0XxrxW+pgyeRUsrzR33Yh2wPQX0LAdOwwnFVaMCMURJerVOuMea71OFTnkqvChCduh5eFtZbOPmNEyeoN043fRW8glKQ+SFGnBv0mVw8YB69v9CkEBe5C/cyWizTL4KJNe1nOsQFBvDGTd5gsFjuhtbBKcPDWlj46ARbgaYZyWIBeoh3JlnZZN/cNqhv7qkev8HNvr8LHzgTqhL7p896G8alPlEG7car4eaHDFWnkQ9OcCnzAFv38tZzLQYmWy8Xlki51DpN7Ch8atzMQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(346002)(136003)(366004)(396003)(39860400002)(451199018)(54906003)(316002)(86362001)(36756003)(38070700005)(38100700002)(478600001)(122000001)(55236004)(83380400001)(6512007)(6506007)(2616005)(1076003)(186003)(26005)(5660300002)(6486002)(91956017)(41300700001)(6916009)(71200400001)(76116006)(64756008)(8936002)(8676002)(2906002)(66556008)(66476007)(66946007)(66446008)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?4TDx9YPjNLFLpEBZ1S4otq+RgnDD?= =?utf-8?q?UmcdrWlYfKCCe7UKkZlpczsf0QVBtmuQoGH8q0dQRBnZLeJ1hqLKVc36pzQV4P2TT?= =?utf-8?q?Z8ddNP5zBy7lTcYTZsJaHrfkG3WwOvN7OcIDcncRZ06IqIzF9f8JgZC0h8vZOSrFn?= =?utf-8?q?6gF+d7YXQCuQsS2bO/leWD6oTR0vW4HIdoMtgXbKJhyPmljBCLh0hNzXu+RqUiDz+?= =?utf-8?q?obA5RsD4a9lSVoaOWty9XpzdE7SLfq5feJjKZrPF8rJkSdqT68NFC4Tw9EtAUnSyd?= =?utf-8?q?w4T9m0tUYRLDwu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fvp1Vna9IkMA/P/WEbsL7VHa73W+dssHQ3PAEqOF64t0Lc0?= =?utf-8?q?sWKdgwaQpvhi76stq2QYs1cLQjCUnJk03SF1v2iGGcP6MYy4MHjT5Q7MwMv+rY7lh?= =?utf-8?q?dUDk6IDu+ZzBmCPcnCu2lizSoLhYkkoTsrmpnDP1eFgcUHqOU2WlmQpUgrc8rGKHz?= =?utf-8?q?G4tkK2Zkn5iL969NanhujK+/W0UhAwLKaQyfDXPnGsMU9dic6Ag69IA+Ebpsv0hCg?= =?utf-8?q?rBTZl5+n29UZ4B6CT3YRD9vYCTZocwd+rKK3AhEt9XU/imJ4NfnzjSiRxQIVIt6Go?= =?utf-8?q?GdYSv6VAFOm3iOT9dv3VssJtmnTNoZjsJ2JgENikykxb5f5BVdjy0AJZDb7t5/seS?= =?utf-8?q?OxIvug1bruwf8K77W+Hcy467E/GkOS3xuw=3D=3D?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2c75151-9880-435d-73ee-08db24ce96c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Mar 2023 20:56:30.3233 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BeVFOYNB++6ARqohR3O3rI9+aHy3QY0383f08DWTZgGCjG/QVv6mxEPV67ddYkN8Vnh+V67cigIFXCWt/61SbwN4ww8Na+sxMJbL4TgSNHo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR03MB7967 X-Proofpoint-ORIG-GUID: Aw_rLXq1YvBHF0Xoz0t-oX8wAnBrjMxz X-Proofpoint-GUID: Aw_rLXq1YvBHF0Xoz0t-oX8wAnBrjMxz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-14_14,2023-03-14_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 clxscore=1015 mlxscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303140168 From: Oleksandr Andrushchenko A guest would be able to read and write those registers which are not emulated and have no respective vPCI handlers, so it will be possible for it to access the hardware directly. In order to prevent a guest from reads and writes from/to the unhandled registers make sure only hardware domain can access the hardware directly and restrict guests from doing so. Suggested-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko --- v3: - No changes Older comments from another series: Since v6: - do not use is_hwdom parameter for vpci_{read|write}_hw and use current->domain internally - update commit message New in v6 Moved into another series --- xen/drivers/vpci/vpci.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 5232f9605b..199ff55672 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -220,6 +220,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, { uint32_t data; + /* Guest domains are not allowed to read real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return ~(uint32_t)0; + switch ( size ) { case 4: @@ -260,9 +264,13 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, return data; } -static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, - uint32_t data) +static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, + unsigned int size, uint32_t data) { + /* Guest domains are not allowed to write real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return; + switch ( size ) { case 4: