From patchwork Thu Oct 12 22:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419857 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 5DD75CDB48A for ; Thu, 12 Oct 2023 22:09:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616065.957779 (Exim 4.92) (envelope-from ) id 1qr3s2-0001Av-BL; Thu, 12 Oct 2023 22:09:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616065.957779; Thu, 12 Oct 2023 22:09:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s2-0001Aa-5N; Thu, 12 Oct 2023 22:09:30 +0000 Received: by outflank-mailman (input) for mailman id 616065; Thu, 12 Oct 2023 22:09:28 +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 1qr3s0-00016s-H8 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:28 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ff93ab1f-694b-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:23 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml6008371; Thu, 12 Oct 2023 22:09:20 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:19 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:16 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:16 +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: ff93ab1f-694b-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwV1CL9F8uqYT/YStuDwHZR4YQ6G9v0Dnik/ojsBNLU9mVIK2fEMZ483/xJS3hcal3szhTlGRpxNZI9EtVzn+ToZPYQPw3GFpGOQgVT53PxGDT8x6vjgwolRNFsprEPHWEukTnU9V3nm8LC/U9zFzSYVRf9WFjxEU27qiol87OJ0Y45hX1zxuy7V34lAmf1u9A/tPHRdqMCHmAFL6mul298QT59EzXmaG9bUP3IyfcHdmhC86V0+TUwJvEJyOll1zlwqmnp4Lf2RshwDnoKryHBCpnkqJLDUCmYmtSmStzED/R1DP2bAjQaJlJWjCxhucW/oFn+/WZTzrrRlVNmwkA== 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=YQA/auCUyQ9aU8VntbUejZ+kWLEP5minC3jSAets2yA=; b=SAxexvi/1Qls45JhUuym0XSFO2xxGma+jxRhZTXRkDFsr/z88HelTDYgQ3SFiwumGRJ2yd3o/v4FP85+DN8QoMwS3MySH9VPN6e4+kJ6dSIVPkog1SFj1kO92yYfGTtPXf2dUrMoscHfPPZUB3/Xm+AMF8B6ExiqNBQ8ww9pg4btosVyz3R3YGqfY6BiSApdBgJ/Rh2qs1kqGRfwVFljeTfC8XNieKZGuS0QxWvfgb2RGuMFbPd4dDLLN0uiC2FJoh9hmN0F/xRCtP+KiGrnURKlZ6zRmwU47Y2dq3bph4GBPPj1cbAQPnecuxbZEcYL5bwvWE9cecxHBHXcd4nHxg== 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=YQA/auCUyQ9aU8VntbUejZ+kWLEP5minC3jSAets2yA=; b=jPyTj5dMXQxkSyCkShcE2yOwiiqiFDb/3SorteaR0KrCWWULvvzwnTdRmaBrRwwSDEYzy4GrQ3cVwU84xx++PJ91U2GD8x2U5xzTV/5O8CLlJomkRpqLRq4+BlwysYqkBE/MPJWGBT1cD7z9ItWLPhrJjf83Xe/MYDs5cLDEwOpx7f3S6oXcdTHf1VUZvDaie7wPYjLAIinTrpck1dMtyLG6EzhyM9cgW4G/8AigMZDbSVGAwtYcrRQSM/CuNb6rABNMTjfXgJE1BDAt/vP/XhkKuPy9181D7D4gO5HE9PVY/kTdodly0x7gUBQeZJ+8f+l6lVF6SXrjhqgR/TUYoQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?utf-8?q?Roger?= =?utf-8?q?_Pau_Monn=C3=A9?= Subject: [PATCH v10 04/17] vpci: restrict unhandled read/write operations for guests Thread-Topic: [PATCH v10 04/17] vpci: restrict unhandled read/write operations for guests Thread-Index: AQHZ/Vi9RFnVSEkUl0CU8ZWONnKP8w== Date: Thu, 12 Oct 2023 22:09:15 +0000 Message-ID: <20231012220854.2736994-5-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 0708c5ce-f72d-4f88-64bc-08dbcb6fdfed x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pCgljNsC/vH2LHKERU8YLBnRmE2rqcuFdfgJXxDu7qHVgk4fsnMHSIMySATppl/Kjs1xXSCHSRitKlkpeFGmEQUX4OnIZPYlDXLWikqDiur5snnt0K+LIlgZNfoIZsuViaDejuhoVncg9BkO7Kp+UzUB1MkJE/UkmW3+Bv9ol8yLWxuNU96pIptzeHPfr/Mts3X1OxJSUkeWIp47tk7BBARkzkQpL4qQ7huorTxXG4kMz7+tHLoTyzX+TQIItZwF/PkK/HE/8ZZSiJLgcqArZWl3OnyvsWBlvY+oQEWTqJwTPSTls7VT/ItXvexvM8rbrpzr2IsghqRWP0S3JAY+lLoRWJl6KM9H3nWf2/XKd6OezEyopduBZldQbtG+ocMlfMauZgD6IIH0AhXeK8IejrjnAQnUefcSYDMcIxGV2IyDUNy3bawJ0QipwXEDz/r9qqTUlIB3lETBLAdc0gTFgDoOyO2aMla9BotxfHoFh8sKdNY0Yujn2JYC3BwjKnHrBBNzkplgQi1HP8bfk9YLTjj6HZ/qQb/np/BC1Gbw6TDk0QFy0Jb6NZbCwYC9M6PRBZme1XZA6MhgTK/zcib6al56ALzuGSl9QvLA5FOs646OoPwFgNqoT9+KuVgcc+3v 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:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?L6fdlRkQ6Sd7ggrslMW5gpZS/T00?= =?utf-8?q?9QgZkWQi1O95Rk1fNGyBvjwTH+Tqo1Eg24uZbWQhoKemlR4dCBb+V31TJy7tQI6N5?= =?utf-8?q?WOeoXW/Cwb4DPGtU8VjMoCbgJ/S4y78wgoi3US2xgRp4zfGIWNcEghyU71YnWS4i1?= =?utf-8?q?jGJtQcHIm3MH9M6JgeU/u4QcMrN9ro3kjMcYYNqYuel9wx92J9GfszaDNhEGDZxcH?= =?utf-8?q?F5zg3MMSfWv+WqVI2EZ9kaYJ9rWahDWtQ8dqKpWlAHjJNCd4EDCwdqv/VVAsr05HG?= =?utf-8?q?/16VLR3g36QEKaWahrny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pd8wW2CjzMxSmPcNi8pdJ8mnMQVqFXFBaVZnQI5Zh?= =?utf-8?q?IwBK1yGSrc/XSYjrb1m/AjyjGdkztpbTBzx6nlLDxOuQtp9e7H7qztjdD0MLrz4U7?= =?utf-8?q?0FO3dnKSaar+DhaeIjCTGDwnJwrMpE5QNw9HTWzjhaqdZs1HMbpjItOzZJpkyqhyE?= =?utf-8?q?ANvkWwfBCk/8lC7X7XxRcxXUiBFCUuexXGjMwwFlMy0HgqkcJGnYSfmdaEFbYUgtb?= =?utf-8?q?eV++PGSl5aEELXg7B95Jlc+On1FqRtBkaU+kfllvHaZNi2PLniotE17AadLzuoVMU?= =?utf-8?q?Ih99/ua5eP+JuB4t9v6DdnmYQtVGbTWCVIvITpB/BaIOPoNfC2BPYxsZMQo3qr9Ae?= =?utf-8?q?Lf1mT8dM5V7RWue8fSubxnNy0iGt40QsJg=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: 0708c5ce-f72d-4f88-64bc-08dbcb6fdfed X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:15.7341 (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: MAeqH9VN3RfHTineyTIwTsWNdPI6IyB2e1jn3Nv8ierpvEOXIgIL1+TazPXWAapZQfWO4a5UirRii5eToyXaa/uzroym+EvnYS0fiHvhPHw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: o8iHpim3AG1REOvPtu8c6yw4aPgPdVM1 X-Proofpoint-ORIG-GUID: o8iHpim3AG1REOvPtu8c6yw4aPgPdVM1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 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 Reviewed-by: Roger Pau Monné --- Since v9: - removed stray formatting change - added Roger's R-b tag Since v6: - do not use is_hwdom parameter for vpci_{read|write}_hw and use current->domain internally - update commit message New in v6 --- xen/drivers/vpci/vpci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 112de56fb3..724987e981 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -233,6 +233,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: @@ -276,6 +280,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, 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: