Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp79736rdb; Wed, 21 Feb 2024 18:11:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+xRas284rldV0tk+rSj7Bfrli3CCkWOUrMti0cXs/AP0bin23jzaLdtvU2RYWUPux5h2dPrKZJBNHakLgmBmqAulovmLtv0ervQdaJg== X-Google-Smtp-Source: AGHT+IEWU1W4m71qeJJ/yvNZeLT1czQ1eBRH2j2j85C67750oSqn/5g3k46nnOp1Zi5YRk9vQ+FR X-Received: by 2002:a17:902:fc4b:b0:1db:be67:a932 with SMTP id me11-20020a170902fc4b00b001dbbe67a932mr19142329plb.36.1708567898201; Wed, 21 Feb 2024 18:11:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708567898; cv=pass; d=google.com; s=arc-20160816; b=CyZVZx+qIKYW/axrzA6E7lW3HZQO2wvbjRJpsbcedCRtyMGSM1JzaK2E+eIBdDJilr yGSemARoKeizQd/ZcSpFkFfDZHd9br/MtCsi6IJ+l1fV4k02v/BgP34duSKkkB7hrAQ5 nmGlBpMuTkIR//gawvTnFAKZMtd2di9hzg5tx56ZjUiT30XyUWQtmvCObG9+UmzLqtZI UTeKsLrD+/5qMYcfVRqm7XPS46Kyt7okK3CNHtSVKkfTGP1fhtJPLO9xwngT7y0JaCXn 5E2isDiP/mPEWrc8qTNiVZnSLEfEkgqTfrLKicTpxHHa/SP0Fd7pk+WUSbkdzbXFbN2s nj8A== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lm6-20020a170903298600b001dbf2d899c3si6517349plb.67.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:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75791-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1E334B22A13 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 4CB0918C1A; 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="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 Content-Transfer-Encoding: 8bit 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; } -- 2.34.1