From patchwork Wed Mar 1 09:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 62812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3539422wrd; Wed, 1 Mar 2023 01:56:27 -0800 (PST) X-Google-Smtp-Source: AK7set9JAlkNuJ0ISg31HSVgXaKOGydAMtbR+LEQg7Xn4GkTQz7tAS5A79ZWNCwGVVViWV0vnB1P X-Received: by 2002:a05:6a20:30d5:b0:cc:9b29:f5ff with SMTP id 21-20020a056a2030d500b000cc9b29f5ffmr6581767pzo.35.1677664586881; Wed, 01 Mar 2023 01:56:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677664586; cv=none; d=google.com; s=arc-20160816; b=gTpAWuXMy3AVk3T38wopBWt4akOAm74uA+vvNY+WYd6Yz0nGQrOTUFBag/8MUUWNmQ aJUFZwAQZE4/WmVUN2xY04OsDTC6iYHCHPOCELLxUUBmPxOtXQh3xsZA4BRvclxHJgvS lRU8f0gR/y/o9ePUURhLVf+B4Ey0nDIzHGr0KdxJjajY2TstiVCpo4TApCklj4vdcqGn 7h5X/xBfbNMdwGzejMSP7dIFAK2U1nk2duwncSY/WumhYdvoZ6b3LR5r+ZZhru3isIvh XwlMhzhR+2UuHQiLybyCsdBoe7TdptC/mCZ0nnLHZi2/NUPqxKfNVTd0yteXp76OaaYb gPTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=AjBYcejPwwKYBVOYzMQ4TIcvZoumdc8c7sD67+6I5es=; b=UYU4I+WLmJg/DbDMDDt4nyLHyCM6XRrQr06f74hDvk6fNEhRdJsCLlQNSFyofEtLNq EB0IdqahLLWsqzRiEe1oc5upZpgNgn7k4EEhZiXKgZOKOvqTkM26foOzBnN05czJZALc aX0hpyOIMaF3HoFZsvx9aZI4Z7fRfZoVlMYUK7RLbgfwtbAabCDLNWVRSVr7RTMYqwNo WMGeZOzZnjE0w+77xVZdJSHhigp0hhJiMLcZTqxgJmBwNn0IP9MLXoYeRrHfGMUjGGBb ZRnlLkRJVFqbiMA9uDrmfzTIhf8rYl7Qu//Q8NaUqzNo/nRgUW75kJ/nA6Fp/TlfgGQb d3Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HdmY4pdz; dkim=neutral (no key) header.i=@linutronix.de header.b=K3w53KBk; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h64-20020a638343000000b00503a8fed57esi18097pge.685.2023.03.01.01.56.13; Wed, 01 Mar 2023 01:56:26 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=HdmY4pdz; dkim=neutral (no key) header.i=@linutronix.de header.b=K3w53KBk; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbjCAJtt (ORCPT + 99 others); Wed, 1 Mar 2023 04:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjCAJts (ORCPT ); Wed, 1 Mar 2023 04:49:48 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87128271B; Wed, 1 Mar 2023 01:49:46 -0800 (PST) Date: Wed, 01 Mar 2023 09:49:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677664184; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AjBYcejPwwKYBVOYzMQ4TIcvZoumdc8c7sD67+6I5es=; b=HdmY4pdz68JHFhefmwNe20cjf3+25B0xeG5/Ca0Kq4QEeAeqdhZi4hXrzTGZ6kpbgDj0E6 X3aKQTG95SyOukBa50ucMVcA1TPuffRNN1nEQ+XnCuWTGz9lwC/+aPK8mtbYUILvdmjrox 5my3H1hL/XtvJCUv8p/RsNX0AuEGq15JYy+3t1xUpHGcDqGBJr8Z5V3GhLxIEo9pWDJt54 w/s3xv0EbEvHR/4x3xa3y/taMHRQX4rVQUd8HuMb++GYlXkzt8/hhVzdYxvTjq5YsXz4V7 7fEToIcGbw2fUXuwGeYPnxpGg87N5hxFBvgpN7TVd676yhOwwseuUDQeNJi4FQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677664184; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AjBYcejPwwKYBVOYzMQ4TIcvZoumdc8c7sD67+6I5es=; b=K3w53KBk5fUtxxp4SG1yyrmNuQljW1V5ii6uBFPzpfsl5yv8aRLQkNBHO4BzkLeNPdDqRv EyeIe/RCIXNLD1Dg== From: "tip-bot2 for Tom Lendacky" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] virt/sev-guest: Return -EIO if certificate buffer is not large enough Cc: Larry Dewey , Tom Lendacky , "Borislav Petkov (AMD)" , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C2afbcae6daf13f7ad5a4296692e0a0fe1bc1e4ee=2E1677083?= =?utf-8?q?979=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= References: =?utf-8?q?=3C2afbcae6daf13f7ad5a4296692e0a0fe1bc1e4ee=2E16770839?= =?utf-8?q?79=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <167766418335.5837.8035431870442051850.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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?1758551016626981049?= X-GMAIL-MSGID: =?utf-8?q?1759158822055953672?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: dd093fb08e8f8a958fec4eef36f9f09eac047f60 Gitweb: https://git.kernel.org/tip/dd093fb08e8f8a958fec4eef36f9f09eac047f60 Author: Tom Lendacky AuthorDate: Wed, 22 Feb 2023 10:39:39 -06:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 01 Mar 2023 10:17:46 +01:00 virt/sev-guest: Return -EIO if certificate buffer is not large enough Commit 47894e0fa6a5 ("virt/sev-guest: Prevent IV reuse in the SNP guest driver") changed the behavior associated with the return value when the caller does not supply a large enough certificate buffer. Prior to the commit a value of -EIO was returned. Now, 0 is returned. This breaks the established ABI with the user. Change the code to detect the buffer size error and return -EIO. Fixes: 47894e0fa6a5 ("virt/sev-guest: Prevent IV reuse in the SNP guest driver") Reported-by: Larry Dewey Signed-off-by: Tom Lendacky Signed-off-by: Borislav Petkov (AMD) Tested-by: Larry Dewey Cc: Link: https://lore.kernel.org/r/2afbcae6daf13f7ad5a4296692e0a0fe1bc1e4ee.1677083979.git.thomas.lendacky@amd.com --- drivers/virt/coco/sev-guest/sev-guest.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 4ec4174..7b4e900 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -377,9 +377,26 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in snp_dev->input.data_npages = certs_npages; } + /* + * Increment the message sequence number. There is no harm in doing + * this now because decryption uses the value stored in the response + * structure and any failure will wipe the VMPCK, preventing further + * use anyway. + */ + snp_inc_msg_seqno(snp_dev); + if (fw_err) *fw_err = err; + /* + * If an extended guest request was issued and the supplied certificate + * buffer was not large enough, a standard guest request was issued to + * prevent IV reuse. If the standard request was successful, return -EIO + * back to the caller as would have originally been returned. + */ + if (!rc && err == SNP_GUEST_REQ_INVALID_LEN) + return -EIO; + if (rc) { dev_alert(snp_dev->dev, "Detected error from ASP request. rc: %d, fw_err: %llu\n", @@ -395,9 +412,6 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in goto disable_vmpck; } - /* Increment to new message sequence after payload decryption was successful. */ - snp_inc_msg_seqno(snp_dev); - return 0; disable_vmpck: