Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp172667lqg; Fri, 1 Mar 2024 01:28:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8ExM0P6C12HuKomsYsX5ss5VdCjsE1swi6SKGmjNiwvuMYGvdpJiiY5mkWVAkrBzCDlDiRzOFp8r2yOPYhtb4cgV6VjyUPFGVkkD3KQ== X-Google-Smtp-Source: AGHT+IG0nVukRcHuqi/MPwkZRKCcobKgwcevnW3FpzeF5UgC68q6N3ofdSHf3k1OGE6OtRPDxrLi X-Received: by 2002:a17:902:c106:b0:1dc:af71:4d46 with SMTP id 6-20020a170902c10600b001dcaf714d46mr898671pli.13.1709285292062; Fri, 01 Mar 2024 01:28:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709285292; cv=pass; d=google.com; s=arc-20160816; b=WwUg1xel0VaZ/P3A3jFcJQ/3A1gZxcGVK7Z8S4hxma/H82APup/wy1uRlafJcLPJQP HihoilI/mbuIjDGrpxcN4T7t4xSkX1uEHVN5Z55Jtq0vSMu7oOLyVggBfiNgvpEn2e6+ Nv421yrk0NtZSWmBsxnPbHzYSDS+xPTmRuSZ8zW1iQa2qJsNCUD3ThRzI/nR/k79PkdI BmKAfSgk6Wf4G1P0AHPyjoZOiJoLUwNzCYSGckO29rE0EHWNWlLFj/YwDkwXM6v6T5vd 5ImP8mnT1bNRMZmJ8Zjmt+h9wtdyx+dDrDtw0Fz3WyxAf6aTMoofh0ja5hXdpuBwe4PT H2LA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=7fp76SLNrOitLz2IPJZxtYaUARyA39f42XEHvT3cwYM=; fh=OWj6DLT3qk3k/OmjNkoz963iZvOruvCwBQpIH3YHbYE=; b=AyutQinGVlC/QWkZ9Q/wXDNVfEx+TFI5q5SEvuND3FYE6ugVt8lVRu34aR82nmXs2P 982OsuSbraLW9Abyr3OL8wc8UQXYa8LE+8DVDnCddHBJZpBSM+utt1wcsiTOewKBbcYk 1wqzIcBuferb3KUyJqImz3lcGwcgZqrhLmDTQ6SGj9ogsIkmbzOG9FQpyMdXRBluJ4I5 MpTXalWAzjosCGHwTuvdaZKej/eoVnCE5SUlmCk+6tQwM71f0FKbaVakkXB9fZP9o8tS qw1E2VANyDMcH0o+P3RBLRlpUaI78is3XPnvwb5nt1PRCu4G7rW7HyDiOMZpjz+jbqcI sGeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-88181-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n8-20020a170903110800b001dc4bffd417si3110875plh.227.2024.03.01.01.28.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:28:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88181-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-88181-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88181-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D92AF283347 for ; Fri, 1 Mar 2024 09:27:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53DAA6BB25; Fri, 1 Mar 2024 09:26:43 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 6F4CD6BB21; Fri, 1 Mar 2024 09:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709285202; cv=none; b=e62GUgS78jEM6BKLfST2m6JYmuMhQ6EivEvWY9ZBuAQ3lQmpg9Y5tirEl8eztALZhCho6UsrYR7CiiNFxl1urJK7DVFcfK82HY0sx5Me4CclbclAMayNYiB5VxcAIIZ0wUZX6j5KxcB5v2cRqX97JBJPTJrYyrYoxu8bTp4i2bo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709285202; c=relaxed/simple; bh=0wdFpKbEyNhuu/RpjYvuz8KPZKT0kttiGp+cGiKwHZk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Uq1Uhv/kX4HOYZfg2hSTmyY5DZtbb94XbzEPjtnO78rFUI/jWwbWzLhTutYhh9QfQcpkEdLCYoGOZWBLdj5eM1lGMRjupXZx1CrUqcQKdj1DUuEsk8sxRjzJeYxrIc/gqhfjtkpy9NdqR2hCVC/9dtJBfC9BY6D/bMzu9biuVcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso1429749a12.3; Fri, 01 Mar 2024 01:26:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709285201; x=1709890001; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7fp76SLNrOitLz2IPJZxtYaUARyA39f42XEHvT3cwYM=; b=wrjuv3Wk9FR/qzOMrvkBV0U6QMzH5WI7lDVlldaTvJWOaD3jqq3UxdtKAaY4Jc40TN 3llrQ+Ka9uGMkYxulCTW+3lNz9ZDIJqh5GTnKOS/PXfY9b5cXY0+LPvQ/iDxPn9Gz4Ie 9UBnHmhPXl38olLNqUQTHQcK5fcEu+PKAuuN75GItuJAufhjMMMtgmOLyJwiA7yiUTkv 3Z777iBLYVu4dIrbbKQ5adrDD+P3kKt0GGKyGL0F64pXH4tWD9DQ9L4nEe5F5i6Cndqv dWjo8oT7NAR14xkxcDTZR9vq7ToDyvitTS46Z/zPwXT9+Jg3Z1RNNotdO58EG6jjibdj jXAA== X-Forwarded-Encrypted: i=1; AJvYcCWyAUSugSMcnDGMbY8YXlwSSzzfpejMofz9LLlv+aYn9QmY77cRxNo85zkzbrC3sDm1H5hGrWOKFQ7qM0zzJyewJOb7hUUHpMpgCGqHVxVn0xffC4BQigRP9PKcCeuMnCur3j+nnNP/d5fySnyc93DY6TxXFQvvURSSWpnuFzx3Wdy6 X-Gm-Message-State: AOJu0Yym9L/5af98h0T37gnOgjiS/7dd8+6l4tocN3iQF6lB53VIMNQj vPKOAt76ssIIKWOnv7jjTF9HGkk35WG1SFYR4dxI+fyiNOuXnTrZ X-Received: by 2002:a05:6a20:7343:b0:1a1:2f17:1bc2 with SMTP id v3-20020a056a20734300b001a12f171bc2mr989042pzc.35.1709285200822; Fri, 01 Mar 2024 01:26:40 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([20.69.120.36]) by smtp.gmail.com with ESMTPSA id d11-20020a170902cecb00b001d739667fc3sm2947317plg.207.2024.03.01.01.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:26:40 -0800 (PST) Date: Fri, 1 Mar 2024 09:26:38 +0000 From: Wei Liu To: Rick Edgecombe Cc: 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, sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com Subject: Re: [RFC RFT PATCH 1/4] hv: Leak pages if set_memory_encrypted() fails Message-ID: References: <20240222021006.2279329-1-rick.p.edgecombe@intel.com> <20240222021006.2279329-2-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240222021006.2279329-2-rick.p.edgecombe@intel.com> On Wed, Feb 21, 2024 at 06:10:03PM -0800, Rick Edgecombe wrote: > 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. "Hyper-V" throughout. > 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]); > + } This silently leaks the pages if set_memory_encrypted() fails. I think there should print some warning or error messages here. Thanks, Wei. > vmbus_connection.monitor_pages[0] = NULL; > vmbus_connection.monitor_pages[1] = NULL; > } > -- > 2.34.1 >