From patchwork Thu Feb 22 02:10:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 204518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1419984dyc; Wed, 21 Feb 2024 18:11:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUKn3uE0HCtOHta3qDZSrPmyn0NM+tQcpN3LwiqjN7ewB+rMzJMxh1KVQ1fgcQmZAU3UNqElERwK6tU8JLltKC/ba8npQ== X-Google-Smtp-Source: AGHT+IH4avgPy3kcwrquQqKrYTxHPHCSutD8vQZ7ARdoZ1v2I+asTjLLPdK3H69T1GnYHAJeg2An X-Received: by 2002:a05:6a20:d70b:b0:19e:5683:e8d0 with SMTP id iz11-20020a056a20d70b00b0019e5683e8d0mr28114866pzb.12.1708567897307; Wed, 21 Feb 2024 18:11:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708567897; cv=pass; d=google.com; s=arc-20160816; b=L9nGF36av1CiLjQkxAKJtRYKa01hkYa+ziDvdgTuMDB4NSnLOy68hM2wGdm8Rl9cl7 a0UDKetO+d2jdAqyh09dWC/zqchcK7/gx82gCKEzjP3Ngp5udhKIqgNkbfrB7BexM0Za RpRzMKMBge8wzY3FnsQUryGh9WpidUcwtDU6pd+w9YMv50WmJzIT9wTOCUED0V2QlGy4 HufmoHwGK1XE9dbjMMPGQruG82B3UAhQl7tCqgDTrcu/gJREaqr0Pe1hH/0DiKczVIar w6VOCfWPdWY2u61a9694X6oyu4TNzL770dZVBtlojQ8m2YFUv3Cv1L0Vhl3/E7tOsCqJ 73Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1A6K7gJyUgb/XqbG7wxY5jixt4RTx15cutdnQRwzMKI=; fh=X9TPmIV9GEMYfi6LJ1MW90VgoxzHHuSuntmVoL+fRLI=; b=lgGleMfJTyQw59llaXGiDVI4ZOgzYu46oicQeki5YAS7Y9i9IGWrDS/+v2Nz+8yC3v IPvigqXf5jdZVidVar4lbqMdW1w+6wWcFLCL9W8fK6+vQJRGMmldlUvDh/aC631183Vq g9QvDb1yE3ZC8tIwBvw9LZ4OHwWGJ/dYz1poAVkhBKzaL+nuGNXTwHF0IUDBfmEzz5/D JAEpB2IBkJt8+/eaRtdmKKGbaSYWdWG+XY95yPHGy5jLR8ZSQIbvP+EJAxuygT9IYCIh ncxS+17MV3ZF/TvakwW+zOke34iAx15e4TUfRPTBQfQwbE9mBVSFDwANKrZ6ssGFwToc NVYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QreDpfsD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id kk7-20020a17090b4a0700b00297117e6a7bsi2604197pjb.176.2024.02.21.18.11.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 18:11:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QreDpfsD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 259892835CE for ; Thu, 22 Feb 2024 02:11:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 567F619452; Thu, 22 Feb 2024 02:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QreDpfsD" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 257DD14016; Thu, 22 Feb 2024 02:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567845; cv=none; b=AKRsZecWqv1X6eQIRKp3U5U9wQNjCCYW7n8w8GCaaJHTG5bB+AA8z21eykIETTI8HCpB1AJ6WZIxlA7MXag4bJZW1PDCsGSfznPch6tzHJXtrlcXEidmsbyQUlIFH+WrsDMVT+AIcvz4ZudyK9vighKGISeN5MtQqlV/m3a+OmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567845; c=relaxed/simple; bh=mjD62jwPXXL/iF50Sop2guy61uKievhhSBMu62CiiMY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aQw0937vKJNQgiFoM5hZoGivF7sORVDZbHcJJMoS4QR3iRPjXoj8gh2/yH3GihYQxUqoqmtFrUR7jBmRE0nVfuJx3sztRH37g0HThV+NT7h5l/agJkHeWsEGGq5XCIaTbPgTW3IXifVt2hFzdt8oAQck3YSdS8A1KPYtdrUtydc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QreDpfsD; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708567844; x=1740103844; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mjD62jwPXXL/iF50Sop2guy61uKievhhSBMu62CiiMY=; b=QreDpfsDU7aLykDX1qtFMC1mLz+YR0iu1wJNDpw6aBeQp8x9MyqiBHBI vSttIIJMrPgBJ3xVJ9ldh2kWSBN5HrevIIcu39tU4+eJqxNwHwo70LyN2 ETRapGt0MuGBvew3u0W3XFz+fZI8ck8xXnfpnqjHuS/wmYw8Tp2fLW2f3 r+3ot0eJmzBxUVF+ZJpDHBETyzj+S9kzZ55BIag98j7ntRR7x4Mbj+A3i 9WoFQ9cE1rMXA0RKz3sqsr6xKf5i6UsAMKRLR60IwxRzwZ1IdYSqWUIWM uaWnv5r5lMVum1xNPACzpN9QMnSe8AXbT0b4/Pkr8M6Ryt4VEOPUDb1En Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2641015" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2641015" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5226886" Received: from nlokaya-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.209.62.65]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:41 -0800 From: Rick Edgecombe To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, mhklinux@outlook.com, linux-hyperv@vger.kernel.org, gregkh@linuxfoundation.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com, rick.p.edgecombe@intel.com Subject: [RFC RFT PATCH 1/4] hv: Leak pages if set_memory_encrypted() fails Date: Wed, 21 Feb 2024 18:10:03 -0800 Message-Id: <20240222021006.2279329-2-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> References: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791563291596067162 X-GMAIL-MSGID: 1791563291596067162 On TDX it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. Hyperv could free decrypted/shared pages if set_memory_encrypted() fails. Leak the pages if this happens. Only compile tested. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Wei Liu Cc: Dexuan Cui Cc: linux-hyperv@vger.kernel.org Signed-off-by: Rick Edgecombe --- drivers/hv/connection.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 3cabeeabb1ca..e39493421bbb 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -315,6 +315,7 @@ int vmbus_connect(void) void vmbus_disconnect(void) { + int ret; /* * First send the unload request to the host. */ @@ -337,11 +338,13 @@ void vmbus_disconnect(void) vmbus_connection.int_page = NULL; } - set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1); - set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1); + ret = set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1); + ret |= set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1); - hv_free_hyperv_page(vmbus_connection.monitor_pages[0]); - hv_free_hyperv_page(vmbus_connection.monitor_pages[1]); + if (!ret) { + hv_free_hyperv_page(vmbus_connection.monitor_pages[0]); + hv_free_hyperv_page(vmbus_connection.monitor_pages[1]); + } vmbus_connection.monitor_pages[0] = NULL; vmbus_connection.monitor_pages[1] = NULL; } From patchwork Thu Feb 22 02:10:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 204521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1420195dyc; Wed, 21 Feb 2024 18:12:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVs/25cZ0mz3zeAWkejX+UD9cvtEezAH5bTG/TgDhtFLfrExY+l4ORH1y6QoHEE5piz+uzkwdkn/xaBEh8ULA+SWrhYKw== X-Google-Smtp-Source: AGHT+IHJx0/aPX2iXR73t70Vabglz0Tgm1T4V0sM4ev2cWGOZ+SBcyHQZurKr7zRWqxc3bJJnX/7 X-Received: by 2002:a17:902:bb17:b0:1db:c6a0:288b with SMTP id im23-20020a170902bb1700b001dbc6a0288bmr12002463plb.7.1708567930937; Wed, 21 Feb 2024 18:12:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708567930; cv=pass; d=google.com; s=arc-20160816; b=HhoGFJfxdanthNcBcmowF2605Kc0SLzwo41UJGnR4KUx+Ws8I3TOTTERDv/i4dlTFl 8W2s15kPvkYyjHeYc/03IV5pnPWJvCdPFWR0Zd7GkvHTpIVq8t0i5VyGthZlo2HE4sV1 180LWOn80+f1v44YwipH2FCkV7xe6CX5VmvOnLEXBz5cMiR2xcUl96j76+lYzVs4mYxL 39Q44W4qn/7htTplVOjkCdYGDD49iRWyMpUGB6Ysvs0ZMSNKuIgbNEFOSxDz5+98X/MM 6ZfdnzIPDzX8Gn6/fndrlLr6WPS0mKbmdtRHRNg/o7kz/PnKPOh4beXITHP1s3JKqliC 4h9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8i67SZ82uRwMR4vw2Ei4PQbJHfZHeilWUZ8X+V+EBk8=; fh=X9TPmIV9GEMYfi6LJ1MW90VgoxzHHuSuntmVoL+fRLI=; b=AZtOrdNl34G1GynRktKOOVKg+I8hPcLU2FHSDMNcP/PdhkVtGvXpQd7C7fU7g6LQ0n ecSuaVlV+3KXxvt5WuGNHBm8BxPf9A3Mg8o+LUNeaH57Xy9CUZ5sYj5zBOLIhe3FZW4c JHhNugGKcQ06do3jEPabun3JB1gWX5dZt7bHYeZSIe0NxNpIwUKw31cjEO8/iRqVa6Mi 8czrrXtYC8SaKkwh/TqhogM+nXJbRIsjYfkhz+4VraWVuHzNrXioB3WsZee2xiqZ49ms /ieBbngy19nu+zg7qWfVaoc/YAxq1L/u5ZWI8R5/JM9VEmMnpbRyxi1o9ozFre+omBB8 f7+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dNEk7N55; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75793-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75793-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jb19-20020a170903259300b001db9dda28f3si8957873plb.468.2024.02.21.18.12.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 18:12:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75793-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dNEk7N55; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75793-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75793-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BDEBD283603 for ; Thu, 22 Feb 2024 02:12:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 727EF1F92C; Thu, 22 Feb 2024 02:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dNEk7N55" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 012431428E; Thu, 22 Feb 2024 02:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; cv=none; b=aY/UmYHlR8bucPj1XnyRclv8N3zxLAb4L1WKQCJ2WVkHuqs6mtWK/NaL1P7pMc3VbdPm+3jBjjoydBQ9Hp30lU0dFutU1ugsYFzlT984ZssMfbzWIT41rceyQALKKRmMX/iBUtAcBPFl0OVdZ7J2wW8Y+UzUJAoaaYkTINqkcrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; c=relaxed/simple; bh=UD5rk9PLkBp1RIi0KMC4OnruwWQq2DUII52if4k3oos=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VpBayZZe3lB+1GJ3cw94tKQ7xisuPPuI5WuFJf1JwJJnAkKc4ZDOTcdtO1pBVyWvOHxp7vj14mGe7K3+4X0f8i63MrzIBRk78dPAmkzpYYB2C+NXwOy9AxdBkCUf4SXIJyU0icUfqbdPZPc3rtMWvjfJyNtERYKZHOiHMI/ADi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dNEk7N55; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708567845; x=1740103845; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UD5rk9PLkBp1RIi0KMC4OnruwWQq2DUII52if4k3oos=; b=dNEk7N55EznqGAthKQ1OxXCUixVolAdw/wTxneFyeVtS264sSbR2dXZZ AqUZxv8pqhxrC2WwjfJvw/N01TpuqTyga3+utRkn7mV8HH4YNFWxGjlZm YZKZxHfI95Sr7ZA7mKFbUV1yL95Ms+GDSRLFYIHXoHQdExE2X7sShm1Ns JMGCYOF9CN/ZYcXbtblROLyurAm3aXFMsJQbDEanYt7A6uFkstjr837xw mPq/Xd7WjVtRFYfJWtEua1TOZE88wjL6eX96JAOpHN+yBJk49bJpJZc+Q ZwA591dGSEpbwpECAai9Vjt5Ll3g7Ot3f3hpg93P/OK8c2s0+uwfPjnIq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2641026" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2641026" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5226890" Received: from nlokaya-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.209.62.65]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:42 -0800 From: Rick Edgecombe To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, mhklinux@outlook.com, linux-hyperv@vger.kernel.org, gregkh@linuxfoundation.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com, rick.p.edgecombe@intel.com Subject: [RFC RFT PATCH 2/4] hv: Track decrypted status in vmbus_gpadl Date: Wed, 21 Feb 2024 18:10:04 -0800 Message-Id: <20240222021006.2279329-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> References: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791563326722819763 X-GMAIL-MSGID: 1791563326722819763 On TDX it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. In order to make sure caller's of vmbus_establish_gpadl() and vmbus_teardown_gpadl() don't return decrypted/shared pages to allocators, add a field in struct vmbus_gpadl to keep track of the decryption status of the buffer's. This will allow the callers to know if they should free or leak the pages. Only compile tested. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Wei Liu Cc: Dexuan Cui Cc: linux-hyperv@vger.kernel.org Signed-off-by: Rick Edgecombe --- drivers/hv/channel.c | 11 ++++++++--- include/linux/hyperv.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 56f7e06c673e..fe5d2f505a39 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -478,6 +478,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, ret = set_memory_decrypted((unsigned long)kbuffer, PFN_UP(size)); if (ret) { + gpadl->decrypted = false; dev_warn(&channel->device_obj->device, "Failed to set host visibility for new GPADL %d.\n", ret); @@ -550,6 +551,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, gpadl->gpadl_handle = gpadlmsg->gpadl; gpadl->buffer = kbuffer; gpadl->size = size; + gpadl->decrypted = true; cleanup: @@ -563,9 +565,10 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, kfree(msginfo); - if (ret) - set_memory_encrypted((unsigned long)kbuffer, - PFN_UP(size)); + if (ret) { + if (set_memory_encrypted((unsigned long)kbuffer, PFN_UP(size))) + gpadl->decrypted = false; + } return ret; } @@ -886,6 +889,8 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, struct vmbus_gpadl *gpad if (ret) pr_warn("Fail to set mem host visibility in GPADL teardown %d.\n", ret); + gpadl->decrypted = ret; + return ret; } EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 2b00faf98017..5bac136c268c 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -812,6 +812,7 @@ struct vmbus_gpadl { u32 gpadl_handle; u32 size; void *buffer; + bool decrypted; }; struct vmbus_channel { From patchwork Thu Feb 22 02:10:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 204520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1420181dyc; Wed, 21 Feb 2024 18:12:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX8s+3f2XASF8JSDhjNej7+qiXjYqgwY8+dWmXanY85NFAPst6HoMOHVi1xcOo/MmdwTwX19Nsf2IMQ+k1QS4o8SiHdHw== X-Google-Smtp-Source: AGHT+IFrduQFbpxuznLzT+iaDLHyvicmO/l639Ie+aXsCFmB+t2BbyCLFQybXN9emL/UPd2nYp68 X-Received: by 2002:a05:622a:447:b0:42c:7c5d:8fac with SMTP id o7-20020a05622a044700b0042c7c5d8facmr26389053qtx.67.1708567929049; Wed, 21 Feb 2024 18:12:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708567929; cv=pass; d=google.com; s=arc-20160816; b=wVPqzvukk/8wTQM2zrRjSnDcTGhRD/l9jtYBJPD1s49iQsZvraFuGXx4XP6dvc7s4j 84v81VAK48xm3fTidBD/anYvpKJGRK2mtvLQaZ8I0s5XnFbbPmdIuR+i5yeqcxOxQ/Oh sqa8mB9LTdSmRd7lQm5y8BmIzXYNEPsbVtNpUvcqR8vqrcUz/BiDtoStXJh4a1ibk3z/ /E9Kg/UupjuoriLa/tmOZd2ZGQeuNdWYQpe80xDEhcacsDLZzV42iq/l1CW2TcaaXJ/k vipaYMTAdNKAVSxXDsL5+vBCptIFUFUlSrXUMNabpH0nE1aOIERWebqmoNFCu/B0jiE6 zWLA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xNBweHMh+3ZF484Nd/OCY3Wi4saUmQvEY2WQsEvod2M=; fh=X9TPmIV9GEMYfi6LJ1MW90VgoxzHHuSuntmVoL+fRLI=; b=seC7ZRT4Ifuy6+FizIx5fS923hu+d/No44MvP6cV9CVXfn8/x1vtaKWVjiisqfsCAX ncjpoMxnB5OJF8O/Ba6zFwkAn5yNu99tttVXQk3qMTagWucHC/l/3lCMuD8nvaVQy6TT AY6TqlIglcceZOWLUFZDN47zxrANHvUbD9siIE3ihAvk9dErnBu7iWMW+FHFqvk2zm5X fsKJv2POhGlMwkZVtiySf+NHSfIe7vvjLeNTeGhQKalU5Bpu1ZwmqpismK3nGc1XayIB JJsw9NNaufjiR9BBltAroBo7eei+2ROerl9ZXOD0PrtV9ALmjyMnqYs6hweUr9Wi7hPx dpxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="T/xjGkef"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75792-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m17-20020a05622a055100b0042d7adcdc22si12945661qtx.651.2024.02.21.18.12.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 18:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="T/xjGkef"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75792-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D34D61C220A0 for ; Thu, 22 Feb 2024 02:12:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DBD91EB5C; Thu, 22 Feb 2024 02:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="T/xjGkef" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BA3514A96; Thu, 22 Feb 2024 02:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; cv=none; b=Gs+zTrQzWMFsPEURP2Z1nojmutr3vtzBe5SHWFRpw+fi+TLxN3JNGMaHUCOzDxO1YRbi9+FWGZSRC1//7erTgOKh4Qv406M64Q0FrWRYQeMc/SDtf7uBRrDb+Vv3DYcW3ghkKz725R6DMBXcW5va3Lo6P6cSKAT0kjNZLdoOzi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; c=relaxed/simple; bh=8XkLUNnnlS6h4MhP9sFztYAow339/JGLs2qnxvPxDGk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S0hKdVG+CxQ/64TEYVtDiBt9YLmtnsH1wBZJRtnTTiccuip4ALsEwzCF62+PXWxkWbKw2o9qE4iDDxPa10lMI9UZd6ZeHtPoQ0fhy8iNxWoTqmjT3s4jQ+yHfaGDgKhbL4Ef6RrKFapdjx3nzmRgZbLP7P2NOp06d0uSyzJfZt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=T/xjGkef; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708567846; x=1740103846; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8XkLUNnnlS6h4MhP9sFztYAow339/JGLs2qnxvPxDGk=; b=T/xjGkef1PZh7rc1gJpvbYkGcHDFto9w7zc8ugyH65oQWUyeSepB968l 1h90SPNv12YUfQv4BecEkz4ypZO0IV2kkErZLQK0S4raCdnIuizAZAZjW SIAwaae0FydEuXTsDc21dGabOJf/OIAbQddrS5WUN0xkajW4nCuDlqdWS N2uS68+Nm8KbIexCVu7QkfE8GPB5jFELqwCUL7a5DGKeFRg3bXXAo0qIc 83jiXRTAM9UqicJ2gseLqDOu9oIryzgPubvTAKlijJlH6gJSiX1FQpWtV h9x+z+dctEpwiXJDCmcDwIaVrTWAbffoUULixDpo0H8Pxe4Htc9Yc6gzy Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2641036" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2641036" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5226895" Received: from nlokaya-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.209.62.65]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:43 -0800 From: Rick Edgecombe To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, mhklinux@outlook.com, linux-hyperv@vger.kernel.org, gregkh@linuxfoundation.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com, rick.p.edgecombe@intel.com Subject: [RFC RFT PATCH 3/4] hv_nstvsc: Don't free decrypted memory Date: Wed, 21 Feb 2024 18:10:05 -0800 Message-Id: <20240222021006.2279329-4-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> References: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791563325023256306 X-GMAIL-MSGID: 1791563325023256306 On TDX it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. hv_nstvsc could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the gpadl before freeing in order to not leak the memory. Only compile tested. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Wei Liu Cc: Dexuan Cui Cc: linux-hyperv@vger.kernel.org Signed-off-by: Rick Edgecombe --- drivers/net/hyperv/netvsc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index a6fcbda64ecc..2b6ec979a62f 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -154,8 +154,11 @@ static void free_netvsc_device(struct rcu_head *head) int i; kfree(nvdev->extension); - vfree(nvdev->recv_buf); - vfree(nvdev->send_buf); + + if (!nvdev->recv_buf_gpadl_handle.decrypted) + vfree(nvdev->recv_buf); + if (!nvdev->send_buf_gpadl_handle.decrypted) + vfree(nvdev->send_buf); bitmap_free(nvdev->send_section_map); for (i = 0; i < VRSS_CHANNEL_MAX; i++) { From patchwork Thu Feb 22 02:10:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 204519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1420169dyc; Wed, 21 Feb 2024 18:12:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVCC4P4g9I3aQ/WOQWOZyKHkPdrzJo5J5I4Y6mlle99Di9hG3tP4fFjqA/a1iCL+f9mT2acO2sNLc6kgN6q1IpET/jCuQ== X-Google-Smtp-Source: AGHT+IENyMkEpI9XsClu6rQtPTZg7Kwq7XQoTjuD/aoZ4cQ4nJZQLpTv0RwzNj084D0pVjC5ifL6 X-Received: by 2002:a05:6214:2681:b0:68f:9051:5879 with SMTP id gm1-20020a056214268100b0068f90515879mr8940923qvb.21.1708567926815; Wed, 21 Feb 2024 18:12:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708567926; cv=pass; d=google.com; s=arc-20160816; b=vKh+l/OSeNJs5jPTsQiDg/gNugYsY/Xmv2NHkV5KO0DlLv6TNmw4CCCBkXBPWGnmOx vvMj7LvoL5uvdB+MrlNPZ/VP3xxiQGWDmvaTK/4MVnuITCKMvIdsHSnZRv6oSdcAMM9Z 5G32OEibIOkw1EoGRgecYhgtVfTbO+TP4TDEgJKwM7AVTKbUvvAnirwURv2vCmglCGw1 /NK57Q6iurVHf3SMF0TWZXvPnX4x6Zrbp+C2lLXQXfzSbNXl9SAt+Nu/6dQcEmP5nLw0 3+i6BBgY8QT29eINO1dFdaJOSCDbYWcZqD68tascm+t6uTKYR0e08YxlrWH7BGWRMmT8 qu4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cQn22U+CaFNzglZA9drV6DWVhDvn+L3lzTGWP/p2/NY=; fh=X9TPmIV9GEMYfi6LJ1MW90VgoxzHHuSuntmVoL+fRLI=; b=axnD0Fyf+gDWVf5kow/S/RFg9dy07LkJT92ofYtGcYOz8VWUvw0AWnfmzpACeOxIJu ag3ETtjkAsmKcDF+H7uQJM2P0fLBr/G8PCiU/ss8N7dR1k3p5F2h6VAr1agf4RLlWSYC 0/F8EXkFpkFJIeEq9VZnlTJC7Yq9ZuM2Esn5X2W55kUbBoA8kW0eUGeyf8D50vadXW3X xd/BPB9h5KlxtEW0+B8HufJkXJcoJ9/jZhXIdTLz2Ri0kNcO/NI++ZWmwSnU09uHng1a m1vh3c+AtWumV2PfP2Rn7TcZ15a1QQAh6/9fMdKpPaVHJvEwT6Fo37xQPTNP5vFlZAJS mKMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BD4RFCGl; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gm7-20020a056214268700b0068f29e8bd48si12107124qvb.87.2024.02.21.18.12.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 18:12:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BD4RFCGl; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 992061C222D6 for ; Thu, 22 Feb 2024 02:12:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 145561DFF7; Thu, 22 Feb 2024 02:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BD4RFCGl" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF13B17553; Thu, 22 Feb 2024 02:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; cv=none; b=CrlUKcN1bp074DjRC05FUCER+ox5celqsWeGqt23Fuve2OCKag6AEN2B3FAr2kjVjaquSTZVGK8yANixbs+P1UOUSPkLLcxXMUqpdEDlf5suA2RPFIXYEt+BFWgo3k+EhJiItS5gZH2Gj17AnbavAj99AISgE6I8tZYYTYrnDjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708567847; c=relaxed/simple; bh=acK3P8RbFbLJ3Y/qsHvg8A7W0ea+PDycu9fLk45ERVg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X8HXA930bbRrK9bNNIjWzg52F7qsfoDD6Wy9WEuNvW+aTHQVi+i2fYC2+io0X5uPqUgtKHAZqt5tsUiBlS+wDJvyxsGCBNhFNp7k5agp9ng5xK7bMBG5E/J4oT/Leg3jT7pw6+kvpub8Ol3dMOwoU/An4hrrAp+IIfgeEiH6i1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BD4RFCGl; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708567846; x=1740103846; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=acK3P8RbFbLJ3Y/qsHvg8A7W0ea+PDycu9fLk45ERVg=; b=BD4RFCGla90w0SBxFBGeu/zVKE5UMnxApkUTGW9fvTLKwtaGdJUReqvg cXziHb3Dldz/oydNujTpkzJjxy1A2kvARb75u49jG8JshKLD3+FonqpKL 9ZMr63N6bbf6KSt4tS6cef19BoTwQfYgw0mTZ4a8yUpIwZhzNAqDouzEa HaOzhx3wuAVGc1IFmqgzqf4Zgh9/NNb1bpnpoILpS7EZmzrgkVOYPB6DE lNpoZVODRtLL9VZdvn3mCO1f9Cv+AkdR5FXXCyH9evvSEoe1pslC3xB3N xVRBmYAO+VULsr45y1nIZBN9pvHwCvSjvvDyN30gsw4niRNdfwN58tEv8 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2641045" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2641045" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5226902" Received: from nlokaya-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.209.62.65]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 18:10:44 -0800 From: Rick Edgecombe To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, mhklinux@outlook.com, linux-hyperv@vger.kernel.org, gregkh@linuxfoundation.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com, rick.p.edgecombe@intel.com Subject: [RFC RFT PATCH 4/4] uio_hv_generic: Don't free decrypted memory Date: Wed, 21 Feb 2024 18:10:06 -0800 Message-Id: <20240222021006.2279329-5-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> References: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791563322598585860 X-GMAIL-MSGID: 1791563322598585860 On TDX it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. uio_hv_generic could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the gpadl before freeing in order to not leak the memory. Only compile tested. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Wei Liu Cc: Dexuan Cui Cc: linux-hyperv@vger.kernel.org Signed-off-by: Rick Edgecombe --- drivers/uio/uio_hv_generic.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 20d9762331bd..6be3462b109f 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -181,12 +181,14 @@ hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) { if (pdata->send_gpadl.gpadl_handle) { vmbus_teardown_gpadl(dev->channel, &pdata->send_gpadl); - vfree(pdata->send_buf); + if (!pdata->send_gpadl.decrypted) + vfree(pdata->send_buf); } if (pdata->recv_gpadl.gpadl_handle) { vmbus_teardown_gpadl(dev->channel, &pdata->recv_gpadl); - vfree(pdata->recv_buf); + if (!pdata->recv_gpadl.decrypted) + vfree(pdata->recv_buf); } } @@ -295,7 +297,8 @@ hv_uio_probe(struct hv_device *dev, ret = vmbus_establish_gpadl(channel, pdata->recv_buf, RECV_BUFFER_SIZE, &pdata->recv_gpadl); if (ret) { - vfree(pdata->recv_buf); + if (!pdata->recv_gpadl.decrypted) + vfree(pdata->recv_buf); goto fail_close; } @@ -317,7 +320,8 @@ hv_uio_probe(struct hv_device *dev, ret = vmbus_establish_gpadl(channel, pdata->send_buf, SEND_BUFFER_SIZE, &pdata->send_gpadl); if (ret) { - vfree(pdata->send_buf); + if (!pdata->send_gpadl.decrypted) + vfree(pdata->send_buf); goto fail_close; }