Message ID | 20240222021006.2279329-5-rick.p.edgecombe@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-75791-ouuuleilei=gmail.com@vger.kernel.org> 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 <ouuuleilei@gmail.com> (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 <ouuuleilei@gmail.com>; 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 <rick.p.edgecombe@intel.com> 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791563322598585860 X-GMAIL-MSGID: 1791563322598585860 |
Series |
Handle set_memory_XXcrypted() errors in hyperv
|
|
Commit Message
Edgecombe, Rick P
Feb. 22, 2024, 2:10 a.m. UTC
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" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
drivers/uio/uio_hv_generic.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Comments
From: Rick Edgecombe <rick.p.edgecombe@intel.com> Sent: Wednesday, February 21, 2024 6:10 PM > > On TDX it is possible for the untrusted host to cause Same comment about TDX vs. CoCo VM. > 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" <kys@microsoft.com> > Cc: Haiyang Zhang <haiyangz@microsoft.com> > Cc: Wei Liu <wei.liu@kernel.org> > Cc: Dexuan Cui <decui@microsoft.com> > Cc: linux-hyperv@vger.kernel.org > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> > --- > 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; > } > > -- > 2.34.1
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; }