Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp920283pxb; Wed, 27 Oct 2021 15:14:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH9/2Caz26o/ye3RydxZ9e4ZLfN2NYO/LmqoFUVYxLbf8p0gvYqp0ccIh4BNotv7DmMRao X-Received: by 2002:a63:7c42:: with SMTP id l2mr357888pgn.90.1635372859752; Wed, 27 Oct 2021 15:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635372859; cv=none; d=google.com; s=arc-20160816; b=n4v/RQ/6g9mRvXeHSYKRyGe28OsRf1eZAIPNmcULEzr4dbTxjQeOHxyN9Rq/wgZAbM H80Bo4eRrodwLvG+s+G+8UOhgkUoCucqmSF9hUvAyUFP9T04EXyGxooLmz1sT2nyRogh Wxd0n3cQsDXgIC9jDDXD22EEQBHxfri+GkS/mtOhax0Y7iXJAMLyipnyOX78T/3/hf3c QLMm9x6Qx/+6hjUmh14mBeBkbQ3Dbb6RQvookYJs6E3AUxUyF3Wd69EdJyQVsTQ5+Gfw PgfhoYyRrMAqy8ZxGTqThBs+R3IWEtUnOo19ShyxlvEzlCkSTQDuPMs8lFgzg4yeg11p 2avg== 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=ZUzj8OdRUyoCesvY9oYCJsi3ZMdPAltpXbUySPTyBuc=; b=splnPLG6Ox50R1GW2IO5SDZwXRi+VEoIMlDJDXU2Gym6q+kyLojbb90zzZumlwmZYL meh80Dx3gxES+jt7mz+d/8D4Zrbr6LGzhLv8FTjykOOjurebpZp8AJpGs1NhwoEBZ9MZ Egth1MDdzv9hwvci1BSSquYqsFAygc2Hd/mpA1bdahTzwihSRYFpOPnwJtTWKNSmbb5N mA+mZgRvPZS8sOzGJGbMt6HUoBjPdBQHH/dK8ggDbSNWeW9wAPuD/2qYpZjThjR3xRRR 4K1mM5K73DINttdr74Iy3+D/LW+ZOPAGXMXJ40IakwWvHxUQQ9zYan8YInfMpFO1JAJ9 TEvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZIKZfwDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d9si1266813pln.400.2021.10.27.15.14.07; Wed, 27 Oct 2021 15:14:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZIKZfwDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S244258AbhJ0VSq (ORCPT + 99 others); Wed, 27 Oct 2021 17:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244252AbhJ0VSG (ORCPT ); Wed, 27 Oct 2021 17:18:06 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4238CC061348 for ; Wed, 27 Oct 2021 14:15:40 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id c28so8875442lfv.13 for ; Wed, 27 Oct 2021 14:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZUzj8OdRUyoCesvY9oYCJsi3ZMdPAltpXbUySPTyBuc=; b=ZIKZfwDyLiBXM4FTpiIdXUlr5R+dGI4KZkzsZUVmNpqPvYo82Eg9+mHUocDVdvsZRp bHC9ooluOVD3eOGj7LPilAH9no8kzTwRRuYP+1gemifBf9EmDbJHIc5OrlyAX3AErpYL rCUkbQ4oC/0/RC8tdZ8NSo7568axnml9rN/sSJ5mA2MGDa5CgiyJRlLuhtN1U3Q4WSCG AnMNeoEa0RpKePUuZlZiGhzIsuYPu5BLCjJhMGzARP7vYLxtIXT7UyovYQkTwrt82WqU 9RBNxTpyNJrocw3u98bizPwdzQxbEvMV670aQO7grbt5qAOhoDZmzAPqEDsUVxS/KD76 ZNrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZUzj8OdRUyoCesvY9oYCJsi3ZMdPAltpXbUySPTyBuc=; b=E//RZY9c6Pk5SJ0NMndqXLTrv4KB2PZ2HDO9zj0QxQTyslFLGl1M/VtJa2c40+qgvC UWKL0gFupYkcgwuU95+RRK4Zfi4hw0cElO0yWOJnWvx/DQOfvPxsYCJehdYuJ+ByWcfU /SPqi5aQZAPq1ZMqb/4+LOQU/Xl7Gka16xegDYisY+fVE/7T7GEiXOdndXfvGKh+sGOg Bq3OunriHGA1znyT/Jcsh0zjxS48QlTw6ufzGoJb2b8WE6f3ghL99Xr20xwyQMJi1PYU mzyFjhr/g0QKiZZnASl6+/BDBaALzfUL2MEPUs2hT6c53iZ6WjYrvx9PTuwDZf78ZW68 rT+w== X-Gm-Message-State: AOAM532SSJM1FdlPlt6lPBp7b/BaeUk6Cmj7qUd1NfQtjZvOcWkAu9Lx hijgj5jgFwk9z0i+bZMe4VHB4dOiTjtH0DG+fUSLyg== X-Received: by 2002:a05:6512:39d1:: with SMTP id k17mr95057lfu.79.1635369338308; Wed, 27 Oct 2021 14:15:38 -0700 (PDT) MIME-Version: 1.0 References: <20211008180453.462291-1-brijesh.singh@amd.com> <20211008180453.462291-41-brijesh.singh@amd.com> <943a1b7d-d867-5daa-e2e7-f0d91de37103@amd.com> In-Reply-To: From: Peter Gonda Date: Wed, 27 Oct 2021 15:15:26 -0600 Message-ID: Subject: Re: [PATCH v6 40/42] virt: Add SEV-SNP guest driver To: Brijesh Singh Cc: x86@kernel.org, LKML , kvm list , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , tony.luck@intel.com, Marc Orr , sathyanarayanan.kuppuswamy@linux.intel.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 27, 2021 at 3:13 PM Brijesh Singh wrote: > > > > On 10/27/21 4:05 PM, Peter Gonda wrote: > .... > > >>>>> > >>>>> Thanks for updating this sequence number logic. But I still have some > >>>>> concerns. In verify_and_dec_payload() we check the encryption header > >>>>> but all these fields are accessible to the hypervisor, meaning it can > >>>>> change the header and cause this sequence number to not get > >>>>> incremented. We then will reuse the sequence number for the next > >>>>> command, which isn't great for AES GCM. It seems very hard to tell if > >>>>> the FW actually got our request and created a response there by > >>>>> incrementing the sequence number by 2, or if the hypervisor is acting > >>>>> in bad faith. It seems like to be safe we need to completely stop > >>>>> using this vmpck if we cannot confirm the PSP has gotten our request > >>>>> and created a response. Thoughts? > >>>>> > >>>> > >>>> Very good point, I think we can detect this condition by rearranging the > >>>> checks. The verify_and_dec_payload() is called only after the command is > >>>> succesful and does the following checks > >>>> > >>>> 1) Verifies the header > >>>> 2) Decrypts the payload > >>>> 3) Later we increment the sequence > >>>> > >>>> If we arrange to the below order then we can avoid this condition. > >>>> 1) Decrypt the payload > >>>> 2) Increment the sequence number > >>>> 3) Verify the header > >>>> > >>>> The descryption will succeed only if PSP constructed the payload. > >>>> > >>>> Does this make sense ? > >>> > >>> Either ordering seems fine to me. I don't think it changes much though > >>> since the header (bytes 30-50 according to the spec) are included in > >>> the authenticated data of the encryption. So any hypervisor modictions > >>> will lead to a decryption failure right? > >>> > >>> Either case if we do fail the decryption, what are your thoughts on > >>> not allowing further use of that VMPCK? > >>> > >> > >> We have limited number of VMPCK (total 3). I am not sure switching to > >> different will change much. HV can quickly exaust it. Once we have SVSM > >> in-place then its possible that SVSM may use of the VMPCK. If the > >> decryption failed, then maybe its safe to erase the key from the secrets > >> page (in other words guest OS cannot use that key for any further > >> communication). A guest can reload the driver will different VMPCK id > >> and try again. > > > > SNP cannot really cover DOS at all since the VMM could just never > > schedule the VM. In this case we know that the hypervisor is trying to > > mess with the guest, so my preference would be to stop sending guest > > messages to prevent that duplicated IV usage. If one caller gets an > > EBADMSG it knows its in this case but the rest of userspace has no > > idea. Maybe log an error? > > > >> > > Yap, we cannot protect against the DOS. This is why I was saying that we > zero the key from secrets page so that guest cannot use that key for any > future communication (whether its from rest of userspace or kexec > kernel). I can update the driver to log the message and ensure that > future messages will *not* use that key. The VMPCK ID is a module > params, so a guest can reload the driver to use different VMPCK. Duh! Sorry I thought you said we needed a VMPL0 SVSM to do that. That sounds great. > > > >> thanks