Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp519836lql; Mon, 11 Mar 2024 09:17:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUS92L+vfHXWl+lGiF/2SLq1c5vgIyniJEny62W1KKXoo3FaBToV+F5QYiI7Uh2KgCJ8zEXx62wjJAocjZrrt/ZI4NP2d+oWw2Lc8oLMQ== X-Google-Smtp-Source: AGHT+IEmHGT3hDqrj/JbK3baK0qiqfJKuM5VIadTAW5v/ZThPnq45EExa2Gtr9rAU94Q8EPtbjyb X-Received: by 2002:a0c:f64c:0:b0:690:bde1:ab85 with SMTP id s12-20020a0cf64c000000b00690bde1ab85mr7339732qvm.50.1710173827958; Mon, 11 Mar 2024 09:17:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710173827; cv=pass; d=google.com; s=arc-20160816; b=AI4eq2DNLv3w1DD5SO2Jwq7LBqxgzv1Njt5DfCviwcATzag3Bxyk0g/E0Cc5/HbfMv /D2o7qE3wpi4rs4sPa6H4HllQaYWLxD8m+Qua89fxOFNbSPvrItNBKbm49ENdyNAkyYg +W5ct4Abn6M1INQTmAm4k1BuuPXAzEY7KPWAkchugLa69tJSGrwjM1+AyonO12xEtrJx FR5XeG8c7fI8lKRsWElVpYjd+tbyrpk7RGXEAq6/oFL18ecyTI/d1uSwa8s3Gzd66Zsv 6MrbekuLMhdsJsPZ9Y57ItUMwQHlj4gehfVYy65EgJHMcA/dXvG2iBBEHPhw5j7G4wRV Zm7A== 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:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4lQ8bQAzdsnyz/nAyILsXiibH//empkPkLI+o99v2ns=; fh=mnp7FeSpFT5EOOWoHYsin8/I5tFX4E2/1wULG8BA1B8=; b=zSjaKOQrVZ0hG8/L6KqCPNJDVgeMy6vH29MYpkK9pIm71do7oi8/TCJTvbxPviFQUN gM1KJghyltry34Old8dNmxWL2zAYi4wzUjLKqX6cdyLGhy5eSTqQzObLeKY9dYqxnHKs 9rjZ9Ptwmz9/eLFYzhK6L/XmGjpq90peF0T3jSrJMyLwRP3TQgqcTbJVDhFUgk51IfH4 Nxg201+jcIY/FevdNOxHNDgnzlBYd1YdR25js0pO3TXy5fmooit92+4vpQHIn+oH1XnA n2AvQ/LsOfDEJhn8V952vRPn+KEhVZHRx8ACaihpF4fNesVHvCMzsaZUW24YdTwluPhn 9luw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=j0n89fpa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99199-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jr6-20020a0562142a8600b0068cd9703420si5650568qvb.332.2024.03.11.09.17.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99199-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=j0n89fpa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99199-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 9BDBD1C20F84 for ; Mon, 11 Mar 2024 16:17:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F23FB4D9E4; Mon, 11 Mar 2024 16:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j0n89fpa" Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3D3481C7; Mon, 11 Mar 2024 16:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173789; cv=none; b=Up/nq0//LMDnVie89tKEkwNe5a3HSOF9bZTRIP+bE8PgsabTEMtGC03o2BtLLAPGPrTrB2H9I8Vj3+TN+k/j5F9lgVRfaocLB60u6gME0PjedZumNLGA2eBrd7GUV4HPENqVQl+mUx/YxNwk+Lu0lFQneLe+gwzYE8/ad9jO7bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173789; c=relaxed/simple; bh=KPYk9JxotgHUynNFnqxGdycQ5ugdp7osOeSdIU/c5rk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KXVCtImhD/1Y73UID6gjTjICbiW85IOyTC+Cm4BRWsKtGPYJzbmEOpYBCbcmQOUpiS1UaJdU/utWF9kEtgG1bCwlJJd2MrGkUIcgp9W13A5t1b9Ee31yu11/FgF7zKyjwsMtI05CGfJYnEQp39jUVWWAcRNc7S0c5NYtSJrZQio= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j0n89fpa; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5e42b4bbfa4so2229061a12.1; Mon, 11 Mar 2024 09:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710173787; x=1710778587; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=4lQ8bQAzdsnyz/nAyILsXiibH//empkPkLI+o99v2ns=; b=j0n89fpawCUkTF1j9vaA2GcxlhpifHRNHry1tcBxEF/Ldc+QWOVibLTodul1ku9mBg e/DWEOVGqVLBJbgBZB7oGsleUdtz4ksqzO7o9u+7SkHV9gejmDS9C0UYI/70aeUoVfoc 50qhMopsSnY2s7FOFZAwyj1qMCB8Owy6KiKAN6ifSQ59ulRdE6IAcimp40G4iVyIfcVq 07SWFY3hqz6XE6/7UxdmcQx8wlKRKe0fkeIzl5eFPp1nCJlVGmZElpKZTWjhsb1xl8Kb xFHTx6Am53awglu0p4Td6lJUmZRSZCw6icJ1B4GC/Vs+OArfPG2+erbaxFtUg8qGHKE1 5CiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710173787; x=1710778587; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4lQ8bQAzdsnyz/nAyILsXiibH//empkPkLI+o99v2ns=; b=dh88e5Q2BEnelVguANMSHxDBoFassfeMSXBfmzm/2Vy1QdSu2yPZaQxr+onMKMfJj1 XFhg278M62A9W1txb0lBjalhp9GNh6jazxEP26fasIhqIpQOMzGT2U73xoTO28t0br34 1E6gozBa2jlr+fLfFUKRLu6fDFIzQVCeO+fWwMsRO8Ge8MbPgITTRQPeIYNv1mJshCK+ U+qkDNpCISeCA1OyxIVRrmj/QisJR2PFkFSwL1v6RYX84wErSiIuEGkc6sQU8DfSigM2 CeLYayzbJXQxwGGxR5zQmSqLu+qG4GsrydlGcR256D6Orjn4+Bbm23x1Ez7ZEmXqmFvF pHHg== X-Forwarded-Encrypted: i=1; AJvYcCX7TRPAncKtbxK6zZRONRjVkSK6MOvd0E1SwNuG1XGVCgDexj6dTnuc2NKMQSiK97PAVdtKSehCJ+s3vK1Yfpgp6O55iPRJfborMokhd3snewuYkXaeUE3SxgNSYiujaV0c2jS8Xz9sgFsHuAH3cd/IlXPXtMD8M8ywc+wMWKtMmcV3 X-Gm-Message-State: AOJu0Yxaoz0Pdkfpe4p53H5muQdp/ZwECSTL4trhHGJp3FuachVnQmds yHPRzfqgcg+sPaNyeF6859XaUUrjNCkvNBfoyZdI4Kx+rrSSkOeg X-Received: by 2002:a05:6a20:d38c:b0:1a1:57f1:1a01 with SMTP id iq12-20020a056a20d38c00b001a157f11a01mr9184678pzb.42.1710173786938; Mon, 11 Mar 2024 09:16:26 -0700 (PDT) Received: from localhost.localdomain (c-73-254-87-52.hsd1.wa.comcast.net. [73.254.87.52]) by smtp.gmail.com with ESMTPSA id m22-20020a056a00081600b006e52ce4ee2fsm4576325pfk.20.2024.03.11.09.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:16:26 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: rick.p.edgecombe@intel.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, gregkh@linuxfoundation.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-coco@lists.linux.dev Cc: sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com Subject: [PATCH v2 2/5] Drivers: hv: vmbus: Track decrypted status in vmbus_gpadl Date: Mon, 11 Mar 2024 09:15:55 -0700 Message-Id: <20240311161558.1310-3-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240311161558.1310-1-mhklinux@outlook.com> References: <20240311161558.1310-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.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 From: Rick Edgecombe In CoCo VMs 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 callers 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 buffers. This will allow the callers to know if they should free or leak the pages. Signed-off-by: Rick Edgecombe Signed-off-by: Michael Kelley --- drivers/hv/channel.c | 25 +++++++++++++++++++++---- include/linux/hyperv.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 56f7e06c673e..bb5abdcda18f 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -472,9 +472,18 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1); ret = create_gpadl_header(type, kbuffer, size, send_offset, &msginfo); - if (ret) + if (ret) { + gpadl->decrypted = false; return ret; + } + /* + * Set the "decrypted" flag to true for the set_memory_decrypted() + * success case. In the failure case, the encryption state of the + * memory is unknown. Leave "decrypted" as true to ensure the + * memory will be leaked instead of going back on the free list. + */ + gpadl->decrypted = true; ret = set_memory_decrypted((unsigned long)kbuffer, PFN_UP(size)); if (ret) { @@ -563,9 +572,15 @@ 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() fails, the decrypted flag is + * left as true so the memory is leaked instead of being + * put back on the free list. + */ + if (!set_memory_encrypted((unsigned long)kbuffer, PFN_UP(size))) + gpadl->decrypted = false; + } return ret; } @@ -886,6 +901,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 { -- 2.25.1