From patchwork Fri Nov 4 20:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 15783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp619725wru; Fri, 4 Nov 2022 13:22:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7234wiqoEekoU4by5rtf8lv9xV4dICsrj8A0cDRX7zQV/xSJ8gEN/8KADHHuqzhmvH5vk+ X-Received: by 2002:a17:906:cc5b:b0:7a9:e58d:bad9 with SMTP id mm27-20020a170906cc5b00b007a9e58dbad9mr35856418ejb.237.1667593351682; Fri, 04 Nov 2022 13:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667593351; cv=none; d=google.com; s=arc-20160816; b=jW8To+CoxAWGEZ67nBNSCxMeK5uMp8AESeUSQ7+ZYvN71kYXcAIoJsQUDJhFUTmSb/ RjpGTjtP9b0siopyvrqqgC0K5eFKyMi1/Q1b+ndnxmeMbq7jKqGiR2mgsCWabIa0ouBo 2BM3Ib1lw22iqC1a7rk64aPwMiA5KZ0PMEm3x92cspVHJj2Oxu17uFP+UXg3219RVX72 QYTHjojYH3FGIg6mjYeVL6TUeiAWOz1rhTO/ejFLEyANcwwBexw3qxJVzeGte5DUe5JF L2UNV+z7n5AA2SHesP4TQV+1URzWt3b4ONN5TiRt0EIX2+QrdYIiqKB6xqSM6CapT6SZ 7w7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=tdpmyp475dYEFKCoWlj/KKgUAoUd0dg/1pKJMqCIFXxUkezNNYt728LV/1JjgOr/cu pBdflp0Pe5AvN6CNKXeK7Wvear9AKNqdYfmiOC4Ao642iD4cj1F9K2AQYaOqRfddHkos U3aKV34QHLSCjF1sJinXJqOczuw8X4yPY09UHF9ywBZM7xJ4tUKgIOVe0Y8gr5O9Gl55 nyhpK1PyT8KN0xMM2zT4R5pVHHFQqEhsl6jgNY1zCaFQ8NNRlNYumFoZMTLkZo4qm8xi WGafXDb6DxF7IqyirsGHVZc4zCm9G1VmyC93g+mBYtGPp6AP87nm/FOgAdLtKpq/VmWN HUDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gD4uBppb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd21-20020a170907629500b007ae10525573si7167478ejc.671.2022.11.04.13.22.07; Fri, 04 Nov 2022 13:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gD4uBppb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229954AbiKDUQo (ORCPT + 99 others); Fri, 4 Nov 2022 16:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbiKDUQi (ORCPT ); Fri, 4 Nov 2022 16:16:38 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AE148762 for ; Fri, 4 Nov 2022 13:16:33 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id q63-20020a632a42000000b0045724b1dfb9so2998118pgq.3 for ; Fri, 04 Nov 2022 13:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=gD4uBppbQwFb6mzboPS+LsD9PYZUuN8/clt/XIhPCFu1284keiCeM33V3amJCXDA1p UHh9XdWGEIOK+r/aYqaAgXeqHBvUeUKULrNrsX/v+Tiry9/SWdtgyumpXnyTtoeEONV8 sJ3gxEvkq0VOu7/LX2v1vHO4aS5cZbXk13KJwjgFgSB8D6WXo5e7ElSkaLed1zBBDdhO 45rcW6a+SFoplxfbQ+bazqHmeRqBYxIqYt0rUquGNq4xl2bW0Ap9aghRZgqYG6bxzGiS 7Q7FESTo4Q6FV/RcIZBcNd8cN629rHx0Cz5X3uMtcMtBuTqXRHHtMfyq1amjB6E4dSvp tM+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=TIud7UMXHDuhBuEisSCtuO1SNpslvP3qMjKg/BA7CDX7VvkEmZKR6c6IFr0xceduNJ U95NWBQ7iQ2GoXpr4zKA/Y8efUwgv/lXOhq+1fWVVNGVQnnFCgC+J1BmOYr5dcqwnPJu Q/glCpLWTKZWo/c17ymktyaX2G+GpUnTI7lPaJDKM4Ff5udW6DHm3yXoATWz35/YC+zC JHTvHzYP7kcAjWgs4OpJqx4KbOomIaVDsJ6LcGk01eliu502eXGrI+tGn/KNzbXkTIqs ZktyJIDH9gZrVxsHMUSWsuH4V1bSaPohNaNm81+6nhEyZOQpabP10zuqW3nZMBBVDywx 4kfA== X-Gm-Message-State: ACrzQf1ZFYitz+85hBBpyELxi0F1TyX2zCNQQYpCNADzq1210AeuZpsc hFouBpSEkogcuANRgTWcFkmCQtQJ9IcAXT3i0Mn0v60+QOu/Uca2fHyX21PeRxgozklpn+Jkhep w1yZslwH3gQqJ5ypFTLzr222hT2CUugQPd3GlJFDCazcQoPRyePNvRW1uF5GpR77xMwiwdA46Mx wLiPg3Zd0= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:4dce:b0:213:9d22:8870 with SMTP id r14-20020a17090a4dce00b002139d228870mr40202745pjl.7.1667592993039; Fri, 04 Nov 2022 13:16:33 -0700 (PDT) Date: Fri, 4 Nov 2022 20:16:15 +0000 In-Reply-To: <20221104201616.2268815-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104201616.2268815-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104201616.2268815-4-dionnaglaze@google.com> Subject: [PATCH v7 3/4] virt: sev-guest: Remove err in handle_guest_request From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Borislav Petkov , Haowen Bai , Liam Merwick , Yang Yingliang X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748598366216032729?= X-GMAIL-MSGID: =?utf-8?q?1748598366216032729?= The err variable may not be set in the call to snp_issue_guest_request, yet it is unconditionally written back to fw_err if fw_err is non-null. This is undefined behavior, and currently returns uninitialized kernel stack memory to user space. The fw_err argument is better to just pass through to snp_issue_guest_request, so we do that. Since the issue_request's signature has changed fw_err to exitinfo2, we change the argument name here. Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Cc: Borislav Petkov Cc: Haowen Bai Cc: Liam Merwick Cc: Yang Yingliang Fixes: fce96cf04430 ("virt: Add SEV-SNP guest driver") Signed-off-by: Dionna Glaze --- drivers/virt/coco/sev-guest/sev-guest.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index d08ff87c2dac..5ebf87651299 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -322,9 +322,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver, u8 type, void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz, __u64 *fw_err) + u32 resp_sz, __u64 *exitinfo2) { - unsigned long err; u64 seqno; int rc; @@ -341,7 +340,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in return rc; /* Call firmware to process the request */ - rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc = snp_issue_guest_request(exit_code, &snp_dev->input, exitinfo2); /* * If the extended guest request fails due to having to small of a @@ -349,19 +348,16 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in * extended data request. */ if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && - err == SNP_GUEST_REQ_INVALID_LEN) { + *exitinfo2 == SNP_GUEST_REQ_INVALID_LEN) { const unsigned int certs_npages = snp_dev->input.data_npages; exit_code = SVM_VMGEXIT_GUEST_REQUEST; - rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc = snp_issue_guest_request(exit_code, &snp_dev->input, exitinfo2); - err = SNP_GUEST_REQ_INVALID_LEN; + *exitinfo2 = SNP_GUEST_REQ_INVALID_LEN; snp_dev->input.data_npages = certs_npages; } - if (fw_err) - *fw_err = err; - if (rc) { dev_alert(snp_dev->dev, "Detected error from ASP request. rc: %d, fw_err: %llu\n",