From patchwork Tue Oct 17 20:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 154502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4381192vqb; Tue, 17 Oct 2023 13:26:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEC5RY613/y17rBSLy2Ez5VfM0OtPUFWQH+Cay+WgDYrL5Bb3AxSyT2X3mwxW9uMla1wgrX X-Received: by 2002:a05:6a20:ce9a:b0:16c:b95c:6d38 with SMTP id if26-20020a056a20ce9a00b0016cb95c6d38mr3069751pzb.2.1697574410469; Tue, 17 Oct 2023 13:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697574410; cv=none; d=google.com; s=arc-20160816; b=HG8rHkW/rGJV53OMl/Y+lOJCIajrdR7EoArnIac6lcIjEl4LYEK7GXIIfM9bPKpp0K jBQ4wyhsxzLYM/eK5wWtH0JWCD6bDaAng/z3vGt88AJ1jxyYaMEycaXBL+Vh9pOCDqNZ HtAULkSo1ENDwvUpGfxLgMupnQ18IWcjJJyTr5wpZHPzEn0Dxq5J+N3P86dzvnE1M0P9 9smhXJYynCZ8AKopMZO27UDFIA3L35CJX5tt9RxWgWSdhiY++PBHBUVqpZfOVpZQ1qA/ JsFUBshnpU5nQyTbU+0wXtUZIX51El15Y9TtGU2h3gyQeKr4vxIP2Vjz4N7niG98FGLo pmuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vn/QWymgXbx5kwDG9AWdS1zUsVcq5hgu1sjNh/vZ5E8=; fh=X9QvV0BO2F+cTly6D10ZZGlmIPBgNYl95NLqT4MLBLo=; b=crsh/Uz0uZyMsbbRJPFWXlMc1Rv3Vi00/Yicww8kibCOYD8fyhTiCwcpw0jcQOduoB vfDFKkEJtTywU4jsaH19HJrffzfXHa9FLsPee6iG81szUIK9UC3lRO++lEpk/OuUQ4IZ T412LlTgfnHNAmR7thujhj/9coLZAcIqV0XAF5U0X63n9lr+2tepjFOcLUpoxRd6VMpM nbvU1CzpPr/xUyyU0xj69UCoeHegBKZ7LzOqIQHNHBvB4AMV+tRIkICGyuWzmlIfB2pe VWRTi7JVQWZN0yABb6oQfmfxIkAYdaHEa4lDxfHBTaMD/1lyLbQ1Lpd64q6FrAOas4vz Fvqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JPwgOfLZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d68-20020a633647000000b00574021e070fsi543522pga.106.2023.10.17.13.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:26:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JPwgOfLZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 053D58090250; Tue, 17 Oct 2023 13:26:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344509AbjJQUZs (ORCPT + 21 others); Tue, 17 Oct 2023 16:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344414AbjJQUZf (ORCPT ); Tue, 17 Oct 2023 16:25:35 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB9DF1; Tue, 17 Oct 2023 13:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697574334; x=1729110334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J1x07zCPUyPDNEiTVhjwVyzpDF64pQWTC5hwW7cc64I=; b=JPwgOfLZ9GdBCkxOf6zyBuHh9bI/hzxijRF9qCVbj79tO1Zq44WeMtrc MB/3ZrdSEl7aDYrISHf1zWT+trYgMeSvGUhd3EmtX+1iyY8S8zoStLkdF WyBDviZUTokGKjcIMCI3du5Mrdo//UW0z4lYWBPvg+hfjP+n+CpM+1vkU RIH/5wvTi8LJrNWGx1GRM/ry5ifWnZf3ZQcGK4AIG+ZW/65aBstNHhCAc jaFpwg5bLUyN4gclLtuoneLZMALDO7KgBLHaWGAwOqUBMG5PJIE5FBxXp uKSaY/JTk8tfpscskWMc4mQowRmLQJU9hmha441tnfWOXzGvB8ep4lutJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="7429543" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="7429543" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 13:25:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="900040454" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="900040454" Received: from rtdinh-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.212.150.155]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 13:23:30 -0700 From: Rick Edgecombe To: x86@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, kirill.shutemov@linux.intel.com, elena.reshetova@intel.com, isaku.yamahata@intel.com, seanjc@google.com, Michael Kelley , thomas.lendacky@amd.com, decui@microsoft.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: rick.p.edgecombe@intel.com, Richard Cochran , netdev@vger.kernel.org Subject: [PATCH 05/10] ptp: Use free_decrypted_pages() Date: Tue, 17 Oct 2023 13:25:00 -0700 Message-Id: <20231017202505.340906-6-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231017202505.340906-1-rick.p.edgecombe@intel.com> References: <20231017202505.340906-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:26:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780035785099172824 X-GMAIL-MSGID: 1780035785099172824 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. Ptp could free decrypted/shared pages if set_memory_decrypted() fails. Use the recently added free_decrypted_pages() to avoid this. Cc: Richard Cochran Cc: netdev@vger.kernel.org Signed-off-by: Rick Edgecombe --- drivers/ptp/ptp_kvm_x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_kvm_x86.c b/drivers/ptp/ptp_kvm_x86.c index 902844cc1a17..203af060013d 100644 --- a/drivers/ptp/ptp_kvm_x86.c +++ b/drivers/ptp/ptp_kvm_x86.c @@ -36,7 +36,7 @@ int kvm_arch_ptp_init(void) clock_pair = page_address(p); ret = set_memory_decrypted((unsigned long)clock_pair, 1); if (ret) { - __free_page(p); + free_decrypted_pages((unsigned long)clock_pair, 0); clock_pair = NULL; goto nofree; }