Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6205922rwb; Mon, 5 Dec 2022 09:10:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6/8swUhgLTJcAZe9gyue9Z0CYFMYR11bCk8QqIgNtgeZ4OvFHXLXaQo996WEJLxt05fjOl X-Received: by 2002:a17:906:9f11:b0:7b4:7758:f1e1 with SMTP id fy17-20020a1709069f1100b007b47758f1e1mr62390524ejc.145.1670260227709; Mon, 05 Dec 2022 09:10:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670260227; cv=none; d=google.com; s=arc-20160816; b=0Pt2q4if9jVwRv3BI59z1UpxEdUdQX3qDyWqXpEGs7SsRRApg79WfOve/CMm/py1tR msWJQKhGJ+sT8j0eFlpuhE7NtpnIN8hPpNVxeMQBb7QFmucZYPa+h9Np7WawFAHxUZZs eZJd1NV/eAqSU+5rtgB+qoAIvDMS1E3hDIXwElQFb5uT09ym67DfsMWy5bqf/lD9l7V3 IBRxnK4d7F329iTT4OpNu1gWjSy8+/PjfXmRqKv13S/owWWhzpBhyj38wqYmeQ4zr3F2 DnuqowNgqwdRMEYca1vs4qgC0ShUsCWSDSIz5EUsenY8GFlKaBFoq9acmaS1KJ16VR2F xcFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UukjrTH+IshIqfcDpBTnIyMeTh3NYMcnhERp1C5DHII=; b=g8L3OB0iCb1sHqBcCyKQaKU01YKrAYfyuoLQGvBde6C5z4i0N9UGe98xl99rsEytBW /CslYBIGe996vZC2QmwD2xxhEsSvIO1VIYIEkNEl0v/bN+JfDFDYYriKZ86Upq6RNnQK eF3sKkoplwho0g4wOHwxVJSBo8htjVqIX6sGlVKhwajSRUSKo9vhR3dRfuTF39wHD2fJ y9bZQIAaeQjnGcEqI3QpvwuemDG3y4MH8vrVmoTVkm17El+f1Qxp8GANNE6l0bhx1BvI 4QbcZ4wqk5DeIpsZdzdzqjC3Ro8o6MVgJ8KsGwqGZiLFjORzwe5BaMKhpKYstTFTXlCa TV8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nNR8ekjl; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk11-20020a1709077f8b00b007ae931d56f9si12368835ejc.89.2022.12.05.09.10.05; Mon, 05 Dec 2022 09:10:27 -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=@google.com header.s=20210112 header.b=nNR8ekjl; 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 S231637AbiLERFz (ORCPT + 82 others); Mon, 5 Dec 2022 12:05:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231538AbiLERFd (ORCPT ); Mon, 5 Dec 2022 12:05:33 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3A94167CD for ; Mon, 5 Dec 2022 09:05:31 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id e205so13723966oif.11 for ; Mon, 05 Dec 2022 09:05:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UukjrTH+IshIqfcDpBTnIyMeTh3NYMcnhERp1C5DHII=; b=nNR8ekjlD1wLymKr9zcw3gIGTUFR3FyouYzo94ItCEPxN5pR8LbiKU7RhyvGGeePTx F4l7gXVWuu0+lAPlbWpZA1TyExD7cvxEnOKwQfpyctebGXO6lxA5nDjMoJbL0CWAvrIJ 0qwxwsGQIJUnspZVN8aHavaxxjqXipm0qrXTjBn2io24ayuBcK+ud2HFz4oSCRT33pTU ZmKjZVjIkbkcD8VJqZMX0UALHsAr/lJs12H85PK92rqlvEMaUy5m4RzrGRpp5Us82GbL KWS9c9f2sRD1VuW1cr0H4sQNhp2rCUGjMuSQQCQlH9xmPeCY1ODrcAQlAiBpDM8FW1cg cwrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UukjrTH+IshIqfcDpBTnIyMeTh3NYMcnhERp1C5DHII=; b=6nm6zGI7ZkEmNU18kYJ8IJXg3V7H1tj/zIQW3tX/ywIuiJT/lgdhpP2xp4jQZSydIC O86D5vx4wtIyER3S4VocRKQbGUveJH00lm6rYWcTGX4p/gk5Ld68bPzarR1l5ki7u386 5NvOOFHwCorMBC95Q/IN9Xs8OVrPfEw7xzUNg2Z2Tktv/cd77uyOPUxVzlWikxteUxfE 166/CaC9PLMtb5Oiez8pLYXjy2AnKWPqDcgXV1uOseNXt8/ebsYQ0xL8TXzY4hfOG+p7 zRdEE69CFLKyrZ6+JZj3ffM1wU265mSYq+EJYLmtHPkxxWRr0JzHJCkYqd3GHGrqf49V T2uQ== X-Gm-Message-State: ANoB5pnh40xNsCwdZBo878dF2Y3PMZIWNuHQmtuWBJwcGgWFl6plUpBK wF1bqW9U5o7XfD6jYMPCBXOh7WjlgB5fDDFi42aydg== X-Received: by 2002:a05:6808:bd5:b0:35b:d4a2:c4f3 with SMTP id o21-20020a0568080bd500b0035bd4a2c4f3mr11649874oik.279.1670259930676; Mon, 05 Dec 2022 09:05:30 -0800 (PST) MIME-Version: 1.0 References: <20221104230040.2346862-1-dionnaglaze@google.com> <20221104230040.2346862-2-dionnaglaze@google.com> In-Reply-To: From: Dionna Amalie Glaze Date: Mon, 5 Dec 2022 09:05:19 -0800 Message-ID: Subject: Re: [PATCH v8 1/4] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Peter Gonda , Thomas Lendacky , Paolo Bonzini , Joerg Roedel , Ingo Molnar , Andy Lutomirsky , John Allen , Herbert Xu , "David S. Miller" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Sat, Dec 3, 2022 at 11:37 AM Borislav Petkov wrote: > > On Sat, Dec 03, 2022 at 10:58:39AM -0800, Dionna Amalie Glaze wrote: > > It doesn't always overwrite psp_ret, such as the initial error checking. > > The value remains uninitialized for -ENODEV, -EBUSY, -EINVAL. > > Thus *error in __sev_platform_init_locked can be set to uninitialized > > memory if psp_ret is not first initialized. > > Lemme see if I understand it correctly: you wanna signal that all early > return cases in __sev_do_cmd_locked() are such that no firmware was > called? > > I.e., everything before the first iowrite into the command buffer? > > But then the commit message says: > > "The PSP can return a "firmware error" code of -1 in circumstances where > the PSP is not actually called." > > which is confusing. How can the PSP return something if it wasn't called? > > Or you mean those cases above where it would fail on some of the checks > before issuing a SEV command? I think you do... > > So I see Tom has ACKed this but I have to ask: is the SEV spec not going > to use -1 ever? > I'll confirm with Tom, since he's changing the GHCB spec for the throttling value. > Also, if this behavior is going to be user-visible, where are we > documenting it? Especially if nothing in the kernel is looking at > that value but only assigning it to a retval which gets looked at by > userspace. Especially then this should be documented. > > Dunno, maybe somewhere in Documentation/x86/amd-memory-encryption.rst or > maybe Tom would have a better idea. > Agreed it should be in both the Linux documentation and the GHCB spec. > > That error points to the kernel copy of the user's argument struct, > > which the ioctl always copies back. In the case of those error codes > > then, without SEV_RET_NO_FW_CALL, user space will get uninitialized > > kernel memory. > > Right, but having a return value which means "firmware wasn't called" > sounds weird. Why does userspace care? > Arguably it shouldn't ever get this value. We're just not very selective when we copy back the kernel copy of the ioctl argument. In all cases user space should treat the value as undefined, but still we don't want to leak uninitialized kernel stack values. Host driver: only on platform init, should just see the negative error value and not try to interpret the fw_err in the argument. Still the data is copied back and therefore should not be uninitialized kernel memory. Possible name: SEV_RET_UNDEFINED, or a return value -1 anyway with a comment that the argument is undefined. Guest driver: The host is issuing a guest request on behalf of the guest using patch 4/4 of this series. The guest is responsible for keeping the sequence number in sync with the PSP, so we want to track if the ghcb_hv_call completed successfully to know we should continue with the incremented IV. Otherwise we run the risk of the sequence numbers getting out of sync and we lock down the VMPCK. The guest driver actually sets exitinfo2 to an undocumented 0xff initial value just in case. =If the host doesn't write back a documented EXIT_INFO_2 value like invalid_len or throttled, then the kernel will emit a log with the initial value 0xff (or -1 after this patch). I've changed it to -1 to name the same kind of error across host and guest: the communication with the PSP didn't complete successfully, so the "error" value is not from the PSP. This value can also get returned to user space during a -ENOTTY result. We can call this NO_FW_CALL or UNDEFINED. I have no real preference. Whatever value we set initially, the VMM can overwrite exitinfo2 during the ghcb_hv_call. I'd rather that the "undefined" values were the same across both, because the guest is merely receiving a value from the host's PSP driver (or should be). It keeps the enum for return values a bit tidier and not concerned with whether the value is viewed from the host or guest. I can see an argument for not using the PSP header for its enum type and instead defining and documenting and using the separate the 0xff value elsewhere, but this seemed as good a place as any. > I mean, you can just as well return any of the negative values -ENODEV, > -EBUSY, -EINVAL too, depending on where you exit. Having three different > retvals could tell you where exactly it failed, even. > That's true, those values are already being returned to user space as the result of the ioctl. > But the question remains: why does userspace needs to know that the > failure happened and firmware wasn't called, as long as it is getting > something negative to signal an error? > I hope the above discussion is clear that it's purely a defined "undefined" because being pickier about what to copy_to_user during exceptional circumstances in order to not overwrite the user's fw_err value seems an unnecessary amount of code. > Thx. > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette -- -Dionna Glaze, PhD (she/her)