Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2619910lqt; Mon, 22 Apr 2024 17:03:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSyYZm+a8XYRUVw4dV2YwjXNG6sirbn/mViFzoUULlioK1Uce5ajm4hjPjZ2AmFNEMbiPJN6X1QchvfTBGQlxArVsvGTdlRYfYxiWgrg== X-Google-Smtp-Source: AGHT+IHQmMAKSsLNndM+4MFZFG15s86RmIUWC+6ePkYwvLWpQz6y9DDsWsR/Bt8FxZIsL6CBhSq0 X-Received: by 2002:a50:9548:0:b0:56e:2bf4:fe02 with SMTP id v8-20020a509548000000b0056e2bf4fe02mr10352579eda.11.1713830580350; Mon, 22 Apr 2024 17:03:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713830580; cv=pass; d=google.com; s=arc-20160816; b=BusmKq0i8NhmsheUqZUukbuFihdzmun956tBBMW03UqAVoktPJMi6QupCvLDfRG61Y oKiRy4FShIHVElbpQRnrDWrD+Oqqu6PoCqdk9bzjAPNBF1yDSPwLa6cCfokS+1fehThU 5Cpjgn/+rBcxkuYFWUAa7AXrsgIYGSfu82Qv4Oq4C+WOs2AZFhC3MsTT79JzJ4ck0M7H 04kAtjAZTocMqht32m9T1VhS6cv1AiXhd/YiesvrZXa2ghOuW7jWCANj41R6SaPRpcDd rMvJiHuTcFv93fjAYqDs0iHeGoZMW0vbmVljXEqZFd6o4i33iU4Nw4KulL1iFUnTcmz/ y3+g== 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=27CrlFmc84/EGg0cRBvk1/YVBwzhdrYs5X4J0r9Qank=; fh=n7WEoARNaf/Q+a4vtFlFPhJ4DJ9MigId2YX9kbDCQkE=; b=TY0Er88C1ZX/8r4odZ7OyLFQJ8/MVJOGpx/bmU1oYkdDXBODf4Rw4xqE/uPYi9cNra lTD0wS8ts53k916lsrKEt7hsvFLPYwjPxfo7tXx0ibj8atTt1Tba+Y0dlsfjeiRlJ9IE kpEhlyIEU2IxNTnY6nMpLxyM8jhctH6dAX/e1eZseGSnjtKJMEragXRqbAejr7SMmnt8 6peA2UszArBarSmd76sxeigJWKhIZVQ6pYzJieynthV4Arh5tfSYqhAhmPuutZO9sJgn oOky+OQm0fr7qJ2n2+eToONzTo3PbEmALnTczYLAO+iJQQd6uVk5TDbmGjodBp69a/pK 47uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OmenZkOd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i12-20020a05640242cc00b00571bc62d561si6767661edc.7.2024.04.22.17.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 17:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OmenZkOd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1A4381F21125 for ; Tue, 23 Apr 2024 00:03:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75F5C15DBAB; Mon, 22 Apr 2024 23:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OmenZkOd" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 931FD15D5C8; Mon, 22 Apr 2024 23:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830138; cv=none; b=s/PH9nrJspjnd1vN5+21PIoe/RRpaWZ78tRD4dbHrAp3c0r6EuhIZ4HZhp8S9AcUJcfkoWLffII7uPyYMmDGFTTO/A+inMfEpysXdXKfPJcUW5v0uidtCiQvedNgsFaYZnQQsJ7Za3VeI9lECNupkSBO7OzzD0BiJ8ZCYL8ePLo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830138; c=relaxed/simple; bh=dqQoY69A4VHgwPnhwclSyQBt2D3ST16MryARgm3ENbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hU52cP/bkvyPrDu4t+ZD6KisljEhfNBZR5es/Var/E5DD4KieCOE729rhscMHRkRqgcnkEi/ldyTYAtZNyXdxTnRyx2YhzCx2FpX8GoPht8/iRhgT3gnh4yoMLyMWUoAF41tDpwfj+UbI2dlqOigBV73d6HL4vpQ+6v+xwhV2eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OmenZkOd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0EB9C32786; Mon, 22 Apr 2024 23:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713830138; bh=dqQoY69A4VHgwPnhwclSyQBt2D3ST16MryARgm3ENbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OmenZkOd+v8gS4rAA1/x9ZtT1CLn9j99A/tRjFsXwSbkFfwasmwB8cTvfGNPDRER6 pzhi2XI1aCq29IhiQC2Q8nypAH5zQv0lsC6IKuDujin3tRI8Kj2AHWMRHFwZ7k26/L ZErL5rRifyVkBlRzUHGO2042d81aN0H44vaxjGhF7eBO9LQNqWGEtDmsRm5mL/V+j2 LfSQTWuUHGTTHz2Cw6DLGMaFwDbTv/vjDx12BpmKvVv/3r2FFq6jr8nAgqHfDmJmqh RgqMWzWNCzx0mXiGD8/VsteHOfr2yk7sQF8eG1Cbzj06x07np+TymKh/LOBP2DK4PF MsxW06uetv5xA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Kelley , Kuppuswamy Sathyanarayanan , "Kirill A . Shutemov" , Wei Liu , Sasha Levin , kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, linux-hyperv@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 39/43] Drivers: hv: vmbus: Don't free ring buffers that couldn't be re-encrypted Date: Mon, 22 Apr 2024 19:14:25 -0400 Message-ID: <20240422231521.1592991-39-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422231521.1592991-1-sashal@kernel.org> References: <20240422231521.1592991-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.7 Content-Transfer-Encoding: 8bit From: Michael Kelley [ Upstream commit 30d18df6567be09c1433e81993e35e3da573ac48 ] 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. The VMBus ring buffer code could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the struct vmbus_gpadl for the ring buffers to decide whether to free the memory. Signed-off-by: Michael Kelley Reviewed-by: Kuppuswamy Sathyanarayanan Acked-by: Kirill A. Shutemov Link: https://lore.kernel.org/r/20240311161558.1310-6-mhklinux@outlook.com Signed-off-by: Wei Liu Message-ID: <20240311161558.1310-6-mhklinux@outlook.com> Signed-off-by: Sasha Levin --- drivers/hv/channel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 98259b4925029..fb8cd8469328e 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -153,7 +153,9 @@ void vmbus_free_ring(struct vmbus_channel *channel) hv_ringbuffer_cleanup(&channel->inbound); if (channel->ringbuffer_page) { - __free_pages(channel->ringbuffer_page, + /* In a CoCo VM leak the memory if it didn't get re-encrypted */ + if (!channel->ringbuffer_gpadlhandle.decrypted) + __free_pages(channel->ringbuffer_page, get_order(channel->ringbuffer_pagecount << PAGE_SHIFT)); channel->ringbuffer_page = NULL; -- 2.43.0